| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include "parse_certificate.h" |
| 16 |
| 17 | #include <gtest/gtest.h> |
| 18 | #include <openssl/pool.h> |
| 19 | #include "cert_errors.h" |
| 20 | #include "general_names.h" |
| 21 | #include "input.h" |
| 22 | #include "parsed_certificate.h" |
| 23 | #include "test_helpers.h" |
| 24 |
| 25 | BSSL_NAMESPACE_BEGIN |
| 26 |
| 27 | namespace { |
| 28 |
| 29 | // Pretty-prints a GeneralizedTime as a human-readable string for use in test |
| 30 | // expectations (it is more readable to specify the expected results as a |
| 31 | // string). |
| 32 | std::string ToString(const der::GeneralizedTime &time) { |
| 33 | std::ostringstream pretty_time; |
| 34 | pretty_time << "year=" << int{time.year} << ", month=" << int{time.month} |
| 35 | << ", day=" << int{time.day} << ", hours=" << int{time.hours} |
| 36 | << ", minutes=" << int{time.minutes} |
| 37 | << ", seconds=" << int{time.seconds}; |
| 38 | return pretty_time.str(); |
| 39 | } |
| 40 |
| 41 | std::string GetFilePath(const std::string &file_name) { |
| 42 | return std::string("testdata/parse_certificate_unittest/") + file_name; |
| 43 | } |
| 44 |
| 45 | // Loads certificate data and expectations from the PEM file |file_name|. |
| 46 | // Verifies that parsing the Certificate matches expectations: |
| 47 | // * If expected to fail, emits the expected errors |
| 48 | // * If expected to succeeds, the parsed fields match expectations |
| 49 | void RunCertificateTest(const std::string &file_name) { |
| 50 | std::string data; |
| 51 | std::string expected_errors; |
| 52 | std::string expected_tbs_certificate; |
| 53 | std::string expected_signature_algorithm; |
| 54 | std::string expected_signature; |
| 55 |
| 56 | // Read the certificate data and test expectations from a single PEM file. |
| 57 | const PemBlockMapping mappings[] = { |
| 58 | {"CERTIFICATE", &data}, |
| 59 | {"ERRORS", &expected_errors, true /*optional*/}, |
| 60 | {"SIGNATURE", &expected_signature, true /*optional*/}, |
| 61 | {"SIGNATURE ALGORITHM", &expected_signature_algorithm, true /*optional*/}, |
| 62 | {"TBS CERTIFICATE", &expected_tbs_certificate, true /*optional*/}, |
| 63 | }; |
| 64 | std::string test_file_path = GetFilePath(file_name); |
| 65 | ASSERT_TRUE(ReadTestDataFromPemFile(test_file_path, mappings)); |
| 66 |
| 67 | // Note that empty expected_errors doesn't necessarily mean success. |
| 68 | bool expected_result = !expected_tbs_certificate.empty(); |
| 69 |
| 70 | // Parsing the certificate. |
| 71 | der::Input tbs_certificate_tlv; |
| 72 | der::Input signature_algorithm_tlv; |
| 73 | der::BitString signature_value; |
| 74 | CertErrors errors; |
| 75 | bool actual_result = |
| 76 | ParseCertificate(der::Input(data), &tbs_certificate_tlv, |
| 77 | &signature_algorithm_tlv, &signature_value, &errors); |
| 78 |
| 79 | EXPECT_EQ(expected_result, actual_result); |
| 80 | VerifyCertErrors(expected_errors, errors, test_file_path); |
| 81 |
| 82 | // Ensure that the parsed certificate matches expectations. |
| 83 | if (expected_result && actual_result) { |
| 84 | EXPECT_EQ(0, signature_value.unused_bits()); |
| 85 | EXPECT_EQ(der::Input(expected_signature), signature_value.bytes()); |
| 86 | EXPECT_EQ(der::Input(expected_signature_algorithm), |
| 87 | signature_algorithm_tlv); |
| 88 | EXPECT_EQ(der::Input(expected_tbs_certificate), tbs_certificate_tlv); |
| 89 | } |
| 90 | } |
| 91 |
| 92 | // Tests parsing a Certificate. |
| 93 | TEST(ParseCertificateTest, Version3) { |
| 94 | RunCertificateTest("cert_version3.pem"); |
| 95 | } |
| 96 |
| 97 | // Tests parsing a simplified Certificate-like structure (the sub-fields for |
| 98 | // algorithm and tbsCertificate are not actually valid, but ParseCertificate() |
| 99 | // doesn't check them) |
| 100 | TEST(ParseCertificateTest, Skeleton) { |
| 101 | RunCertificateTest("cert_skeleton.pem"); |
| 102 | } |
| 103 |
| 104 | // Tests parsing a Certificate that is not a sequence fails. |
| 105 | TEST(ParseCertificateTest, NotSequence) { |
| 106 | RunCertificateTest("cert_not_sequence.pem"); |
| 107 | } |
| 108 |
| 109 | // Tests that uncomsumed data is not allowed after the main SEQUENCE. |
| 110 | TEST(ParseCertificateTest, DataAfterSignature) { |
| 111 | RunCertificateTest("cert_data_after_signature.pem"); |
| 112 | } |
| 113 |
| 114 | // Tests that parsing fails if the signature BIT STRING is missing. |
| 115 | TEST(ParseCertificateTest, MissingSignature) { |
| 116 | RunCertificateTest("cert_missing_signature.pem"); |
| 117 | } |
| 118 |
| 119 | // Tests that parsing fails if the signature is present but not a BIT STRING. |
| 120 | TEST(ParseCertificateTest, SignatureNotBitString) { |
| 121 | RunCertificateTest("cert_signature_not_bit_string.pem"); |
| 122 | } |
| 123 |
| 124 | // Tests that parsing fails if the main SEQUENCE is empty (missing all the |
| 125 | // fields). |
| 126 | TEST(ParseCertificateTest, EmptySequence) { |
| 127 | RunCertificateTest("cert_empty_sequence.pem"); |
| 128 | } |
| 129 |
| 130 | // Tests what happens when the signature algorithm is present, but has the wrong |
| 131 | // tag. |
| 132 | TEST(ParseCertificateTest, AlgorithmNotSequence) { |
| 133 | RunCertificateTest("cert_algorithm_not_sequence.pem"); |
| 134 | } |
| 135 |
| 136 | // Loads tbsCertificate data and expectations from the PEM file |file_name|. |
| 137 | // Verifies that parsing the TBSCertificate succeeds, and each parsed field |
| 138 | // matches the expectations. |
| 139 | // |
| 140 | // TODO(eroman): Get rid of the |expected_version| parameter -- this should be |
| 141 | // encoded in the test expectations file. |
| 142 | void RunTbsCertificateTestGivenVersion(const std::string &file_name, |
| 143 | CertificateVersion expected_version) { |
| 144 | std::string data; |
| 145 | std::string expected_serial_number; |
| 146 | std::string expected_signature_algorithm; |
| 147 | std::string expected_issuer; |
| 148 | std::string expected_validity_not_before; |
| 149 | std::string expected_validity_not_after; |
| 150 | std::string expected_subject; |
| 151 | std::string expected_spki; |
| 152 | std::string expected_issuer_unique_id; |
| 153 | std::string expected_subject_unique_id; |
| 154 | std::string expected_extensions; |
| 155 | std::string expected_errors; |
| 156 |
| 157 | // Read the certificate data and test expectations from a single PEM file. |
| 158 | const PemBlockMapping mappings[] = { |
| 159 | {"TBS CERTIFICATE", &data}, |
| 160 | {"SIGNATURE ALGORITHM", &expected_signature_algorithm, true}, |
| 161 | {"SERIAL NUMBER", &expected_serial_number, true}, |
| 162 | {"ISSUER", &expected_issuer, true}, |
| 163 | {"VALIDITY NOTBEFORE", &expected_validity_not_before, true}, |
| 164 | {"VALIDITY NOTAFTER", &expected_validity_not_after, true}, |
| 165 | {"SUBJECT", &expected_subject, true}, |
| 166 | {"SPKI", &expected_spki, true}, |
| 167 | {"ISSUER UNIQUE ID", &expected_issuer_unique_id, true}, |
| 168 | {"SUBJECT UNIQUE ID", &expected_subject_unique_id, true}, |
| 169 | {"EXTENSIONS", &expected_extensions, true}, |
| 170 | {"ERRORS", &expected_errors, true}, |
| 171 | }; |
| 172 | std::string test_file_path = GetFilePath(file_name); |
| 173 | ASSERT_TRUE(ReadTestDataFromPemFile(test_file_path, mappings)); |
| 174 |
| 175 | bool expected_result = !expected_spki.empty(); |
| 176 |
| 177 | ParsedTbsCertificate parsed; |
| 178 | CertErrors errors; |
| 179 | bool actual_result = |
| 180 | ParseTbsCertificate(der::Input(data), {}, &parsed, &errors); |
| 181 |
| 182 | EXPECT_EQ(expected_result, actual_result); |
| 183 | VerifyCertErrors(expected_errors, errors, test_file_path); |
| 184 |
| 185 | if (!expected_result || !actual_result) { |
| 186 | return; |
| 187 | } |
| 188 |
| 189 | // Ensure that the ParsedTbsCertificate matches expectations. |
| 190 | EXPECT_EQ(expected_version, parsed.version); |
| 191 |
| 192 | EXPECT_EQ(der::Input(expected_serial_number), parsed.serial_number); |
| 193 | EXPECT_EQ(der::Input(expected_signature_algorithm), |
| 194 | parsed.signature_algorithm_tlv); |
| 195 |
| 196 | EXPECT_EQ(der::Input(expected_issuer), parsed.issuer_tlv); |
| 197 |
| 198 | // In the test expectations PEM file, validity is described as a |
| 199 | // textual string of the parsed value (rather than as DER). |
| 200 | EXPECT_EQ(expected_validity_not_before, ToString(parsed.validity_not_before)); |
| 201 | EXPECT_EQ(expected_validity_not_after, ToString(parsed.validity_not_after)); |
| 202 |
| 203 | EXPECT_EQ(der::Input(expected_subject), parsed.subject_tlv); |
| 204 | EXPECT_EQ(der::Input(expected_spki), parsed.spki_tlv); |
| 205 |
| 206 | EXPECT_EQ(!expected_issuer_unique_id.empty(), |
| 207 | parsed.issuer_unique_id.has_value()); |
| 208 | if (parsed.issuer_unique_id.has_value()) { |
| 209 | EXPECT_EQ(der::Input(expected_issuer_unique_id), |
| 210 | parsed.issuer_unique_id->bytes()); |
| 211 | } |
| 212 | EXPECT_EQ(!expected_subject_unique_id.empty(), |
| 213 | parsed.subject_unique_id.has_value()); |
| 214 | if (parsed.subject_unique_id.has_value()) { |
| 215 | EXPECT_EQ(der::Input(expected_subject_unique_id), |
| 216 | parsed.subject_unique_id->bytes()); |
| 217 | } |
| 218 |
| 219 | EXPECT_EQ(!expected_extensions.empty(), parsed.extensions_tlv.has_value()); |
| 220 | if (parsed.extensions_tlv) { |
| 221 | EXPECT_EQ(der::Input(expected_extensions), parsed.extensions_tlv.value()); |
| 222 | } |
| 223 | } |
| 224 |
| 225 | void RunTbsCertificateTest(const std::string &file_name) { |
| 226 | RunTbsCertificateTestGivenVersion(file_name, CertificateVersion::V3); |
| 227 | } |
| 228 |
| 229 | // Tests parsing a TBSCertificate for v3 that contains no optional fields. |
| 230 | TEST(ParseTbsCertificateTest, Version3NoOptionals) { |
| 231 | RunTbsCertificateTest("tbs_v3_no_optionals.pem"); |
| 232 | } |
| 233 |
| 234 | // Tests parsing a TBSCertificate for v3 that contains extensions. |
| 235 | TEST(ParseTbsCertificateTest, Version3WithExtensions) { |
| 236 | RunTbsCertificateTest("tbs_v3_extensions.pem"); |
| 237 | } |
| 238 |
| 239 | // Tests parsing a TBSCertificate which lacks a version number (causing it to |
| 240 | // default to v1). |
| 241 | TEST(ParseTbsCertificateTest, Version1) { |
| 242 | RunTbsCertificateTestGivenVersion("tbs_v1.pem", CertificateVersion::V1); |
| 243 | } |
| 244 |
| 245 | // The version was set to v1 explicitly rather than omitting the version field. |
| 246 | TEST(ParseTbsCertificateTest, ExplicitVersion1) { |
| 247 | RunTbsCertificateTest("tbs_explicit_v1.pem"); |
| 248 | } |
| 249 |
| 250 | // Extensions are not defined in version 1. |
| 251 | TEST(ParseTbsCertificateTest, Version1WithExtensions) { |
| 252 | RunTbsCertificateTest("tbs_v1_extensions.pem"); |
| 253 | } |
| 254 |
| 255 | // Extensions are not defined in version 2. |
| 256 | TEST(ParseTbsCertificateTest, Version2WithExtensions) { |
| 257 | RunTbsCertificateTest("tbs_v2_extensions.pem"); |
| 258 | } |
| 259 |
| 260 | // A boring version 2 certificate with none of the optional fields. |
| 261 | TEST(ParseTbsCertificateTest, Version2NoOptionals) { |
| 262 | RunTbsCertificateTestGivenVersion("tbs_v2_no_optionals.pem", |
| 263 | CertificateVersion::V2); |
| 264 | } |
| 265 |
| 266 | // A version 2 certificate with an issuer unique ID field. |
| 267 | TEST(ParseTbsCertificateTest, Version2IssuerUniqueId) { |
| 268 | RunTbsCertificateTestGivenVersion("tbs_v2_issuer_unique_id.pem", |
| 269 | CertificateVersion::V2); |
| 270 | } |
| 271 |
| 272 | // A version 2 certificate with both a issuer and subject unique ID field. |
| 273 | TEST(ParseTbsCertificateTest, Version2IssuerAndSubjectUniqueId) { |
| 274 | RunTbsCertificateTestGivenVersion("tbs_v2_issuer_and_subject_unique_id.pem", |
| 275 | CertificateVersion::V2); |
| 276 | } |
| 277 |
| 278 | // A version 3 certificate with all of the optional fields (issuer unique id, |
| 279 | // subject unique id, and extensions). |
| 280 | TEST(ParseTbsCertificateTest, Version3AllOptionals) { |
| 281 | RunTbsCertificateTest("tbs_v3_all_optionals.pem"); |
| 282 | } |
| 283 |
| 284 | // The version was set to v4, which is unrecognized. |
| 285 | TEST(ParseTbsCertificateTest, Version4) { RunTbsCertificateTest("tbs_v4.pem"); } |
| 286 |
| 287 | // Tests that extraneous data after extensions in a v3 is rejected. |
| 288 | TEST(ParseTbsCertificateTest, Version3DataAfterExtensions) { |
| 289 | RunTbsCertificateTest("tbs_v3_data_after_extensions.pem"); |
| 290 | } |
| 291 |
| 292 | // Tests using a real-world certificate (whereas the other tests are fabricated |
| 293 | // (and in fact invalid) data. |
| 294 | TEST(ParseTbsCertificateTest, Version3Real) { |
| 295 | RunTbsCertificateTest("tbs_v3_real.pem"); |
| 296 | } |
| 297 |
| 298 | // Parses a TBSCertificate whose "validity" field expresses both notBefore |
| 299 | // and notAfter using UTCTime. |
| 300 | TEST(ParseTbsCertificateTest, ValidityBothUtcTime) { |
| 301 | RunTbsCertificateTest("tbs_validity_both_utc_time.pem"); |
| 302 | } |
| 303 |
| 304 | // Parses a TBSCertificate whose "validity" field expresses both notBefore |
| 305 | // and notAfter using GeneralizedTime. |
| 306 | TEST(ParseTbsCertificateTest, ValidityBothGeneralizedTime) { |
| 307 | RunTbsCertificateTest("tbs_validity_both_generalized_time.pem"); |
| 308 | } |
| 309 |
| 310 | // Parses a TBSCertificate whose "validity" field expresses notBefore using |
| 311 | // UTCTime and notAfter using GeneralizedTime. |
| 312 | TEST(ParseTbsCertificateTest, ValidityUTCTimeAndGeneralizedTime) { |
| 313 | RunTbsCertificateTest("tbs_validity_utc_time_and_generalized_time.pem"); |
| 314 | } |
| 315 |
| 316 | // Parses a TBSCertificate whose validity" field expresses notBefore using |
| 317 | // GeneralizedTime and notAfter using UTCTime. Also of interest, notBefore > |
| 318 | // notAfter. Parsing will succeed, however no time can satisfy this constraint. |
| 319 | TEST(ParseTbsCertificateTest, ValidityGeneralizedTimeAndUTCTime) { |
| 320 | RunTbsCertificateTest("tbs_validity_generalized_time_and_utc_time.pem"); |
| 321 | } |
| 322 |
| 323 | // Parses a TBSCertificate whose "validity" field does not strictly follow |
| 324 | // the DER rules (and fails to be parsed). |
| 325 | TEST(ParseTbsCertificateTest, ValidityRelaxed) { |
| 326 | RunTbsCertificateTest("tbs_validity_relaxed.pem"); |
| 327 | } |
| 328 |
| 329 | // Parses a KeyUsage with a single 0 bit. |
| 330 | TEST(ParseKeyUsageTest, OneBitAllZeros) { |
| 331 | const uint8_t der[] = { |
| 332 | 0x03, 0x02, // BIT STRING |
| 333 | 0x07, // Number of unused bits |
| 334 | 0x00, // bits |
| 335 | }; |
| 336 |
| 337 | der::BitString key_usage; |
| 338 | ASSERT_FALSE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 339 | } |
| 340 |
| 341 | // Parses a KeyUsage with 32 bits that are all 0. |
| 342 | TEST(ParseKeyUsageTest, 32BitsAllZeros) { |
| 343 | const uint8_t der[] = { |
| 344 | 0x03, 0x05, // BIT STRING |
| 345 | 0x00, // Number of unused bits |
| 346 | 0x00, 0x00, 0x00, 0x00, |
| 347 | }; |
| 348 |
| 349 | der::BitString key_usage; |
| 350 | ASSERT_FALSE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 351 | } |
| 352 |
| 353 | // Parses a KeyUsage with 32 bits, one of which is 1 (but not in recognized |
| 354 | // set). |
| 355 | TEST(ParseKeyUsageTest, 32BitsOneSet) { |
| 356 | const uint8_t der[] = { |
| 357 | 0x03, 0x05, // BIT STRING |
| 358 | 0x00, // Number of unused bits |
| 359 | 0x00, 0x00, 0x00, 0x02, |
| 360 | }; |
| 361 |
| 362 | der::BitString key_usage; |
| 363 | ASSERT_TRUE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 364 |
| 365 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE)); |
| 366 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_NON_REPUDIATION)); |
| 367 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_ENCIPHERMENT)); |
| 368 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DATA_ENCIPHERMENT)); |
| 369 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_AGREEMENT)); |
| 370 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_CERT_SIGN)); |
| 371 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_CRL_SIGN)); |
| 372 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_ENCIPHER_ONLY)); |
| 373 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DECIPHER_ONLY)); |
| 374 | } |
| 375 |
| 376 | // Parses a KeyUsage containing bit string 101. |
| 377 | TEST(ParseKeyUsageTest, ThreeBits) { |
| 378 | const uint8_t der[] = { |
| 379 | 0x03, 0x02, // BIT STRING |
| 380 | 0x05, // Number of unused bits |
| 381 | 0xA0, // bits |
| 382 | }; |
| 383 |
| 384 | der::BitString key_usage; |
| 385 | ASSERT_TRUE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 386 |
| 387 | EXPECT_TRUE(key_usage.AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE)); |
| 388 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_NON_REPUDIATION)); |
| 389 | EXPECT_TRUE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_ENCIPHERMENT)); |
| 390 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DATA_ENCIPHERMENT)); |
| 391 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_AGREEMENT)); |
| 392 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_CERT_SIGN)); |
| 393 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_CRL_SIGN)); |
| 394 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_ENCIPHER_ONLY)); |
| 395 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DECIPHER_ONLY)); |
| 396 | } |
| 397 |
| 398 | // Parses a KeyUsage containing DECIPHER_ONLY, which is the |
| 399 | // only bit that doesn't fit in the first byte. |
| 400 | TEST(ParseKeyUsageTest, DecipherOnly) { |
| 401 | const uint8_t der[] = { |
| 402 | 0x03, 0x03, // BIT STRING |
| 403 | 0x07, // Number of unused bits |
| 404 | 0x00, 0x80, // bits |
| 405 | }; |
| 406 |
| 407 | der::BitString key_usage; |
| 408 | ASSERT_TRUE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 409 |
| 410 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE)); |
| 411 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_NON_REPUDIATION)); |
| 412 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_ENCIPHERMENT)); |
| 413 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_DATA_ENCIPHERMENT)); |
| 414 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_AGREEMENT)); |
| 415 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_KEY_CERT_SIGN)); |
| 416 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_CRL_SIGN)); |
| 417 | EXPECT_FALSE(key_usage.AssertsBit(KEY_USAGE_BIT_ENCIPHER_ONLY)); |
| 418 | EXPECT_TRUE(key_usage.AssertsBit(KEY_USAGE_BIT_DECIPHER_ONLY)); |
| 419 | } |
| 420 |
| 421 | // Parses an empty KeyUsage. |
| 422 | TEST(ParseKeyUsageTest, Empty) { |
| 423 | const uint8_t der[] = { |
| 424 | 0x03, 0x01, // BIT STRING |
| 425 | 0x00, // Number of unused bits |
| 426 | }; |
| 427 |
| 428 | der::BitString key_usage; |
| 429 | ASSERT_FALSE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 430 | } |
| 431 |
| 432 | TEST(ParseAuthorityInfoAccess, BasicTests) { |
| 433 | // SEQUENCE { |
| 434 | // SEQUENCE { |
| 435 | // # ocsp with directoryName |
| 436 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.1 } |
| 437 | // [4] { |
| 438 | // SEQUENCE { |
| 439 | // SET { |
| 440 | // SEQUENCE { |
| 441 | // # commonName |
| 442 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 443 | // PrintableString { "ocsp" } |
| 444 | // } |
| 445 | // } |
| 446 | // } |
| 447 | // } |
| 448 | // } |
| 449 | // SEQUENCE { |
| 450 | // # caIssuers with directoryName |
| 451 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.2 } |
| 452 | // [4] { |
| 453 | // SEQUENCE { |
| 454 | // SET { |
| 455 | // SEQUENCE { |
| 456 | // # commonName |
| 457 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 458 | // PrintableString { "ca issuer" } |
| 459 | // } |
| 460 | // } |
| 461 | // } |
| 462 | // } |
| 463 | // } |
| 464 | // SEQUENCE { |
| 465 | // # non-standard method with URI |
| 466 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.3 } |
| 467 | // [6 PRIMITIVE] { "http://nonstandard.example.com" } |
| 468 | // } |
| 469 | // SEQUENCE { |
| 470 | // # ocsp with URI |
| 471 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.1 } |
| 472 | // [6 PRIMITIVE] { "http://ocsp.example.com" } |
| 473 | // } |
| 474 | // SEQUENCE { |
| 475 | // # caIssuers with URI |
| 476 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.2 } |
| 477 | // [6 PRIMITIVE] { "http://www.example.com/issuer.crt" } |
| 478 | // } |
| 479 | // } |
| 480 | const uint8_t der[] = { |
| 481 | 0x30, 0x81, 0xc3, 0x30, 0x1d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, |
| 482 | 0x07, 0x30, 0x01, 0xa4, 0x11, 0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, 0x06, |
| 483 | 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x6f, 0x63, 0x73, 0x70, 0x30, 0x22, |
| 484 | 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0xa4, 0x16, |
| 485 | 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, |
| 486 | 0x09, 0x63, 0x61, 0x20, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x30, 0x2a, |
| 487 | 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x03, 0x86, 0x1e, |
| 488 | 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6e, 0x6f, 0x6e, 0x73, 0x74, |
| 489 | 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, |
| 490 | 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x23, 0x06, 0x08, 0x2b, 0x06, |
| 491 | 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, |
| 492 | 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, 0x65, 0x78, 0x61, 0x6d, |
| 493 | 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x2d, 0x06, 0x08, 0x2b, |
| 494 | 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x21, 0x68, 0x74, 0x74, |
| 495 | 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x65, 0x78, 0x61, 0x6d, |
| 496 | 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x73, 0x73, 0x75, |
| 497 | 0x65, 0x72, 0x2e, 0x63, 0x72, 0x74}; |
| 498 |
| 499 | std::vector<AuthorityInfoAccessDescription> access_descriptions; |
| 500 | ASSERT_TRUE(ParseAuthorityInfoAccess(der::Input(der), &access_descriptions)); |
| 501 | ASSERT_EQ(5u, access_descriptions.size()); |
| 502 | { |
| 503 | const auto &desc = access_descriptions[0]; |
| 504 | EXPECT_EQ(der::Input(kAdOcspOid), desc.access_method_oid); |
| 505 | const uint8_t location_der[] = {0xa4, 0x11, 0x30, 0x0f, 0x31, 0x0d, 0x30, |
| 506 | 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, |
| 507 | 0x04, 0x6f, 0x63, 0x73, 0x70}; |
| 508 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 509 | } |
| 510 | { |
| 511 | const auto &desc = access_descriptions[1]; |
| 512 | EXPECT_EQ(der::Input(kAdCaIssuersOid), desc.access_method_oid); |
| 513 | const uint8_t location_der[] = { |
| 514 | 0xa4, 0x16, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, |
| 515 | 0x03, 0x13, 0x09, 0x63, 0x61, 0x20, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72}; |
| 516 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 517 | } |
| 518 | { |
| 519 | const auto &desc = access_descriptions[2]; |
| 520 | const uint8_t method_oid[] = {0x2b, 0x06, 0x01, 0x05, |
| 521 | 0x05, 0x07, 0x30, 0x03}; |
| 522 | EXPECT_EQ(der::Input(method_oid), desc.access_method_oid); |
| 523 | const uint8_t location_der[] = { |
| 524 | 0x86, 0x1e, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6e, 0x6f, |
| 525 | 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x2e, 0x65, |
| 526 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d}; |
| 527 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 528 | } |
| 529 | { |
| 530 | const auto &desc = access_descriptions[3]; |
| 531 | EXPECT_EQ(der::Input(kAdOcspOid), desc.access_method_oid); |
| 532 | const uint8_t location_der[] = {0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x3a, |
| 533 | 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, |
| 534 | 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, |
| 535 | 0x2e, 0x63, 0x6f, 0x6d}; |
| 536 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 537 | } |
| 538 | { |
| 539 | const auto &desc = access_descriptions[4]; |
| 540 | EXPECT_EQ(der::Input(kAdCaIssuersOid), desc.access_method_oid); |
| 541 | const uint8_t location_der[] = { |
| 542 | 0x86, 0x21, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, |
| 543 | 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, |
| 544 | 0x2f, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x2e, 0x63, 0x72, 0x74}; |
| 545 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 546 | } |
| 547 |
| 548 | std::vector<std::string_view> ca_issuers_uris, ocsp_uris; |
| 549 | ASSERT_TRUE(ParseAuthorityInfoAccessURIs(der::Input(der), &ca_issuers_uris, |
| 550 | &ocsp_uris)); |
| 551 | ASSERT_EQ(1u, ca_issuers_uris.size()); |
| 552 | EXPECT_EQ("http://www.example.com/issuer.crt", ca_issuers_uris.front()); |
| 553 | ASSERT_EQ(1u, ocsp_uris.size()); |
| 554 | EXPECT_EQ("http://ocsp.example.com", ocsp_uris.front()); |
| 555 | } |
| 556 |
| 557 | TEST(ParseAuthorityInfoAccess, NoOcspOrCaIssuersURIs) { |
| 558 | // SEQUENCE { |
| 559 | // SEQUENCE { |
| 560 | // # non-standard method with directoryName |
| 561 | // OBJECT_IDENTIFIER { 1.2.3 } |
| 562 | // [4] { |
| 563 | // SEQUENCE { |
| 564 | // SET { |
| 565 | // SEQUENCE { |
| 566 | // # commonName |
| 567 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 568 | // PrintableString { "foo" } |
| 569 | // } |
| 570 | // } |
| 571 | // } |
| 572 | // } |
| 573 | // } |
| 574 | // } |
| 575 | const uint8_t der[] = {0x30, 0x18, 0x30, 0x16, 0x06, 0x02, 0x2a, 0x03, 0xa4, |
| 576 | 0x10, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, |
| 577 | 0x55, 0x04, 0x03, 0x13, 0x03, 0x66, 0x6f, 0x6f}; |
| 578 |
| 579 | std::vector<AuthorityInfoAccessDescription> access_descriptions; |
| 580 | ASSERT_TRUE(ParseAuthorityInfoAccess(der::Input(der), &access_descriptions)); |
| 581 | ASSERT_EQ(1u, access_descriptions.size()); |
| 582 | const auto &desc = access_descriptions[0]; |
| 583 | const uint8_t method_oid[] = {0x2a, 0x03}; |
| 584 | EXPECT_EQ(der::Input(method_oid), desc.access_method_oid); |
| 585 | const uint8_t location_der[] = {0xa4, 0x10, 0x30, 0x0e, 0x31, 0x0c, |
| 586 | 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, |
| 587 | 0x03, 0x13, 0x03, 0x66, 0x6f, 0x6f}; |
| 588 | EXPECT_EQ(der::Input(location_der), desc.access_location); |
| 589 |
| 590 | std::vector<std::string_view> ca_issuers_uris, ocsp_uris; |
| 591 | // ParseAuthorityInfoAccessURIs should still return success since it was a |
| 592 | // valid AuthorityInfoAccess extension, even though it did not contain any |
| 593 | // elements we care about, and both output vectors should be empty. |
| 594 | ASSERT_TRUE(ParseAuthorityInfoAccessURIs(der::Input(der), &ca_issuers_uris, |
| 595 | &ocsp_uris)); |
| 596 | EXPECT_EQ(0u, ca_issuers_uris.size()); |
| 597 | EXPECT_EQ(0u, ocsp_uris.size()); |
| 598 | } |
| 599 |
| 600 | TEST(ParseAuthorityInfoAccess, IncompleteAccessDescription) { |
| 601 | // SEQUENCE { |
| 602 | // # first entry is ok |
| 603 | // SEQUENCE { |
| 604 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.1 } |
| 605 | // [6 PRIMITIVE] { "http://ocsp.example.com" } |
| 606 | // } |
| 607 | // # second is missing accessLocation field |
| 608 | // SEQUENCE { |
| 609 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.2 } |
| 610 | // } |
| 611 | // } |
| 612 | const uint8_t der[] = {0x30, 0x31, 0x30, 0x23, 0x06, 0x08, 0x2b, 0x06, 0x01, |
| 613 | 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, |
| 614 | 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, |
| 615 | 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, |
| 616 | 0x63, 0x6f, 0x6d, 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, |
| 617 | 0x01, 0x05, 0x05, 0x07, 0x30, 0x02}; |
| 618 |
| 619 | std::vector<AuthorityInfoAccessDescription> access_descriptions; |
| 620 | EXPECT_FALSE(ParseAuthorityInfoAccess(der::Input(der), &access_descriptions)); |
| 621 |
| 622 | std::vector<std::string_view> ca_issuers_uris, ocsp_uris; |
| 623 | EXPECT_FALSE(ParseAuthorityInfoAccessURIs(der::Input(der), &ca_issuers_uris, |
| 624 | &ocsp_uris)); |
| 625 | } |
| 626 |
| 627 | TEST(ParseAuthorityInfoAccess, ExtraDataInAccessDescription) { |
| 628 | // SEQUENCE { |
| 629 | // SEQUENCE { |
| 630 | // OBJECT_IDENTIFIER { 1.3.6.1.5.5.7.48.1 } |
| 631 | // [6 PRIMITIVE] { "http://ocsp.example.com" } |
| 632 | // # invalid, AccessDescription only has 2 fields |
| 633 | // PrintableString { "henlo" } |
| 634 | // } |
| 635 | // } |
| 636 | const uint8_t der[] = { |
| 637 | 0x30, 0x2c, 0x30, 0x2a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, |
| 638 | 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, |
| 639 | 0x63, 0x73, 0x70, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, |
| 640 | 0x63, 0x6f, 0x6d, 0x13, 0x05, 0x68, 0x65, 0x6e, 0x6c, 0x6f}; |
| 641 |
| 642 | std::vector<AuthorityInfoAccessDescription> access_descriptions; |
| 643 | EXPECT_FALSE(ParseAuthorityInfoAccess(der::Input(der), &access_descriptions)); |
| 644 |
| 645 | std::vector<std::string_view> ca_issuers_uris, ocsp_uris; |
| 646 | EXPECT_FALSE(ParseAuthorityInfoAccessURIs(der::Input(der), &ca_issuers_uris, |
| 647 | &ocsp_uris)); |
| 648 | } |
| 649 |
| 650 | TEST(ParseAuthorityInfoAccess, EmptySequence) { |
| 651 | // SEQUENCE { } |
| 652 | const uint8_t der[] = {0x30, 0x00}; |
| 653 |
| 654 | std::vector<AuthorityInfoAccessDescription> access_descriptions; |
| 655 | EXPECT_FALSE(ParseAuthorityInfoAccess(der::Input(der), &access_descriptions)); |
| 656 |
| 657 | std::vector<std::string_view> ca_issuers_uris, ocsp_uris; |
| 658 | EXPECT_FALSE(ParseAuthorityInfoAccessURIs(der::Input(der), &ca_issuers_uris, |
| 659 | &ocsp_uris)); |
| 660 | } |
| 661 |
| 662 | // Test fixture for testing ParseCrlDistributionPoints. |
| 663 | // |
| 664 | // Test data is encoded in certificate files. This fixture is responsible for |
| 665 | // reading and parsing the certificates to get at the extension under test. |
| 666 | class ParseCrlDistributionPointsTest : public ::testing::Test { |
| 667 | public: |
| 668 | protected: |
| 669 | bool GetCrlDps(const char *file_name, |
| 670 | std::vector<ParsedDistributionPoint> *dps) { |
| 671 | std::string cert_bytes; |
| 672 | // Read the test certificate file. |
| 673 | const PemBlockMapping mappings[] = { |
| 674 | {"CERTIFICATE", &cert_bytes}, |
| 675 | }; |
| 676 | std::string test_file_path = GetFilePath(file_name); |
| 677 | EXPECT_TRUE(ReadTestDataFromPemFile(test_file_path, mappings)); |
| 678 |
| 679 | // Extract the CRLDP from the test Certificate. |
| 680 | CertErrors errors; |
| 681 | std::shared_ptr<const ParsedCertificate> cert = ParsedCertificate::Create( |
| 682 | bssl::UniquePtr<CRYPTO_BUFFER>(CRYPTO_BUFFER_new( |
| 683 | reinterpret_cast<const uint8_t *>(cert_bytes.data()), |
| 684 | cert_bytes.size(), nullptr)), |
| 685 | {}, &errors); |
| 686 |
| 687 | if (!cert) { |
| 688 | return false; |
| 689 | } |
| 690 |
| 691 | auto it = cert->extensions().find(der::Input(kCrlDistributionPointsOid)); |
| 692 | if (it == cert->extensions().end()) { |
| 693 | return false; |
| 694 | } |
| 695 |
| 696 | der::Input crl_dp_tlv = it->second.value; |
| 697 |
| 698 | // Keep the certificate data alive, since this function will return |
| 699 | // der::Inputs that reference it. Run the function under test (for parsing |
| 700 | // |
| 701 | // TODO(eroman): The use of ParsedCertificate in this test should be removed |
| 702 | // in lieu of lazy parsing. |
| 703 | keep_alive_certs_.push_back(cert); |
| 704 |
| 705 | return ParseCrlDistributionPoints(crl_dp_tlv, dps); |
| 706 | } |
| 707 |
| 708 | private: |
| 709 | ParsedCertificateList keep_alive_certs_; |
| 710 | }; |
| 711 |
| 712 | TEST_F(ParseCrlDistributionPointsTest, OneUriNoIssuer) { |
| 713 | std::vector<ParsedDistributionPoint> dps; |
| 714 | ASSERT_TRUE(GetCrlDps("crldp_1uri_noissuer.pem", &dps)); |
| 715 |
| 716 | ASSERT_EQ(1u, dps.size()); |
| 717 | const ParsedDistributionPoint &dp1 = dps.front(); |
| 718 |
| 719 | ASSERT_TRUE(dp1.distribution_point_fullname); |
| 720 | const GeneralNames &fullname = *dp1.distribution_point_fullname; |
| 721 | EXPECT_EQ(GENERAL_NAME_UNIFORM_RESOURCE_IDENTIFIER, |
| 722 | fullname.present_name_types); |
| 723 | ASSERT_EQ(1u, fullname.uniform_resource_identifiers.size()); |
| 724 | EXPECT_EQ(fullname.uniform_resource_identifiers.front(), |
| 725 | std::string("http://www.example.com/foo.crl")); |
| 726 |
| 727 | EXPECT_FALSE(dp1.distribution_point_name_relative_to_crl_issuer); |
| 728 | EXPECT_FALSE(dp1.reasons); |
| 729 | EXPECT_FALSE(dp1.crl_issuer); |
| 730 | } |
| 731 |
| 732 | TEST_F(ParseCrlDistributionPointsTest, ThreeUrisNoIssuer) { |
| 733 | std::vector<ParsedDistributionPoint> dps; |
| 734 | ASSERT_TRUE(GetCrlDps("crldp_3uri_noissuer.pem", &dps)); |
| 735 |
| 736 | ASSERT_EQ(1u, dps.size()); |
| 737 | const ParsedDistributionPoint &dp1 = dps.front(); |
| 738 |
| 739 | ASSERT_TRUE(dp1.distribution_point_fullname); |
| 740 | const GeneralNames &fullname = *dp1.distribution_point_fullname; |
| 741 | EXPECT_EQ(GENERAL_NAME_UNIFORM_RESOURCE_IDENTIFIER, |
| 742 | fullname.present_name_types); |
| 743 | ASSERT_EQ(3u, fullname.uniform_resource_identifiers.size()); |
| 744 | EXPECT_EQ(fullname.uniform_resource_identifiers[0], |
| 745 | std::string("http://www.example.com/foo1.crl")); |
| 746 | EXPECT_EQ(fullname.uniform_resource_identifiers[1], |
| 747 | std::string("http://www.example.com/blah.crl")); |
| 748 | EXPECT_EQ(fullname.uniform_resource_identifiers[2], |
| 749 | std::string("not-even-a-url")); |
| 750 |
| 751 | EXPECT_FALSE(dp1.distribution_point_name_relative_to_crl_issuer); |
| 752 | EXPECT_FALSE(dp1.reasons); |
| 753 | EXPECT_FALSE(dp1.crl_issuer); |
| 754 | } |
| 755 |
| 756 | TEST_F(ParseCrlDistributionPointsTest, CrlIssuerAsDirname) { |
| 757 | std::vector<ParsedDistributionPoint> dps; |
| 758 | ASSERT_TRUE(GetCrlDps("crldp_issuer_as_dirname.pem", &dps)); |
| 759 |
| 760 | ASSERT_EQ(1u, dps.size()); |
| 761 | const ParsedDistributionPoint &dp1 = dps.front(); |
| 762 | ASSERT_TRUE(dp1.distribution_point_fullname); |
| 763 | const GeneralNames &fullname = *dp1.distribution_point_fullname; |
| 764 | EXPECT_EQ(GENERAL_NAME_DIRECTORY_NAME, fullname.present_name_types); |
| 765 | // Generated by `ascii2der | xxd -i` from the Name value in |
| 766 | // crldp_issuer_as_dirname.pem. |
| 767 | const uint8_t kExpectedName[] = { |
| 768 | 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, |
| 769 | 0x53, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x16, |
| 770 | 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, |
| 771 | 0x63, 0x61, 0x74, 0x65, 0x73, 0x20, 0x32, 0x30, 0x31, 0x31, 0x31, 0x22, |
| 772 | 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x19, 0x69, 0x6e, 0x64, |
| 773 | 0x69, 0x72, 0x65, 0x63, 0x74, 0x43, 0x52, 0x4c, 0x20, 0x43, 0x41, 0x33, |
| 774 | 0x20, 0x63, 0x52, 0x4c, 0x49, 0x73, 0x73, 0x75, 0x65, 0x72, 0x31, 0x29, |
| 775 | 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x20, 0x69, 0x6e, 0x64, |
| 776 | 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x43, 0x52, 0x4c, 0x20, 0x66, 0x6f, |
| 777 | 0x72, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x43, 0x52, |
| 778 | 0x4c, 0x20, 0x43, 0x41, 0x33}; |
| 779 | ASSERT_EQ(1u, fullname.directory_names.size()); |
| 780 | EXPECT_EQ(der::Input(kExpectedName), fullname.directory_names[0]); |
| 781 |
| 782 | EXPECT_FALSE(dp1.distribution_point_name_relative_to_crl_issuer); |
| 783 | EXPECT_FALSE(dp1.reasons); |
| 784 |
| 785 | ASSERT_TRUE(dp1.crl_issuer); |
| 786 | // Generated by `ascii2der | xxd -i` from the cRLIssuer value in |
| 787 | // crldp_issuer_as_dirname.pem. |
| 788 | const uint8_t kExpectedCrlIssuer[] = { |
| 789 | 0xa4, 0x54, 0x30, 0x52, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
| 790 | 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x1f, 0x30, 0x1d, 0x06, |
| 791 | 0x03, 0x55, 0x04, 0x0a, 0x13, 0x16, 0x54, 0x65, 0x73, 0x74, 0x20, |
| 792 | 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, |
| 793 | 0x73, 0x20, 0x32, 0x30, 0x31, 0x31, 0x31, 0x22, 0x30, 0x20, 0x06, |
| 794 | 0x03, 0x55, 0x04, 0x0b, 0x13, 0x19, 0x69, 0x6e, 0x64, 0x69, 0x72, |
| 795 | 0x65, 0x63, 0x74, 0x43, 0x52, 0x4c, 0x20, 0x43, 0x41, 0x33, 0x20, |
| 796 | 0x63, 0x52, 0x4c, 0x49, 0x73, 0x73, 0x75, 0x65, 0x72}; |
| 797 | EXPECT_EQ(der::Input(kExpectedCrlIssuer), dp1.crl_issuer); |
| 798 | } |
| 799 |
| 800 | TEST_F(ParseCrlDistributionPointsTest, FullnameAsDirname) { |
| 801 | std::vector<ParsedDistributionPoint> dps; |
| 802 | ASSERT_TRUE(GetCrlDps("crldp_full_name_as_dirname.pem", &dps)); |
| 803 |
| 804 | ASSERT_EQ(1u, dps.size()); |
| 805 | const ParsedDistributionPoint &dp1 = dps.front(); |
| 806 |
| 807 | ASSERT_TRUE(dp1.distribution_point_fullname); |
| 808 | const GeneralNames &fullname = *dp1.distribution_point_fullname; |
| 809 | EXPECT_EQ(GENERAL_NAME_DIRECTORY_NAME, fullname.present_name_types); |
| 810 | // Generated by `ascii2der | xxd -i` from the Name value in |
| 811 | // crldp_full_name_as_dirname.pem. |
| 812 | const uint8_t kExpectedName[] = { |
| 813 | 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, |
| 814 | 0x53, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x16, |
| 815 | 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, |
| 816 | 0x63, 0x61, 0x74, 0x65, 0x73, 0x20, 0x32, 0x30, 0x31, 0x31, 0x31, 0x45, |
| 817 | 0x30, 0x43, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x3c, 0x53, 0x65, 0x6c, |
| 818 | 0x66, 0x2d, 0x49, 0x73, 0x73, 0x75, 0x65, 0x64, 0x20, 0x43, 0x65, 0x72, |
| 819 | 0x74, 0x20, 0x44, 0x50, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x42, 0x61, 0x73, |
| 820 | 0x69, 0x63, 0x20, 0x53, 0x65, 0x6c, 0x66, 0x2d, 0x49, 0x73, 0x73, 0x75, |
| 821 | 0x65, 0x64, 0x20, 0x43, 0x52, 0x4c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, |
| 822 | 0x6e, 0x67, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x43, 0x41}; |
| 823 | ASSERT_EQ(1u, fullname.directory_names.size()); |
| 824 | EXPECT_EQ(der::Input(kExpectedName), fullname.directory_names[0]); |
| 825 |
| 826 | EXPECT_FALSE(dp1.distribution_point_name_relative_to_crl_issuer); |
| 827 | EXPECT_FALSE(dp1.reasons); |
| 828 | EXPECT_FALSE(dp1.crl_issuer); |
| 829 | } |
| 830 |
| 831 | TEST_F(ParseCrlDistributionPointsTest, RelativeNameAndReasonsAndMultipleDPs) { |
| 832 | // SEQUENCE { |
| 833 | // SEQUENCE { |
| 834 | // # distributionPoint |
| 835 | // [0] { |
| 836 | // # nameRelativeToCRLIssuer |
| 837 | // [1] { |
| 838 | // SET { |
| 839 | // SEQUENCE { |
| 840 | // # commonName |
| 841 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 842 | // PrintableString { "CRL1" } |
| 843 | // } |
| 844 | // } |
| 845 | // } |
| 846 | // } |
| 847 | // # reasons |
| 848 | // [1 PRIMITIVE] { b`011` } |
| 849 | // } |
| 850 | // SEQUENCE { |
| 851 | // # distributionPoint |
| 852 | // [0] { |
| 853 | // # fullName |
| 854 | // [0] { |
| 855 | // [4] { |
| 856 | // SEQUENCE { |
| 857 | // SET { |
| 858 | // SEQUENCE { |
| 859 | // # commonName |
| 860 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 861 | // PrintableString { "CRL2" } |
| 862 | // } |
| 863 | // } |
| 864 | // } |
| 865 | // } |
| 866 | // } |
| 867 | // } |
| 868 | // # reasons |
| 869 | // [1 PRIMITIVE] { b`100111111` } |
| 870 | // } |
| 871 | // } |
| 872 | const uint8_t kInputDer[] = { |
| 873 | 0x30, 0x37, 0x30, 0x17, 0xa0, 0x11, 0xa1, 0x0f, 0x31, 0x0d, 0x30, 0x0b, |
| 874 | 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x43, 0x52, 0x4c, 0x31, 0x81, |
| 875 | 0x02, 0x05, 0x60, 0x30, 0x1c, 0xa0, 0x15, 0xa0, 0x13, 0xa4, 0x11, 0x30, |
| 876 | 0x0f, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, |
| 877 | 0x43, 0x52, 0x4c, 0x32, 0x81, 0x03, 0x07, 0x9f, 0x80}; |
| 878 |
| 879 | std::vector<ParsedDistributionPoint> dps; |
| 880 | ASSERT_TRUE(ParseCrlDistributionPoints(der::Input(kInputDer), &dps)); |
| 881 | ASSERT_EQ(2u, dps.size()); |
| 882 | { |
| 883 | const ParsedDistributionPoint &dp = dps[0]; |
| 884 | EXPECT_FALSE(dp.distribution_point_fullname); |
| 885 |
| 886 | ASSERT_TRUE(dp.distribution_point_name_relative_to_crl_issuer); |
| 887 | // SET { |
| 888 | // SEQUENCE { |
| 889 | // # commonName |
| 890 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 891 | // PrintableString { "CRL1" } |
| 892 | // } |
| 893 | // } |
| 894 | const uint8_t kExpectedRDN[] = {0x31, 0x0d, 0x30, 0x0b, 0x06, |
| 895 | 0x03, 0x55, 0x04, 0x03, 0x13, |
| 896 | 0x04, 0x43, 0x52, 0x4c, 0x31}; |
| 897 | EXPECT_EQ(der::Input(kExpectedRDN), |
| 898 | *dp.distribution_point_name_relative_to_crl_issuer); |
| 899 |
| 900 | ASSERT_TRUE(dp.reasons); |
| 901 | const uint8_t kExpectedReasons[] = {0x05, 0x60}; |
| 902 | EXPECT_EQ(der::Input(kExpectedReasons), *dp.reasons); |
| 903 |
| 904 | EXPECT_FALSE(dp.crl_issuer); |
| 905 | } |
| 906 | { |
| 907 | const ParsedDistributionPoint &dp = dps[1]; |
| 908 | ASSERT_TRUE(dp.distribution_point_fullname); |
| 909 | const GeneralNames &fullname = *dp.distribution_point_fullname; |
| 910 | EXPECT_EQ(GENERAL_NAME_DIRECTORY_NAME, fullname.present_name_types); |
| 911 | // SET { |
| 912 | // SEQUENCE { |
| 913 | // # commonName |
| 914 | // OBJECT_IDENTIFIER { 2.5.4.3 } |
| 915 | // PrintableString { "CRL2" } |
| 916 | // } |
| 917 | // } |
| 918 | const uint8_t kExpectedName[] = {0x31, 0x0d, 0x30, 0x0b, 0x06, |
| 919 | 0x03, 0x55, 0x04, 0x03, 0x13, |
| 920 | 0x04, 0x43, 0x52, 0x4c, 0x32}; |
| 921 | ASSERT_EQ(1u, fullname.directory_names.size()); |
| 922 | EXPECT_EQ(der::Input(kExpectedName), fullname.directory_names[0]); |
| 923 |
| 924 | EXPECT_FALSE(dp.distribution_point_name_relative_to_crl_issuer); |
| 925 |
| 926 | ASSERT_TRUE(dp.reasons); |
| 927 | const uint8_t kExpectedReasons[] = {0x07, 0x9f, 0x80}; |
| 928 | EXPECT_EQ(der::Input(kExpectedReasons), *dp.reasons); |
| 929 |
| 930 | EXPECT_FALSE(dp.crl_issuer); |
| 931 | } |
| 932 | } |
| 933 |
| 934 | TEST_F(ParseCrlDistributionPointsTest, NoDistributionPointName) { |
| 935 | // SEQUENCE { |
| 936 | // SEQUENCE { |
| 937 | // # cRLIssuer |
| 938 | // [2] { |
| 939 | // [4] { |
| 940 | // SEQUENCE { |
| 941 | // SET { |
| 942 | // SEQUENCE { |
| 943 | // # organizationUnitName |
| 944 | // OBJECT_IDENTIFIER { 2.5.4.11 } |
| 945 | // PrintableString { "crl issuer" } |
| 946 | // } |
| 947 | // } |
| 948 | // } |
| 949 | // } |
| 950 | // } |
| 951 | // } |
| 952 | // } |
| 953 | const uint8_t kInputDer[] = {0x30, 0x1d, 0x30, 0x1b, 0xa2, 0x19, 0xa4, 0x17, |
| 954 | 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
| 955 | 0x55, 0x04, 0x0b, 0x13, 0x0a, 0x63, 0x72, 0x6c, |
| 956 | 0x20, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72}; |
| 957 |
| 958 | std::vector<ParsedDistributionPoint> dps; |
| 959 | ASSERT_TRUE(ParseCrlDistributionPoints(der::Input(kInputDer), &dps)); |
| 960 | ASSERT_EQ(1u, dps.size()); |
| 961 | const ParsedDistributionPoint &dp = dps[0]; |
| 962 | EXPECT_FALSE(dp.distribution_point_fullname); |
| 963 |
| 964 | EXPECT_FALSE(dp.distribution_point_name_relative_to_crl_issuer); |
| 965 |
| 966 | EXPECT_FALSE(dp.reasons); |
| 967 |
| 968 | ASSERT_TRUE(dp.crl_issuer); |
| 969 | const uint8_t kExpectedDer[] = {0xa4, 0x17, 0x30, 0x15, 0x31, 0x13, 0x30, |
| 970 | 0x11, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, |
| 971 | 0x0a, 0x63, 0x72, 0x6c, 0x20, 0x69, 0x73, |
| 972 | 0x73, 0x75, 0x65, 0x72}; |
| 973 | EXPECT_EQ(der::Input(kExpectedDer), *dp.crl_issuer); |
| 974 | } |
| 975 |
| 976 | TEST_F(ParseCrlDistributionPointsTest, OnlyReasons) { |
| 977 | // SEQUENCE { |
| 978 | // SEQUENCE { |
| 979 | // # reasons |
| 980 | // [1 PRIMITIVE] { b`011` } |
| 981 | // } |
| 982 | // } |
| 983 | const uint8_t kInputDer[] = {0x30, 0x06, 0x30, 0x04, 0x81, 0x02, 0x05, 0x60}; |
| 984 |
| 985 | std::vector<ParsedDistributionPoint> dps; |
| 986 | EXPECT_FALSE(ParseCrlDistributionPoints(der::Input(kInputDer), &dps)); |
| 987 | } |
| 988 |
| 989 | TEST_F(ParseCrlDistributionPointsTest, EmptyDistributionPoint) { |
| 990 | // SEQUENCE { |
| 991 | // SEQUENCE { |
| 992 | // } |
| 993 | // } |
| 994 | const uint8_t kInputDer[] = {0x30, 0x02, 0x30, 0x00}; |
| 995 |
| 996 | std::vector<ParsedDistributionPoint> dps; |
| 997 | EXPECT_FALSE(ParseCrlDistributionPoints(der::Input(kInputDer), &dps)); |
| 998 | } |
| 999 |
| 1000 | TEST_F(ParseCrlDistributionPointsTest, EmptyDistributionPoints) { |
| 1001 | // SEQUENCE { } |
| 1002 | const uint8_t kInputDer[] = {0x30, 0x00}; |
| 1003 |
| 1004 | std::vector<ParsedDistributionPoint> dps; |
| 1005 | EXPECT_FALSE(ParseCrlDistributionPoints(der::Input(kInputDer), &dps)); |
| 1006 | } |
| 1007 |
| 1008 | bool ParseAuthorityKeyIdentifierTestData( |
| 1009 | const char *file_name, std::string *backing_bytes, |
| 1010 | ParsedAuthorityKeyIdentifier *authority_key_identifier) { |
| 1011 | // Read the test file. |
| 1012 | const PemBlockMapping mappings[] = { |
| 1013 | {"AUTHORITY_KEY_IDENTIFIER", backing_bytes}, |
| 1014 | }; |
| 1015 | std::string test_file_path = |
| 1016 | std::string( |
| 1017 | "testdata/parse_certificate_unittest/authority_key_identifier/") + |
| 1018 | file_name; |
| 1019 | EXPECT_TRUE(ReadTestDataFromPemFile(test_file_path, mappings)); |
| 1020 |
| 1021 | return ParseAuthorityKeyIdentifier(der::Input(*backing_bytes), |
| 1022 | authority_key_identifier); |
| 1023 | } |
| 1024 |
| 1025 | TEST(ParseAuthorityKeyIdentifierTest, EmptyInput) { |
| 1026 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1027 | EXPECT_FALSE( |
| 1028 | ParseAuthorityKeyIdentifier(der::Input(), &authority_key_identifier)); |
| 1029 | } |
| 1030 |
| 1031 | TEST(ParseAuthorityKeyIdentifierTest, EmptySequence) { |
| 1032 | std::string backing_bytes; |
| 1033 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1034 | // TODO(mattm): should this be an error? RFC 5280 doesn't explicitly say it. |
| 1035 | ASSERT_TRUE(ParseAuthorityKeyIdentifierTestData( |
| 1036 | "empty_sequence.pem", &backing_bytes, &authority_key_identifier)); |
| 1037 |
| 1038 | EXPECT_FALSE(authority_key_identifier.key_identifier); |
| 1039 | EXPECT_FALSE(authority_key_identifier.authority_cert_issuer); |
| 1040 | EXPECT_FALSE(authority_key_identifier.authority_cert_serial_number); |
| 1041 | } |
| 1042 |
| 1043 | TEST(ParseAuthorityKeyIdentifierTest, KeyIdentifier) { |
| 1044 | std::string backing_bytes; |
| 1045 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1046 | ASSERT_TRUE(ParseAuthorityKeyIdentifierTestData( |
| 1047 | "key_identifier.pem", &backing_bytes, &authority_key_identifier)); |
| 1048 |
| 1049 | ASSERT_TRUE(authority_key_identifier.key_identifier); |
| 1050 | const uint8_t kExpectedValue[] = {0xDE, 0xAD, 0xB0, 0x0F}; |
| 1051 | EXPECT_EQ(der::Input(kExpectedValue), |
| 1052 | authority_key_identifier.key_identifier); |
| 1053 | } |
| 1054 |
| 1055 | TEST(ParseAuthorityKeyIdentifierTest, IssuerAndSerial) { |
| 1056 | std::string backing_bytes; |
| 1057 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1058 | ASSERT_TRUE(ParseAuthorityKeyIdentifierTestData( |
| 1059 | "issuer_and_serial.pem", &backing_bytes, &authority_key_identifier)); |
| 1060 |
| 1061 | EXPECT_FALSE(authority_key_identifier.key_identifier); |
| 1062 |
| 1063 | ASSERT_TRUE(authority_key_identifier.authority_cert_issuer); |
| 1064 | const uint8_t kExpectedIssuer[] = {0xa4, 0x11, 0x30, 0x0f, 0x31, 0x0d, 0x30, |
| 1065 | 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, |
| 1066 | 0x04, 0x52, 0x6f, 0x6f, 0x74}; |
| 1067 | EXPECT_EQ(der::Input(kExpectedIssuer), |
| 1068 | authority_key_identifier.authority_cert_issuer); |
| 1069 |
| 1070 | ASSERT_TRUE(authority_key_identifier.authority_cert_serial_number); |
| 1071 | const uint8_t kExpectedSerial[] = {0x27, 0x4F}; |
| 1072 | EXPECT_EQ(der::Input(kExpectedSerial), |
| 1073 | authority_key_identifier.authority_cert_serial_number); |
| 1074 | } |
| 1075 |
| 1076 | TEST(ParseAuthorityKeyIdentifierTest, KeyIdentifierAndIssuerAndSerial) { |
| 1077 | std::string backing_bytes; |
| 1078 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1079 | ASSERT_TRUE(ParseAuthorityKeyIdentifierTestData( |
| 1080 | "key_identifier_and_issuer_and_serial.pem", &backing_bytes, |
| 1081 | &authority_key_identifier)); |
| 1082 |
| 1083 | ASSERT_TRUE(authority_key_identifier.key_identifier); |
| 1084 | const uint8_t kExpectedValue[] = {0xDE, 0xAD, 0xB0, 0x0F}; |
| 1085 | EXPECT_EQ(der::Input(kExpectedValue), |
| 1086 | authority_key_identifier.key_identifier); |
| 1087 |
| 1088 | ASSERT_TRUE(authority_key_identifier.authority_cert_issuer); |
| 1089 | const uint8_t kExpectedIssuer[] = {0xa4, 0x11, 0x30, 0x0f, 0x31, 0x0d, 0x30, |
| 1090 | 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, |
| 1091 | 0x04, 0x52, 0x6f, 0x6f, 0x74}; |
| 1092 | EXPECT_EQ(der::Input(kExpectedIssuer), |
| 1093 | authority_key_identifier.authority_cert_issuer); |
| 1094 |
| 1095 | ASSERT_TRUE(authority_key_identifier.authority_cert_serial_number); |
| 1096 | const uint8_t kExpectedSerial[] = {0x27, 0x4F}; |
| 1097 | EXPECT_EQ(der::Input(kExpectedSerial), |
| 1098 | authority_key_identifier.authority_cert_serial_number); |
| 1099 | } |
| 1100 |
| 1101 | TEST(ParseAuthorityKeyIdentifierTest, IssuerOnly) { |
| 1102 | std::string backing_bytes; |
| 1103 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1104 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1105 | "issuer_only.pem", &backing_bytes, &authority_key_identifier)); |
| 1106 | } |
| 1107 |
| 1108 | TEST(ParseAuthorityKeyIdentifierTest, SerialOnly) { |
| 1109 | std::string backing_bytes; |
| 1110 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1111 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1112 | "serial_only.pem", &backing_bytes, &authority_key_identifier)); |
| 1113 | } |
| 1114 |
| 1115 | TEST(ParseAuthorityKeyIdentifierTest, InvalidContents) { |
| 1116 | std::string backing_bytes; |
| 1117 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1118 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1119 | "invalid_contents.pem", &backing_bytes, &authority_key_identifier)); |
| 1120 | } |
| 1121 |
| 1122 | TEST(ParseAuthorityKeyIdentifierTest, InvalidKeyIdentifier) { |
| 1123 | std::string backing_bytes; |
| 1124 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1125 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1126 | "invalid_key_identifier.pem", &backing_bytes, &authority_key_identifier)); |
| 1127 | } |
| 1128 |
| 1129 | TEST(ParseAuthorityKeyIdentifierTest, InvalidIssuer) { |
| 1130 | std::string backing_bytes; |
| 1131 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1132 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1133 | "invalid_issuer.pem", &backing_bytes, &authority_key_identifier)); |
| 1134 | } |
| 1135 |
| 1136 | TEST(ParseAuthorityKeyIdentifierTest, InvalidSerial) { |
| 1137 | std::string backing_bytes; |
| 1138 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1139 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1140 | "invalid_serial.pem", &backing_bytes, &authority_key_identifier)); |
| 1141 | } |
| 1142 |
| 1143 | TEST(ParseAuthorityKeyIdentifierTest, ExtraContentsAfterIssuerAndSerial) { |
| 1144 | std::string backing_bytes; |
| 1145 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1146 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1147 | "extra_contents_after_issuer_and_serial.pem", &backing_bytes, |
| 1148 | &authority_key_identifier)); |
| 1149 | } |
| 1150 |
| 1151 | TEST(ParseAuthorityKeyIdentifierTest, ExtraContentsAfterExtensionSequence) { |
| 1152 | std::string backing_bytes; |
| 1153 | ParsedAuthorityKeyIdentifier authority_key_identifier; |
| 1154 | EXPECT_FALSE(ParseAuthorityKeyIdentifierTestData( |
| 1155 | "extra_contents_after_extension_sequence.pem", &backing_bytes, |
| 1156 | &authority_key_identifier)); |
| 1157 | } |
| 1158 |
| 1159 | TEST(ParseSubjectKeyIdentifierTest, EmptyInput) { |
| 1160 | der::Input subject_key_identifier; |
| 1161 | EXPECT_FALSE( |
| 1162 | ParseSubjectKeyIdentifier(der::Input(), &subject_key_identifier)); |
| 1163 | } |
| 1164 |
| 1165 | TEST(ParseSubjectKeyIdentifierTest, Valid) { |
| 1166 | // OCTET_STRING {`abcd`} |
| 1167 | const uint8_t kInput[] = {0x04, 0x02, 0xab, 0xcd}; |
| 1168 | const uint8_t kExpected[] = {0xab, 0xcd}; |
| 1169 | der::Input subject_key_identifier; |
| 1170 | EXPECT_TRUE( |
| 1171 | ParseSubjectKeyIdentifier(der::Input(kInput), &subject_key_identifier)); |
| 1172 | EXPECT_EQ(der::Input(kExpected), subject_key_identifier); |
| 1173 | } |
| 1174 |
| 1175 | TEST(ParseSubjectKeyIdentifierTest, ExtraData) { |
| 1176 | // OCTET_STRING {`abcd`} |
| 1177 | // NULL |
| 1178 | const uint8_t kInput[] = {0x04, 0x02, 0xab, 0xcd, 0x05}; |
| 1179 | der::Input subject_key_identifier; |
| 1180 | EXPECT_FALSE( |
| 1181 | ParseSubjectKeyIdentifier(der::Input(kInput), &subject_key_identifier)); |
| 1182 | } |
| 1183 |
| 1184 | } // namespace |
| 1185 |
| 1186 | BSSL_NAMESPACE_END |
| 1187 |