-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: expose certificate decoding function #30675
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1145,7 +1145,6 @@ static void IsExtraRootCertsFileLoaded( | |
return args.GetReturnValue().Set(extra_root_certs_loaded); | ||
} | ||
|
||
|
||
void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { | ||
SecureContext* sc; | ||
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder()); | ||
|
@@ -2176,6 +2175,39 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { | |
} | ||
|
||
|
||
static void ParseX509(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
|
||
CHECK(args[0]->IsArrayBufferView()); | ||
ArrayBufferViewContents<unsigned char> buf(args[0].As<ArrayBufferView>()); | ||
const unsigned char* data = buf.data(); | ||
unsigned data_len = buf.length(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple of width/sign issues here: size_t data_len = buf.length();
CHECK_LE(data_len, INT_MAX); |
||
|
||
ClearErrorOnReturn clear_error_on_return; | ||
BIOPointer bio(LoadBIO(env, args[0])); | ||
if (!bio) | ||
return ThrowCryptoError(env, ERR_get_error()); | ||
|
||
X509Pointer pem(PEM_read_bio_X509_AUX( | ||
bio.get(), nullptr, NoPasswordCallback, nullptr)); | ||
|
||
if (!pem) { | ||
// Try as DER, but return the original PEM failure if it isn't DER. | ||
MarkPopErrorOnReturn mark_here; | ||
|
||
X509Pointer der(d2i_X509(nullptr, &data, data_len)); | ||
if (der) { | ||
args.GetReturnValue().Set(X509ToObject(env, der.get())); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/local consistency: no braces, ditto on line 2219. |
||
} | ||
if (!pem) { | ||
return ThrowCryptoError(env, ERR_get_error()); | ||
} | ||
|
||
args.GetReturnValue().Set(X509ToObject(env, pem.get())); | ||
} | ||
|
||
|
||
static Local<Object> AddIssuerChainToObject(X509Pointer* cert, | ||
Local<Object> object, | ||
StackOfX509&& peer_certs, | ||
|
@@ -7358,6 +7390,8 @@ void Initialize(Local<Object> target, | |
// Exposed for testing purposes only. | ||
env->SetMethodNoSideEffect(target, "isExtraRootCertsFileLoaded", | ||
IsExtraRootCertsFileLoaded); | ||
env->SetMethodNoSideEffect(target, "parseX509", | ||
ParseX509); | ||
|
||
env->SetMethodNoSideEffect(target, "ECDHConvertKey", ConvertKey); | ||
#ifndef OPENSSL_NO_ENGINE | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintended change?