Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a893b42

Browse filesBrowse files
danbevMylesBorins
authored andcommitted
crypto: use non-deprecated v8::Object::Set
This commit updates node_crypto to use the non-deprecated Set functions that return a v8::Maybe<bool>. PR-URL: #17482 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 8b2a272 commit a893b42
Copy full SHA for a893b42

File tree

Expand file treeCollapse file tree

1 file changed

+86
-55
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+86
-55
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+86-55Lines changed: 86 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,26 +1745,31 @@ void SSLWrap<Base>::OnClientHello(void* arg,
17451745
Base* w = static_cast<Base*>(arg);
17461746
Environment* env = w->ssl_env();
17471747
HandleScope handle_scope(env->isolate());
1748-
Context::Scope context_scope(env->context());
1748+
Local<Context> context = env->context();
1749+
Context::Scope context_scope(context);
17491750

17501751
Local<Object> hello_obj = Object::New(env->isolate());
17511752
Local<Object> buff = Buffer::Copy(
17521753
env,
17531754
reinterpret_cast<const char*>(hello.session_id()),
17541755
hello.session_size()).ToLocalChecked();
1755-
hello_obj->Set(env->session_id_string(), buff);
1756+
hello_obj->Set(context, env->session_id_string(), buff).FromJust();
17561757
if (hello.servername() == nullptr) {
1757-
hello_obj->Set(env->servername_string(), String::Empty(env->isolate()));
1758+
hello_obj->Set(context,
1759+
env->servername_string(),
1760+
String::Empty(env->isolate())).FromJust();
17581761
} else {
17591762
Local<String> servername = OneByteString(env->isolate(),
17601763
hello.servername(),
17611764
hello.servername_size());
1762-
hello_obj->Set(env->servername_string(), servername);
1765+
hello_obj->Set(context, env->servername_string(), servername).FromJust();
17631766
}
1764-
hello_obj->Set(env->tls_ticket_string(),
1765-
Boolean::New(env->isolate(), hello.has_ticket()));
1766-
hello_obj->Set(env->ocsp_request_string(),
1767-
Boolean::New(env->isolate(), hello.ocsp_request()));
1767+
hello_obj->Set(context,
1768+
env->tls_ticket_string(),
1769+
Boolean::New(env->isolate(), hello.has_ticket())).FromJust();
1770+
hello_obj->Set(context,
1771+
env->ocsp_request_string(),
1772+
Boolean::New(env->isolate(), hello.ocsp_request())).FromJust();
17681773

17691774
Local<Value> argv[] = { hello_obj };
17701775
w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv);
@@ -1809,7 +1814,7 @@ static bool SafeX509ExtPrint(BIO* out, X509_EXTENSION* ext) {
18091814

18101815
static Local<Object> X509ToObject(Environment* env, X509* cert) {
18111816
EscapableHandleScope scope(env->isolate());
1812-
1817+
Local<Context> context = env->context();
18131818
Local<Object> info = Object::New(env->isolate());
18141819

18151820
BIO* bio = BIO_new(BIO_s_mem());
@@ -1819,18 +1824,20 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18191824
0,
18201825
X509_NAME_FLAGS) > 0) {
18211826
BIO_get_mem_ptr(bio, &mem);
1822-
info->Set(env->subject_string(),
1827+
info->Set(context, env->subject_string(),
18231828
String::NewFromUtf8(env->isolate(), mem->data,
1824-
String::kNormalString, mem->length));
1829+
String::kNormalString,
1830+
mem->length)).FromJust();
18251831
}
18261832
USE(BIO_reset(bio));
18271833

18281834
X509_NAME* issuer_name = X509_get_issuer_name(cert);
18291835
if (X509_NAME_print_ex(bio, issuer_name, 0, X509_NAME_FLAGS) > 0) {
18301836
BIO_get_mem_ptr(bio, &mem);
1831-
info->Set(env->issuer_string(),
1837+
info->Set(context, env->issuer_string(),
18321838
String::NewFromUtf8(env->isolate(), mem->data,
1833-
String::kNormalString, mem->length));
1839+
String::kNormalString,
1840+
mem->length)).FromJust();
18341841
}
18351842
USE(BIO_reset(bio));
18361843

@@ -1855,9 +1862,10 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18551862
}
18561863

18571864
BIO_get_mem_ptr(bio, &mem);
1858-
info->Set(keys[i],
1865+
info->Set(context, keys[i],
18591866
String::NewFromUtf8(env->isolate(), mem->data,
1860-
String::kNormalString, mem->length));
1867+
String::kNormalString,
1868+
mem->length)).FromJust();
18611869

18621870
USE(BIO_reset(bio));
18631871
}
@@ -1873,9 +1881,10 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18731881
RSA_get0_key(rsa, &n, &e, nullptr);
18741882
BN_print(bio, n);
18751883
BIO_get_mem_ptr(bio, &mem);
1876-
info->Set(env->modulus_string(),
1884+
info->Set(context, env->modulus_string(),
18771885
String::NewFromUtf8(env->isolate(), mem->data,
1878-
String::kNormalString, mem->length));
1886+
String::kNormalString,
1887+
mem->length)).FromJust();
18791888
USE(BIO_reset(bio));
18801889

18811890
uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(e));
@@ -1887,9 +1896,10 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18871896
BIO_printf(bio, "0x%x%08x", hi, lo);
18881897
}
18891898
BIO_get_mem_ptr(bio, &mem);
1890-
info->Set(env->exponent_string(),
1899+
info->Set(context, env->exponent_string(),
18911900
String::NewFromUtf8(env->isolate(), mem->data,
1892-
String::kNormalString, mem->length));
1901+
String::kNormalString,
1902+
mem->length)).FromJust();
18931903
USE(BIO_reset(bio));
18941904
}
18951905

@@ -1904,16 +1914,18 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
19041914

19051915
ASN1_TIME_print(bio, X509_get_notBefore(cert));
19061916
BIO_get_mem_ptr(bio, &mem);
1907-
info->Set(env->valid_from_string(),
1917+
info->Set(context, env->valid_from_string(),
19081918
String::NewFromUtf8(env->isolate(), mem->data,
1909-
String::kNormalString, mem->length));
1919+
String::kNormalString,
1920+
mem->length)).FromJust();
19101921
USE(BIO_reset(bio));
19111922

19121923
ASN1_TIME_print(bio, X509_get_notAfter(cert));
19131924
BIO_get_mem_ptr(bio, &mem);
1914-
info->Set(env->valid_to_string(),
1925+
info->Set(context, env->valid_to_string(),
19151926
String::NewFromUtf8(env->isolate(), mem->data,
1916-
String::kNormalString, mem->length));
1927+
String::kNormalString,
1928+
mem->length)).FromJust();
19171929
BIO_free_all(bio);
19181930

19191931
unsigned int md_size, i;
@@ -1934,8 +1946,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
19341946
fingerprint[0] = '\0';
19351947
}
19361948

1937-
info->Set(env->fingerprint_string(),
1938-
OneByteString(env->isolate(), fingerprint));
1949+
info->Set(context, env->fingerprint_string(),
1950+
OneByteString(env->isolate(), fingerprint)).FromJust();
19391951
}
19401952

19411953
STACK_OF(ASN1_OBJECT)* eku = static_cast<STACK_OF(ASN1_OBJECT)*>(
@@ -1947,18 +1959,20 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
19471959
int j = 0;
19481960
for (int i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
19491961
if (OBJ_obj2txt(buf, sizeof(buf), sk_ASN1_OBJECT_value(eku, i), 1) >= 0)
1950-
ext_key_usage->Set(j++, OneByteString(env->isolate(), buf));
1962+
ext_key_usage->Set(context,
1963+
j++,
1964+
OneByteString(env->isolate(), buf)).FromJust();
19511965
}
19521966

19531967
sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
1954-
info->Set(env->ext_key_usage_string(), ext_key_usage);
1968+
info->Set(context, env->ext_key_usage_string(), ext_key_usage).FromJust();
19551969
}
19561970

19571971
if (ASN1_INTEGER* serial_number = X509_get_serialNumber(cert)) {
19581972
if (BIGNUM* bn = ASN1_INTEGER_to_BN(serial_number, nullptr)) {
19591973
if (char* buf = BN_bn2hex(bn)) {
1960-
info->Set(env->serial_number_string(),
1961-
OneByteString(env->isolate(), buf));
1974+
info->Set(context, env->serial_number_string(),
1975+
OneByteString(env->isolate(), buf)).FromJust();
19621976
OPENSSL_free(buf);
19631977
}
19641978
BN_free(bn);
@@ -1971,7 +1985,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
19711985
unsigned char* serialized = reinterpret_cast<unsigned char*>(
19721986
Buffer::Data(buff));
19731987
i2d_X509(cert, &serialized);
1974-
info->Set(env->raw_string(), buff);
1988+
info->Set(context, env->raw_string(), buff).FromJust();
19751989

19761990
return scope.Escape(info);
19771991
}
@@ -1984,6 +1998,7 @@ void SSLWrap<Base>::GetPeerCertificate(
19841998
Base* w;
19851999
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
19862000
Environment* env = w->ssl_env();
2001+
Local<Context> context = env->context();
19872002

19882003
ClearErrorOnReturn clear_error_on_return;
19892004

@@ -2035,7 +2050,7 @@ void SSLWrap<Base>::GetPeerCertificate(
20352050
continue;
20362051

20372052
Local<Object> ca_info = X509ToObject(env, ca);
2038-
info->Set(env->issuercert_string(), ca_info);
2053+
info->Set(context, env->issuercert_string(), ca_info).FromJust();
20392054
info = ca_info;
20402055

20412056
// NOTE: Intentionally freeing cert that is not used anymore
@@ -2058,7 +2073,7 @@ void SSLWrap<Base>::GetPeerCertificate(
20582073
break;
20592074

20602075
Local<Object> ca_info = X509ToObject(env, ca);
2061-
info->Set(env->issuercert_string(), ca_info);
2076+
info->Set(context, env->issuercert_string(), ca_info).FromJust();
20622077
info = ca_info;
20632078

20642079
// NOTE: Intentionally freeing cert that is not used anymore
@@ -2070,7 +2085,7 @@ void SSLWrap<Base>::GetPeerCertificate(
20702085

20712086
// Self-issued certificate
20722087
if (X509_check_issued(cert, cert) == X509_V_OK)
2073-
info->Set(env->issuercert_string(), info);
2088+
info->Set(context, env->issuercert_string(), info).FromJust();
20742089

20752090
CHECK_NE(cert, nullptr);
20762091

@@ -2266,6 +2281,7 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
22662281
Base* w;
22672282
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
22682283
Environment* env = Environment::GetCurrent(args);
2284+
Local<Context> context = env->context();
22692285

22702286
CHECK_NE(w->ssl_, nullptr);
22712287

@@ -2280,22 +2296,24 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
22802296
if (SSL_get_server_tmp_key(w->ssl_, &key)) {
22812297
switch (EVP_PKEY_id(key)) {
22822298
case EVP_PKEY_DH:
2283-
info->Set(env->type_string(),
2284-
FIXED_ONE_BYTE_STRING(env->isolate(), "DH"));
2285-
info->Set(env->size_string(),
2286-
Integer::New(env->isolate(), EVP_PKEY_bits(key)));
2299+
info->Set(context, env->type_string(),
2300+
FIXED_ONE_BYTE_STRING(env->isolate(), "DH")).FromJust();
2301+
info->Set(context, env->size_string(),
2302+
Integer::New(env->isolate(), EVP_PKEY_bits(key))).FromJust();
22872303
break;
22882304
case EVP_PKEY_EC:
22892305
{
22902306
EC_KEY* ec = EVP_PKEY_get1_EC_KEY(key);
22912307
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
22922308
EC_KEY_free(ec);
2293-
info->Set(env->type_string(),
2294-
FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"));
2295-
info->Set(env->name_string(),
2296-
OneByteString(args.GetIsolate(), OBJ_nid2sn(nid)));
2297-
info->Set(env->size_string(),
2298-
Integer::New(env->isolate(), EVP_PKEY_bits(key)));
2309+
info->Set(context, env->type_string(),
2310+
FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH")).FromJust();
2311+
info->Set(context, env->name_string(),
2312+
OneByteString(args.GetIsolate(),
2313+
OBJ_nid2sn(nid))).FromJust();
2314+
info->Set(context, env->size_string(),
2315+
Integer::New(env->isolate(),
2316+
EVP_PKEY_bits(key))).FromJust();
22992317
}
23002318
}
23012319
EVP_PKEY_free(key);
@@ -2388,7 +2406,8 @@ void SSLWrap<Base>::VerifyError(const FunctionCallbackInfo<Value>& args) {
23882406
Local<String> reason_string = OneByteString(isolate, reason);
23892407
Local<Value> exception_value = Exception::Error(reason_string);
23902408
Local<Object> exception_object = exception_value->ToObject(isolate);
2391-
exception_object->Set(w->env()->code_string(), OneByteString(isolate, code));
2409+
exception_object->Set(w->env()->context(), w->env()->code_string(),
2410+
OneByteString(isolate, code)).FromJust();
23922411
args.GetReturnValue().Set(exception_object);
23932412
}
23942413

@@ -2398,16 +2417,18 @@ void SSLWrap<Base>::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
23982417
Base* w;
23992418
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
24002419
Environment* env = w->ssl_env();
2420+
Local<Context> context = env->context();
24012421

24022422
const SSL_CIPHER* c = SSL_get_current_cipher(w->ssl_);
24032423
if (c == nullptr)
24042424
return;
24052425

24062426
Local<Object> info = Object::New(env->isolate());
24072427
const char* cipher_name = SSL_CIPHER_get_name(c);
2408-
info->Set(env->name_string(), OneByteString(args.GetIsolate(), cipher_name));
2409-
info->Set(env->version_string(),
2410-
OneByteString(args.GetIsolate(), "TLSv1/SSLv3"));
2428+
info->Set(context, env->name_string(),
2429+
OneByteString(args.GetIsolate(), cipher_name)).FromJust();
2430+
info->Set(context, env->version_string(),
2431+
OneByteString(args.GetIsolate(), "TLSv1/SSLv3")).FromJust();
24112432
args.GetReturnValue().Set(info);
24122433
}
24132434

@@ -2716,27 +2737,31 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
27162737
return -1;
27172738

27182739
Environment* env = w->env();
2740+
Local<Context> context = env->context();
27192741
HandleScope handle_scope(env->isolate());
2720-
Context::Scope context_scope(env->context());
2742+
Context::Scope context_scope(context);
27212743
w->cert_cb_running_ = true;
27222744

27232745
Local<Object> info = Object::New(env->isolate());
27242746

27252747
const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
27262748
if (servername == nullptr) {
2727-
info->Set(env->servername_string(), String::Empty(env->isolate()));
2749+
info->Set(context,
2750+
env->servername_string(),
2751+
String::Empty(env->isolate())).FromJust();
27282752
} else {
27292753
Local<String> str = OneByteString(env->isolate(), servername,
27302754
strlen(servername));
2731-
info->Set(env->servername_string(), str);
2755+
info->Set(context, env->servername_string(), str).FromJust();
27322756
}
27332757

27342758
bool ocsp = false;
27352759
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
27362760
ocsp = SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp;
27372761
#endif
27382762

2739-
info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp));
2763+
info->Set(context, env->ocsp_request_string(),
2764+
Boolean::New(env->isolate(), ocsp)).FromJust();
27402765

27412766
Local<Value> argv[] = { info };
27422767
w->MakeCallback(env->oncertcb_string(), arraysize(argv), argv);
@@ -5653,7 +5678,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
56535678
keylen));
56545679

56555680
if (args[5]->IsFunction()) {
5656-
obj->Set(env->ondone_string(), args[5]);
5681+
obj->Set(env->context(), env->ondone_string(), args[5]).FromJust();
56575682

56585683
uv_queue_work(env->event_loop(),
56595684
req.release()->work_req(),
@@ -5841,7 +5866,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
58415866
RandomBytesRequest::FREE_DATA));
58425867

58435868
if (args[1]->IsFunction()) {
5844-
obj->Set(env->ondone_string(), args[1]);
5869+
obj->Set(env->context(), env->ondone_string(), args[1]).FromJust();
58455870

58465871
uv_queue_work(env->event_loop(),
58475872
req.release()->work_req(),
@@ -5910,7 +5935,10 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
59105935

59115936
for (int i = 0; i < sk_SSL_CIPHER_num(ciphers); ++i) {
59125937
const SSL_CIPHER* cipher = sk_SSL_CIPHER_value(ciphers, i);
5913-
arr->Set(i, OneByteString(args.GetIsolate(), SSL_CIPHER_get_name(cipher)));
5938+
arr->Set(env->context(),
5939+
i,
5940+
OneByteString(args.GetIsolate(),
5941+
SSL_CIPHER_get_name(cipher))).FromJust();
59145942
}
59155943

59165944
SSL_free(ssl);
@@ -5973,7 +6001,10 @@ void GetCurves(const FunctionCallbackInfo<Value>& args) {
59736001

59746002
if (EC_get_builtin_curves(curves, num_curves)) {
59756003
for (size_t i = 0; i < num_curves; i++) {
5976-
arr->Set(i, OneByteString(env->isolate(), OBJ_nid2sn(curves[i].nid)));
6004+
arr->Set(env->context(),
6005+
i,
6006+
OneByteString(env->isolate(),
6007+
OBJ_nid2sn(curves[i].nid))).FromJust();
59776008
}
59786009
}
59796010

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.