Skip to content

Commit 32a8266

Browse files
davidbenMylesBorins
authored andcommitted
crypto: account for new 1.1.0 SSL APIs
This is cherry-picked from PR #8491 and tidied up. This change does *not* account for the larger ticket key in OpenSSL 1.1.0. That will be done in a follow-up commit as the 48-byte ticket key is part of Node's public API. rvagg: removed BORINGSSL defines before landing PR-URL: #16130 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 22177e5 commit 32a8266

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

src/node_crypto.cc

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ using v8::String;
114114
using v8::Value;
115115

116116

117+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
118+
static void SSL_SESSION_get0_ticket(const SSL_SESSION* s,
119+
const unsigned char** tick, size_t* len) {
120+
*len = s->tlsext_ticklen;
121+
if (tick != nullptr) {
122+
*tick = s->tlsext_tick;
123+
}
124+
}
125+
126+
#define SSL_get_tlsext_status_type(ssl) (ssl->tlsext_status_type)
127+
128+
static int X509_STORE_up_ref(X509_STORE* store) {
129+
CRYPTO_add(&store->references, 1, CRYPTO_LOCK_X509_STORE);
130+
return 1;
131+
}
132+
133+
static int X509_up_ref(X509* cert) {
134+
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
135+
return 1;
136+
}
137+
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
138+
117139
// Subject DER of CNNIC ROOT CA and CNNIC EV ROOT CA are taken from
118140
// https://hg.mozilla.org/mozilla-central/file/98820360ab66/security/
119141
// certverifier/NSSCertDBTrustDomain.cpp#l672
@@ -158,11 +180,19 @@ template void SSLWrap<TLSWrap>::AddMethods(Environment* env,
158180
template void SSLWrap<TLSWrap>::InitNPN(SecureContext* sc);
159181
template void SSLWrap<TLSWrap>::SetSNIContext(SecureContext* sc);
160182
template int SSLWrap<TLSWrap>::SetCACerts(SecureContext* sc);
183+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
161184
template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback(
162185
SSL* s,
163186
unsigned char* key,
164187
int len,
165188
int* copy);
189+
#else
190+
template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback(
191+
SSL* s,
192+
const unsigned char* key,
193+
int len,
194+
int* copy);
195+
#endif
166196
template int SSLWrap<TLSWrap>::NewSessionCallback(SSL* s,
167197
SSL_SESSION* sess);
168198
template void SSLWrap<TLSWrap>::OnClientHello(
@@ -759,22 +789,6 @@ void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) {
759789
}
760790

761791

762-
#if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL)
763-
// This section contains OpenSSL 1.1.0 functions reimplemented for OpenSSL
764-
// 1.0.2 so that the following code can be written without lots of #if lines.
765-
766-
static int X509_STORE_up_ref(X509_STORE* store) {
767-
CRYPTO_add(&store->references, 1, CRYPTO_LOCK_X509_STORE);
768-
return 1;
769-
}
770-
771-
static int X509_up_ref(X509* cert) {
772-
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
773-
return 1;
774-
}
775-
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L && !OPENSSL_IS_BORINGSSL
776-
777-
778792
static X509_STORE* NewRootCertStore() {
779793
static std::vector<X509*> root_certs_vector;
780794
if (root_certs_vector.empty()) {
@@ -1221,7 +1235,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
12211235

12221236

12231237
void SecureContext::SetFreeListLength(const FunctionCallbackInfo<Value>& args) {
1224-
#if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL)
1238+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
12251239
// |freelist_max_len| was removed in OpenSSL 1.1.0. In that version OpenSSL
12261240
// mallocs and frees buffers directly, without the use of a freelist.
12271241
SecureContext* wrap;
@@ -1428,11 +1442,19 @@ void SSLWrap<Base>::InitNPN(SecureContext* sc) {
14281442
}
14291443

14301444

1445+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
14311446
template <class Base>
14321447
SSL_SESSION* SSLWrap<Base>::GetSessionCallback(SSL* s,
14331448
unsigned char* key,
14341449
int len,
14351450
int* copy) {
1451+
#else
1452+
template <class Base>
1453+
SSL_SESSION* SSLWrap<Base>::GetSessionCallback(SSL* s,
1454+
const unsigned char* key,
1455+
int len,
1456+
int* copy) {
1457+
#endif
14361458
Base* w = static_cast<Base*>(SSL_get_app_data(s));
14371459

14381460
*copy = 0;
@@ -1942,13 +1964,18 @@ void SSLWrap<Base>::GetTLSTicket(const FunctionCallbackInfo<Value>& args) {
19421964
Environment* env = w->ssl_env();
19431965

19441966
SSL_SESSION* sess = SSL_get_session(w->ssl_);
1945-
if (sess == nullptr || sess->tlsext_tick == nullptr)
1967+
if (sess == nullptr)
1968+
return;
1969+
1970+
const unsigned char *ticket;
1971+
size_t length;
1972+
SSL_SESSION_get0_ticket(sess, &ticket, &length);
1973+
1974+
if (ticket == nullptr)
19461975
return;
19471976

19481977
Local<Object> buff = Buffer::Copy(
1949-
env,
1950-
reinterpret_cast<char*>(sess->tlsext_tick),
1951-
sess->tlsext_ticklen).ToLocalChecked();
1978+
env, reinterpret_cast<const char*>(ticket), length).ToLocalChecked();
19521979

19531980
args.GetReturnValue().Set(buff);
19541981
}
@@ -2475,7 +2502,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
24752502

24762503
bool ocsp = false;
24772504
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
2478-
ocsp = s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp;
2505+
ocsp = SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp;
24792506
#endif
24802507

24812508
info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp));

src/node_crypto.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,17 @@ class SSLWrap {
241241
static void InitNPN(SecureContext* sc);
242242
static void AddMethods(Environment* env, v8::Local<v8::FunctionTemplate> t);
243243

244+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
244245
static SSL_SESSION* GetSessionCallback(SSL* s,
245246
unsigned char* key,
246247
int len,
247248
int* copy);
249+
#else
250+
static SSL_SESSION* GetSessionCallback(SSL* s,
251+
const unsigned char* key,
252+
int len,
253+
int* copy);
254+
#endif
248255
static int NewSessionCallback(SSL* s, SSL_SESSION* sess);
249256
static void OnClientHello(void* arg,
250257
const ClientHelloParser::ClientHello& hello);

0 commit comments

Comments
 (0)