@@ -45,40 +45,25 @@ index 5ce466582823ae1304731610da61b7fde77fc65a..c40f03e56fce2d5edae179170d384651
4545
4646 size_t out_len = 0;
4747diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc
48- index 8feefde819ea8b67c92afd2af7edf1fcc00aabd0..70f318bd63c49ff5919f363f1d3c5f94d2e4b007 100644
48+ index 8feefde819ea8b67c92afd2af7edf1fcc00aabd0..af360270e74ecca8f72ab1cb5083acacab4ae9df 100644
4949--- a/src/crypto/crypto_context.cc
5050+++ b/src/crypto/crypto_context.cc
51- @@ -493,12 +493,14 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
52- // OpenSSL 1.1.0 changed the ticket key size, but the OpenSSL 1.0.x size was
53- // exposed in the public API. To retain compatibility, install a callback
54- // which restores the old algorithm.
55- + #ifndef OPENSSL_IS_BORINGSSL
56- if (RAND_bytes(sc->ticket_key_name_, sizeof(sc->ticket_key_name_)) <= 0 ||
57- RAND_bytes(sc->ticket_key_hmac_, sizeof(sc->ticket_key_hmac_)) <= 0 ||
58- RAND_bytes(sc->ticket_key_aes_, sizeof(sc->ticket_key_aes_)) <= 0) {
59- return THROW_ERR_CRYPTO_OPERATION_FAILED(
60- env, "Error generating ticket keys");
61- }
62- + #endif
63- SSL_CTX_set_tlsext_ticket_key_cb(sc->ctx_.get(), TicketCompatibilityCallback);
64- }
51+ @@ -13,6 +13,7 @@
6552
66- @@ -1194,6 +1196,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
67-
68- if (enc) {
69- memcpy(name, sc->ticket_key_name_, sizeof(sc->ticket_key_name_));
70- + #ifndef OPENSSL_IS_BORINGSSL
71- if (RAND_bytes(iv, 16) <= 0 ||
72- EVP_EncryptInit_ex(ectx, EVP_aes_128_cbc(), nullptr,
73- sc->ticket_key_aes_, iv) <= 0 ||
74- @@ -1201,6 +1204,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
53+ #include <openssl/x509.h>
54+ #include <openssl/pkcs12.h>
55+ + #include <openssl/rand.h>
56+ #ifndef OPENSSL_NO_ENGINE
57+ #include <openssl/engine.h>
58+ #endif // !OPENSSL_NO_ENGINE
59+ @@ -1201,7 +1202,6 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
7560 EVP_sha256(), nullptr) <= 0) {
7661 return -1;
7762 }
78- + #endif
79- return 1;
63+ - return 1;
8064 }
8165
66+ if (memcmp(name, sc->ticket_key_name_, sizeof(sc->ticket_key_name_)) != 0) {
8267diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
8368index 1c48f98656fd211403354bb88331450e51ffb3e5..7c3ee76b91dbc4f4f5d72594218cce07231edcb7 100644
8469--- a/src/crypto/crypto_dh.cc
@@ -189,23 +174,18 @@ index 0aa96ada47abe4b66fb616c665101278bbe0afb6..1e9a4863c5faea5f6b275483ca16f3a6
189174
190175 void HKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
191176diff --git a/src/crypto/crypto_random.cc b/src/crypto/crypto_random.cc
192- index b24f8f32136ffaed54310d5dc02e57b0f69450d6..587a313f0fcd3e705f167bfb8652c26c176dbebe 100644
177+ index b24f8f32136ffaed54310d5dc02e57b0f69450d6..50a6663966cdb147a702df21240fa449850c3549 100644
193178--- a/src/crypto/crypto_random.cc
194179+++ b/src/crypto/crypto_random.cc
195- @@ -66,8 +66,12 @@ bool RandomBytesTraits::DeriveBits(
196- Environment* env,
197- const RandomBytesConfig& params,
198- ByteSource* unused) {
199- + #ifndef OPENSSL_IS_BORINGSSL
200- CheckEntropy(); // Ensure that OpenSSL's PRNG is properly seeded.
201- return RAND_bytes(params.buffer, params.size) != 0;
202- + #else
203- + return false;
204- + #endif
205- }
180+ @@ -8,6 +8,7 @@
181+ #include "v8.h"
182+
183+ #include <openssl/bn.h>
184+ + #include <openssl/rand.h>
206185
207- void RandomPrimeConfig::MemoryInfo(MemoryTracker* tracker) const {
208- @@ -149,7 +153,7 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
186+ namespace node {
187+
188+ @@ -149,7 +150,7 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
209189
210190 params->bits = bits;
211191 params->safe = safe;
@@ -232,55 +212,35 @@ index 5fa91cce1a6ad2bc1167e20a4dadcfdfc2343440..d6db572ffac83b82eb3356a4d3258ae8
232212
233213 size_t out_len = 0;
234214diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc
235- index fbe4c0f06c10df7c8a492711594381c27c6f81f7..1684a4242d160f5536c30ffef2a3acffa258cc4f 100644
215+ index fbe4c0f06c10df7c8a492711594381c27c6f81f7..76c8c037ffd3c8b67179d7d881ad6ea530b00686 100644
236216--- a/src/crypto/crypto_util.cc
237217+++ b/src/crypto/crypto_util.cc
238- @@ -61,6 +61,7 @@ int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx) {
239- }
240-
241- void CheckEntropy() {
242- + #ifndef OPENSSL_IS_BORINGSSL
243- for (;;) {
244- int status = RAND_status();
245- CHECK_GE(status, 0); // Cannot fail.
246- @@ -71,15 +72,20 @@ void CheckEntropy() {
247- if (RAND_poll() == 0)
248- break;
249- }
250- + #endif
251- }
218+ @@ -20,6 +20,8 @@
219+ #endif
220+ #endif
252221
253- bool EntropySource(unsigned char* buffer, size_t length) {
254- + #ifndef OPENSSL_IS_BORINGSSL
255- // Ensure that OpenSSL's PRNG is properly seeded.
256- CheckEntropy();
257- // RAND_bytes() can return 0 to indicate that the entropy data is not truly
258- // random. That's okay, it's still better than V8's stock source of entropy,
259- // which is /dev/urandom on UNIX platforms and the current time on Windows.
260- return RAND_bytes(buffer, length) != -1;
261- + #else
262- + return false;
263- + #endif
264- }
222+ + #include <openssl/rand.h>
223+ +
224+ namespace node {
265225
266- int PasswordCallback(char* buf, int size, int rwflag, void* u) {
267- @@ -118,7 +124 ,6 @@ void InitCryptoOnce() {
226+ using v8::ArrayBuffer;
227+ @@ -118,7 +120 ,6 @@ void InitCryptoOnce() {
268228 OPENSSL_init_ssl(0, settings);
269229 OPENSSL_INIT_free(settings);
270230 settings = nullptr;
271231- #endif
272232
273233 #ifndef _WIN32
274234 if (per_process::cli_options->secure_heap != 0) {
275- @@ -137,6 +142 ,7 @@ void InitCryptoOnce() {
235+ @@ -137,6 +138 ,7 @@ void InitCryptoOnce() {
276236 break;
277237 }
278238 }
279239+ #endif
280240 #endif
281241
282242 /* Override FIPS settings in cnf file, if needed. */
283- @@ -675,10 +681 ,12 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
243+ @@ -675,10 +677 ,12 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
284244 }
285245
286246 void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) {
0 commit comments