• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifdef UNSAFE_BUFFERS_BUILD
6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
7 #pragma allow_unsafe_buffers
8 #endif
9 
10 #include "net/cert/symantec_certs.h"
11 
12 #include <algorithm>
13 
14 #include "net/base/hash_value.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 
17 namespace net {
18 
19 // Tests that IsLegacySymantecCert() returns false for non-Symantec hash values.
TEST(SymantecCertsTest,IsUnrelatedCertSymantecLegacyCert)20 TEST(SymantecCertsTest, IsUnrelatedCertSymantecLegacyCert) {
21   SHA256HashValue unrelated_hash_value = {{0x01, 0x02}};
22   HashValueVector unrelated_hashes;
23   unrelated_hashes.push_back(HashValue(unrelated_hash_value));
24   EXPECT_FALSE(IsLegacySymantecCert(unrelated_hashes));
25 }
26 
27 // Tests that IsLegacySymantecCert() works correctly for excluded and
28 // non-excluded Symantec roots.
TEST(SymantecCertsTest,IsLegacySymantecCert)29 TEST(SymantecCertsTest, IsLegacySymantecCert) {
30   SHA256HashValue symantec_hash_value = {
31       {0xb2, 0xde, 0xf5, 0x36, 0x2a, 0xd3, 0xfa, 0xcd, 0x04, 0xbd, 0x29,
32        0x04, 0x7a, 0x43, 0x84, 0x4f, 0x76, 0x70, 0x34, 0xea, 0x48, 0x92,
33        0xf8, 0x0e, 0x56, 0xbe, 0xe6, 0x90, 0x24, 0x3e, 0x25, 0x02}};
34   SHA256HashValue google_hash_value = {
35       {0xec, 0x72, 0x29, 0x69, 0xcb, 0x64, 0x20, 0x0a, 0xb6, 0x63, 0x8f,
36        0x68, 0xac, 0x53, 0x8e, 0x40, 0xab, 0xab, 0x5b, 0x19, 0xa6, 0x48,
37        0x56, 0x61, 0x04, 0x2a, 0x10, 0x61, 0xc4, 0x61, 0x27, 0x76}};
38 
39   // Test that IsLegacySymantecCert returns true for a Symantec root.
40   HashValueVector hashes;
41   hashes.push_back(HashValue(symantec_hash_value));
42   EXPECT_TRUE(IsLegacySymantecCert(hashes));
43 
44   // ... but false when the chain includes a root on the exceptions list.
45   hashes.push_back(HashValue(google_hash_value));
46   EXPECT_FALSE(IsLegacySymantecCert(hashes));
47 }
48 
TEST(SymantecCertsTest,AreSortedArrays)49 TEST(SymantecCertsTest, AreSortedArrays) {
50   ASSERT_TRUE(
51       std::is_sorted(kSymantecRoots, kSymantecRoots + kSymantecRootsLength));
52   ASSERT_TRUE(std::is_sorted(kSymantecExceptions,
53                              kSymantecExceptions + kSymantecExceptionsLength));
54   ASSERT_TRUE(std::is_sorted(kSymantecManagedCAs,
55                              kSymantecManagedCAs + kSymantecManagedCAsLength));
56 }
57 
58 }  // namespace net
59