Skip to content

Commit

Permalink
Compilation fixes for OpenSSL 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kedazo committed Apr 13, 2018
1 parent 9d6bf8c commit bfbe06c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/mongo/crypto/crypto_openssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@ namespace crypto {
* Computes a SHA-1 hash of 'input'.
*/
bool sha1(const unsigned char* input, const size_t inputLen, unsigned char* output) {
EVP_MD_CTX digestCtx;
EVP_MD_CTX_init(&digestCtx);
ON_BLOCK_EXIT(EVP_MD_CTX_cleanup, &digestCtx);
EVP_MD_CTX *digestCtx = EVP_MD_CTX_create();
if (!digestCtx) {
return false;
}

EVP_MD_CTX_init(digestCtx);
#if OPENSSL_VERSION_NUMBER < 0x10100000L
ON_BLOCK_EXIT(EVP_MD_CTX_destroy, digestCtx);
#else
ON_BLOCK_EXIT(EVP_MD_CTX_free, digestCtx);
#endif

if (1 != EVP_DigestInit_ex(&digestCtx, EVP_sha1(), NULL)) {
if (1 != EVP_DigestInit_ex(digestCtx, EVP_sha1(), NULL)) {
return false;
}

if (1 != EVP_DigestUpdate(&digestCtx, input, inputLen)) {
if (1 != EVP_DigestUpdate(digestCtx, input, inputLen)) {
return false;
}

return (1 == EVP_DigestFinal_ex(&digestCtx, output, NULL));
return (1 == EVP_DigestFinal_ex(digestCtx, output, NULL));
}

/*
Expand Down
7 changes: 6 additions & 1 deletion src/mongo/util/net/ssl_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ bool SSLManager::_initSSLContext(SSL_CTX** context, const Params& params) {

bool SSLManager::_setSubjectName(const std::string& keyFile, std::string& subjectName) {
// Read the certificate subject name and store it
BIO* in = BIO_new(BIO_s_file_internal());
BIO* in;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
in = BIO_new(BIO_s_file_internal());
#else
in = BIO_new(BIO_s_file());
#endif
if (NULL == in) {
error() << "failed to allocate BIO object: " << getSSLErrorMessage(ERR_get_error()) << endl;
return false;
Expand Down

0 comments on commit bfbe06c

Please sign in to comment.