From 024b0ce853635420a273c85ff0b65860317108d4 Mon Sep 17 00:00:00 2001 From: mosuem <27859082+mosuem@users.noreply.github.com> Date: Sun, 4 Oct 2026 03:50:41 +0000 Subject: [PATCH] Update BoringSSL to dd73e69a --- CHANGELOG.md | 1 + lib/src/bindings/boringssl.g.dart | 3 - .../gen/bcm/aesni-gcm-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/aesni-x86_64-win.asm | 6 +- .../gen/bcm/ghash-ssse3-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/ghash-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/p256-x86_64-asm-win.asm | 2 +- .../boringssl/gen/bcm/rsaz-avx2-win.asm | 2 +- .../boringssl/gen/bcm/sha1-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/sha256-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/sha512-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/vpaes-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/x86_64-mont5-win.asm | 2 +- .../gen/crypto/chacha-x86_64-win.asm | 2 +- .../crypto/fipsmodule/entropy/jitter.cc.inc | 42 ++++-- third_party/boringssl/src/crypto/hpke/hpke.cc | 64 ++++++--- .../boringssl/src/crypto/x509/internal.h | 26 +--- .../boringssl/src/crypto/x509/v3_crld.cc | 50 +------ .../boringssl/src/crypto/x509/v3_purp.cc | 24 ---- .../boringssl/src/crypto/x509/x509_vfy.cc | 135 ++++++------------ .../boringssl/src/crypto/x509/x_crl.cc | 51 +------ .../boringssl/src/include/openssl/hpke.h | 23 +++ .../src/include/openssl/prefix_symbols.h | 8 +- .../boringssl/src/include/openssl/x509.h | 4 +- tool/REVISION | 2 +- 25 files changed, 174 insertions(+), 287 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f5c40..79b9b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.4.2-wip - Update BoringSSL to e98a6564. +- Update BoringSSL to dd73e69a. ## 0.4.1 diff --git a/lib/src/bindings/boringssl.g.dart b/lib/src/bindings/boringssl.g.dart index 32916f6..d98c90e 100644 --- a/lib/src/bindings/boringssl.g.dart +++ b/lib/src/bindings/boringssl.g.dart @@ -32447,9 +32447,6 @@ final class DIST_POINT_NAME_st extends ffi.Struct { external int type; external UnnamedUnion$4 name; - - /// If relativename then this contains the full distribution point name - external ffi.Pointer dpname; } /// A DIST_POINT_st, aka `DIST_POINT`, represents a DistributionPoint structure diff --git a/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm b/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm index a17d4f4..258862e 100644 --- a/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm @@ -967,7 +967,7 @@ $L$one_lsb: DB 89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112 DB 114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 ALIGN 64 -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm b/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm index 7f55ea4..9a79ff0 100644 --- a/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm @@ -2499,7 +2499,7 @@ $L$key_rcon1b: DB 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115 DB 115,108,46,111,114,103,62,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind @@ -2695,7 +2695,7 @@ $L$SEH_info_ctr32: $L$SEH_info_cbc: DB 9,0,0,0 DD cbc_se_handler wrt ..imagebase -section .pdata +section .pdata rdata align=4 ALIGN 4 DD $L$SEH_begin_aes_hw_set_encrypt_key_base_1 wrt ..imagebase DD $L$SEH_end_aes_hw_set_encrypt_key_base_4 wrt ..imagebase @@ -2706,7 +2706,7 @@ ALIGN 4 DD $L$SEH_info_aes_hw_set_encrypt_key_alt_0 wrt ..imagebase -section .xdata +section .xdata rdata align=8 ALIGN 4 $L$SEH_info_aes_hw_set_encrypt_key_base_0: DB 1 ; version 1, no flags diff --git a/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm b/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm index 4794beb..64faab6 100644 --- a/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm @@ -450,7 +450,7 @@ $L$reverse_bytes: ; .Llow4_mask is an XMM mask which selects the low four bits of each byte. $L$low4_mask: DQ 0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm b/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm index eacd900..abdbb70 100644 --- a/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm @@ -1214,7 +1214,7 @@ ALIGN 64 DB 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111 DB 114,103,62,0 ALIGN 64 -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm b/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm index 9976ab3..c82ea79 100644 --- a/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm +++ b/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm @@ -35,7 +35,7 @@ $L$ord: DQ 0xf3b9cac2fc632551,0xbce6faada7179e84,0xffffffffffffffff,0xffffffff00000000 $L$ordK: DQ 0xccd1c8aaee00bc4f -section .text +section .text code align=64 ; ############################################################################### diff --git a/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm b/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm index a142c27..4272093 100644 --- a/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm +++ b/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm @@ -1846,7 +1846,7 @@ $L$inc: DD 2,2,2,2,3,3,3,3 DD 4,4,4,4,4,4,4,4 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm index b59fb5d..b3a9225 100644 --- a/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm @@ -5560,7 +5560,7 @@ K_XX_XX: DB 97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114 DB 103,62,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm index 339f23a..7f3a21b 100644 --- a/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm @@ -1785,7 +1785,7 @@ K256: DB 52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 DB 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 DB 111,114,103,62,0 -section .text +section .text code align=64 global sha256_block_data_order_hw diff --git a/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm index 2e6760c..9f79afb 100644 --- a/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm @@ -1829,7 +1829,7 @@ K512: DB 52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 DB 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 DB 111,114,103,62,0 -section .text +section .text code align=64 global sha512_block_data_order_avx diff --git a/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm b/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm index 001618c..cea2195 100644 --- a/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm @@ -1348,7 +1348,7 @@ $L$ctr_add_two: DB 85,110,105,118,101,114,115,105,116,121,41,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm b/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm index 05e9759..4b73b80 100644 --- a/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm +++ b/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm @@ -3698,7 +3698,7 @@ $L$inc: DB 114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79 DB 71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111 DB 112,101,110,115,115,108,46,111,114,103,62,0 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm b/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm index e37e31f..9cd683b 100644 --- a/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm +++ b/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm @@ -50,7 +50,7 @@ $L$sixteen: DB 95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32 DB 98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115 DB 108,46,111,114,103,62,0 -section .text +section .text code align=64 global ChaCha20_ctr32_nohw diff --git a/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc index ebe3a5c..f4767a8 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc @@ -32,6 +32,7 @@ #include +#include "../../internal.h" #include "internal.h" #include "sha512.cc.inc" @@ -88,6 +89,11 @@ class MemoryAccessSampler { array_size_ & (array_size_ - 1)) { abort(); } + + if (boringssl_fips_break_test("JITTER_APT")) { + // In this break test, array_[0] is used to keep state. See below. + array_[0] = 0; + } } ~MemoryAccessSampler() { OPENSSL_free(const_cast(array_)); } @@ -104,16 +110,28 @@ class MemoryAccessSampler { } bool Next(uint64_t *out) { - // Perform some memory accesses and measure how long it took. The LCG is - // intended to defeat any CPU predictors and thus expose this code to as - // much system entropy as possible. - for (unsigned i = 0; i < num_samples_; i++) { - // The lower bits of an LCG tend to fall into short cycles and so are - // discarded here. - array_[(lcg_.Next() >> 6) & (array_size_ - 1)] += 1; - } + if (boringssl_fips_break_test("JITTER_RCT")) { + // To break the repetition test a constant value is returned. + *out = 1; + } else if (boringssl_fips_break_test("JITTER_APT")) { + // To break the adaptive test, but not the repetition test, a counter + // that advances every fourth call is returned. Since samples are + // processed by `DeltaSampler`, the tests see 0,0,0,1,... which exceeds + // the APT cutoff (348/512) without tripping the RCT (26). + *out = array_[0] >> 2; + array_[0]++; + } else { + // Perform some memory accesses and measure how long it took. The LCG is + // intended to defeat any CPU predictors and thus expose this code to as + // much system entropy as possible. + for (unsigned i = 0; i < num_samples_; i++) { + // The lower bits of an LCG tend to fall into short cycles and so are + // discarded here. + array_[(lcg_.Next() >> 6) & (array_size_ - 1)] += 1; + } - *out = GetTimestamp(); + *out = GetTimestamp(); + } return true; } @@ -226,6 +244,9 @@ class RepetitionCountTest { last_sample_ = sample; } if (count_ >= kThreshold) { +#if defined(BORINGSSL_FIPS_BREAK_TESTS) + fprintf(stderr, "Jitter RCT failure.\n"); +#endif return false; } *out = sample; @@ -351,6 +372,9 @@ class AdaptiveProportionTest { const uint16_t new_count = ++counts_[sample]; if (new_count > kThreshold) { +#if defined(BORINGSSL_FIPS_BREAK_TESTS) + fprintf(stderr, "Jitter APT failure.\n"); +#endif return false; } diff --git a/third_party/boringssl/src/crypto/hpke/hpke.cc b/third_party/boringssl/src/crypto/hpke/hpke.cc index 11f61ba..30d12df 100644 --- a/third_party/boringssl/src/crypto/hpke/hpke.cc +++ b/third_party/boringssl/src/crypto/hpke/hpke.cc @@ -856,6 +856,18 @@ size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem) { return kem->enc_len; } +// TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported +// HPKE KEMs. +size_t EVP_HPKE_KEM_shared_secret_len(const EVP_HPKE_KEM *kem) { + if (uses_evp(kem)) { + return EVP_KEM_secret_len(kem->evp_kem_func()); + } + // All other KEMs have the same shared secret length. We assume we'll finish + // https://crbug.com/503758094 and move all KEMs to EVP before adding one that + // breaks this. + return SHA256_DIGEST_LENGTH; +} + // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. void EVP_HPKE_KEY_zero(EVP_HPKE_KEY *key) { @@ -1274,44 +1286,58 @@ int EVP_HPKE_CTX_setup_sender_with_seed_for_testing( return 1; } +int EVP_HPKE_CTX_setup_recipient_with_shared_secret( + EVP_HPKE_CTX *ctx, const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, + const EVP_HPKE_AEAD *aead, const uint8_t *shared_secret, + size_t shared_secret_len, const uint8_t *info, size_t info_len) { + EVP_HPKE_CTX_zero(ctx); + + if (shared_secret_len != EVP_HPKE_KEM_shared_secret_len(kem)) { + OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE); + return 0; + } + + ctx->is_sender = 0; + ctx->kem = kem; + ctx->kdf = kdf; + ctx->aead = aead; + if (!hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, shared_secret_len, + info, info_len)) { + EVP_HPKE_CTX_cleanup(ctx); + return 0; + } + return 1; +} + int EVP_HPKE_CTX_setup_recipient(EVP_HPKE_CTX *ctx, const EVP_HPKE_KEY *key, const EVP_HPKE_KDF *kdf, const EVP_HPKE_AEAD *aead, const uint8_t *enc, size_t enc_len, const uint8_t *info, size_t info_len) { EVP_HPKE_CTX_zero(ctx); - ctx->is_sender = 0; - ctx->kem = key->kem; - ctx->kdf = kdf; - ctx->aead = aead; + uint8_t shared_secret[MAX_SHARED_SECRET_LEN]; size_t shared_secret_len; // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. + int decap_ok; if (uses_evp(key->kem)) { const EVP_KEM *evp_kem = key->kem->evp_kem_func(); const EVP_PKEY *decap_key = key->pkey; shared_secret_len = EVP_KEM_secret_len(evp_kem); assert(size_t{MAX_SHARED_SECRET_LEN} >= shared_secret_len); - if (!EVP_KEM_decap(evp_kem, shared_secret, shared_secret_len, enc, enc_len, - decap_key) || - !hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, - shared_secret_len, info, info_len)) { - EVP_HPKE_CTX_cleanup(ctx); - return 0; - } - return 1; + decap_ok = EVP_KEM_decap(evp_kem, shared_secret, shared_secret_len, enc, + enc_len, decap_key); + } else { + decap_ok = key->kem->decap(key, shared_secret, &shared_secret_len, enc, + enc_len); } - if (!key->kem->decap(key, shared_secret, &shared_secret_len, enc, enc_len) || - !hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, shared_secret_len, - info, info_len)) { - EVP_HPKE_CTX_cleanup(ctx); - return 0; - } - return 1; + return decap_ok && EVP_HPKE_CTX_setup_recipient_with_shared_secret( + ctx, key->kem, kdf, aead, shared_secret, + shared_secret_len, info, info_len); } diff --git a/third_party/boringssl/src/crypto/x509/internal.h b/third_party/boringssl/src/crypto/x509/internal.h index f5a76da..ab07fec 100644 --- a/third_party/boringssl/src/crypto/x509/internal.h +++ b/third_party/boringssl/src/crypto/x509/internal.h @@ -263,22 +263,6 @@ DECLARE_ASN1_FUNCTIONS_const(X509_CRL_INFO) BSSL_NAMESPACE_END -// Values in idp_flags field -// IDP present -#define IDP_PRESENT 0x1 -// IDP values inconsistent -#define IDP_INVALID 0x2 -// onlyuser true -#define IDP_ONLYUSER 0x4 -// onlyCA true -#define IDP_ONLYCA 0x8 -// onlyattr true -#define IDP_ONLYATTR 0x10 -// indirectCRL true -#define IDP_INDIRECT 0x20 -// onlysomereasons present -#define IDP_REASONS 0x40 - struct X509_crl_st { // actual signature bssl::X509_CRL_INFO *crl; @@ -289,8 +273,6 @@ struct X509_crl_st { // Copies of various extensions AUTHORITY_KEYID *akid; ISSUING_DIST_POINT *idp; - // Convenient breakdown of IDP - int idp_flags; unsigned char crl_hash[SHA256_DIGEST_LENGTH]; } /* X509_CRL */; @@ -625,10 +607,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); // GENERAL_NAME_cmp returns zero if `a` and `b` are equal and a non-zero // value otherwise. Note this function does not provide a comparison suitable // for sorting. -// -// This function is exported for testing. -OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a, - const GENERAL_NAME *b); +int GENERAL_NAME_cmp(const GENERAL_NAME *a, const GENERAL_NAME *b); // X509_VERIFY_PARAM_lookup returns a pre-defined `X509_VERIFY_PARAM` named by // `name`, or NULL if no such name is defined. @@ -650,9 +629,6 @@ int X509_is_valid_trust_id(int trust); int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); -// TODO(https://crbug.com/boringssl/695): Remove this. -int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); - // x509_parse_name parses a DER-encoded, X.509 Name from `cbs` and writes the // result to `*out`. It returns one on success and zero on error. int x509_parse_name(CBS *cbs, X509_NAME *out); diff --git a/third_party/boringssl/src/crypto/x509/v3_crld.cc b/third_party/boringssl/src/crypto/x509/v3_crld.cc index 48d1538..6db3c62 100644 --- a/third_party/boringssl/src/crypto/x509/v3_crld.cc +++ b/third_party/boringssl/src/crypto/x509/v3_crld.cc @@ -286,27 +286,10 @@ static void *v2i_crld(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, return crld.release(); } -static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, - void *exarg) { - DIST_POINT_NAME *dpn = asn1_load_ptr_as(pval); - - switch (operation) { - case ASN1_OP_NEW_POST: - dpn->dpname = nullptr; - break; - - case ASN1_OP_FREE_POST: - X509_NAME_free(dpn->dpname); - break; - } - return 1; -} - - -ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = { +ASN1_CHOICE(DIST_POINT_NAME) = { ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0), ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1), -} ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type) +} ASN1_CHOICE_END(DIST_POINT_NAME) IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT_NAME) @@ -486,32 +469,3 @@ static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, } return 1; } - -int bssl::DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname) { - size_t i; - STACK_OF(X509_NAME_ENTRY) *frag; - X509_NAME_ENTRY *ne; - if (!dpn || (dpn->type != 1)) { - return 1; - } - frag = dpn->name.relativename; - dpn->dpname = X509_NAME_dup(iname); - if (!dpn->dpname) { - return 0; - } - for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++) { - ne = sk_X509_NAME_ENTRY_value(frag, i); - if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1)) { - X509_NAME_free(dpn->dpname); - dpn->dpname = nullptr; - return 0; - } - } - // generate cached encoding of name - if (i2d_X509_NAME(dpn->dpname, nullptr) < 0) { - X509_NAME_free(dpn->dpname); - dpn->dpname = nullptr; - return 0; - } - return 1; -} diff --git a/third_party/boringssl/src/crypto/x509/v3_purp.cc b/third_party/boringssl/src/crypto/x509/v3_purp.cc index d832c5b..86f23b8 100644 --- a/third_party/boringssl/src/crypto/x509/v3_purp.cc +++ b/third_party/boringssl/src/crypto/x509/v3_purp.cc @@ -146,25 +146,6 @@ int X509_supported_extension(const X509_EXTENSION *ex) { nid == NID_pe_mtcCertificationAuthority_draft; } -static int setup_dp(X509 *x, DIST_POINT *dp) { - if (!dp->distpoint || (dp->distpoint->type != 1)) { - return 1; - } - X509_NAME *iname = nullptr; - for (size_t i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) { - GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i); - if (gen->type == GEN_DIRNAME) { - iname = gen->d.directoryName; - break; - } - } - if (!iname) { - iname = X509_get_issuer_name(x); - } - - return DIST_POINT_set_dpname(dp->distpoint, iname); -} - static int setup_crldp(X509 *x) { int j; auto *impl = FromOpaque(x); @@ -173,11 +154,6 @@ static int setup_crldp(X509 *x) { if (impl->crldp == nullptr && j != -1) { return 0; } - for (size_t i = 0; i < sk_DIST_POINT_num(impl->crldp.get()); i++) { - if (!setup_dp(x, sk_DIST_POINT_value(impl->crldp.get(), i))) { - return 0; - } - } return 1; } diff --git a/third_party/boringssl/src/crypto/x509/x509_vfy.cc b/third_party/boringssl/src/crypto/x509/x509_vfy.cc index 90a9d1f..6ceaed3 100644 --- a/third_party/boringssl/src/crypto/x509/x509_vfy.cc +++ b/third_party/boringssl/src/crypto/x509/x509_vfy.cc @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include #include @@ -828,24 +827,28 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 **pissuer, // the certificate issuer this is returned in *pissuer. static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl, X509 *x) { - int crl_score = 0; - - // First see if we can reject CRL straight away - - // Invalid IDP cannot be processed - if (crl->idp_flags & IDP_INVALID) { - return 0; - } - // Reason codes and indirect CRLs are not supported. - if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS)) { - return 0; + if (crl->idp) { + // Per RFC 5280, section 5.2.5, at most one of onlyContainsUserCerts, + // onlyContainsCACerts, and onlyContainsAttributeCerts may be true. + // TODO(crbug.com/42290307): Move this check to the `ISSUING_DIST_POINT` + // parser. + int num_only = + (!!crl->idp->onlyuser) + (!!crl->idp->onlyCA) + (!!crl->idp->onlyattr); + if (num_only > 1) { + return 0; + } + // Reason codes and indirect CRLs are not supported. + if (crl->idp->indirectCRL || crl->idp->onlysomereasons) { + return 0; + } } + // We do not support indirect CRLs, so the issuer names must match. if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl))) { return 0; } - crl_score |= CRL_SCORE_ISSUER_NAME; + int crl_score = CRL_SCORE_ISSUER_NAME; if (!(crl->flags & EXFLAG_CRITICAL)) { crl_score |= CRL_SCORE_NOCRITICAL; } @@ -902,93 +905,52 @@ static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, return 0; } -// Check for match between two dist point names: three separate cases. 1. -// Both are relative names and compare X509_NAME types. 2. One full, one -// relative. Compare X509_NAME to GENERAL_NAMES. 3. Both are full names and -// compare two GENERAL_NAMES. 4. One is NULL: automatic match. -static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b) { - X509_NAME *nm = nullptr; - GENERAL_NAMES *gens = nullptr; - GENERAL_NAME *gena, *genb; - size_t i, j; - if (!a || !b) { +static int idp_check_dp(const DIST_POINT_NAME *dp_cert, + const DIST_POINT_NAME *dp_crl) { + // If the CRL IDP does not have a distributionPoint field, the CRL is scoped + // to the entire CA and matches everything. + // + // TODO(crbug.com/42290219): This covers a null `dp_crl`, but not `dp_cert`. + // If `dp_cert` is null, that means the certificate's DistributionPoint lacks + // a distributionPoint. However, DistributionPoints are required to have + // either distributionPoint or cRLIssuer (indirect CRL) and we reject the + // latter. However, we don't seem to check this in the parser. Enforce this so + // that `dp_cert` cannot be null. + if (!dp_cert || !dp_crl) { return 1; } - if (a->type == 1) { - if (!a->dpname) { - return 0; - } - // Case 1: two X509_NAME - if (b->type == 1) { - if (!b->dpname) { - return 0; - } - if (!X509_NAME_cmp(a->dpname, b->dpname)) { - return 1; - } else { - return 0; - } - } - // Case 2: set name and GENERAL_NAMES appropriately - nm = a->dpname; - gens = b->name.fullname; - } else if (b->type == 1) { - if (!b->dpname) { - return 0; - } - // Case 2: set name and GENERAL_NAMES appropriately - gens = a->name.fullname; - nm = b->dpname; - } - - // Handle case 2 with one GENERAL_NAMES and one X509_NAME - if (nm) { - for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { - gena = sk_GENERAL_NAME_value(gens, i); - if (gena->type != GEN_DIRNAME) { - continue; - } - if (!X509_NAME_cmp(nm, gena->d.directoryName)) { - return 1; - } - } + // We only support fullName, not nameRelativeToCRLIssuer. + if (dp_cert->type != 0 || dp_crl->type != 0) { return 0; } - - // Else case 3: two GENERAL_NAMES - - for (i = 0; i < sk_GENERAL_NAME_num(a->name.fullname); i++) { - gena = sk_GENERAL_NAME_value(a->name.fullname, i); - for (j = 0; j < sk_GENERAL_NAME_num(b->name.fullname); j++) { - genb = sk_GENERAL_NAME_value(b->name.fullname, j); - if (!GENERAL_NAME_cmp(gena, genb)) { + // Check that the CRL's distributionPoint has some name in common with the + // certificate's. A CA might shard across multiple CRLs. This check ensures we + // are looking at the right shard. + // + // TODO(crbug.com/565047760): This should not be an O(N^2) comparison. + for (const GENERAL_NAME *gen_cert : dp_cert->name.fullname) { + for (const GENERAL_NAME *gen_crl : dp_crl->name.fullname) { + if (GENERAL_NAME_cmp(gen_cert, gen_crl) == 0) { return 1; } } } - return 0; } // Check CRLDP and IDP static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) { auto *impl = FromOpaque(x); - // TODO(bbe): crbug.com/409778435 Make tests for the corner cases we hit - // here so that we stay correct for RFC 5280 6.3.3 steps b.1 and b.2 - if (crl->idp_flags & IDP_ONLYATTR) { - return 0; - } if (impl->ex_flags & EXFLAG_CA) { - if (crl->idp_flags & IDP_ONLYUSER) { + if (crl->idp && crl->idp->onlyuser) { return 0; } } else { - if (crl->idp_flags & IDP_ONLYCA) { + if (crl->idp && crl->idp->onlyCA) { return 0; } } - for (size_t i = 0; i < sk_DIST_POINT_num(impl->crldp.get()); i++) { - DIST_POINT *dp = sk_DIST_POINT_value(impl->crldp.get(), i); + for (const DIST_POINT *dp : impl->crldp.get()) { // Skip distribution points with a reasons field or a CRL issuer: // // We do not support CRLs partitioned by reason code. RFC 5280 requires CAs @@ -1009,10 +971,10 @@ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) { } // If the CRL does not specify an issuing distribution point, allow it to - // match anything. - // - // TODO(davidben): Does this match RFC 5280? It's hard to follow because RFC - // 5280 starts from distribution points, while this starts from CRLs. + // match anything. This partially implements RFC 5280. The final paragraph of + // RFC 5280, section 6.3.3, specifies a default CRL-DP. This default would + // match IDP-less CRLs and CRLs with an IDP of the default CRL-DP. We do not + // implement the second condition. return !crl->idp || !crl->idp->distpoint; } @@ -1089,13 +1051,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { } } - if (crl->idp_flags & IDP_INVALID) { - ctx->error = X509_V_ERR_INVALID_EXTENSION; - if (!call_verify_cb(0, ctx)) { - return 0; - } - } - if (!(ctx->current_crl_score & CRL_SCORE_TIME)) { if (!check_crl_time(ctx, crl, 1)) { return 0; diff --git a/third_party/boringssl/src/crypto/x509/x_crl.cc b/third_party/boringssl/src/crypto/x509/x_crl.cc index d30c172..d67e458 100644 --- a/third_party/boringssl/src/crypto/x509/x_crl.cc +++ b/third_party/boringssl/src/crypto/x509/x_crl.cc @@ -33,7 +33,6 @@ using namespace bssl; static int X509_REVOKED_cmp(const X509_REVOKED *const *a, const X509_REVOKED *const *b); -static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); BSSL_NAMESPACE_BEGIN @@ -141,7 +140,6 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->idp = nullptr; crl->akid = nullptr; crl->flags = 0; - crl->idp_flags = 0; break; case ASN1_OP_D2I_POST: { @@ -176,11 +174,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->idp = reinterpret_cast(X509_CRL_get_ext_d2i( crl, NID_issuing_distribution_point, &i, nullptr)); - if (crl->idp != nullptr) { - if (!setup_idp(crl, crl->idp)) { - return 0; - } - } else if (i != -1) { + if (crl->idp == nullptr && i != -1) { return 0; } @@ -223,49 +217,6 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } -// Convert IDP into a more convenient form -// -// TODO(davidben): Each of these flags are already booleans, so this is not -// really more convenient. We can probably remove `idp_flags`. -static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) { - int idp_only = 0; - // Set various flags according to IDP - crl->idp_flags |= IDP_PRESENT; - if (idp->onlyuser > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYUSER; - } - if (idp->onlyCA > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYCA; - } - if (idp->onlyattr > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYATTR; - } - - // Per RFC 5280, section 5.2.5, at most one of onlyContainsUserCerts, - // onlyContainsCACerts, and onlyContainsAttributeCerts may be true. - // - // TODO(crbug.com/boringssl/443): Move this check to the `ISSUING_DIST_POINT` - // parser. - if (idp_only > 1) { - crl->idp_flags |= IDP_INVALID; - } - - if (idp->indirectCRL > 0) { - crl->idp_flags |= IDP_INDIRECT; - } - - if (idp->onlysomereasons) { - crl->idp_flags |= IDP_REASONS; - } - - // TODO(davidben): The new verifier does not support nameRelativeToCRLIssuer. - // Remove this? - return DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); -} - BSSL_NAMESPACE_BEGIN ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { diff --git a/third_party/boringssl/src/include/openssl/hpke.h b/third_party/boringssl/src/include/openssl/hpke.h index 9e1a77e..a9e4a17 100644 --- a/third_party/boringssl/src/include/openssl/hpke.h +++ b/third_party/boringssl/src/include/openssl/hpke.h @@ -83,6 +83,10 @@ OPENSSL_EXPORT size_t EVP_HPKE_KEM_private_key_len(const EVP_HPKE_KEM *kem); // secret, for `kem`. This value will be at most `EVP_HPKE_MAX_ENC_LENGTH`. OPENSSL_EXPORT size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem); +// EVP_HPKE_KEM_shared_secret_len returns the length of the shared secret +// produced by `kem`. +OPENSSL_EXPORT size_t EVP_HPKE_KEM_shared_secret_len(const EVP_HPKE_KEM *kem); + // The following constants are KDF identifiers. #define EVP_HPKE_HKDF_SHA256 0x0001 #define EVP_HPKE_HKDF_SHA384 0x0002 @@ -271,6 +275,25 @@ OPENSSL_EXPORT int EVP_HPKE_CTX_setup_recipient( const EVP_HPKE_AEAD *aead, const uint8_t *enc, size_t enc_len, const uint8_t *info, size_t info_len); +// EVP_HPKE_CTX_setup_recipient_with_shared_secret behaves like +// `EVP_HPKE_CTX_setup_recipient`, but takes the shared secret explicitly. +// +// WARNING: `shared_secret` must be the result of decapsulating the sender's +// `enc` value with the recipient's private key. Using the wrong shared secret +// will result in an `EVP_HPKE_CTX` that cannot decrypt the sender's messages. +// Additionally, an attacker with knowledge of `shared_secret` will be able to +// decrypt and forge encrypted messages. +// +// It returns one on success and zero on error. +// +// On success, callers may call `EVP_HPKE_CTX_open` to decrypt messages from the +// sender. Callers must then call `EVP_HPKE_CTX_cleanup` when done. On failure, +// calling `EVP_HPKE_CTX_cleanup` is safe, but not required. +OPENSSL_EXPORT int EVP_HPKE_CTX_setup_recipient_with_shared_secret( + EVP_HPKE_CTX *ctx, const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, + const EVP_HPKE_AEAD *aead, const uint8_t *shared_secret, + size_t shared_secret_len, const uint8_t *info, size_t info_len); + // EVP_HPKE_CTX_setup_auth_sender implements the SetupAuthS HPKE operation. It // behaves like `EVP_HPKE_CTX_setup_sender` but authenticates the resulting // context with `key`. diff --git a/third_party/boringssl/src/include/openssl/prefix_symbols.h b/third_party/boringssl/src/include/openssl/prefix_symbols.h index a328dfc..f59abe8 100644 --- a/third_party/boringssl/src/include/openssl/prefix_symbols.h +++ b/third_party/boringssl/src/include/openssl/prefix_symbols.h @@ -1057,6 +1057,7 @@ #pragma redefine_extname EVP_HPKE_CTX_setup_auth_sender BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_auth_sender) #pragma redefine_extname EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing) #pragma redefine_extname EVP_HPKE_CTX_setup_recipient BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_recipient) +#pragma redefine_extname EVP_HPKE_CTX_setup_recipient_with_shared_secret BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_recipient_with_shared_secret) #pragma redefine_extname EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_sender) #pragma redefine_extname EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #pragma redefine_extname EVP_HPKE_CTX_zero BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_zero) @@ -1066,6 +1067,7 @@ #pragma redefine_extname EVP_HPKE_KEM_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_id) #pragma redefine_extname EVP_HPKE_KEM_private_key_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_private_key_len) #pragma redefine_extname EVP_HPKE_KEM_public_key_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_public_key_len) +#pragma redefine_extname EVP_HPKE_KEM_shared_secret_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_shared_secret_len) #pragma redefine_extname EVP_HPKE_KEY_cleanup BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_cleanup) #pragma redefine_extname EVP_HPKE_KEY_copy BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_copy) #pragma redefine_extname EVP_HPKE_KEY_derive BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_derive) @@ -1899,7 +1901,7 @@ #pragma redefine_extname SSL_COMP_get_compression_methods BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_compression_methods) #pragma redefine_extname SSL_COMP_get_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_id) #pragma redefine_extname SSL_COMP_get_name BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_name) -#pragma redefine_extname SSL_CREDENTIAL_add1_trust_anchor_group_inclusion BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group_inclusion) +#pragma redefine_extname SSL_CREDENTIAL_add1_trust_anchor_group BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group) #pragma redefine_extname SSL_CREDENTIAL_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_dup_ref) #pragma redefine_extname SSL_CREDENTIAL_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_free) #pragma redefine_extname SSL_CREDENTIAL_get0_pre_shared_key_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_get0_pre_shared_key_id) @@ -4207,6 +4209,7 @@ #define EVP_HPKE_CTX_setup_auth_sender BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_auth_sender) #define EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing) #define EVP_HPKE_CTX_setup_recipient BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_recipient) +#define EVP_HPKE_CTX_setup_recipient_with_shared_secret BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_recipient_with_shared_secret) #define EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_sender) #define EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #define EVP_HPKE_CTX_zero BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_zero) @@ -4216,6 +4219,7 @@ #define EVP_HPKE_KEM_id BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_id) #define EVP_HPKE_KEM_private_key_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_private_key_len) #define EVP_HPKE_KEM_public_key_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_public_key_len) +#define EVP_HPKE_KEM_shared_secret_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_shared_secret_len) #define EVP_HPKE_KEY_cleanup BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_cleanup) #define EVP_HPKE_KEY_copy BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_copy) #define EVP_HPKE_KEY_derive BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_derive) @@ -5049,7 +5053,7 @@ #define SSL_COMP_get_compression_methods BORINGSSL_ADD_PREFIX(SSL_COMP_get_compression_methods) #define SSL_COMP_get_id BORINGSSL_ADD_PREFIX(SSL_COMP_get_id) #define SSL_COMP_get_name BORINGSSL_ADD_PREFIX(SSL_COMP_get_name) -#define SSL_CREDENTIAL_add1_trust_anchor_group_inclusion BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group_inclusion) +#define SSL_CREDENTIAL_add1_trust_anchor_group BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group) #define SSL_CREDENTIAL_dup_ref BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_dup_ref) #define SSL_CREDENTIAL_free BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_free) #define SSL_CREDENTIAL_get0_pre_shared_key_id BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_get0_pre_shared_key_id) diff --git a/third_party/boringssl/src/include/openssl/x509.h b/third_party/boringssl/src/include/openssl/x509.h index 0ef08e6..df57bb3 100644 --- a/third_party/boringssl/src/include/openssl/x509.h +++ b/third_party/boringssl/src/include/openssl/x509.h @@ -2311,8 +2311,6 @@ typedef struct DIST_POINT_NAME_st { GENERAL_NAMES *fullname; STACK_OF(X509_NAME_ENTRY) *relativename; } name; - // If relativename then this contains the full distribution point name - X509_NAME *dpname; } DIST_POINT_NAME; // DIST_POINT_NAME_new returns a newly-allocated, empty `DIST_POINT_NAME` @@ -5316,8 +5314,10 @@ BORINGSSL_MAKE_DELETER(BASIC_CONSTRAINTS, BASIC_CONSTRAINTS_free) // TODO(davidben): Move this to conf.h and rename to CONF_VALUE_free. BORINGSSL_MAKE_DELETER(CONF_VALUE, X509V3_conf_free) BORINGSSL_MAKE_DELETER(DIST_POINT, DIST_POINT_free) +BORINGSSL_MAKE_DELETER(DIST_POINT_NAME, DIST_POINT_NAME_free) BORINGSSL_MAKE_DELETER(GENERAL_NAME, GENERAL_NAME_free) BORINGSSL_MAKE_DELETER(GENERAL_SUBTREE, GENERAL_SUBTREE_free) +BORINGSSL_MAKE_DELETER(ISSUING_DIST_POINT, ISSUING_DIST_POINT_free) BORINGSSL_MAKE_DELETER(NAME_CONSTRAINTS, NAME_CONSTRAINTS_free) BORINGSSL_MAKE_DELETER(NETSCAPE_SPKI, NETSCAPE_SPKI_free) BORINGSSL_MAKE_DELETER(NOTICEREF, NOTICEREF_free) diff --git a/tool/REVISION b/tool/REVISION index 978305a..41a6b0d 100644 --- a/tool/REVISION +++ b/tool/REVISION @@ -1 +1 @@ -e98a6564575520260ef95b2389e5d63a24917093 +dd73e69a4e86fa178a4d19033c691e9b42cc1088