| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b8f102c commit 4823c5e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,13 +48,23 @@ static constexpr int kX509NameFlagsMultiline = | |||
| 48 | 48 | XN_FLAG_SEP_MULTILINE | | |
| 49 | 49 | XN_FLAG_FN_SN; | |
| 50 | 50 | ||
| 51 | - bool SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert, X509** issuer) { | ||
| 51 | + static constexpr int kX509NameFlagsRFC2253WithinUtf8JSON = | ||
| 52 | + XN_FLAG_RFC2253 & | ||
| 53 | + ~ASN1_STRFLGS_ESC_MSB & | ||
| 54 | + ~ASN1_STRFLGS_ESC_CTRL; | ||
| 55 | + | ||
| 56 | + X509Pointer SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert) { | ||
| 52 | 57 | X509_STORE* store = SSL_CTX_get_cert_store(ctx); | |
| 53 | 58 | DeleteFnPtr<X509_STORE_CTX, X509_STORE_CTX_free> store_ctx( | |
| 54 | 59 | X509_STORE_CTX_new()); | |
| 55 | - return store_ctx.get() != nullptr && | ||
| 56 | - X509_STORE_CTX_init(store_ctx.get(), store, nullptr, nullptr) == 1 && | ||
| 57 | - X509_STORE_CTX_get1_issuer(issuer, store_ctx.get(), cert) == 1; | ||
| 60 | + X509Pointer result; | ||
| 61 | + X509* issuer; | ||
| 62 | + if (store_ctx.get() != nullptr && | ||
| 63 | + X509_STORE_CTX_init(store_ctx.get(), store, nullptr, nullptr) == 1 && | ||
| 64 | + X509_STORE_CTX_get1_issuer(&issuer, store_ctx.get(), cert) == 1) { | ||
| 65 | + result.reset(issuer); | ||
| 66 | + } | ||
| 67 | + return result; | ||
| 58 | 68 | } | |
| 59 | 69 | ||
| 60 | 70 | void LogSecret( | |
@@ -386,29 +396,27 @@ MaybeLocal<Object> GetLastIssuedCert( | |||
| 386 | 396 | Environment* const env) { | |
| 387 | 397 | Local<Context> context = env->isolate()->GetCurrentContext(); | |
| 388 | 398 | while (X509_check_issued(cert->get(), cert->get()) != X509_V_OK) { | |
| 389 | - X509* ca; | ||
| 390 | - if (SSL_CTX_get_issuer(SSL_get_SSL_CTX(ssl.get()), cert->get(), &ca) <= 0) | ||
| 399 | + X509Pointer ca; | ||
| 400 | + if (!(ca = SSL_CTX_get_issuer(SSL_get_SSL_CTX(ssl.get()), cert->get()))) | ||
| 391 | 401 | break; | |
| 392 | 402 | ||
| 393 | 403 | Local<Object> ca_info; | |
| 394 | - MaybeLocal<Object> maybe_ca_info = X509ToObject(env, ca); | ||
| 404 | + MaybeLocal<Object> maybe_ca_info = X509ToObject(env, ca.get()); | ||
| 395 | 405 | if (!maybe_ca_info.ToLocal(&ca_info)) | |
| 396 | 406 | return MaybeLocal<Object>(); | |
| 397 | 407 | ||
| 398 | 408 | if (!Set<Object>(context, issuer_chain, env->issuercert_string(), ca_info)) | |
| 399 | 409 | return MaybeLocal<Object>(); | |
| 400 | 410 | issuer_chain = ca_info; | |
| 401 | 411 | ||
| 402 | - // Take the value of cert->get() before the call to cert->reset() | ||
| 403 | - // in order to compare it to ca after and provide a way to exit this loop | ||
| 404 | - // in case it gets stuck. | ||
| 405 | - X509* value_before_reset = cert->get(); | ||
| 412 | + // For self-signed certificates whose keyUsage field does not include | ||
| 413 | + // keyCertSign, X509_check_issued() will return false. Avoid going into an | ||
| 414 | + // infinite loop by checking if SSL_CTX_get_issuer() returned the same | ||
| 415 | + // certificate. | ||
| 416 | + if (cert->get() == ca.get()) break; | ||
| 406 | 417 | ||
| 407 | 418 | // Delete previous cert and continue aggregating issuers. | |
| 408 | - cert->reset(ca); | ||
| 409 | - | ||
| 410 | - if (value_before_reset == ca) | ||
| 411 | - break; | ||
| 419 | + *cert = std::move(ca); | ||
| 412 | 420 | } | |
| 413 | 421 | return MaybeLocal<Object>(issuer_chain); | |
| 414 | 422 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ struct StackOfXASN1Deleter { | |||
| 25 | 25 | }; | |
| 26 | 26 | using StackOfASN1 = std::unique_ptr<STACK_OF(ASN1_OBJECT), StackOfXASN1Deleter>; | |
| 27 | 27 | ||
| 28 | - bool SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert, X509** issuer); | ||
| 28 | + X509Pointer SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert); | ||
| 29 | 29 | ||
| 30 | 30 | void LogSecret( | |
| 31 | 31 | const SSLPointer& ssl, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,21 +110,21 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, | |||
| 110 | 110 | // Try getting issuer from a cert store | |
| 111 | 111 | if (ret) { | |
| 112 | 112 | if (issuer == nullptr) { | |
| 113 | - ret = SSL_CTX_get_issuer(ctx, x.get(), &issuer); | ||
| 114 | - ret = ret < 0 ? 0 : 1; | ||
| 113 | + // TODO(tniessen): SSL_CTX_get_issuer does not allow the caller to | ||
| 114 | + // distinguish between a failed operation and an empty result. Fix that | ||
| 115 | + // and then handle the potential error properly here (set ret to 0). | ||
| 116 | + *issuer_ = SSL_CTX_get_issuer(ctx, x.get()); | ||
| 115 | 117 | // NOTE: get_cert_store doesn't increment reference count, | |
| 116 | 118 | // no need to free `store` | |
| 117 | 119 | } else { | |
| 118 | 120 | // Increment issuer reference count | |
| 119 | - issuer = X509_dup(issuer); | ||
| 120 | - if (issuer == nullptr) { | ||
| 121 | + issuer_->reset(X509_dup(issuer)); | ||
| 122 | + if (!*issuer_) { | ||
| 121 | 123 | ret = 0; | |
| 122 | 124 | } | |
| 123 | 125 | } | |
| 124 | 126 | } | |
| 125 | 127 | ||
| 126 | - issuer_->reset(issuer); | ||
| 127 | - | ||
| 128 | 128 | if (ret && x != nullptr) { | |
| 129 | 129 | cert->reset(X509_dup(x.get())); | |
| 130 | 130 | if (!*cert) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments