Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: net/cert/internal/parse_certificate_unittest.cc

Issue 1383873002: Add a function for parsing an RFC 5280 Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix U-A-F in tests Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const PemBlockMapping mappings[] = {
335 {"EXTENSION", data},
336 };
337
338 EXPECT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings));
339 return ParseExtension(InputFromString(data), out);
340 }
341
342 // Parses an Extension whose critical field is true (255).
343 TEST(ParseExtensionTest, Critical) {
344 std::string data;
345 ParsedExtension extension;
346 ASSERT_TRUE(
347 ParseExtensionFromFile("extension_critical.pem", &extension, &data));
348
349 EXPECT_TRUE(extension.critical);
350
351 const uint8_t kExpectedOid[] = {0x55, 0x1d, 0x13};
352 EXPECT_EQ(der::Input(kExpectedOid), extension.oid);
353
354 const uint8_t kExpectedValue[] = {0x30, 0x00};
355 EXPECT_EQ(der::Input(kExpectedValue), extension.value);
356 }
357
358 // Parses an Extension whose critical field is false (omitted).
359 TEST(ParseExtensionTest, NotCritical) {
360 std::string data;
361 ParsedExtension extension;
362 ASSERT_TRUE(
363 ParseExtensionFromFile("extension_not_critical.pem", &extension, &data));
364
365 EXPECT_FALSE(extension.critical);
366
367 const uint8_t kExpectedOid[] = {0x55, 0x1d, 0x13};
368 EXPECT_EQ(der::Input(kExpectedOid), extension.oid);
369
370 const uint8_t kExpectedValue[] = {0x30, 0x00};
371 EXPECT_EQ(der::Input(kExpectedValue), extension.value);
372 }
373
374 // Parses an Extension whose critical field is 0. This is in one sense FALSE,
375 // however because critical has DEFAULT of false this is in fact invalid
376 // DER-encoding.
377 TEST(ParseExtensionTest, Critical0) {
378 std::string data;
379 ParsedExtension extension;
380 ASSERT_FALSE(
381 ParseExtensionFromFile("extension_critical_0.pem", &extension, &data));
382 }
383
384 // Parses an Extension whose critical field is 3. Under DER-encoding BOOLEAN
385 // values must an octet of either all zero bits, or all 1 bits, so this is not
386 // valid.
387 TEST(ParseExtensionTest, Critical3) {
388 std::string data;
389 ParsedExtension extension;
390 ASSERT_FALSE(
391 ParseExtensionFromFile("extension_critical_3.pem", &extension, &data));
392 }
393
329 } // namespace 394 } // namespace
330 395
331 } // namespace net 396 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/internal/parse_certificate.cc ('k') | net/data/parse_certificate_unittest/extension_critical.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698