// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "signature_algorithm.h" #include <openssl/bytestring.h> #include <openssl/digest.h> #include "input.h" #include "parse_values.h" #include "parser.h" BSSL_NAMESPACE_BEGIN namespace { // From RFC 5912: // // sha1WithRSAEncryption OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) // pkcs-1(1) 5 } // // In dotted notation: 1.2.840.113549.1.1.5 const uint8_t kOidSha1WithRsaEncryption[] = …; // sha1WithRSASignature is a deprecated equivalent of // sha1WithRSAEncryption. // // It originates from the NIST Open Systems Environment (OSE) // Implementor's Workshop (OIW). // // It is supported for compatibility with Microsoft's certificate APIs and // tools, particularly makecert.exe, which default(ed/s) to this OID for SHA-1. // // See also: https://bugzilla.mozilla.org/show_bug.cgi?id=1042479 // // In dotted notation: 1.3.14.3.2.29 const uint8_t kOidSha1WithRsaSignature[] = …; // From RFC 5912: // // pkcs-1 OBJECT IDENTIFIER ::= // { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } // From RFC 5912: // // sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 11 } // // In dotted notation: 1.2.840.113549.1.1.11 const uint8_t kOidSha256WithRsaEncryption[] = …; // From RFC 5912: // // sha384WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 12 } // // In dotted notation: 1.2.840.113549.1.1.11 const uint8_t kOidSha384WithRsaEncryption[] = …; // From RFC 5912: // // sha512WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 13 } // // In dotted notation: 1.2.840.113549.1.1.13 const uint8_t kOidSha512WithRsaEncryption[] = …; // From RFC 5912: // // ecdsa-with-SHA1 OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) ansi-X9-62(10045) // signatures(4) 1 } // // In dotted notation: 1.2.840.10045.4.1 const uint8_t kOidEcdsaWithSha1[] = …; // From RFC 5912: // // ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) // ecdsa-with-SHA2(3) 2 } // // In dotted notation: 1.2.840.10045.4.3.2 const uint8_t kOidEcdsaWithSha256[] = …; // From RFC 5912: // // ecdsa-with-SHA384 OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) // ecdsa-with-SHA2(3) 3 } // // In dotted notation: 1.2.840.10045.4.3.3 const uint8_t kOidEcdsaWithSha384[] = …; // From RFC 5912: // // ecdsa-with-SHA512 OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) // ecdsa-with-SHA2(3) 4 } // // In dotted notation: 1.2.840.10045.4.3.4 const uint8_t kOidEcdsaWithSha512[] = …; // From RFC 5912: // // id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } // // In dotted notation: 1.2.840.113549.1.1.10 const uint8_t kOidRsaSsaPss[] = …; // From RFC 5912: // // id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } // // In dotted notation: 1.2.840.113549.1.1.8 const uint8_t kOidMgf1[] = …; // Returns true if the entirety of the input is a NULL value. [[nodiscard]] bool IsNull(der::Input input) { … } [[nodiscard]] bool IsNullOrEmpty(der::Input input) { … } // Parses a MaskGenAlgorithm as defined by RFC 5912: // // MaskGenAlgorithm ::= AlgorithmIdentifier{ALGORITHM, // {PKCS1MGFAlgorithms}} // // mgf1SHA1 MaskGenAlgorithm ::= { // algorithm id-mgf1, // parameters HashAlgorithm : sha1Identifier // } // // -- // -- Define the set of mask generation functions // -- // -- If the identifier is id-mgf1, any of the listed hash // -- algorithms may be used. // -- // // PKCS1MGFAlgorithms ALGORITHM ::= { // { IDENTIFIER id-mgf1 PARAMS TYPE HashAlgorithm ARE required }, // ... // } // // Note that the possible mask gen algorithms is extensible. However at present // the only function supported is MGF1, as that is the singular mask gen // function defined by RFC 4055 / RFC 5912. [[nodiscard]] bool ParseMaskGenAlgorithm(const der::Input input, DigestAlgorithm *mgf1_hash) { … } // Parses the parameters for an RSASSA-PSS signature algorithm, as defined by // RFC 5912: // // sa-rsaSSA-PSS SIGNATURE-ALGORITHM ::= { // IDENTIFIER id-RSASSA-PSS // PARAMS TYPE RSASSA-PSS-params ARE required // HASHES { mda-sha1 | mda-sha224 | mda-sha256 | mda-sha384 // | mda-sha512 } // PUBLIC-KEYS { pk-rsa | pk-rsaSSA-PSS } // SMIME-CAPS { IDENTIFIED BY id-RSASSA-PSS } // } // // RSASSA-PSS-params ::= SEQUENCE { // hashAlgorithm [0] HashAlgorithm DEFAULT sha1Identifier, // maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, // saltLength [2] INTEGER DEFAULT 20, // trailerField [3] INTEGER DEFAULT 1 // } // // Which is to say the parameters MUST be present, and of type // RSASSA-PSS-params. Additionally, we only support the RSA-PSS parameter // combinations representable by TLS 1.3 (RFC 8446). // // Note also that DER encoding (ITU-T X.690 section 11.5) prohibits // specifying default values explicitly. The parameter should instead be // omitted to indicate a default value. std::optional<SignatureAlgorithm> ParseRsaPss(der::Input params) { … } } // namespace [[nodiscard]] bool ParseAlgorithmIdentifier(der::Input input, der::Input *algorithm, der::Input *parameters) { … } [[nodiscard]] bool ParseHashAlgorithm(der::Input input, DigestAlgorithm *out) { … } std::optional<SignatureAlgorithm> ParseSignatureAlgorithm( der::Input algorithm_identifier) { … } std::optional<DigestAlgorithm> GetTlsServerEndpointDigestAlgorithm( SignatureAlgorithm alg) { … } BSSL_NAMESPACE_END