HDFS-15918. Replace deprecated RAND_pseudo_bytes (#2811)

This commit is contained in:
Gautham B A 2021-03-24 23:22:33 +05:30 committed by GitHub
parent 85d3bba555
commit 654555783d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -49,7 +49,7 @@ private:
static size_t NextToken(const std::string &payload, size_t off,
std::string *tok);
void GenerateCNonce();
Status GenerateCNonce();
std::string username_;
std::string password_;
std::string nonce_;

View File

@ -21,6 +21,7 @@
#include <openssl/rand.h>
#include <openssl/md5.h>
#include <openssl/err.h>
#include <iomanip>
#include <map>
@ -91,12 +92,19 @@ size_t DigestMD5Authenticator::NextToken(const std::string &payload, size_t off,
return off;
}
void DigestMD5Authenticator::GenerateCNonce() {
if (!TEST_mock_cnonce_) {
char buf[8] = {0,};
RAND_pseudo_bytes(reinterpret_cast<unsigned char *>(buf), sizeof(buf));
cnonce_ = Base64Encode(std::string(buf, sizeof(buf)));
Status DigestMD5Authenticator::GenerateCNonce() {
if (TEST_mock_cnonce_) {
return Status::OK();
}
char buf[8] = { 0, };
if (RAND_bytes(reinterpret_cast<unsigned char*>(buf), sizeof(buf)) == 1) {
cnonce_ = Base64Encode(std::string(buf, sizeof(buf)));
return Status::OK();
}
const auto* error = ERR_reason_error_string(ERR_get_error());
return Status::Error(error);
}
Status DigestMD5Authenticator::ParseFirstChallenge(const std::string &payload) {
@ -155,8 +163,11 @@ Status DigestMD5Authenticator::GenerateFirstResponse(std::string *result) {
return Status::Unimplemented();
}
if (auto status = GenerateCNonce(); !status.ok()) {
return status;
}
std::stringstream ss;
GenerateCNonce();
ss << "charset=utf-8,username=\"" << QuoteString(username_) << "\""
<< ",authzid=\"" << QuoteString(username_) << "\""
<< ",nonce=\"" << QuoteString(nonce_) << "\""