OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/x509_util.h" | 5 #include "net/cert/x509_util.h" |
6 #include "net/cert/x509_util_nss.h" | 6 #include "net/cert/x509_util_nss.h" |
7 | 7 |
8 #include <cert.h> | 8 #include <cert.h> |
9 #include <secoid.h> | 9 #include <secoid.h> |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 ASSERT_TRUE(ok); | 70 ASSERT_TRUE(ok); |
71 verifier.VerifyUpdate(sd.data.data, | 71 verifier.VerifyUpdate(sd.data.data, |
72 sd.data.len); | 72 sd.data.len); |
73 | 73 |
74 ok = verifier.VerifyFinal(); | 74 ok = verifier.VerifyFinal(); |
75 EXPECT_TRUE(ok); | 75 EXPECT_TRUE(ok); |
76 } | 76 } |
77 #endif // !defined(OS_WIN) && !defined(OS_MACOSX) | 77 #endif // !defined(OS_WIN) && !defined(OS_MACOSX) |
78 | 78 |
79 void VerifyDomainBoundCert(const std::string& domain, | 79 void VerifyChannelID(const std::string& domain, |
80 const std::string& der_cert) { | 80 const std::string& der_cert) { |
81 // Origin Bound Cert OID. | 81 // Origin Bound Cert OID. |
82 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6"; | 82 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6"; |
83 | 83 |
84 // Create object neccessary for extension lookup call. | 84 // Create object neccessary for extension lookup call. |
85 SECItem extension_object = { | 85 SECItem extension_object = { |
86 siAsciiString, | 86 siAsciiString, |
87 (unsigned char*)domain.data(), | 87 (unsigned char*)domain.data(), |
88 static_cast<unsigned int>(domain.size()) | 88 static_cast<unsigned int>(domain.size()) |
89 }; | 89 }; |
90 | 90 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 // Do Cleanup. | 137 // Do Cleanup. |
138 SECITEM_FreeItem(&actual, PR_FALSE); | 138 SECITEM_FreeItem(&actual, PR_FALSE); |
139 PORT_FreeArena(arena, PR_FALSE); | 139 PORT_FreeArena(arena, PR_FALSE); |
140 } | 140 } |
141 | 141 |
142 } // namespace | 142 } // namespace |
143 | 143 |
144 // This test creates a domain-bound cert and an EC private key and | 144 // This test creates a domain-bound cert and an EC private key and |
145 // then verifies the content of the certificate. | 145 // then verifies the content of the certificate. |
146 TEST(X509UtilNSSTest, CreateKeyAndDomainBoundCertEC) { | 146 TEST(X509UtilNSSTest, CreateKeyAndChannelIDEC) { |
147 // Create a sample ASCII weborigin. | 147 // Create a sample ASCII weborigin. |
148 std::string domain = "weborigin.com"; | 148 std::string domain = "weborigin.com"; |
149 base::Time now = base::Time::Now(); | 149 base::Time now = base::Time::Now(); |
150 | 150 |
151 scoped_ptr<crypto::ECPrivateKey> private_key; | 151 scoped_ptr<crypto::ECPrivateKey> private_key; |
152 std::string der_cert; | 152 std::string der_cert; |
153 ASSERT_TRUE(x509_util::CreateKeyAndDomainBoundCertEC( | 153 ASSERT_TRUE(x509_util::CreateKeyAndChannelIDEC( |
154 domain, 1, | 154 domain, 1, |
155 now, | 155 now, |
156 now + base::TimeDelta::FromDays(1), | 156 now + base::TimeDelta::FromDays(1), |
157 &private_key, | 157 &private_key, |
158 &der_cert)); | 158 &der_cert)); |
159 | 159 |
160 VerifyDomainBoundCert(domain, der_cert); | 160 VerifyChannelID(domain, der_cert); |
161 | 161 |
162 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 162 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
163 // signature_verifier_win and signature_verifier_mac can't handle EC certs. | 163 // signature_verifier_win and signature_verifier_mac can't handle EC certs. |
164 std::vector<uint8> spki; | 164 std::vector<uint8> spki; |
165 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); | 165 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); |
166 VerifyCertificateSignature(der_cert, spki); | 166 VerifyCertificateSignature(der_cert, spki); |
167 #endif | 167 #endif |
168 } | 168 } |
169 | 169 |
170 } // namespace net | 170 } // namespace net |
OLD | NEW |