Skip to content

Commit 26fe5c9

Browse files
committed
Merge #9326: Update for OpenSSL 1.1 API.
b05b1af Fix qt/paymentrequestplus.cpp for OpenSSL 1.1 API. (Gregory Maxwell) bae1eef Fix wallet/test/crypto_tests.cpp for OpenSSL 1.1 API. (Gregory Maxwell)
2 parents 5233aef + b05b1af commit 26fe5c9

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/qt/paymentrequestplus.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,24 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
159159
std::string data_to_verify; // Everything but the signature
160160
rcopy.SerializeToString(&data_to_verify);
161161

162-
EVP_MD_CTX ctx;
162+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
163+
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
164+
if (!ctx) throw SSLVerifyError("Error allocating OpenSSL context.");
165+
#else
166+
EVP_MD_CTX _ctx;
167+
EVP_MD_CTX *ctx;
168+
ctx = &_ctx;
169+
#endif
163170
EVP_PKEY *pubkey = X509_get_pubkey(signing_cert);
164-
EVP_MD_CTX_init(&ctx);
165-
if (!EVP_VerifyInit_ex(&ctx, digestAlgorithm, NULL) ||
166-
!EVP_VerifyUpdate(&ctx, data_to_verify.data(), data_to_verify.size()) ||
167-
!EVP_VerifyFinal(&ctx, (const unsigned char*)paymentRequest.signature().data(), (unsigned int)paymentRequest.signature().size(), pubkey)) {
171+
EVP_MD_CTX_init(ctx);
172+
if (!EVP_VerifyInit_ex(ctx, digestAlgorithm, NULL) ||
173+
!EVP_VerifyUpdate(ctx, data_to_verify.data(), data_to_verify.size()) ||
174+
!EVP_VerifyFinal(ctx, (const unsigned char*)paymentRequest.signature().data(), (unsigned int)paymentRequest.signature().size(), pubkey)) {
168175
throw SSLVerifyError("Bad signature, invalid payment request.");
169176
}
177+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
178+
EVP_MD_CTX_free(ctx);
179+
#endif
170180

171181
// OpenSSL API for getting human printable strings from certs is baroque.
172182
int textlen = X509_NAME_get_text_by_NID(certname, NID_commonName, NULL, 0);

src/wallet/test/crypto_tests.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ bool OldEncrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char>
4242
int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
4343
vchCiphertext = std::vector<unsigned char> (nCLen);
4444

45-
EVP_CIPHER_CTX ctx;
45+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
46+
47+
if (!ctx) return false;
4648

4749
bool fOk = true;
4850

49-
EVP_CIPHER_CTX_init(&ctx);
50-
if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
51-
if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
52-
if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
53-
EVP_CIPHER_CTX_cleanup(&ctx);
51+
EVP_CIPHER_CTX_init(ctx);
52+
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
53+
if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
54+
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
55+
EVP_CIPHER_CTX_cleanup(ctx);
56+
57+
EVP_CIPHER_CTX_free(ctx);
5458

5559
if (!fOk) return false;
5660

@@ -66,15 +70,19 @@ bool OldDecrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial
6670

6771
vchPlaintext = CKeyingMaterial(nPLen);
6872

69-
EVP_CIPHER_CTX ctx;
73+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
74+
75+
if (!ctx) return false;
7076

7177
bool fOk = true;
7278

73-
EVP_CIPHER_CTX_init(&ctx);
74-
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
75-
if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen) != 0;
76-
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0]) + nPLen, &nFLen) != 0;
77-
EVP_CIPHER_CTX_cleanup(&ctx);
79+
EVP_CIPHER_CTX_init(ctx);
80+
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
81+
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen) != 0;
82+
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0]) + nPLen, &nFLen) != 0;
83+
EVP_CIPHER_CTX_cleanup(ctx);
84+
85+
EVP_CIPHER_CTX_free(ctx);
7886

7987
if (!fOk) return false;
8088

0 commit comments

Comments
 (0)