| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/internal/parse_certificate.h" | 5 #include "net/cert/internal/parse_certificate.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "net/cert/internal/test_helpers.h" | 8 #include "net/cert/internal/test_helpers.h" |
| 9 #include "net/der/input.h" | 9 #include "net/der/input.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 EnsureParsingTbsSucceeds("tbs_validity_generalized_time_and_utc_time.pem", | 319 EnsureParsingTbsSucceeds("tbs_validity_generalized_time_and_utc_time.pem", |
| 320 CertificateVersion::V3); | 320 CertificateVersion::V3); |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Parses a TBSCertificate whose "validity" field does not strictly follow | 323 // Parses a TBSCertificate whose "validity" field does not strictly follow |
| 324 // the DER rules (and fails to be parsed). | 324 // the DER rules (and fails to be parsed). |
| 325 TEST(ParseTbsCertificateTest, ValidityRelaxed) { | 325 TEST(ParseTbsCertificateTest, ValidityRelaxed) { |
| 326 EnsureParsingTbsFails("tbs_validity_relaxed.pem"); | 326 EnsureParsingTbsFails("tbs_validity_relaxed.pem"); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Reads a PEM file containing a block "EXTENSION". This input will be |
| 330 // passed to ParseExtension, and the results filled in |out|. |
| 331 bool ParseExtensionFromFile(const std::string& file_name, |
| 332 ParsedExtension* out) { |
| 333 std::string data; |
| 334 |
| 335 const PemBlockMapping mappings[] = { |
| 336 {"EXTENSION", &data}, |
| 337 }; |
| 338 |
| 339 EXPECT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings)); |
| 340 return ParseExtension(InputFromString(&data), out); |
| 341 } |
| 342 |
| 343 // Parses an Extension whose critical field is true (255). |
| 344 TEST(ParseExtensionTest, Critical) { |
| 345 ParsedExtension extension; |
| 346 ASSERT_TRUE(ParseExtensionFromFile("extension_critical.pem", &extension)); |
| 347 |
| 348 EXPECT_EQ(true, extension.critical); |
| 349 |
| 350 const uint8_t kExpectedOid[] = {0x55, 0x1d, 0x13}; |
| 351 EXPECT_EQ(der::Input(kExpectedOid), extension.oid); |
| 352 |
| 353 const uint8_t kExpectedValue[] = {0x30, 0x00}; |
| 354 EXPECT_EQ(der::Input(kExpectedValue), extension.value); |
| 355 } |
| 356 |
| 357 // Parses an Extension whose critical field is false (omitted). |
| 358 TEST(ParseExtensionTest, NotCritical) { |
| 359 ParsedExtension extension; |
| 360 ASSERT_TRUE(ParseExtensionFromFile("extension_not_critical.pem", &extension)); |
| 361 |
| 362 EXPECT_EQ(false, extension.critical); |
| 363 |
| 364 const uint8_t kExpectedOid[] = {0x55, 0x1d, 0x13}; |
| 365 EXPECT_EQ(der::Input(kExpectedOid), extension.oid); |
| 366 |
| 367 const uint8_t kExpectedValue[] = {0x30, 0x00}; |
| 368 EXPECT_EQ(der::Input(kExpectedValue), extension.value); |
| 369 } |
| 370 |
| 371 // Parses an Extension whose critical field is 0. This is in one sense FALSE, |
| 372 // however because critical has DEFAULT of false this is in fact invalid |
| 373 // DER-encoding. |
| 374 TEST(ParseExtensionTest, Critical0) { |
| 375 ParsedExtension extension; |
| 376 ASSERT_FALSE(ParseExtensionFromFile("extension_critical_0.pem", &extension)); |
| 377 } |
| 378 |
| 379 // Parses an Extension whose critical field is 3. Under DER-encoding BOOLEAN |
| 380 // values must an octet of either all zero bits, or all 1 bits, so this is not |
| 381 // valid. |
| 382 TEST(ParseExtensionTest, Critical3) { |
| 383 ParsedExtension extension; |
| 384 ASSERT_FALSE(ParseExtensionFromFile("extension_critical_3.pem", &extension)); |
| 385 } |
| 386 |
| 329 } // namespace | 387 } // namespace |
| 330 | 388 |
| 331 } // namespace net | 389 } // namespace net |
| OLD | NEW |