// 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 <memory> #include <gtest/gtest.h> #include "input.h" #include "parser.h" BSSL_NAMESPACE_BEGIN namespace { // Parses a SignatureAlgorithm given an empty DER input. TEST(SignatureAlgorithmTest, ParseDerEmpty) { … } // Parses a SignatureAlgorithm given invalid DER input. TEST(SignatureAlgorithmTest, ParseDerBogus) { … } // Parses a SignatureAlgorithm with an unsupported algorithm OID. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 66 (bogus) TEST(SignatureAlgorithmTest, ParseDerRsaPssUnsupportedAlgorithmOid) { … } // Parses a sha1WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 // NULL TEST(SignatureAlgorithmTest, ParseDerSha1WithRSAEncryptionNullParams) { … } // Parses a sha1WithRSAEncryption which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 TEST(SignatureAlgorithmTest, ParseDerSha1WithRSAEncryptionNoParams) { … } // Parses a sha1WithRSAEncryption which contains an unexpected parameters // field. Instead of being NULL it is an integer. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 // INTEGER 0 TEST(SignatureAlgorithmTest, ParseDerSha1WithRSAEncryptionNonNullParams) { … } // Parses a sha1WithRSASignature which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.3.14.3.2.29 // NULL TEST(SignatureAlgorithmTest, ParseDerSha1WithRSASignatureNullParams) { … } // Parses a sha1WithRSASignature which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.3.14.3.2.29 TEST(SignatureAlgorithmTest, ParseDerSha1WithRSASignatureNoParams) { … } // Parses a sha1WithRSAEncryption which contains values after the sequence. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 // NULL // INTEGER 0 TEST(SignatureAlgorithmTest, ParseDerSha1WithRsaEncryptionDataAfterSequence) { … } // Parses a sha1WithRSAEncryption which contains a bad NULL parameters field. // Normally NULL is encoded as {0x05, 0x00} (tag for NULL and length of 0). Here // NULL is encoded as having a length of 1 instead, followed by data 0x09. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 // NULL TEST(SignatureAlgorithmTest, ParseDerSha1WithRSAEncryptionBadNullParams) { … } // Parses a sha1WithRSAEncryption which contains a NULL parameters field, // followed by an integer. // // SEQUENCE (3 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.5 // NULL // INTEGER 0 TEST(SignatureAlgorithmTest, ParseDerSha1WithRSAEncryptionNullParamsThenInteger) { … } // Parses a SignatureAlgorithm given DER which does not encode a sequence. // // INTEGER 0 TEST(SignatureAlgorithmTest, ParseDerNotASequence) { … } // Parses a sha256WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.11 // NULL TEST(SignatureAlgorithmTest, ParseDerSha256WithRSAEncryptionNullParams) { … } // Parses a sha256WithRSAEncryption which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.11 TEST(SignatureAlgorithmTest, ParseDerSha256WithRSAEncryptionNoParams) { … } // Parses a sha384WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.12 // NULL TEST(SignatureAlgorithmTest, ParseDerSha384WithRSAEncryptionNullParams) { … } // Parses a sha384WithRSAEncryption which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.12 TEST(SignatureAlgorithmTest, ParseDerSha384WithRSAEncryptionNoParams) { … } // Parses a sha512WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.13 // NULL TEST(SignatureAlgorithmTest, ParseDerSha512WithRSAEncryptionNullParams) { … } // Parses a sha512WithRSAEncryption which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.13 TEST(SignatureAlgorithmTest, ParseDerSha512WithRSAEncryptionNoParams) { … } // Parses a sha224WithRSAEncryption which contains a NULL parameters field. // This fails because the parsing code does not enumerate this OID (even though // it is in fact valid). // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.14 // NULL TEST(SignatureAlgorithmTest, ParseDerSha224WithRSAEncryptionNullParams) { … } // Parses a ecdsa-with-SHA1 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.1 TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA1NoParams) { … } // Parses a ecdsa-with-SHA1 which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.1 // NULL TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA1NullParams) { … } // Parses a ecdsa-with-SHA256 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.2 TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA256NoParams) { … } // Parses a ecdsa-with-SHA256 which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.2 // NULL TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA256NullParams) { … } // Parses a ecdsa-with-SHA384 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.3 TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA384NoParams) { … } // Parses a ecdsa-with-SHA384 which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.3 // NULL TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA384NullParams) { … } // Parses a ecdsa-with-SHA512 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.4 TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA512NoParams) { … } // Parses a ecdsa-with-SHA512 which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.10045.4.3.4 // NULL TEST(SignatureAlgorithmTest, ParseDerEcdsaWithSHA512NullParams) { … } // Parses a rsaPss algorithm that uses SHA256 and a salt length of 32. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (4 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 // NULL // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 // NULL // [2] (1 elem) // INTEGER 32 TEST(SignatureAlgorithmTest, ParseDerRsaPss) { … } // Parses a rsaPss algorithm that has an empty parameters. This encodes the // default, SHA-1, which we do not support. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (0 elem) TEST(SignatureAlgorithmTest, ParseDerRsaPssEmptyParams) { … } // Parses a rsaPss algorithm that has NULL parameters. This fails. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssNullParams) { … } // Parses a rsaPss algorithm that has no parameters. This fails. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 TEST(SignatureAlgorithmTest, ParseDerRsaPssNoParams) { … } // Parses a rsaPss algorithm that has data after the parameters sequence. // // SEQUENCE (3 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (0 elem) // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssDataAfterParams) { … } // Parses a rsaPss algorithm that has unrecognized data (NULL) within the // parameters sequence. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (2 elem) // [2] (1 elem) // INTEGER 23 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssNullInsideParams) { … } // Parses a rsaPss algorithm that has an unsupported trailer value (2). Only // trailer values of 1 are allowed by RFC 4055. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [3] (1 elem) // INTEGER 2 TEST(SignatureAlgorithmTest, ParseDerRsaPssUnsupportedTrailer) { … } // Parses a rsaPss algorithm that has extra data appearing after the trailer in // the [3] section. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [3] (2 elem) // INTEGER 1 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssBadTrailer) { … } // Parses a rsaPss algorithm that uses SHA384 for the hash, and leaves the rest // as defaults, specifying a SHA-1 MGF-1 hash. This fails because we require // the hashes match. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.2 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssNonDefaultHash) { … } // Parses a rsaPss algorithm that uses an invalid hash algorithm (twiddled the // bytes for the SHA-384 OID a bit). // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [0] (1 elem) // SEQUENCE (1 elem) // OBJECT IDENTIFIER 2.16.840.2.103.19.4.2.2 TEST(SignatureAlgorithmTest, ParseDerRsaPssUnsupportedHashOid) { … } // Parses a rsaPss algorithm that uses SHA512 MGF1 for the mask gen, and // defaults (SHA-1) for the rest. This fails because we require the hashes // match. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssNonDefaultMaskGen) { … } // Parses a rsaPss algorithm that uses a mask gen with an unrecognized OID // (twiddled some of the bits). // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113618.1.2.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssUnsupportedMaskGen) { … } // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA512 for the // MGF1. This fails because we require the hashes match. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (2 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 // NULL // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssNonDefaultHashAndMaskGen) { … } // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA256 for the // MGF1, and a salt length of 10. This fails because we require a standard salt // length. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (3 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 // NULL // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 // NULL // [2] (1 elem) // INTEGER 10 TEST(SignatureAlgorithmTest, ParseDerRsaPssNonDefaultHashAndMaskGenAndSalt) { … } // Parses a rsaPss algorithm that specifies default hash (SHA1). // It is invalid to specify the default. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.3.14.3.2.26 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssSpecifiedDefaultHash) { … } // Parses a rsaPss algorithm that specifies default mask gen algorithm (SHA1). // It is invalid to specify the default. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.3.14.3.2.26 // NULL TEST(SignatureAlgorithmTest, ParseDerRsaPssSpecifiedDefaultMaskGen) { … } // Parses a rsaPss algorithm that specifies default salt length. // It is invalid to specify the default. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (1 elem) // [2] (1 elem) // INTEGER 20 TEST(SignatureAlgorithmTest, ParseDerRsaPssSpecifiedDefaultSaltLength) { … } // Parses a rsaPss algorithm that specifies default trailer field. // It is invalid to specify the default. TEST(SignatureAlgorithmTest, ParseDerRsaPssSpecifiedDefaultTrailerField) { … } // Parses a rsaPss algorithm that specifies multiple default parameter values. // It is invalid to specify a default value. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 // SEQUENCE (3 elem) // [0] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.3.14.3.2.26 // NULL // [1] (1 elem) // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.3.14.3.2.26 // NULL // [2] (1 elem) // INTEGER 20 // [3] (1 elem) // INTEGER 1 TEST(SignatureAlgorithmTest, ParseDerRsaPssMultipleDefaultParameterValues) { … } TEST(SignatureAlgorithmTest, ParseRsaPss) { … } // Parses a md5WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.4 // NULL TEST(SignatureAlgorithmTest, ParseDerMd5WithRsaEncryptionNullParams) { … } // Parses a md4WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.3 // NULL TEST(SignatureAlgorithmTest, ParseDerMd4WithRsaEncryptionNullParams) { … } // Parses a md2WithRSAEncryption which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.113549.1.1.2 // NULL TEST(SignatureAlgorithmTest, ParseDerMd2WithRsaEncryptionNullParams) { … } // Parses a dsaWithSha1 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 1.2.840.10040.4.3 TEST(SignatureAlgorithmTest, ParseDerDsaWithSha1NoParams) { … } // Parses a dsaWithSha1 which contains a NULL parameters field. // // SEQUENCE (2 elem) // OBJECT IDENTIFIER 1.2.840.10040.4.3 // NULL TEST(SignatureAlgorithmTest, ParseDerDsaWithSha1NullParams) { … } // Parses a dsaWithSha256 which contains no parameters field. // // SEQUENCE (1 elem) // OBJECT IDENTIFIER 2.16.840.1.101.3.4.3.2 TEST(SignatureAlgorithmTest, ParseDerDsaWithSha256NoParams) { … } } // namespace BSSL_NAMESPACE_END