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

Side by Side Diff: net/base/cert_verify_proc_unittest.cc

Issue 9812035: Introduce CertVerifierProc to handle system cert validation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Lint Created 8 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « net/base/cert_verify_proc.cc ('k') | net/base/multi_threaded_cert_verifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/cert_verify_proc.h"
6
7 #include <vector>
8
5 #include "base/file_path.h" 9 #include "base/file_path.h"
6 #include "base/file_util.h" 10 #include "base/string_number_conversions.h"
7 #include "base/path_service.h"
8 #include "base/pickle.h"
9 #include "base/sha1.h" 11 #include "base/sha1.h"
10 #include "base/string_number_conversions.h"
11 #include "base/string_split.h"
12 #include "crypto/rsa_private_key.h"
13 #include "net/base/asn1_util.h"
14 #include "net/base/cert_status_flags.h" 12 #include "net/base/cert_status_flags.h"
15 #include "net/base/cert_test_util.h" 13 #include "net/base/cert_test_util.h"
16 #include "net/base/cert_verify_result.h" 14 #include "net/base/cert_verify_result.h"
17 #include "net/base/crl_set.h" 15 #include "net/base/crl_set.h"
18 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
19 #include "net/base/test_certificate_data.h" 17 #include "net/base/test_certificate_data.h"
20 #include "net/base/test_root_certs.h" 18 #include "net/base/test_root_certs.h"
21 #include "net/base/x509_certificate.h" 19 #include "net/base/x509_certificate.h"
22 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
23 21
24 #if defined(USE_NSS)
25 #include <cert.h>
26 #endif
27
28 #if defined(OS_WIN) 22 #if defined(OS_WIN)
29 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
30 #elif defined(OS_MACOSX) 24 #elif defined(OS_MACOSX)
31 #include "base/mac/mac_util.h" 25 #include "base/mac/mac_util.h"
32 #endif 26 #endif
33 27
34 using base::HexEncode; 28 using base::HexEncode;
35 using base::Time;
36 29
37 namespace net { 30 namespace net {
38 31
39 // Certificates for test data. They're obtained with: 32 namespace {
40 //
41 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null
42 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der
43 //
44 // For fingerprint
45 // $ openssl x509 -inform DER -fingerprint -noout < /tmp/host.der
46
47 // For valid_start, valid_expiry
48 // $ openssl x509 -inform DER -text -noout < /tmp/host.der |
49 // grep -A 2 Validity
50 // $ date +%s -d '<date str>'
51
52 // Google's cert.
53 unsigned char google_fingerprint[] = {
54 0xab, 0xbe, 0x5e, 0xb4, 0x93, 0x88, 0x4e, 0xe4, 0x60, 0xc6, 0xef, 0xf8,
55 0xea, 0xd4, 0xb1, 0x55, 0x4b, 0xc9, 0x59, 0x3c
56 };
57
58 // webkit.org's cert.
59 unsigned char webkit_fingerprint[] = {
60 0xa1, 0x4a, 0x94, 0x46, 0x22, 0x8e, 0x70, 0x66, 0x2b, 0x94, 0xf9, 0xf8,
61 0x57, 0x83, 0x2d, 0xa2, 0xff, 0xbc, 0x84, 0xc2
62 };
63
64 // thawte.com's cert (it's EV-licious!).
65 unsigned char thawte_fingerprint[] = {
66 0x85, 0x04, 0x2d, 0xfd, 0x2b, 0x0e, 0xc6, 0xc8, 0xaf, 0x2d, 0x77, 0xd6,
67 0xa1, 0x3a, 0x64, 0x04, 0x27, 0x90, 0x97, 0x37
68 };
69 33
70 // A certificate for www.paypal.com with a NULL byte in the common name. 34 // A certificate for www.paypal.com with a NULL byte in the common name.
71 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 35 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363
72 unsigned char paypal_null_fingerprint[] = { 36 unsigned char paypal_null_fingerprint[] = {
73 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba, 37 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba,
74 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7 38 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7
75 }; 39 };
76 40
77 // A certificate for https://www.unosoft.hu/, whose AIA extension contains 41 } // namespace
78 // an LDAP URL without a host name. 42
79 unsigned char unosoft_hu_fingerprint[] = { 43 class CertVerifyProcTest : public testing::Test {
80 0x32, 0xff, 0xe3, 0xbe, 0x2c, 0x3b, 0xc7, 0xca, 0xbf, 0x2d, 0x64, 0xbd, 44 public:
81 0x25, 0x66, 0xf2, 0xec, 0x8b, 0x0f, 0xbf, 0xd8 45 CertVerifyProcTest()
46 : verify_proc_(CertVerifyProc::CreateDefault()) {
47 }
48 virtual ~CertVerifyProcTest() {}
49
50 protected:
51 int Verify(X509Certificate* cert,
52 const std::string& hostname,
53 int flags,
54 CRLSet* crl_set,
55 CertVerifyResult* verify_result) {
56 return verify_proc_->Verify(cert, hostname, flags, crl_set,
57 verify_result);
58 }
59
60 private:
61 scoped_refptr<CertVerifyProc> verify_proc_;
82 }; 62 };
83 63
84 // The fingerprint of the Google certificate used in the parsing tests, 64 TEST_F(CertVerifyProcTest, WithoutRevocationChecking) {
85 // which is newer than the one included in the x509_certificate_data.h
86 unsigned char google_parse_fingerprint[] = {
87 0x40, 0x50, 0x62, 0xe5, 0xbe, 0xfd, 0xe4, 0xaf, 0x97, 0xe9, 0x38, 0x2a,
88 0xf1, 0x6c, 0xc8, 0x7c, 0x8f, 0xb7, 0xc4, 0xe2
89 };
90
91 // The fingerprint for the Thawte SGC certificate
92 unsigned char thawte_parse_fingerprint[] = {
93 0xec, 0x07, 0x10, 0x03, 0xd8, 0xf5, 0xa3, 0x7f, 0x42, 0xc4, 0x55, 0x7f,
94 0x65, 0x6a, 0xae, 0x86, 0x65, 0xfa, 0x4b, 0x02
95 };
96
97 // Dec 18 00:00:00 2009 GMT
98 const double kGoogleParseValidFrom = 1261094400;
99 // Dec 18 23:59:59 2011 GMT
100 const double kGoogleParseValidTo = 1324252799;
101
102 struct CertificateFormatTestData {
103 const char* file_name;
104 X509Certificate::Format format;
105 unsigned char* chain_fingerprints[3];
106 };
107
108 const CertificateFormatTestData FormatTestData[] = {
109 // DER Parsing - single certificate, DER encoded
110 { "google.single.der", X509Certificate::FORMAT_SINGLE_CERTIFICATE,
111 { google_parse_fingerprint,
112 NULL, } },
113 // DER parsing - single certificate, PEM encoded
114 { "google.single.pem", X509Certificate::FORMAT_SINGLE_CERTIFICATE,
115 { google_parse_fingerprint,
116 NULL, } },
117 // PEM parsing - single certificate, PEM encoded with a PEB of
118 // "CERTIFICATE"
119 { "google.single.pem", X509Certificate::FORMAT_PEM_CERT_SEQUENCE,
120 { google_parse_fingerprint,
121 NULL, } },
122 // PEM parsing - sequence of certificates, PEM encoded with a PEB of
123 // "CERTIFICATE"
124 { "google.chain.pem", X509Certificate::FORMAT_PEM_CERT_SEQUENCE,
125 { google_parse_fingerprint,
126 thawte_parse_fingerprint,
127 NULL, } },
128 // PKCS#7 parsing - "degenerate" SignedData collection of certificates, DER
129 // encoding
130 { "google.binary.p7b", X509Certificate::FORMAT_PKCS7,
131 { google_parse_fingerprint,
132 thawte_parse_fingerprint,
133 NULL, } },
134 // PKCS#7 parsing - "degenerate" SignedData collection of certificates, PEM
135 // encoded with a PEM PEB of "CERTIFICATE"
136 { "google.pem_cert.p7b", X509Certificate::FORMAT_PKCS7,
137 { google_parse_fingerprint,
138 thawte_parse_fingerprint,
139 NULL, } },
140 // PKCS#7 parsing - "degenerate" SignedData collection of certificates, PEM
141 // encoded with a PEM PEB of "PKCS7"
142 { "google.pem_pkcs7.p7b", X509Certificate::FORMAT_PKCS7,
143 { google_parse_fingerprint,
144 thawte_parse_fingerprint,
145 NULL, } },
146 // All of the above, this time using auto-detection
147 { "google.single.der", X509Certificate::FORMAT_AUTO,
148 { google_parse_fingerprint,
149 NULL, } },
150 { "google.single.pem", X509Certificate::FORMAT_AUTO,
151 { google_parse_fingerprint,
152 NULL, } },
153 { "google.chain.pem", X509Certificate::FORMAT_AUTO,
154 { google_parse_fingerprint,
155 thawte_parse_fingerprint,
156 NULL, } },
157 { "google.binary.p7b", X509Certificate::FORMAT_AUTO,
158 { google_parse_fingerprint,
159 thawte_parse_fingerprint,
160 NULL, } },
161 { "google.pem_cert.p7b", X509Certificate::FORMAT_AUTO,
162 { google_parse_fingerprint,
163 thawte_parse_fingerprint,
164 NULL, } },
165 { "google.pem_pkcs7.p7b", X509Certificate::FORMAT_AUTO,
166 { google_parse_fingerprint,
167 thawte_parse_fingerprint,
168 NULL, } },
169 };
170
171 void CheckGoogleCert(const scoped_refptr<X509Certificate>& google_cert,
172 unsigned char* expected_fingerprint,
173 double valid_from, double valid_to) {
174 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_cert);
175
176 const CertPrincipal& subject = google_cert->subject();
177 EXPECT_EQ("www.google.com", subject.common_name);
178 EXPECT_EQ("Mountain View", subject.locality_name);
179 EXPECT_EQ("California", subject.state_or_province_name);
180 EXPECT_EQ("US", subject.country_name);
181 EXPECT_EQ(0U, subject.street_addresses.size());
182 ASSERT_EQ(1U, subject.organization_names.size());
183 EXPECT_EQ("Google Inc", subject.organization_names[0]);
184 EXPECT_EQ(0U, subject.organization_unit_names.size());
185 EXPECT_EQ(0U, subject.domain_components.size());
186
187 const CertPrincipal& issuer = google_cert->issuer();
188 EXPECT_EQ("Thawte SGC CA", issuer.common_name);
189 EXPECT_EQ("", issuer.locality_name);
190 EXPECT_EQ("", issuer.state_or_province_name);
191 EXPECT_EQ("ZA", issuer.country_name);
192 EXPECT_EQ(0U, issuer.street_addresses.size());
193 ASSERT_EQ(1U, issuer.organization_names.size());
194 EXPECT_EQ("Thawte Consulting (Pty) Ltd.", issuer.organization_names[0]);
195 EXPECT_EQ(0U, issuer.organization_unit_names.size());
196 EXPECT_EQ(0U, issuer.domain_components.size());
197
198 // Use DoubleT because its epoch is the same on all platforms
199 const Time& valid_start = google_cert->valid_start();
200 EXPECT_EQ(valid_from, valid_start.ToDoubleT());
201
202 const Time& valid_expiry = google_cert->valid_expiry();
203 EXPECT_EQ(valid_to, valid_expiry.ToDoubleT());
204
205 const SHA1Fingerprint& fingerprint = google_cert->fingerprint();
206 for (size_t i = 0; i < 20; ++i)
207 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]);
208
209 std::vector<std::string> dns_names;
210 google_cert->GetDNSNames(&dns_names);
211 ASSERT_EQ(1U, dns_names.size());
212 EXPECT_EQ("www.google.com", dns_names[0]);
213 }
214
215 TEST(X509CertificateTest, GoogleCertParsing) {
216 scoped_refptr<X509Certificate> google_cert(
217 X509Certificate::CreateFromBytes(
218 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
219
220 CheckGoogleCert(google_cert, google_fingerprint,
221 1238192407, // Mar 27 22:20:07 2009 GMT
222 1269728407); // Mar 27 22:20:07 2010 GMT
223 }
224
225 TEST(X509CertificateTest, WebkitCertParsing) {
226 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
227 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
228
229 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert);
230
231 const CertPrincipal& subject = webkit_cert->subject();
232 EXPECT_EQ("Cupertino", subject.locality_name);
233 EXPECT_EQ("California", subject.state_or_province_name);
234 EXPECT_EQ("US", subject.country_name);
235 EXPECT_EQ(0U, subject.street_addresses.size());
236 ASSERT_EQ(1U, subject.organization_names.size());
237 EXPECT_EQ("Apple Inc.", subject.organization_names[0]);
238 ASSERT_EQ(1U, subject.organization_unit_names.size());
239 EXPECT_EQ("Mac OS Forge", subject.organization_unit_names[0]);
240 EXPECT_EQ(0U, subject.domain_components.size());
241
242 const CertPrincipal& issuer = webkit_cert->issuer();
243 EXPECT_EQ("Go Daddy Secure Certification Authority", issuer.common_name);
244 EXPECT_EQ("Scottsdale", issuer.locality_name);
245 EXPECT_EQ("Arizona", issuer.state_or_province_name);
246 EXPECT_EQ("US", issuer.country_name);
247 EXPECT_EQ(0U, issuer.street_addresses.size());
248 ASSERT_EQ(1U, issuer.organization_names.size());
249 EXPECT_EQ("GoDaddy.com, Inc.", issuer.organization_names[0]);
250 ASSERT_EQ(1U, issuer.organization_unit_names.size());
251 EXPECT_EQ("http://certificates.godaddy.com/repository",
252 issuer.organization_unit_names[0]);
253 EXPECT_EQ(0U, issuer.domain_components.size());
254
255 // Use DoubleT because its epoch is the same on all platforms
256 const Time& valid_start = webkit_cert->valid_start();
257 EXPECT_EQ(1205883319, valid_start.ToDoubleT()); // Mar 18 23:35:19 2008 GMT
258
259 const Time& valid_expiry = webkit_cert->valid_expiry();
260 EXPECT_EQ(1300491319, valid_expiry.ToDoubleT()); // Mar 18 23:35:19 2011 GMT
261
262 const SHA1Fingerprint& fingerprint = webkit_cert->fingerprint();
263 for (size_t i = 0; i < 20; ++i)
264 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]);
265
266 std::vector<std::string> dns_names;
267 webkit_cert->GetDNSNames(&dns_names);
268 ASSERT_EQ(2U, dns_names.size());
269 EXPECT_EQ("*.webkit.org", dns_names[0]);
270 EXPECT_EQ("webkit.org", dns_names[1]);
271
272 // Test that the wildcard cert matches properly.
273 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org"));
274 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org"));
275 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org"));
276 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com"));
277 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com"));
278 }
279
280 TEST(X509CertificateTest, WithoutRevocationChecking) {
281 // Check that verification without revocation checking works. 65 // Check that verification without revocation checking works.
282 CertificateList certs = CreateCertificateListFromFile( 66 CertificateList certs = CreateCertificateListFromFile(
283 GetTestCertsDirectory(), 67 GetTestCertsDirectory(),
284 "googlenew.chain.pem", 68 "googlenew.chain.pem",
285 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 69 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
286 70
287 X509Certificate::OSCertHandles intermediates; 71 X509Certificate::OSCertHandles intermediates;
288 intermediates.push_back(certs[1]->os_cert_handle()); 72 intermediates.push_back(certs[1]->os_cert_handle());
289 73
290 scoped_refptr<X509Certificate> google_full_chain = 74 scoped_refptr<X509Certificate> google_full_chain =
291 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 75 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
292 intermediates); 76 intermediates);
293 77
294 CertVerifyResult verify_result; 78 CertVerifyResult verify_result;
295 EXPECT_EQ(OK, google_full_chain->Verify("www.google.com", 0 /* flags */, NULL, 79 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */,
296 &verify_result)); 80 NULL, &verify_result));
297 }
298
299 TEST(X509CertificateTest, ThawteCertParsing) {
300 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes(
301 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
302
303 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert);
304
305 const CertPrincipal& subject = thawte_cert->subject();
306 EXPECT_EQ("www.thawte.com", subject.common_name);
307 EXPECT_EQ("Mountain View", subject.locality_name);
308 EXPECT_EQ("California", subject.state_or_province_name);
309 EXPECT_EQ("US", subject.country_name);
310 EXPECT_EQ(0U, subject.street_addresses.size());
311 ASSERT_EQ(1U, subject.organization_names.size());
312 EXPECT_EQ("Thawte Inc", subject.organization_names[0]);
313 EXPECT_EQ(0U, subject.organization_unit_names.size());
314 EXPECT_EQ(0U, subject.domain_components.size());
315
316 const CertPrincipal& issuer = thawte_cert->issuer();
317 EXPECT_EQ("thawte Extended Validation SSL CA", issuer.common_name);
318 EXPECT_EQ("", issuer.locality_name);
319 EXPECT_EQ("", issuer.state_or_province_name);
320 EXPECT_EQ("US", issuer.country_name);
321 EXPECT_EQ(0U, issuer.street_addresses.size());
322 ASSERT_EQ(1U, issuer.organization_names.size());
323 EXPECT_EQ("thawte, Inc.", issuer.organization_names[0]);
324 ASSERT_EQ(1U, issuer.organization_unit_names.size());
325 EXPECT_EQ("Terms of use at https://www.thawte.com/cps (c)06",
326 issuer.organization_unit_names[0]);
327 EXPECT_EQ(0U, issuer.domain_components.size());
328
329 // Use DoubleT because its epoch is the same on all platforms
330 const Time& valid_start = thawte_cert->valid_start();
331 EXPECT_EQ(1227052800, valid_start.ToDoubleT()); // Nov 19 00:00:00 2008 GMT
332
333 const Time& valid_expiry = thawte_cert->valid_expiry();
334 EXPECT_EQ(1263772799, valid_expiry.ToDoubleT()); // Jan 17 23:59:59 2010 GMT
335
336 const SHA1Fingerprint& fingerprint = thawte_cert->fingerprint();
337 for (size_t i = 0; i < 20; ++i)
338 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]);
339
340 std::vector<std::string> dns_names;
341 thawte_cert->GetDNSNames(&dns_names);
342 ASSERT_EQ(1U, dns_names.size());
343 EXPECT_EQ("www.thawte.com", dns_names[0]);
344 } 81 }
345 82
346 #if defined(OS_ANDROID) || defined(USE_OPENSSL) 83 #if defined(OS_ANDROID) || defined(USE_OPENSSL)
347 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 84 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
348 #define MAYBE_EVVerification DISABLED_EVVerification 85 #define MAYBE_EVVerification DISABLED_EVVerification
349 #else 86 #else
350 #define MAYBE_EVVerification EVVerification 87 #define MAYBE_EVVerification EVVerification
351 #endif 88 #endif
352 TEST(X509CertificateTest, MAYBE_EVVerification) { 89 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) {
353 // This certificate will expire Jun 21, 2013. 90 // This certificate will expire Jun 21, 2013.
354 CertificateList certs = CreateCertificateListFromFile( 91 CertificateList certs = CreateCertificateListFromFile(
355 GetTestCertsDirectory(), 92 GetTestCertsDirectory(),
356 "comodo.chain.pem", 93 "comodo.chain.pem",
357 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 94 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
358 ASSERT_EQ(3U, certs.size()); 95 ASSERT_EQ(3U, certs.size());
359 96
360 X509Certificate::OSCertHandles intermediates; 97 X509Certificate::OSCertHandles intermediates;
361 intermediates.push_back(certs[1]->os_cert_handle()); 98 intermediates.push_back(certs[1]->os_cert_handle());
362 intermediates.push_back(certs[2]->os_cert_handle()); 99 intermediates.push_back(certs[2]->os_cert_handle());
363 100
364 scoped_refptr<X509Certificate> comodo_chain = 101 scoped_refptr<X509Certificate> comodo_chain =
365 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 102 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
366 intermediates); 103 intermediates);
367 104
368 scoped_refptr<CRLSet> crl_set(CRLSet::EmptyCRLSetForTesting()); 105 scoped_refptr<CRLSet> crl_set(CRLSet::EmptyCRLSetForTesting());
369 CertVerifyResult verify_result; 106 CertVerifyResult verify_result;
370 int flags = X509Certificate::VERIFY_EV_CERT; 107 int flags = X509Certificate::VERIFY_EV_CERT;
371 int error = comodo_chain->Verify( 108 int error = Verify(comodo_chain, "comodo.com", flags, crl_set.get(),
372 "comodo.com", flags, crl_set.get(), &verify_result); 109 &verify_result);
373 EXPECT_EQ(OK, error); 110 EXPECT_EQ(OK, error);
374 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 111 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
375 } 112 }
376 113
377 // Test that all desired AttributeAndValue pairs can be extracted when only 114 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) {
378 // a single RelativeDistinguishedName is present. "Normally" there is only
379 // one AVA per RDN, but some CAs place all AVAs within a single RDN.
380 // This is a regression test for http://crbug.com/101009
381 TEST(X509CertificateTest, MultivalueRDN) {
382 FilePath certs_dir = GetTestCertsDirectory();
383
384 scoped_refptr<X509Certificate> multivalue_rdn_cert =
385 ImportCertFromFile(certs_dir, "multivalue_rdn.pem");
386 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert);
387
388 const CertPrincipal& subject = multivalue_rdn_cert->subject();
389 EXPECT_EQ("Multivalue RDN Test", subject.common_name);
390 EXPECT_EQ("", subject.locality_name);
391 EXPECT_EQ("", subject.state_or_province_name);
392 EXPECT_EQ("US", subject.country_name);
393 EXPECT_EQ(0U, subject.street_addresses.size());
394 ASSERT_EQ(1U, subject.organization_names.size());
395 EXPECT_EQ("Chromium", subject.organization_names[0]);
396 ASSERT_EQ(1U, subject.organization_unit_names.size());
397 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]);
398 ASSERT_EQ(1U, subject.domain_components.size());
399 EXPECT_EQ("Chromium", subject.domain_components[0]);
400 }
401
402 // Test that characters which would normally be escaped in the string form,
403 // such as '=' or '"', are not escaped when parsed as individual components.
404 // This is a regression test for http://crbug.com/102839
405 TEST(X509CertificateTest, UnescapedSpecialCharacters) {
406 FilePath certs_dir = GetTestCertsDirectory();
407
408 scoped_refptr<X509Certificate> unescaped_cert =
409 ImportCertFromFile(certs_dir, "unescaped.pem");
410 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert);
411
412 const CertPrincipal& subject = unescaped_cert->subject();
413 EXPECT_EQ("127.0.0.1", subject.common_name);
414 EXPECT_EQ("Mountain View", subject.locality_name);
415 EXPECT_EQ("California", subject.state_or_province_name);
416 EXPECT_EQ("US", subject.country_name);
417 ASSERT_EQ(1U, subject.street_addresses.size());
418 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]);
419 ASSERT_EQ(1U, subject.organization_names.size());
420 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]);
421 ASSERT_EQ(2U, subject.organization_unit_names.size());
422 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]);
423 EXPECT_EQ("Chromium", subject.organization_unit_names[1]);
424 EXPECT_EQ(0U, subject.domain_components.size());
425 }
426
427 TEST(X509CertificateTest, PaypalNullCertParsing) {
428 scoped_refptr<X509Certificate> paypal_null_cert( 115 scoped_refptr<X509Certificate> paypal_null_cert(
429 X509Certificate::CreateFromBytes( 116 X509Certificate::CreateFromBytes(
430 reinterpret_cast<const char*>(paypal_null_der), 117 reinterpret_cast<const char*>(paypal_null_der),
431 sizeof(paypal_null_der))); 118 sizeof(paypal_null_der)));
432 119
433 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); 120 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
434 121
435 const SHA1Fingerprint& fingerprint = 122 const SHA1Fingerprint& fingerprint =
436 paypal_null_cert->fingerprint(); 123 paypal_null_cert->fingerprint();
437 for (size_t i = 0; i < 20; ++i) 124 for (size_t i = 0; i < 20; ++i)
438 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); 125 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
439 126
440 int flags = 0; 127 int flags = 0;
441 CertVerifyResult verify_result; 128 CertVerifyResult verify_result;
442 int error = paypal_null_cert->Verify("www.paypal.com", flags, NULL, 129 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL,
443 &verify_result); 130 &verify_result);
444 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) 131 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN)
445 // TOOD(bulach): investigate why macosx and win aren't returning 132 // TOOD(bulach): investigate why macosx and win aren't returning
446 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. 133 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
447 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 134 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
448 #else 135 #else
449 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); 136 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
450 #endif 137 #endif
451 // Either the system crypto library should correctly report a certificate 138 // Either the system crypto library should correctly report a certificate
452 // name mismatch, or our certificate blacklist should cause us to report an 139 // name mismatch, or our certificate blacklist should cause us to report an
453 // invalid certificate. 140 // invalid certificate.
454 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) 141 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL)
455 EXPECT_TRUE(verify_result.cert_status & 142 EXPECT_TRUE(verify_result.cert_status &
456 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); 143 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
457 #endif 144 #endif
458 } 145 }
459 146
460 TEST(X509CertificateTest, SerialNumbers) {
461 scoped_refptr<X509Certificate> google_cert(
462 X509Certificate::CreateFromBytes(
463 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
464
465 static const uint8 google_serial[16] = {
466 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9,
467 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a,
468 };
469
470 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size());
471 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial,
472 sizeof(google_serial)) == 0);
473
474 // We also want to check a serial number where the first byte is >= 0x80 in
475 // case the underlying library tries to pad it.
476 scoped_refptr<X509Certificate> paypal_null_cert(
477 X509Certificate::CreateFromBytes(
478 reinterpret_cast<const char*>(paypal_null_der),
479 sizeof(paypal_null_der)));
480
481 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b};
482 ASSERT_EQ(sizeof(paypal_null_serial),
483 paypal_null_cert->serial_number().size());
484 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(),
485 paypal_null_serial, sizeof(paypal_null_serial)) == 0);
486 }
487
488 TEST(X509CertificateTest, CAFingerprints) {
489 FilePath certs_dir = GetTestCertsDirectory();
490
491 scoped_refptr<X509Certificate> server_cert =
492 ImportCertFromFile(certs_dir, "salesforce_com_test.pem");
493 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
494
495 scoped_refptr<X509Certificate> intermediate_cert1 =
496 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem");
497 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1);
498
499 scoped_refptr<X509Certificate> intermediate_cert2 =
500 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2016.pem");
501 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert2);
502
503 X509Certificate::OSCertHandles intermediates;
504 intermediates.push_back(intermediate_cert1->os_cert_handle());
505 scoped_refptr<X509Certificate> cert_chain1 =
506 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
507 intermediates);
508
509 intermediates.clear();
510 intermediates.push_back(intermediate_cert2->os_cert_handle());
511 scoped_refptr<X509Certificate> cert_chain2 =
512 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
513 intermediates);
514
515 // No intermediate CA certicates.
516 intermediates.clear();
517 scoped_refptr<X509Certificate> cert_chain3 =
518 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
519 intermediates);
520
521 static const uint8 cert_chain1_ca_fingerprint[20] = {
522 0xc2, 0xf0, 0x08, 0x7d, 0x01, 0xe6, 0x86, 0x05, 0x3a, 0x4d,
523 0x63, 0x3e, 0x7e, 0x70, 0xd4, 0xef, 0x65, 0xc2, 0xcc, 0x4f
524 };
525 static const uint8 cert_chain2_ca_fingerprint[20] = {
526 0xd5, 0x59, 0xa5, 0x86, 0x66, 0x9b, 0x08, 0xf4, 0x6a, 0x30,
527 0xa1, 0x33, 0xf8, 0xa9, 0xed, 0x3d, 0x03, 0x8e, 0x2e, 0xa8
528 };
529 // The SHA-1 hash of nothing.
530 static const uint8 cert_chain3_ca_fingerprint[20] = {
531 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55,
532 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09
533 };
534 EXPECT_TRUE(memcmp(cert_chain1->ca_fingerprint().data,
535 cert_chain1_ca_fingerprint, 20) == 0);
536 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data,
537 cert_chain2_ca_fingerprint, 20) == 0);
538 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data,
539 cert_chain3_ca_fingerprint, 20) == 0);
540 }
541
542 // A regression test for http://crbug.com/31497. 147 // A regression test for http://crbug.com/31497.
543 // This certificate will expire on 2012-04-08. The test will still 148 // This certificate will expire on 2012-04-08. The test will still
544 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test 149 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test
545 // certificates for this unit test. http://crbug.com/111742 150 // certificates for this unit test. http://crbug.com/111742
546 TEST(X509CertificateTest, IntermediateCARequireExplicitPolicy) { 151 TEST_F(CertVerifyProcTest, IntermediateCARequireExplicitPolicy) {
547 FilePath certs_dir = GetTestCertsDirectory(); 152 FilePath certs_dir = GetTestCertsDirectory();
548 153
549 scoped_refptr<X509Certificate> server_cert = 154 scoped_refptr<X509Certificate> server_cert =
550 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); 155 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der");
551 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 156 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
552 157
553 // The intermediate CA certificate's policyConstraints extension has a 158 // The intermediate CA certificate's policyConstraints extension has a
554 // requireExplicitPolicy field with SkipCerts=0. 159 // requireExplicitPolicy field with SkipCerts=0.
555 scoped_refptr<X509Certificate> intermediate_cert = 160 scoped_refptr<X509Certificate> intermediate_cert =
556 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); 161 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
557 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 162 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
558 163
559 scoped_refptr<X509Certificate> root_cert = 164 scoped_refptr<X509Certificate> root_cert =
560 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); 165 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
561 ScopedTestRoot scoped_root(root_cert); 166 ScopedTestRoot scoped_root(root_cert);
562 167
563 X509Certificate::OSCertHandles intermediates; 168 X509Certificate::OSCertHandles intermediates;
564 intermediates.push_back(intermediate_cert->os_cert_handle()); 169 intermediates.push_back(intermediate_cert->os_cert_handle());
565 scoped_refptr<X509Certificate> cert_chain = 170 scoped_refptr<X509Certificate> cert_chain =
566 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 171 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
567 intermediates); 172 intermediates);
568 173
569 int flags = 0; 174 int flags = 0;
570 CertVerifyResult verify_result; 175 CertVerifyResult verify_result;
571 int error = cert_chain->Verify("www.us.army.mil", flags, NULL, 176 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL,
572 &verify_result); 177 &verify_result);
573 if (error == OK) { 178 if (error == OK) {
574 EXPECT_EQ(0U, verify_result.cert_status); 179 EXPECT_EQ(0U, verify_result.cert_status);
575 } else { 180 } else {
576 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 181 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
577 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); 182 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status);
578 } 183 }
579 } 184 }
580 185
186
581 // Test for bug 58437. 187 // Test for bug 58437.
582 // This certificate will expire on 2011-12-21. The test will still 188 // This certificate will expire on 2011-12-21. The test will still
583 // pass if error == ERR_CERT_DATE_INVALID. 189 // pass if error == ERR_CERT_DATE_INVALID.
584 // This test is DISABLED because it appears that we cannot do 190 // This test is DISABLED because it appears that we cannot do
585 // certificate revocation checking when running all of the net unit tests. 191 // certificate revocation checking when running all of the net unit tests.
586 // This test passes when run individually, but when run with all of the net 192 // This test passes when run individually, but when run with all of the net
587 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is 193 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is
588 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation 194 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation
589 // status, i.e. that the revocation check is failing for some reason. 195 // status, i.e. that the revocation check is failing for some reason.
590 TEST(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { 196 TEST_F(CertVerifyProcTest, DISABLED_GlobalSignR3EVTest) {
591 FilePath certs_dir = GetTestCertsDirectory(); 197 FilePath certs_dir = GetTestCertsDirectory();
592 198
593 scoped_refptr<X509Certificate> server_cert = 199 scoped_refptr<X509Certificate> server_cert =
594 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); 200 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem");
595 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 201 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
596 202
597 scoped_refptr<X509Certificate> intermediate_cert = 203 scoped_refptr<X509Certificate> intermediate_cert =
598 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); 204 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem");
599 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 205 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
600 206
601 X509Certificate::OSCertHandles intermediates; 207 X509Certificate::OSCertHandles intermediates;
602 intermediates.push_back(intermediate_cert->os_cert_handle()); 208 intermediates.push_back(intermediate_cert->os_cert_handle());
603 scoped_refptr<X509Certificate> cert_chain = 209 scoped_refptr<X509Certificate> cert_chain =
604 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 210 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
605 intermediates); 211 intermediates);
606 212
607 CertVerifyResult verify_result; 213 CertVerifyResult verify_result;
608 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | 214 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
609 X509Certificate::VERIFY_EV_CERT; 215 X509Certificate::VERIFY_EV_CERT;
610 int error = cert_chain->Verify("2029.globalsign.com", flags, NULL, 216 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL,
611 &verify_result); 217 &verify_result);
612 if (error == OK) 218 if (error == OK)
613 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 219 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
614 else 220 else
615 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 221 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
616 } 222 }
617 223
618 // Currently, only RSA and DSA keys are checked for weakness, and our example 224 // Currently, only RSA and DSA keys are checked for weakness, and our example
619 // weak size is 768. These could change in the future. 225 // weak size is 768. These could change in the future.
620 // 226 //
621 // Note that this means there may be false negatives: keys for other 227 // Note that this means there may be false negatives: keys for other
622 // algorithms and which are weak will pass this test. 228 // algorithms and which are weak will pass this test.
623 static bool IsWeakKeyType(const std::string& key_type) { 229 static bool IsWeakKeyType(const std::string& key_type) {
624 size_t pos = key_type.find("-"); 230 size_t pos = key_type.find("-");
625 std::string size = key_type.substr(0, pos); 231 std::string size = key_type.substr(0, pos);
626 std::string type = key_type.substr(pos + 1); 232 std::string type = key_type.substr(pos + 1);
627 233
628 if (type == "rsa" || type == "dsa") 234 if (type == "rsa" || type == "dsa")
629 return size == "768"; 235 return size == "768";
630 236
631 return false; 237 return false;
632 } 238 }
633 239
634 TEST(X509CertificateTest, RejectWeakKeys) { 240 TEST_F(CertVerifyProcTest, RejectWeakKeys) {
635 FilePath certs_dir = GetTestCertsDirectory(); 241 FilePath certs_dir = GetTestCertsDirectory();
636 typedef std::vector<std::string> Strings; 242 typedef std::vector<std::string> Strings;
637 Strings key_types; 243 Strings key_types;
638 244
639 // generate-weak-test-chains.sh currently has: 245 // generate-weak-test-chains.sh currently has:
640 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" 246 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
641 // We must use the same key types here. The filenames generated look like: 247 // We must use the same key types here. The filenames generated look like:
642 // 2048-rsa-ee-by-768-rsa-intermediate.pem 248 // 2048-rsa-ee-by-768-rsa-intermediate.pem
643 key_types.push_back("768-rsa"); 249 key_types.push_back("768-rsa");
644 key_types.push_back("1024-rsa"); 250 key_types.push_back("1024-rsa");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 ImportCertFromFile(certs_dir, basename); 283 ImportCertFromFile(certs_dir, basename);
678 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); 284 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate);
679 285
680 X509Certificate::OSCertHandles intermediates; 286 X509Certificate::OSCertHandles intermediates;
681 intermediates.push_back(intermediate->os_cert_handle()); 287 intermediates.push_back(intermediate->os_cert_handle());
682 scoped_refptr<X509Certificate> cert_chain = 288 scoped_refptr<X509Certificate> cert_chain =
683 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 289 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
684 intermediates); 290 intermediates);
685 291
686 CertVerifyResult verify_result; 292 CertVerifyResult verify_result;
687 int error = cert_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 293 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result);
688 294
689 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { 295 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) {
690 EXPECT_NE(OK, error); 296 EXPECT_NE(OK, error);
691 EXPECT_EQ(CERT_STATUS_WEAK_KEY, 297 EXPECT_EQ(CERT_STATUS_WEAK_KEY,
692 verify_result.cert_status & CERT_STATUS_WEAK_KEY); 298 verify_result.cert_status & CERT_STATUS_WEAK_KEY);
693 } else { 299 } else {
694 EXPECT_EQ(OK, error); 300 EXPECT_EQ(OK, error);
695 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); 301 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY);
696 } 302 }
697 } 303 }
698 } 304 }
699 } 305 }
700 306
701 // Test for bug 108514. 307 // Test for bug 108514.
702 // The certificate will expire on 2012-07-20. The test will still 308 // The certificate will expire on 2012-07-20. The test will still
703 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test 309 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test
704 // certificates for this unit test. http://crbug.com/111730 310 // certificates for this unit test. http://crbug.com/111730
705 TEST(X509CertificateTest, ExtraneousMD5RootCert) { 311 TEST_F(CertVerifyProcTest, ExtraneousMD5RootCert) {
706 FilePath certs_dir = GetTestCertsDirectory(); 312 FilePath certs_dir = GetTestCertsDirectory();
707 313
708 scoped_refptr<X509Certificate> server_cert = 314 scoped_refptr<X509Certificate> server_cert =
709 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); 315 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem");
710 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 316 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
711 317
712 scoped_refptr<X509Certificate> intermediate_cert = 318 scoped_refptr<X509Certificate> intermediate_cert =
713 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); 319 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem");
714 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 320 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
715 321
716 scoped_refptr<X509Certificate> md5_root_cert = 322 scoped_refptr<X509Certificate> md5_root_cert =
717 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); 323 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem");
718 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); 324 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert);
719 325
720 X509Certificate::OSCertHandles intermediates; 326 X509Certificate::OSCertHandles intermediates;
721 intermediates.push_back(intermediate_cert->os_cert_handle()); 327 intermediates.push_back(intermediate_cert->os_cert_handle());
722 intermediates.push_back(md5_root_cert->os_cert_handle()); 328 intermediates.push_back(md5_root_cert->os_cert_handle());
723 scoped_refptr<X509Certificate> cert_chain = 329 scoped_refptr<X509Certificate> cert_chain =
724 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 330 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
725 intermediates); 331 intermediates);
726 332
727 CertVerifyResult verify_result; 333 CertVerifyResult verify_result;
728 int flags = 0; 334 int flags = 0;
729 int error = cert_chain->Verify("images.etrade.wallst.com", flags, NULL, 335 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL,
730 &verify_result); 336 &verify_result);
731 if (error != OK) 337 if (error != OK)
732 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 338 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
733 339
734 EXPECT_FALSE(verify_result.has_md5); 340 EXPECT_FALSE(verify_result.has_md5);
735 EXPECT_FALSE(verify_result.has_md5_ca); 341 EXPECT_FALSE(verify_result.has_md5_ca);
736 } 342 }
737 343
738 // Test for bug 94673. 344 // Test for bug 94673.
739 TEST(X509CertificateTest, GoogleDigiNotarTest) { 345 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) {
740 FilePath certs_dir = GetTestCertsDirectory(); 346 FilePath certs_dir = GetTestCertsDirectory();
741 347
742 scoped_refptr<X509Certificate> server_cert = 348 scoped_refptr<X509Certificate> server_cert =
743 ImportCertFromFile(certs_dir, "google_diginotar.pem"); 349 ImportCertFromFile(certs_dir, "google_diginotar.pem");
744 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 350 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
745 351
746 scoped_refptr<X509Certificate> intermediate_cert = 352 scoped_refptr<X509Certificate> intermediate_cert =
747 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); 353 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
748 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 354 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
749 355
750 X509Certificate::OSCertHandles intermediates; 356 X509Certificate::OSCertHandles intermediates;
751 intermediates.push_back(intermediate_cert->os_cert_handle()); 357 intermediates.push_back(intermediate_cert->os_cert_handle());
752 scoped_refptr<X509Certificate> cert_chain = 358 scoped_refptr<X509Certificate> cert_chain =
753 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 359 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
754 intermediates); 360 intermediates);
755 361
756 CertVerifyResult verify_result; 362 CertVerifyResult verify_result;
757 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; 363 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED;
758 int error = cert_chain->Verify("mail.google.com", flags, NULL, 364 int error = Verify(cert_chain, "mail.google.com", flags, NULL,
759 &verify_result); 365 &verify_result);
760 EXPECT_NE(OK, error); 366 EXPECT_NE(OK, error);
761 367
762 // Now turn off revocation checking. Certificate verification should still 368 // Now turn off revocation checking. Certificate verification should still
763 // fail. 369 // fail.
764 flags = 0; 370 flags = 0;
765 error = cert_chain->Verify("mail.google.com", flags, NULL, &verify_result); 371 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result);
766 EXPECT_NE(OK, error); 372 EXPECT_NE(OK, error);
767 } 373 }
768 374
769 TEST(X509CertificateTest, DigiNotarCerts) {
770 static const char* const kDigiNotarFilenames[] = {
771 "diginotar_root_ca.pem",
772 "diginotar_cyber_ca.pem",
773 "diginotar_services_1024_ca.pem",
774 "diginotar_pkioverheid.pem",
775 "diginotar_pkioverheid_g2.pem",
776 NULL,
777 };
778
779 FilePath certs_dir = GetTestCertsDirectory();
780
781 for (size_t i = 0; kDigiNotarFilenames[i]; i++) {
782 scoped_refptr<X509Certificate> diginotar_cert =
783 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
784 std::string der_bytes;
785 ASSERT_TRUE(X509Certificate::GetDEREncoded(
786 diginotar_cert->os_cert_handle(), &der_bytes));
787
788 base::StringPiece spki;
789 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
790
791 std::string spki_sha1 = base::SHA1HashString(spki.as_string());
792
793 std::vector<SHA1Fingerprint> public_keys;
794 SHA1Fingerprint fingerprint;
795 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size());
796 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size());
797 public_keys.push_back(fingerprint);
798
799 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) <<
800 "Public key not blocked for " << kDigiNotarFilenames[i];
801 }
802 }
803
804 // Bug 111893: This test needs a new certificate. 375 // Bug 111893: This test needs a new certificate.
805 TEST(X509CertificateTest, DISABLED_TestKnownRoot) { 376 TEST_F(CertVerifyProcTest, DISABLED_TestKnownRoot) {
806 FilePath certs_dir = GetTestCertsDirectory(); 377 FilePath certs_dir = GetTestCertsDirectory();
807 scoped_refptr<X509Certificate> cert = 378 scoped_refptr<X509Certificate> cert =
808 ImportCertFromFile(certs_dir, "nist.der"); 379 ImportCertFromFile(certs_dir, "nist.der");
809 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 380 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
810 381
811 // This intermediate is only needed for old Linux machines. Modern NSS 382 // This intermediate is only needed for old Linux machines. Modern NSS
812 // includes it as a root already. 383 // includes it as a root already.
813 scoped_refptr<X509Certificate> intermediate_cert = 384 scoped_refptr<X509Certificate> intermediate_cert =
814 ImportCertFromFile(certs_dir, "nist_intermediate.der"); 385 ImportCertFromFile(certs_dir, "nist_intermediate.der");
815 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 386 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
816 387
817 X509Certificate::OSCertHandles intermediates; 388 X509Certificate::OSCertHandles intermediates;
818 intermediates.push_back(intermediate_cert->os_cert_handle()); 389 intermediates.push_back(intermediate_cert->os_cert_handle());
819 scoped_refptr<X509Certificate> cert_chain = 390 scoped_refptr<X509Certificate> cert_chain =
820 X509Certificate::CreateFromHandle(cert->os_cert_handle(), 391 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
821 intermediates); 392 intermediates);
822 393
823 int flags = 0; 394 int flags = 0;
824 CertVerifyResult verify_result; 395 CertVerifyResult verify_result;
825 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug 396 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
826 // against agl. Also see PublicKeyHashes in this file. 397 // against agl. Also see PublicKeyHashes in this file.
827 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); 398 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
828 EXPECT_EQ(OK, error); 399 EXPECT_EQ(OK, error);
829 EXPECT_EQ(0U, verify_result.cert_status); 400 EXPECT_EQ(0U, verify_result.cert_status);
830 EXPECT_TRUE(verify_result.is_issued_by_known_root); 401 EXPECT_TRUE(verify_result.is_issued_by_known_root);
831 } 402 }
832 403
833 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der.
834 static const char nistSPKIHash[] =
835 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82"
836 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35";
837
838 TEST(X509CertificateTest, ExtractSPKIFromDERCert) {
839 FilePath certs_dir = GetTestCertsDirectory();
840 scoped_refptr<X509Certificate> cert =
841 ImportCertFromFile(certs_dir, "nist.der");
842 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
843
844 std::string derBytes;
845 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
846 &derBytes));
847
848 base::StringPiece spkiBytes;
849 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes));
850
851 uint8 hash[base::kSHA1Length];
852 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()),
853 spkiBytes.size(), hash);
854
855 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash)));
856 }
857
858 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) {
859 FilePath certs_dir = GetTestCertsDirectory();
860 scoped_refptr<X509Certificate> cert =
861 ImportCertFromFile(certs_dir, "nist.der");
862 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
863
864 std::string derBytes;
865 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
866 &derBytes));
867
868 std::vector<base::StringPiece> crl_urls;
869 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls));
870
871 EXPECT_EQ(1u, crl_urls.size());
872 if (crl_urls.size() > 0) {
873 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl",
874 crl_urls[0].as_string());
875 }
876 }
877
878 // Bug 111893: This test needs a new certificate. 404 // Bug 111893: This test needs a new certificate.
879 TEST(X509CertificateTest, DISABLED_PublicKeyHashes) { 405 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) {
880 FilePath certs_dir = GetTestCertsDirectory(); 406 FilePath certs_dir = GetTestCertsDirectory();
881 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug 407 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
882 // against agl. Also see TestKnownRoot in this file. 408 // against agl. Also see TestKnownRoot in this file.
883 scoped_refptr<X509Certificate> cert = 409 scoped_refptr<X509Certificate> cert =
884 ImportCertFromFile(certs_dir, "nist.der"); 410 ImportCertFromFile(certs_dir, "nist.der");
885 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 411 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
886 412
887 // This intermediate is only needed for old Linux machines. Modern NSS 413 // This intermediate is only needed for old Linux machines. Modern NSS
888 // includes it as a root already. 414 // includes it as a root already.
889 scoped_refptr<X509Certificate> intermediate_cert = 415 scoped_refptr<X509Certificate> intermediate_cert =
890 ImportCertFromFile(certs_dir, "nist_intermediate.der"); 416 ImportCertFromFile(certs_dir, "nist_intermediate.der");
891 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 417 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
892 418
893 ScopedTestRoot scoped_intermediate(intermediate_cert); 419 ScopedTestRoot scoped_intermediate(intermediate_cert);
894 420
895 X509Certificate::OSCertHandles intermediates; 421 X509Certificate::OSCertHandles intermediates;
896 intermediates.push_back(intermediate_cert->os_cert_handle()); 422 intermediates.push_back(intermediate_cert->os_cert_handle());
897 scoped_refptr<X509Certificate> cert_chain = 423 scoped_refptr<X509Certificate> cert_chain =
898 X509Certificate::CreateFromHandle(cert->os_cert_handle(), 424 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
899 intermediates); 425 intermediates);
900 426
901 int flags = 0; 427 int flags = 0;
902 CertVerifyResult verify_result; 428 CertVerifyResult verify_result;
903 429
904 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); 430 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
905 EXPECT_EQ(OK, error); 431 EXPECT_EQ(OK, error);
906 EXPECT_EQ(0U, verify_result.cert_status); 432 EXPECT_EQ(0U, verify_result.cert_status);
907 ASSERT_LE(2u, verify_result.public_key_hashes.size()); 433 ASSERT_LE(2u, verify_result.public_key_hashes.size());
908 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), 434 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length),
909 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); 435 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length));
910 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", 436 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD",
911 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); 437 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length));
912 } 438 }
913 439
914 // A regression test for http://crbug.com/70293. 440 // A regression test for http://crbug.com/70293.
915 // The Key Usage extension in this RSA SSL server certificate does not have 441 // The Key Usage extension in this RSA SSL server certificate does not have
916 // the keyEncipherment bit. 442 // the keyEncipherment bit.
917 TEST(X509CertificateTest, InvalidKeyUsage) { 443 TEST_F(CertVerifyProcTest, InvalidKeyUsage) {
918 FilePath certs_dir = GetTestCertsDirectory(); 444 FilePath certs_dir = GetTestCertsDirectory();
919 445
920 scoped_refptr<X509Certificate> server_cert = 446 scoped_refptr<X509Certificate> server_cert =
921 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); 447 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der");
922 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 448 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
923 449
924 int flags = 0; 450 int flags = 0;
925 CertVerifyResult verify_result; 451 CertVerifyResult verify_result;
926 int error = server_cert->Verify("jira.aquameta.com", flags, NULL, 452 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL,
927 &verify_result); 453 &verify_result);
928 #if defined(USE_OPENSSL) 454 #if defined(USE_OPENSSL)
929 // This certificate has two errors: "invalid key usage" and "untrusted CA". 455 // This certificate has two errors: "invalid key usage" and "untrusted CA".
930 // However, OpenSSL returns only one (the latter), and we can't detect 456 // However, OpenSSL returns only one (the latter), and we can't detect
931 // the other errors. 457 // the other errors.
932 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 458 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
933 #else 459 #else
934 EXPECT_EQ(ERR_CERT_INVALID, error); 460 EXPECT_EQ(ERR_CERT_INVALID, error);
935 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 461 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
936 #endif 462 #endif
937 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors 463 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
938 // from NSS. 464 // from NSS.
939 #if !defined(USE_NSS) 465 #if !defined(USE_NSS)
940 // The certificate is issued by an unknown CA. 466 // The certificate is issued by an unknown CA.
941 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); 467 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
942 #endif 468 #endif
943 } 469 }
944 470
945 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We
946 // call X509Certificate::CreateFromHandle several times and observe whether
947 // it returns a cached or new OSCertHandle.
948 TEST(X509CertificateTest, Cache) {
949 X509Certificate::OSCertHandle google_cert_handle;
950 X509Certificate::OSCertHandle thawte_cert_handle;
951
952 // Add a single certificate to the certificate cache.
953 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
954 reinterpret_cast<const char*>(google_der), sizeof(google_der));
955 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle(
956 google_cert_handle, X509Certificate::OSCertHandles()));
957 X509Certificate::FreeOSCertHandle(google_cert_handle);
958
959 // Add the same certificate, but as a new handle.
960 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
961 reinterpret_cast<const char*>(google_der), sizeof(google_der));
962 scoped_refptr<X509Certificate> cert2(X509Certificate::CreateFromHandle(
963 google_cert_handle, X509Certificate::OSCertHandles()));
964 X509Certificate::FreeOSCertHandle(google_cert_handle);
965
966 // A new X509Certificate should be returned.
967 EXPECT_NE(cert1.get(), cert2.get());
968 // But both instances should share the underlying OS certificate handle.
969 EXPECT_EQ(cert1->os_cert_handle(), cert2->os_cert_handle());
970 EXPECT_EQ(0u, cert1->GetIntermediateCertificates().size());
971 EXPECT_EQ(0u, cert2->GetIntermediateCertificates().size());
972
973 // Add the same certificate, but this time with an intermediate. This
974 // should result in the intermediate being cached. Note that this is not
975 // a legitimate chain, but is suitable for testing.
976 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
977 reinterpret_cast<const char*>(google_der), sizeof(google_der));
978 thawte_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
979 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der));
980 X509Certificate::OSCertHandles intermediates;
981 intermediates.push_back(thawte_cert_handle);
982 scoped_refptr<X509Certificate> cert3(X509Certificate::CreateFromHandle(
983 google_cert_handle, intermediates));
984 X509Certificate::FreeOSCertHandle(google_cert_handle);
985 X509Certificate::FreeOSCertHandle(thawte_cert_handle);
986
987 // Test that the new certificate, even with intermediates, results in the
988 // same underlying handle being used.
989 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle());
990 // Though they use the same OS handle, the intermediates should be different.
991 EXPECT_NE(cert1->GetIntermediateCertificates().size(),
992 cert3->GetIntermediateCertificates().size());
993 }
994
995 TEST(X509CertificateTest, Pickle) {
996 X509Certificate::OSCertHandle google_cert_handle =
997 X509Certificate::CreateOSCertHandleFromBytes(
998 reinterpret_cast<const char*>(google_der), sizeof(google_der));
999 X509Certificate::OSCertHandle thawte_cert_handle =
1000 X509Certificate::CreateOSCertHandleFromBytes(
1001 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der));
1002
1003 X509Certificate::OSCertHandles intermediates;
1004 intermediates.push_back(thawte_cert_handle);
1005 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
1006 google_cert_handle, intermediates);
1007 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get());
1008
1009 X509Certificate::FreeOSCertHandle(google_cert_handle);
1010 X509Certificate::FreeOSCertHandle(thawte_cert_handle);
1011
1012 Pickle pickle;
1013 cert->Persist(&pickle);
1014
1015 PickleIterator iter(pickle);
1016 scoped_refptr<X509Certificate> cert_from_pickle =
1017 X509Certificate::CreateFromPickle(
1018 pickle, &iter, X509Certificate::PICKLETYPE_CERTIFICATE_CHAIN);
1019 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert_from_pickle);
1020 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1021 cert->os_cert_handle(), cert_from_pickle->os_cert_handle()));
1022 const X509Certificate::OSCertHandles& cert_intermediates =
1023 cert->GetIntermediateCertificates();
1024 const X509Certificate::OSCertHandles& pickle_intermediates =
1025 cert_from_pickle->GetIntermediateCertificates();
1026 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size());
1027 for (size_t i = 0; i < cert_intermediates.size(); ++i) {
1028 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i],
1029 pickle_intermediates[i]));
1030 }
1031 }
1032
1033 TEST(X509CertificateTest, Policy) {
1034 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes(
1035 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
1036
1037 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
1038 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1039
1040 CertPolicy policy;
1041
1042 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN);
1043 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN);
1044 EXPECT_FALSE(policy.HasAllowedCert());
1045 EXPECT_FALSE(policy.HasDeniedCert());
1046
1047 policy.Allow(google_cert.get());
1048
1049 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::ALLOWED);
1050 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN);
1051 EXPECT_TRUE(policy.HasAllowedCert());
1052 EXPECT_FALSE(policy.HasDeniedCert());
1053
1054 policy.Deny(google_cert.get());
1055
1056 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED);
1057 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN);
1058 EXPECT_FALSE(policy.HasAllowedCert());
1059 EXPECT_TRUE(policy.HasDeniedCert());
1060
1061 policy.Allow(webkit_cert.get());
1062
1063 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED);
1064 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED);
1065 EXPECT_TRUE(policy.HasAllowedCert());
1066 EXPECT_TRUE(policy.HasDeniedCert());
1067 }
1068
1069 TEST(X509CertificateTest, IntermediateCertificates) {
1070 scoped_refptr<X509Certificate> webkit_cert(
1071 X509Certificate::CreateFromBytes(
1072 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1073
1074 scoped_refptr<X509Certificate> thawte_cert(
1075 X509Certificate::CreateFromBytes(
1076 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
1077
1078 X509Certificate::OSCertHandle google_handle;
1079 // Create object with no intermediates:
1080 google_handle = X509Certificate::CreateOSCertHandleFromBytes(
1081 reinterpret_cast<const char*>(google_der), sizeof(google_der));
1082 X509Certificate::OSCertHandles intermediates1;
1083 scoped_refptr<X509Certificate> cert1;
1084 cert1 = X509Certificate::CreateFromHandle(google_handle, intermediates1);
1085 EXPECT_EQ(0u, cert1->GetIntermediateCertificates().size());
1086
1087 // Create object with 2 intermediates:
1088 X509Certificate::OSCertHandles intermediates2;
1089 intermediates2.push_back(webkit_cert->os_cert_handle());
1090 intermediates2.push_back(thawte_cert->os_cert_handle());
1091 scoped_refptr<X509Certificate> cert2;
1092 cert2 = X509Certificate::CreateFromHandle(google_handle, intermediates2);
1093
1094 // Verify it has all the intermediates:
1095 const X509Certificate::OSCertHandles& cert2_intermediates =
1096 cert2->GetIntermediateCertificates();
1097 ASSERT_EQ(2u, cert2_intermediates.size());
1098 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0],
1099 webkit_cert->os_cert_handle()));
1100 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1],
1101 thawte_cert->os_cert_handle()));
1102
1103 // Cleanup
1104 X509Certificate::FreeOSCertHandle(google_handle);
1105 }
1106
1107 // Basic test for returning the chain in CertVerifyResult. Note that the 471 // Basic test for returning the chain in CertVerifyResult. Note that the
1108 // returned chain may just be a reflection of the originally supplied chain; 472 // returned chain may just be a reflection of the originally supplied chain;
1109 // that is, if any errors occur, the default chain returned is an exact copy 473 // that is, if any errors occur, the default chain returned is an exact copy
1110 // of the certificate to be verified. The remaining VerifyReturn* tests are 474 // of the certificate to be verified. The remaining VerifyReturn* tests are
1111 // used to ensure that the actual, verified chain is being returned by 475 // used to ensure that the actual, verified chain is being returned by
1112 // Verify(). 476 // Verify().
1113 TEST(X509CertificateTest, VerifyReturnChainBasic) { 477 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) {
1114 FilePath certs_dir = GetTestCertsDirectory(); 478 FilePath certs_dir = GetTestCertsDirectory();
1115 CertificateList certs = CreateCertificateListFromFile( 479 CertificateList certs = CreateCertificateListFromFile(
1116 certs_dir, "x509_verify_results.chain.pem", 480 certs_dir, "x509_verify_results.chain.pem",
1117 X509Certificate::FORMAT_AUTO); 481 X509Certificate::FORMAT_AUTO);
1118 ASSERT_EQ(3U, certs.size()); 482 ASSERT_EQ(3U, certs.size());
1119 483
1120 X509Certificate::OSCertHandles intermediates; 484 X509Certificate::OSCertHandles intermediates;
1121 intermediates.push_back(certs[1]->os_cert_handle()); 485 intermediates.push_back(certs[1]->os_cert_handle());
1122 intermediates.push_back(certs[2]->os_cert_handle()); 486 intermediates.push_back(certs[2]->os_cert_handle());
1123 487
1124 ScopedTestRoot scoped_root(certs[2]); 488 ScopedTestRoot scoped_root(certs[2]);
1125 489
1126 scoped_refptr<X509Certificate> google_full_chain = 490 scoped_refptr<X509Certificate> google_full_chain =
1127 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 491 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1128 intermediates); 492 intermediates);
1129 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 493 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1130 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 494 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1131 495
1132 CertVerifyResult verify_result; 496 CertVerifyResult verify_result;
1133 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 497 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1134 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 498 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1135 EXPECT_EQ(OK, error); 499 EXPECT_EQ(OK, error);
1136 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 500 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1137 501
1138 EXPECT_NE(google_full_chain, verify_result.verified_cert); 502 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1139 EXPECT_TRUE(X509Certificate::IsSameOSCert( 503 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1140 google_full_chain->os_cert_handle(), 504 google_full_chain->os_cert_handle(),
1141 verify_result.verified_cert->os_cert_handle())); 505 verify_result.verified_cert->os_cert_handle()));
1142 const X509Certificate::OSCertHandles& return_intermediates = 506 const X509Certificate::OSCertHandles& return_intermediates =
1143 verify_result.verified_cert->GetIntermediateCertificates(); 507 verify_result.verified_cert->GetIntermediateCertificates();
1144 ASSERT_EQ(2U, return_intermediates.size()); 508 ASSERT_EQ(2U, return_intermediates.size());
1145 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 509 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1146 certs[1]->os_cert_handle())); 510 certs[1]->os_cert_handle()));
1147 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 511 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1148 certs[2]->os_cert_handle())); 512 certs[2]->os_cert_handle()));
1149 } 513 }
1150 514
1151 // Test that the certificate returned in CertVerifyResult is able to reorder 515 // Test that the certificate returned in CertVerifyResult is able to reorder
1152 // certificates that are not ordered from end-entity to root. While this is 516 // certificates that are not ordered from end-entity to root. While this is
1153 // a protocol violation if sent during a TLS handshake, if multiple sources 517 // a protocol violation if sent during a TLS handshake, if multiple sources
1154 // of intermediate certificates are combined, it's possible that order may 518 // of intermediate certificates are combined, it's possible that order may
1155 // not be maintained. 519 // not be maintained.
1156 TEST(X509CertificateTest, VerifyReturnChainProperlyOrdered) { 520 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) {
1157 FilePath certs_dir = GetTestCertsDirectory(); 521 FilePath certs_dir = GetTestCertsDirectory();
1158 CertificateList certs = CreateCertificateListFromFile( 522 CertificateList certs = CreateCertificateListFromFile(
1159 certs_dir, "x509_verify_results.chain.pem", 523 certs_dir, "x509_verify_results.chain.pem",
1160 X509Certificate::FORMAT_AUTO); 524 X509Certificate::FORMAT_AUTO);
1161 ASSERT_EQ(3U, certs.size()); 525 ASSERT_EQ(3U, certs.size());
1162 526
1163 // Construct the chain out of order. 527 // Construct the chain out of order.
1164 X509Certificate::OSCertHandles intermediates; 528 X509Certificate::OSCertHandles intermediates;
1165 intermediates.push_back(certs[2]->os_cert_handle()); 529 intermediates.push_back(certs[2]->os_cert_handle());
1166 intermediates.push_back(certs[1]->os_cert_handle()); 530 intermediates.push_back(certs[1]->os_cert_handle());
1167 531
1168 ScopedTestRoot scoped_root(certs[2]); 532 ScopedTestRoot scoped_root(certs[2]);
1169 533
1170 scoped_refptr<X509Certificate> google_full_chain = 534 scoped_refptr<X509Certificate> google_full_chain =
1171 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 535 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1172 intermediates); 536 intermediates);
1173 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 537 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1174 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 538 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1175 539
1176 CertVerifyResult verify_result; 540 CertVerifyResult verify_result;
1177 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 541 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1178 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 542 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1179 EXPECT_EQ(OK, error); 543 EXPECT_EQ(OK, error);
1180 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 544 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1181 545
1182 EXPECT_NE(google_full_chain, verify_result.verified_cert); 546 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1183 EXPECT_TRUE(X509Certificate::IsSameOSCert( 547 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1184 google_full_chain->os_cert_handle(), 548 google_full_chain->os_cert_handle(),
1185 verify_result.verified_cert->os_cert_handle())); 549 verify_result.verified_cert->os_cert_handle()));
1186 const X509Certificate::OSCertHandles& return_intermediates = 550 const X509Certificate::OSCertHandles& return_intermediates =
1187 verify_result.verified_cert->GetIntermediateCertificates(); 551 verify_result.verified_cert->GetIntermediateCertificates();
1188 ASSERT_EQ(2U, return_intermediates.size()); 552 ASSERT_EQ(2U, return_intermediates.size());
1189 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 553 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1190 certs[1]->os_cert_handle())); 554 certs[1]->os_cert_handle()));
1191 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 555 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1192 certs[2]->os_cert_handle())); 556 certs[2]->os_cert_handle()));
1193 } 557 }
1194 558
1195 // Test that Verify() filters out certificates which are not related to 559 // Test that Verify() filters out certificates which are not related to
1196 // or part of the certificate chain being verified. 560 // or part of the certificate chain being verified.
1197 TEST(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { 561 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) {
1198 FilePath certs_dir = GetTestCertsDirectory(); 562 FilePath certs_dir = GetTestCertsDirectory();
1199 CertificateList certs = CreateCertificateListFromFile( 563 CertificateList certs = CreateCertificateListFromFile(
1200 certs_dir, "x509_verify_results.chain.pem", 564 certs_dir, "x509_verify_results.chain.pem",
1201 X509Certificate::FORMAT_AUTO); 565 X509Certificate::FORMAT_AUTO);
1202 ASSERT_EQ(3U, certs.size()); 566 ASSERT_EQ(3U, certs.size());
1203 ScopedTestRoot scoped_root(certs[2]); 567 ScopedTestRoot scoped_root(certs[2]);
1204 568
1205 scoped_refptr<X509Certificate> unrelated_dod_certificate = 569 scoped_refptr<X509Certificate> unrelated_dod_certificate =
1206 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); 570 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
1207 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = 571 scoped_refptr<X509Certificate> unrelated_dod_certificate2 =
1208 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); 572 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
1209 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); 573 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate);
1210 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); 574 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2);
1211 575
1212 // Interject unrelated certificates into the list of intermediates. 576 // Interject unrelated certificates into the list of intermediates.
1213 X509Certificate::OSCertHandles intermediates; 577 X509Certificate::OSCertHandles intermediates;
1214 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); 578 intermediates.push_back(unrelated_dod_certificate->os_cert_handle());
1215 intermediates.push_back(certs[1]->os_cert_handle()); 579 intermediates.push_back(certs[1]->os_cert_handle());
1216 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); 580 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle());
1217 intermediates.push_back(certs[2]->os_cert_handle()); 581 intermediates.push_back(certs[2]->os_cert_handle());
1218 582
1219 scoped_refptr<X509Certificate> google_full_chain = 583 scoped_refptr<X509Certificate> google_full_chain =
1220 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 584 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1221 intermediates); 585 intermediates);
1222 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 586 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1223 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); 587 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size());
1224 588
1225 CertVerifyResult verify_result; 589 CertVerifyResult verify_result;
1226 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 590 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1227 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 591 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1228 EXPECT_EQ(OK, error); 592 EXPECT_EQ(OK, error);
1229 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 593 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1230 594
1231 EXPECT_NE(google_full_chain, verify_result.verified_cert); 595 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1232 EXPECT_TRUE(X509Certificate::IsSameOSCert( 596 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1233 google_full_chain->os_cert_handle(), 597 google_full_chain->os_cert_handle(),
1234 verify_result.verified_cert->os_cert_handle())); 598 verify_result.verified_cert->os_cert_handle()));
1235 const X509Certificate::OSCertHandles& return_intermediates = 599 const X509Certificate::OSCertHandles& return_intermediates =
1236 verify_result.verified_cert->GetIntermediateCertificates(); 600 verify_result.verified_cert->GetIntermediateCertificates();
1237 ASSERT_EQ(2U, return_intermediates.size()); 601 ASSERT_EQ(2U, return_intermediates.size());
1238 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 602 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1239 certs[1]->os_cert_handle())); 603 certs[1]->os_cert_handle()));
1240 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 604 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1241 certs[2]->os_cert_handle())); 605 certs[2]->os_cert_handle()));
1242 } 606 }
1243 607
1244 #if defined(OS_MACOSX)
1245 TEST(X509CertificateTest, IsIssuedBy) {
1246 FilePath certs_dir = GetTestCertsDirectory();
1247
1248 // Test a client certificate from MIT.
1249 scoped_refptr<X509Certificate> mit_davidben_cert(
1250 ImportCertFromFile(certs_dir, "mit.davidben.der"));
1251 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert);
1252
1253 CertPrincipal mit_issuer;
1254 mit_issuer.country_name = "US";
1255 mit_issuer.state_or_province_name = "Massachusetts";
1256 mit_issuer.organization_names.push_back(
1257 "Massachusetts Institute of Technology");
1258 mit_issuer.organization_unit_names.push_back("Client CA v1");
1259
1260 // IsIssuedBy should return true even if it cannot build a chain
1261 // with that principal.
1262 std::vector<CertPrincipal> mit_issuers(1, mit_issuer);
1263 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(mit_issuers));
1264
1265 // Test a client certificate from FOAF.ME.
1266 scoped_refptr<X509Certificate> foaf_me_chromium_test_cert(
1267 ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der"));
1268 ASSERT_NE(static_cast<X509Certificate*>(NULL), foaf_me_chromium_test_cert);
1269
1270 CertPrincipal foaf_issuer;
1271 foaf_issuer.common_name = "FOAF.ME";
1272 foaf_issuer.locality_name = "Wimbledon";
1273 foaf_issuer.state_or_province_name = "LONDON";
1274 foaf_issuer.country_name = "GB";
1275 foaf_issuer.organization_names.push_back("FOAF.ME");
1276
1277 std::vector<CertPrincipal> foaf_issuers(1, foaf_issuer);
1278 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(foaf_issuers));
1279
1280 // And test some combinations and mismatches.
1281 std::vector<CertPrincipal> both_issuers;
1282 both_issuers.push_back(mit_issuer);
1283 both_issuers.push_back(foaf_issuer);
1284 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers));
1285 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
1286 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
1287 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
1288 }
1289 #endif // defined(OS_MACOSX)
1290
1291 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
1292 // This test creates a self-signed cert from a private key and then verify the
1293 // content of the certificate.
1294 TEST(X509CertificateTest, CreateSelfSigned) {
1295 scoped_ptr<crypto::RSAPrivateKey> private_key(
1296 crypto::RSAPrivateKey::Create(1024));
1297 scoped_refptr<X509Certificate> cert =
1298 X509Certificate::CreateSelfSigned(
1299 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1300
1301 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1302 EXPECT_FALSE(cert->HasExpired());
1303
1304 const uint8 private_key_info[] = {
1305 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
1306 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
1307 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
1308 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01,
1309 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b,
1310 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61,
1311 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
1312 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64,
1313 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4,
1314 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a,
1315 0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f,
1316 0x9e, 0x36, 0x74, 0x30, 0xda, 0x8a, 0x31, 0x4f,
1317 0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17,
1318 0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5,
1319 0xb2, 0x65, 0x7a, 0x89, 0x4e, 0xb6, 0x47, 0xff,
1320 0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85,
1321 0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9,
1322 0x96, 0xd0, 0xd6, 0x14, 0x6f, 0x13, 0x8d, 0xc5,
1323 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
1324 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93,
1325 0xe7, 0x1f, 0x0f, 0xe6, 0x0f, 0x02, 0x03, 0x01,
1326 0x00, 0x01, 0x02, 0x81, 0x80, 0x03, 0x61, 0x89,
1327 0x37, 0xcb, 0xf2, 0x98, 0xa0, 0xce, 0xb4, 0xcb,
1328 0x16, 0x13, 0xf0, 0xe6, 0xaf, 0x5c, 0xc5, 0xa7,
1329 0x69, 0x71, 0xca, 0xba, 0x8d, 0xe0, 0x4d, 0xdd,
1330 0xed, 0xb8, 0x48, 0x8b, 0x16, 0x93, 0x36, 0x95,
1331 0xc2, 0x91, 0x40, 0x65, 0x17, 0xbd, 0x7f, 0xd6,
1332 0xad, 0x9e, 0x30, 0x28, 0x46, 0xe4, 0x3e, 0xcc,
1333 0x43, 0x78, 0xf9, 0xfe, 0x1f, 0x33, 0x23, 0x1e,
1334 0x31, 0x12, 0x9d, 0x3c, 0xa7, 0x08, 0x82, 0x7b,
1335 0x7d, 0x25, 0x4e, 0x5e, 0x19, 0xa8, 0x9b, 0xed,
1336 0x86, 0xb2, 0xcb, 0x3c, 0xfe, 0x4e, 0xa1, 0xfa,
1337 0x62, 0x87, 0x3a, 0x17, 0xf7, 0x60, 0xec, 0x38,
1338 0x29, 0xe8, 0x4f, 0x34, 0x9f, 0x76, 0x9d, 0xee,
1339 0xa3, 0xf6, 0x85, 0x6b, 0x84, 0x43, 0xc9, 0x1e,
1340 0x01, 0xff, 0xfd, 0xd0, 0x29, 0x4c, 0xfa, 0x8e,
1341 0x57, 0x0c, 0xc0, 0x71, 0xa5, 0xbb, 0x88, 0x46,
1342 0x29, 0x5c, 0xc0, 0x4f, 0x01, 0x02, 0x41, 0x00,
1343 0xf5, 0x83, 0xa4, 0x64, 0x4a, 0xf2, 0xdd, 0x8c,
1344 0x2c, 0xed, 0xa8, 0xd5, 0x60, 0x5a, 0xe4, 0xc7,
1345 0xcc, 0x61, 0xcd, 0x38, 0x42, 0x20, 0xd3, 0x82,
1346 0x18, 0xf2, 0x35, 0x00, 0x72, 0x2d, 0xf7, 0x89,
1347 0x80, 0x67, 0xb5, 0x93, 0x05, 0x5f, 0xdd, 0x42,
1348 0xba, 0x16, 0x1a, 0xea, 0x15, 0xc6, 0xf0, 0xb8,
1349 0x8c, 0xbc, 0xbf, 0x54, 0x9e, 0xf1, 0xc1, 0xb2,
1350 0xb3, 0x8b, 0xb6, 0x26, 0x02, 0x30, 0xc4, 0x81,
1351 0x02, 0x41, 0x00, 0xc0, 0x60, 0x62, 0x80, 0xe1,
1352 0x22, 0x78, 0xf6, 0x9d, 0x83, 0x18, 0xeb, 0x72,
1353 0x45, 0xd7, 0xc8, 0x01, 0x7f, 0xa9, 0xca, 0x8f,
1354 0x7d, 0xd6, 0xb8, 0x31, 0x2b, 0x84, 0x7f, 0x62,
1355 0xd9, 0xa9, 0x22, 0x17, 0x7d, 0x06, 0x35, 0x6c,
1356 0xf3, 0xc1, 0x94, 0x17, 0x85, 0x5a, 0xaf, 0x9c,
1357 0x5c, 0x09, 0x3c, 0xcf, 0x2f, 0x44, 0x9d, 0xb6,
1358 0x52, 0x68, 0x5f, 0xf9, 0x59, 0xc8, 0x84, 0x2b,
1359 0x39, 0x22, 0x8f, 0x02, 0x41, 0x00, 0xb2, 0x04,
1360 0xe2, 0x0e, 0x56, 0xca, 0x03, 0x1a, 0xc0, 0xf9,
1361 0x12, 0x92, 0xa5, 0x6b, 0x42, 0xb8, 0x1c, 0xda,
1362 0x4d, 0x93, 0x9d, 0x5f, 0x6f, 0xfd, 0xc5, 0x58,
1363 0xda, 0x55, 0x98, 0x74, 0xfc, 0x28, 0x17, 0x93,
1364 0x1b, 0x75, 0x9f, 0x50, 0x03, 0x7f, 0x7e, 0xae,
1365 0xc8, 0x95, 0x33, 0x75, 0x2c, 0xd6, 0xa4, 0x35,
1366 0xb8, 0x06, 0x03, 0xba, 0x08, 0x59, 0x2b, 0x17,
1367 0x02, 0xdc, 0x4c, 0x7a, 0x50, 0x01, 0x02, 0x41,
1368 0x00, 0x9d, 0xdb, 0x39, 0x59, 0x09, 0xe4, 0x30,
1369 0xa0, 0x24, 0xf5, 0xdb, 0x2f, 0xf0, 0x2f, 0xf1,
1370 0x75, 0x74, 0x0d, 0x5e, 0xb5, 0x11, 0x73, 0xb0,
1371 0x0a, 0xaa, 0x86, 0x4c, 0x0d, 0xff, 0x7e, 0x1d,
1372 0xb4, 0x14, 0xd4, 0x09, 0x91, 0x33, 0x5a, 0xfd,
1373 0xa0, 0x58, 0x80, 0x9b, 0xbe, 0x78, 0x2e, 0x69,
1374 0x82, 0x15, 0x7c, 0x72, 0xf0, 0x7b, 0x18, 0x39,
1375 0xff, 0x6e, 0xeb, 0xc6, 0x86, 0xf5, 0xb4, 0xc7,
1376 0x6f, 0x02, 0x41, 0x00, 0x8d, 0x1a, 0x37, 0x0f,
1377 0x76, 0xc4, 0x82, 0xfa, 0x5c, 0xc3, 0x79, 0x35,
1378 0x3e, 0x70, 0x8a, 0xbf, 0x27, 0x49, 0xb0, 0x99,
1379 0x63, 0xcb, 0x77, 0x5f, 0xa8, 0x82, 0x65, 0xf6,
1380 0x03, 0x52, 0x51, 0xf1, 0xae, 0x2e, 0x05, 0xb3,
1381 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
1382 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
1383 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
1384 0xb1, 0xc5, 0x15, 0xf3
1385 };
1386
1387 std::vector<uint8> input;
1388 input.resize(sizeof(private_key_info));
1389 memcpy(&input.front(), private_key_info, sizeof(private_key_info));
1390
1391 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
1392 ASSERT_TRUE(private_key.get());
1393
1394 cert = X509Certificate::CreateSelfSigned(
1395 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1396
1397 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1398 EXPECT_FALSE(cert->HasExpired());
1399 }
1400
1401 TEST(X509CertificateTest, GetDEREncoded) {
1402 scoped_ptr<crypto::RSAPrivateKey> private_key(
1403 crypto::RSAPrivateKey::Create(1024));
1404 scoped_refptr<X509Certificate> cert =
1405 X509Certificate::CreateSelfSigned(
1406 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
1407
1408 std::string der_cert;
1409 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
1410 &der_cert));
1411 EXPECT_FALSE(der_cert.empty());
1412 }
1413 #endif
1414
1415 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 608 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
1416 static const uint8 kCRLSetThawteSPKIBlocked[] = { 609 static const uint8 kCRLSetThawteSPKIBlocked[] = {
1417 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 610 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
1418 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 611 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
1419 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, 612 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
1420 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, 613 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1421 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, 614 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
1422 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 615 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
1423 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 616 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1424 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x36, 0x58, 0x36, 0x4d, 0x78, 0x52, 0x37, 617 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x36, 0x58, 0x36, 0x4d, 0x78, 0x52, 0x37,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 649 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1457 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, 650 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7,
1458 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, 651 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52,
1459 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, 652 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5,
1460 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, 653 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b,
1461 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, 654 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d,
1462 }; 655 };
1463 656
1464 // Test that CRLSets are effective in making a certificate appear to be 657 // Test that CRLSets are effective in making a certificate appear to be
1465 // revoked. 658 // revoked.
1466 TEST(X509CertificateTest, CRLSet) { 659 TEST_F(CertVerifyProcTest, CRLSet) {
1467 CertificateList certs = CreateCertificateListFromFile( 660 CertificateList certs = CreateCertificateListFromFile(
1468 GetTestCertsDirectory(), 661 GetTestCertsDirectory(),
1469 "googlenew.chain.pem", 662 "googlenew.chain.pem",
1470 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 663 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
1471 664
1472 X509Certificate::OSCertHandles intermediates; 665 X509Certificate::OSCertHandles intermediates;
1473 intermediates.push_back(certs[1]->os_cert_handle()); 666 intermediates.push_back(certs[1]->os_cert_handle());
1474 667
1475 scoped_refptr<X509Certificate> google_full_chain = 668 scoped_refptr<X509Certificate> google_full_chain =
1476 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 669 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1477 intermediates); 670 intermediates);
1478 671
1479 CertVerifyResult verify_result; 672 CertVerifyResult verify_result;
1480 int error = google_full_chain->Verify( 673 int error = Verify(google_full_chain, "www.google.com", 0, NULL,
1481 "www.google.com", 0, NULL, &verify_result); 674 &verify_result);
1482 EXPECT_EQ(OK, error); 675 EXPECT_EQ(OK, error);
1483 676
1484 // First test blocking by SPKI. 677 // First test blocking by SPKI.
1485 base::StringPiece crl_set_bytes( 678 base::StringPiece crl_set_bytes(
1486 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), 679 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked),
1487 sizeof(kCRLSetThawteSPKIBlocked)); 680 sizeof(kCRLSetThawteSPKIBlocked));
1488 scoped_refptr<CRLSet> crl_set; 681 scoped_refptr<CRLSet> crl_set;
1489 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 682 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1490 683
1491 error = google_full_chain->Verify( 684 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1492 "www.google.com", 0, crl_set.get(), &verify_result); 685 &verify_result);
1493 EXPECT_EQ(ERR_CERT_REVOKED, error); 686 EXPECT_EQ(ERR_CERT_REVOKED, error);
1494 687
1495 // Second, test revocation by serial number of a cert directly under the 688 // Second, test revocation by serial number of a cert directly under the
1496 // root. 689 // root.
1497 crl_set_bytes = base::StringPiece( 690 crl_set_bytes = base::StringPiece(
1498 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), 691 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked),
1499 sizeof(kCRLSetThawteSerialBlocked)); 692 sizeof(kCRLSetThawteSerialBlocked));
1500 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 693 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1501 694
1502 error = google_full_chain->Verify( 695 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1503 "www.google.com", 0, crl_set.get(), &verify_result); 696 &verify_result);
1504 EXPECT_EQ(ERR_CERT_REVOKED, error); 697 EXPECT_EQ(ERR_CERT_REVOKED, error);
1505 698
1506 // Lastly, test revocation by serial number of a certificate not under the 699 // Lastly, test revocation by serial number of a certificate not under the
1507 // root. 700 // root.
1508 crl_set_bytes = base::StringPiece( 701 crl_set_bytes = base::StringPiece(
1509 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), 702 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked),
1510 sizeof(kCRLSetGoogleSerialBlocked)); 703 sizeof(kCRLSetGoogleSerialBlocked));
1511 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 704 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1512 705
1513 error = google_full_chain->Verify( 706 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1514 "www.google.com", 0, crl_set.get(), &verify_result); 707 &verify_result);
1515 EXPECT_EQ(ERR_CERT_REVOKED, error); 708 EXPECT_EQ(ERR_CERT_REVOKED, error);
1516 } 709 }
1517 #endif 710 #endif
1518 711
1519 class X509CertificateParseTest
1520 : public testing::TestWithParam<CertificateFormatTestData> {
1521 public:
1522 virtual ~X509CertificateParseTest() {}
1523 virtual void SetUp() {
1524 test_data_ = GetParam();
1525 }
1526 virtual void TearDown() {}
1527
1528 protected:
1529 CertificateFormatTestData test_data_;
1530 };
1531
1532 TEST_P(X509CertificateParseTest, CanParseFormat) {
1533 FilePath certs_dir = GetTestCertsDirectory();
1534 CertificateList certs = CreateCertificateListFromFile(
1535 certs_dir, test_data_.file_name, test_data_.format);
1536 ASSERT_FALSE(certs.empty());
1537 ASSERT_LE(certs.size(), arraysize(test_data_.chain_fingerprints));
1538 CheckGoogleCert(certs.front(), google_parse_fingerprint,
1539 kGoogleParseValidFrom, kGoogleParseValidTo);
1540
1541 size_t i;
1542 for (i = 0; i < arraysize(test_data_.chain_fingerprints); ++i) {
1543 if (test_data_.chain_fingerprints[i] == NULL) {
1544 // No more test certificates expected - make sure no more were
1545 // returned before marking this test a success.
1546 EXPECT_EQ(i, certs.size());
1547 break;
1548 }
1549
1550 // A cert is expected - make sure that one was parsed.
1551 ASSERT_LT(i, certs.size());
1552
1553 // Compare the parsed certificate with the expected certificate, by
1554 // comparing fingerprints.
1555 const X509Certificate* cert = certs[i];
1556 const SHA1Fingerprint& actual_fingerprint = cert->fingerprint();
1557 unsigned char* expected_fingerprint = test_data_.chain_fingerprints[i];
1558
1559 for (size_t j = 0; j < 20; ++j)
1560 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]);
1561 }
1562 }
1563
1564 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest,
1565 testing::ValuesIn(FormatTestData));
1566
1567 struct CertificateNameVerifyTestData {
1568 // true iff we expect hostname to match an entry in cert_names.
1569 bool expected;
1570 // The hostname to match.
1571 const char* hostname;
1572 // Common name, may be used if |dns_names| or |ip_addrs| are empty.
1573 const char* common_name;
1574 // Comma separated list of certificate names to match against. Any occurrence
1575 // of '#' will be replaced with a null character before processing.
1576 const char* dns_names;
1577 // Comma separated list of certificate IP Addresses to match against. Each
1578 // address is x prefixed 16 byte hex code for v6 or dotted-decimals for v4.
1579 const char* ip_addrs;
1580 };
1581
1582 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1583 // to output the parameter that was passed. Without this, it will simply
1584 // attempt to print out the first twenty bytes of the object, which depending
1585 // on platform and alignment, may result in an invalid read.
1586 void PrintTo(const CertificateNameVerifyTestData& data, std::ostream* os) {
1587 ASSERT_TRUE(data.hostname && data.common_name);
1588 // Using StringPiece to allow for optional fields being NULL.
1589 *os << " expected: " << data.expected
1590 << "; hostname: " << data.hostname
1591 << "; common_name: " << data.common_name
1592 << "; dns_names: " << base::StringPiece(data.dns_names)
1593 << "; ip_addrs: " << base::StringPiece(data.ip_addrs);
1594 }
1595
1596 const CertificateNameVerifyTestData kNameVerifyTestData[] = {
1597 { true, "foo.com", "foo.com" },
1598 { true, "f", "f" },
1599 { false, "h", "i" },
1600 { true, "bar.foo.com", "*.foo.com" },
1601 { true, "www.test.fr", "common.name",
1602 "*.test.com,*.test.co.uk,*.test.de,*.test.fr" },
1603 { true, "wwW.tESt.fr", "common.name",
1604 ",*.*,*.test.de,*.test.FR,www" },
1605 { false, "f.uk", ".uk" },
1606 { false, "w.bar.foo.com", "?.bar.foo.com" },
1607 { false, "www.foo.com", "(www|ftp).foo.com" },
1608 { false, "www.foo.com", "www.foo.com#" }, // # = null char.
1609 { false, "www.foo.com", "", "www.foo.com#*.foo.com,#,#" },
1610 { false, "www.house.example", "ww.house.example" },
1611 { false, "test.org", "", "www.test.org,*.test.org,*.org" },
1612 { false, "w.bar.foo.com", "w*.bar.foo.com" },
1613 { false, "www.bar.foo.com", "ww*ww.bar.foo.com" },
1614 { false, "wwww.bar.foo.com", "ww*ww.bar.foo.com" },
1615 { true, "wwww.bar.foo.com", "w*w.bar.foo.com" },
1616 { false, "wwww.bar.foo.com", "w*w.bar.foo.c0m" },
1617 { true, "WALLY.bar.foo.com", "wa*.bar.foo.com" },
1618 { true, "wally.bar.foo.com", "*Ly.bar.foo.com" },
1619 { true, "ww%57.foo.com", "", "www.foo.com" },
1620 { true, "www&.foo.com", "www%26.foo.com" },
1621 // Common name must not be used if subject alternative name was provided.
1622 { false, "www.test.co.jp", "www.test.co.jp",
1623 "*.test.de,*.jp,www.test.co.uk,www.*.co.jp" },
1624 { false, "www.bar.foo.com", "www.bar.foo.com",
1625 "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com," },
1626 { false, "www.bath.org", "www.bath.org", "", "20.30.40.50" },
1627 { false, "66.77.88.99", "www.bath.org", "www.bath.org" },
1628 // IDN tests
1629 { true, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br" },
1630 { true, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
1631 { false, "xn--poema-9qae5a.com.br", "", "*.xn--poema-9qae5a.com.br,"
1632 "xn--poema-*.com.br,"
1633 "xn--*-9qae5a.com.br,"
1634 "*--poema-9qae5a.com.br" },
1635 { true, "xn--poema-9qae5a.com.br", "*.com.br" },
1636 // The following are adapted from the examples quoted from
1637 // http://tools.ietf.org/html/rfc6125#section-6.4.3
1638 // (e.g., *.example.com would match foo.example.com but
1639 // not bar.foo.example.com or example.com).
1640 { true, "foo.example.com", "*.example.com" },
1641 { false, "bar.foo.example.com", "*.example.com" },
1642 { false, "example.com", "*.example.com" },
1643 // (e.g., baz*.example.net and *baz.example.net and b*z.example.net would
1644 // be taken to match baz1.example.net and foobaz.example.net and
1645 // buzz.example.net, respectively
1646 { true, "baz1.example.net", "baz*.example.net" },
1647 { true, "foobaz.example.net", "*baz.example.net" },
1648 { true, "buzz.example.net", "b*z.example.net" },
1649 // Wildcards should not be valid unless there are at least three name
1650 // components.
1651 { true, "h.co.uk", "*.co.uk" },
1652 { false, "foo.com", "*.com" },
1653 { false, "foo.us", "*.us" },
1654 { false, "foo", "*" },
1655 // Multiple wildcards are not valid.
1656 { false, "foo.example.com", "*.*.com" },
1657 { false, "foo.bar.example.com", "*.bar.*.com" },
1658 // Absolute vs relative DNS name tests. Although not explicitly specified
1659 // in RFC 6125, absolute reference names (those ending in a .) should
1660 // match either absolute or relative presented names.
1661 { true, "foo.com", "foo.com." },
1662 { true, "foo.com.", "foo.com" },
1663 { true, "foo.com.", "foo.com." },
1664 { true, "f", "f." },
1665 { true, "f.", "f" },
1666 { true, "f.", "f." },
1667 { true, "www-3.bar.foo.com", "*.bar.foo.com." },
1668 { true, "www-3.bar.foo.com.", "*.bar.foo.com" },
1669 { true, "www-3.bar.foo.com.", "*.bar.foo.com." },
1670 { false, ".", "." },
1671 { false, "example.com", "*.com." },
1672 { false, "example.com.", "*.com" },
1673 { false, "example.com.", "*.com." },
1674 { false, "foo.", "*." },
1675 // IP addresses in common name; IPv4 only.
1676 { true, "127.0.0.1", "127.0.0.1" },
1677 { true, "192.168.1.1", "192.168.1.1" },
1678 { true, "676768", "0.10.83.160" },
1679 { true, "1.2.3", "1.2.0.3" },
1680 { false, "192.169.1.1", "192.168.1.1" },
1681 { false, "12.19.1.1", "12.19.1.1/255.255.255.0" },
1682 { false, "FEDC:ba98:7654:3210:FEDC:BA98:7654:3210",
1683 "FEDC:BA98:7654:3210:FEDC:ba98:7654:3210" },
1684 { false, "1111:2222:3333:4444:5555:6666:7777:8888",
1685 "1111:2222:3333:4444:5555:6666:7777:8888" },
1686 { false, "::192.9.5.5", "[::192.9.5.5]" },
1687 // No wildcard matching in valid IP addresses
1688 { false, "::192.9.5.5", "*.9.5.5" },
1689 { false, "2010:836B:4179::836B:4179", "*:836B:4179::836B:4179" },
1690 { false, "192.168.1.11", "*.168.1.11" },
1691 { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "*.]" },
1692 // IP addresses in subject alternative name (common name ignored)
1693 { true, "10.1.2.3", "", "", "10.1.2.3" },
1694 { true, "14.15", "", "", "14.0.0.15" },
1695 { false, "10.1.2.7", "10.1.2.7", "", "10.1.2.6,10.1.2.8" },
1696 { false, "10.1.2.8", "10.20.2.8", "foo" },
1697 { true, "::4.5.6.7", "", "", "x00000000000000000000000004050607" },
1698 { false, "::6.7.8.9", "::6.7.8.9", "::6.7.8.9",
1699 "x00000000000000000000000006070808,x0000000000000000000000000607080a,"
1700 "xff000000000000000000000006070809,6.7.8.9" },
1701 { true, "FE80::200:f8ff:fe21:67cf", "no.common.name", "",
1702 "x00000000000000000000000006070808,xfe800000000000000200f8fffe2167cf,"
1703 "xff0000000000000000000000060708ff,10.0.0.1" },
1704 // Numeric only hostnames (none of these are considered valid IP addresses).
1705 { false, "12345.6", "12345.6" },
1706 { false, "121.2.3.512", "", "1*1.2.3.512,*1.2.3.512,1*.2.3.512,*.2.3.512",
1707 "121.2.3.0"},
1708 { false, "1.2.3.4.5.6", "*.2.3.4.5.6" },
1709 { true, "1.2.3.4.5", "", "1.2.3.4.5" },
1710 // Invalid host names.
1711 { false, "junk)(£)$*!@~#", "junk)(£)$*!@~#" },
1712 { false, "www.*.com", "www.*.com" },
1713 { false, "w$w.f.com", "w$w.f.com" },
1714 { false, "nocolonallowed:example", "", "nocolonallowed:example" },
1715 { false, "www-1.[::FFFF:129.144.52.38]", "*.[::FFFF:129.144.52.38]" },
1716 { false, "[::4.5.6.9]", "", "", "x00000000000000000000000004050609" },
1717 };
1718
1719 class X509CertificateNameVerifyTest
1720 : public testing::TestWithParam<CertificateNameVerifyTestData> {
1721 };
1722
1723 TEST_P(X509CertificateNameVerifyTest, VerifyHostname) {
1724 CertificateNameVerifyTestData test_data = GetParam();
1725
1726 std::string common_name(test_data.common_name);
1727 ASSERT_EQ(std::string::npos, common_name.find(','));
1728 std::replace(common_name.begin(), common_name.end(), '#', '\0');
1729
1730 std::vector<std::string> dns_names, ip_addressses;
1731 if (test_data.dns_names) {
1732 // Build up the certificate DNS names list.
1733 std::string dns_name_line(test_data.dns_names);
1734 std::replace(dns_name_line.begin(), dns_name_line.end(), '#', '\0');
1735 base::SplitString(dns_name_line, ',', &dns_names);
1736 }
1737
1738 if (test_data.ip_addrs) {
1739 // Build up the certificate IP address list.
1740 std::string ip_addrs_line(test_data.ip_addrs);
1741 std::vector<std::string> ip_addressses_ascii;
1742 base::SplitString(ip_addrs_line, ',', &ip_addressses_ascii);
1743 for (size_t i = 0; i < ip_addressses_ascii.size(); ++i) {
1744 std::string& addr_ascii = ip_addressses_ascii[i];
1745 ASSERT_NE(0U, addr_ascii.length());
1746 if (addr_ascii[0] == 'x') { // Hex encoded address
1747 addr_ascii.erase(0, 1);
1748 std::vector<uint8> bytes;
1749 EXPECT_TRUE(base::HexStringToBytes(addr_ascii, &bytes))
1750 << "Could not parse hex address " << addr_ascii << " i = " << i;
1751 ip_addressses.push_back(std::string(reinterpret_cast<char*>(&bytes[0]),
1752 bytes.size()));
1753 ASSERT_EQ(16U, ip_addressses.back().size()) << i;
1754 } else { // Decimal groups
1755 std::vector<std::string> decimals_ascii;
1756 base::SplitString(addr_ascii, '.', &decimals_ascii);
1757 EXPECT_EQ(4U, decimals_ascii.size()) << i;
1758 std::string addr_bytes;
1759 for (size_t j = 0; j < decimals_ascii.size(); ++j) {
1760 int decimal_value;
1761 EXPECT_TRUE(base::StringToInt(decimals_ascii[j], &decimal_value));
1762 EXPECT_GE(decimal_value, 0);
1763 EXPECT_LE(decimal_value, 255);
1764 addr_bytes.push_back(static_cast<char>(decimal_value));
1765 }
1766 ip_addressses.push_back(addr_bytes);
1767 ASSERT_EQ(4U, ip_addressses.back().size()) << i;
1768 }
1769 }
1770 }
1771
1772 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1773 test_data.hostname, common_name, dns_names, ip_addressses));
1774 }
1775
1776 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1777 testing::ValuesIn(kNameVerifyTestData));
1778
1779 struct WeakDigestTestData { 712 struct WeakDigestTestData {
1780 const char* root_cert_filename; 713 const char* root_cert_filename;
1781 const char* intermediate_cert_filename; 714 const char* intermediate_cert_filename;
1782 const char* ee_cert_filename; 715 const char* ee_cert_filename;
1783 bool expected_has_md5; 716 bool expected_has_md5;
1784 bool expected_has_md4; 717 bool expected_has_md4;
1785 bool expected_has_md2; 718 bool expected_has_md2;
1786 bool expected_has_md5_ca; 719 bool expected_has_md5_ca;
1787 bool expected_has_md2_ca; 720 bool expected_has_md2_ca;
1788 }; 721 };
1789 722
1790 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how 723 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1791 // to output the parameter that was passed. Without this, it will simply 724 // to output the parameter that was passed. Without this, it will simply
1792 // attempt to print out the first twenty bytes of the object, which depending 725 // attempt to print out the first twenty bytes of the object, which depending
1793 // on platform and alignment, may result in an invalid read. 726 // on platform and alignment, may result in an invalid read.
1794 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { 727 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1795 *os << "root: " 728 *os << "root: "
1796 << (data.root_cert_filename ? data.root_cert_filename : "none") 729 << (data.root_cert_filename ? data.root_cert_filename : "none")
1797 << "; intermediate: " << data.intermediate_cert_filename 730 << "; intermediate: " << data.intermediate_cert_filename
1798 << "; end-entity: " << data.ee_cert_filename; 731 << "; end-entity: " << data.ee_cert_filename;
1799 } 732 }
1800 733
1801 class X509CertificateWeakDigestTest 734 class CertVerifyProcWeakDigestTest
1802 : public testing::TestWithParam<WeakDigestTestData> { 735 : public CertVerifyProcTest,
736 public testing::WithParamInterface<WeakDigestTestData> {
1803 public: 737 public:
1804 X509CertificateWeakDigestTest() {} 738 CertVerifyProcWeakDigestTest() {}
1805 virtual ~X509CertificateWeakDigestTest() {} 739 virtual ~CertVerifyProcWeakDigestTest() {}
1806 }; 740 };
1807 741
1808 TEST_P(X509CertificateWeakDigestTest, Verify) { 742 TEST_P(CertVerifyProcWeakDigestTest, Verify) {
1809 WeakDigestTestData data = GetParam(); 743 WeakDigestTestData data = GetParam();
1810 FilePath certs_dir = GetTestCertsDirectory(); 744 FilePath certs_dir = GetTestCertsDirectory();
1811 745
1812 ScopedTestRoot test_root; 746 ScopedTestRoot test_root;
1813 if (data.root_cert_filename) { 747 if (data.root_cert_filename) {
1814 scoped_refptr<X509Certificate> root_cert = 748 scoped_refptr<X509Certificate> root_cert =
1815 ImportCertFromFile(certs_dir, data.root_cert_filename); 749 ImportCertFromFile(certs_dir, data.root_cert_filename);
1816 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert); 750 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
1817 test_root.Reset(root_cert); 751 test_root.Reset(root_cert);
1818 } 752 }
1819 753
1820 scoped_refptr<X509Certificate> intermediate_cert = 754 scoped_refptr<X509Certificate> intermediate_cert =
1821 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); 755 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1822 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 756 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
1823 scoped_refptr<X509Certificate> ee_cert = 757 scoped_refptr<X509Certificate> ee_cert =
1824 ImportCertFromFile(certs_dir, data.ee_cert_filename); 758 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1825 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert); 759 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
1826 760
1827 X509Certificate::OSCertHandles intermediates; 761 X509Certificate::OSCertHandles intermediates;
1828 intermediates.push_back(intermediate_cert->os_cert_handle()); 762 intermediates.push_back(intermediate_cert->os_cert_handle());
1829 763
1830 scoped_refptr<X509Certificate> ee_chain = 764 scoped_refptr<X509Certificate> ee_chain =
1831 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 765 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1832 intermediates); 766 intermediates);
1833 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); 767 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1834 768
1835 int flags = 0; 769 int flags = 0;
1836 CertVerifyResult verify_result; 770 CertVerifyResult verify_result;
1837 int rv = ee_chain->Verify("127.0.0.1", flags, NULL, &verify_result); 771 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result);
1838 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); 772 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1839 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); 773 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1840 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); 774 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
1841 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); 775 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca);
1842 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); 776 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca);
1843 777
1844 // Ensure that MD4 and MD2 are tagged as invalid. 778 // Ensure that MD4 and MD2 are tagged as invalid.
1845 if (data.expected_has_md4 || data.expected_has_md2) { 779 if (data.expected_has_md4 || data.expected_has_md2) {
1846 EXPECT_EQ(CERT_STATUS_INVALID, 780 EXPECT_EQ(CERT_STATUS_INVALID,
1847 verify_result.cert_status & CERT_STATUS_INVALID); 781 verify_result.cert_status & CERT_STATUS_INVALID);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 const WeakDigestTestData kVerifyRootCATestData[] = { 819 const WeakDigestTestData kVerifyRootCATestData[] = {
1886 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem", 820 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
1887 "weak_digest_sha1_ee.pem", false, false, false, false, false }, 821 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1888 #if !defined(OS_MACOSX) // MD4 is not supported. 822 #if !defined(OS_MACOSX) // MD4 is not supported.
1889 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem", 823 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
1890 "weak_digest_sha1_ee.pem", false, false, false, false, false }, 824 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1891 #endif 825 #endif
1892 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem", 826 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
1893 "weak_digest_sha1_ee.pem", false, false, false, false, false }, 827 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1894 }; 828 };
1895 INSTANTIATE_TEST_CASE_P(VerifyRoot, X509CertificateWeakDigestTest, 829 INSTANTIATE_TEST_CASE_P(VerifyRoot, CertVerifyProcWeakDigestTest,
1896 testing::ValuesIn(kVerifyRootCATestData)); 830 testing::ValuesIn(kVerifyRootCATestData));
1897 831
1898 // The signature algorithm of intermediates should be properly detected. 832 // The signature algorithm of intermediates should be properly detected.
1899 const WeakDigestTestData kVerifyIntermediateCATestData[] = { 833 const WeakDigestTestData kVerifyIntermediateCATestData[] = {
1900 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 834 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1901 "weak_digest_sha1_ee.pem", true, false, false, true, false }, 835 "weak_digest_sha1_ee.pem", true, false, false, true, false },
1902 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported. 836 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported.
1903 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 837 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1904 "weak_digest_sha1_ee.pem", false, true, false, false, false }, 838 "weak_digest_sha1_ee.pem", false, true, false, false, false },
1905 #endif 839 #endif
1906 #if !defined(USE_NSS) // MD2 is disabled by default. 840 #if !defined(USE_NSS) // MD2 is disabled by default.
1907 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 841 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1908 "weak_digest_sha1_ee.pem", false, false, true, false, true }, 842 "weak_digest_sha1_ee.pem", false, false, true, false, true },
1909 #endif 843 #endif
1910 }; 844 };
1911 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, X509CertificateWeakDigestTest, 845 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, CertVerifyProcWeakDigestTest,
1912 testing::ValuesIn(kVerifyIntermediateCATestData)); 846 testing::ValuesIn(kVerifyIntermediateCATestData));
1913 847
1914 // The signature algorithm of end-entity should be properly detected. 848 // The signature algorithm of end-entity should be properly detected.
1915 const WeakDigestTestData kVerifyEndEntityTestData[] = { 849 const WeakDigestTestData kVerifyEndEntityTestData[] = {
1916 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 850 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1917 "weak_digest_md5_ee.pem", true, false, false, false, false }, 851 "weak_digest_md5_ee.pem", true, false, false, false, false },
1918 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported. 852 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported.
1919 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 853 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1920 "weak_digest_md4_ee.pem", false, true, false, false, false }, 854 "weak_digest_md4_ee.pem", false, true, false, false, false },
1921 #endif 855 #endif
1922 #if !defined(USE_NSS) // MD2 is disabled by default. 856 #if !defined(USE_NSS) // MD2 is disabled by default.
1923 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 857 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1924 "weak_digest_md2_ee.pem", false, false, true, false, false }, 858 "weak_digest_md2_ee.pem", false, false, true, false, false },
1925 #endif 859 #endif
1926 }; 860 };
1927 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot 861 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot
1928 // be cleared until NSS is cleanly shutdown, which is not presently supported 862 // be cleared until NSS is cleanly shutdown, which is not presently supported
1929 // in Chromium. 863 // in Chromium.
1930 #if defined(USE_NSS) 864 #if defined(USE_NSS)
1931 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity 865 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity
1932 #else 866 #else
1933 #define MAYBE_VerifyEndEntity VerifyEndEntity 867 #define MAYBE_VerifyEndEntity VerifyEndEntity
1934 #endif 868 #endif
1935 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity, 869 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity,
1936 X509CertificateWeakDigestTest, 870 CertVerifyProcWeakDigestTest,
1937 testing::ValuesIn(kVerifyEndEntityTestData)); 871 testing::ValuesIn(kVerifyEndEntityTestData));
1938 872
1939 // Incomplete chains should still report the status of the intermediate. 873 // Incomplete chains should still report the status of the intermediate.
1940 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = { 874 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = {
1941 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem", 875 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem",
1942 true, false, false, true, false }, 876 true, false, false, true, false },
1943 #if !defined(OS_MACOSX) // MD4 is not supported. 877 #if !defined(OS_MACOSX) // MD4 is not supported.
1944 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem", 878 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem",
1945 false, true, false, false, false }, 879 false, true, false, false, false },
1946 #endif 880 #endif
1947 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem", 881 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem",
1948 false, false, true, false, true }, 882 false, false, true, false, true },
1949 }; 883 };
1950 // Disabled on NSS - libpkix does not return constructed chains on error, 884 // Disabled on NSS - libpkix does not return constructed chains on error,
1951 // preventing us from detecting/inspecting the verified chain. 885 // preventing us from detecting/inspecting the verified chain.
1952 #if defined(USE_NSS) 886 #if defined(USE_NSS)
1953 #define MAYBE_VerifyIncompleteIntermediate \ 887 #define MAYBE_VerifyIncompleteIntermediate \
1954 DISABLED_VerifyIncompleteIntermediate 888 DISABLED_VerifyIncompleteIntermediate
1955 #else 889 #else
1956 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate 890 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate
1957 #endif 891 #endif
1958 WRAPPED_INSTANTIATE_TEST_CASE_P( 892 WRAPPED_INSTANTIATE_TEST_CASE_P(
1959 MAYBE_VerifyIncompleteIntermediate, 893 MAYBE_VerifyIncompleteIntermediate,
1960 X509CertificateWeakDigestTest, 894 CertVerifyProcWeakDigestTest,
1961 testing::ValuesIn(kVerifyIncompleteIntermediateTestData)); 895 testing::ValuesIn(kVerifyIncompleteIntermediateTestData));
1962 896
1963 // Incomplete chains should still report the status of the end-entity. 897 // Incomplete chains should still report the status of the end-entity.
1964 const WeakDigestTestData kVerifyIncompleteEETestData[] = { 898 const WeakDigestTestData kVerifyIncompleteEETestData[] = {
1965 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem", 899 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem",
1966 true, false, false, false, false }, 900 true, false, false, false, false },
1967 #if !defined(OS_MACOSX) // MD4 is not supported. 901 #if !defined(OS_MACOSX) // MD4 is not supported.
1968 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem", 902 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem",
1969 false, true, false, false, false }, 903 false, true, false, false, false },
1970 #endif 904 #endif
1971 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem", 905 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
1972 false, false, true, false, false }, 906 false, false, true, false, false },
1973 }; 907 };
1974 // Disabled on NSS - libpkix does not return constructed chains on error, 908 // Disabled on NSS - libpkix does not return constructed chains on error,
1975 // preventing us from detecting/inspecting the verified chain. 909 // preventing us from detecting/inspecting the verified chain.
1976 #if defined(USE_NSS) 910 #if defined(USE_NSS)
1977 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity 911 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity
1978 #else 912 #else
1979 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity 913 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity
1980 #endif 914 #endif
1981 WRAPPED_INSTANTIATE_TEST_CASE_P( 915 WRAPPED_INSTANTIATE_TEST_CASE_P(
1982 MAYBE_VerifyIncompleteEndEntity, 916 MAYBE_VerifyIncompleteEndEntity,
1983 X509CertificateWeakDigestTest, 917 CertVerifyProcWeakDigestTest,
1984 testing::ValuesIn(kVerifyIncompleteEETestData)); 918 testing::ValuesIn(kVerifyIncompleteEETestData));
1985 919
1986 // Differing algorithms between the intermediate and the EE should still be 920 // Differing algorithms between the intermediate and the EE should still be
1987 // reported. 921 // reported.
1988 const WeakDigestTestData kVerifyMixedTestData[] = { 922 const WeakDigestTestData kVerifyMixedTestData[] = {
1989 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 923 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1990 "weak_digest_md2_ee.pem", true, false, true, true, false }, 924 "weak_digest_md2_ee.pem", true, false, true, true, false },
1991 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 925 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1992 "weak_digest_md5_ee.pem", true, false, true, false, true }, 926 "weak_digest_md5_ee.pem", true, false, true, false, true },
1993 #if !defined(OS_MACOSX) // MD4 is not supported. 927 #if !defined(OS_MACOSX) // MD4 is not supported.
1994 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 928 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1995 "weak_digest_md2_ee.pem", false, true, true, false, false }, 929 "weak_digest_md2_ee.pem", false, true, true, false, false },
1996 #endif 930 #endif
1997 }; 931 };
1998 // NSS does not support MD4 and does not enable MD2 by default, making all 932 // NSS does not support MD4 and does not enable MD2 by default, making all
1999 // permutations invalid. 933 // permutations invalid.
2000 #if defined(USE_NSS) 934 #if defined(USE_NSS)
2001 #define MAYBE_VerifyMixed DISABLED_VerifyMixed 935 #define MAYBE_VerifyMixed DISABLED_VerifyMixed
2002 #else 936 #else
2003 #define MAYBE_VerifyMixed VerifyMixed 937 #define MAYBE_VerifyMixed VerifyMixed
2004 #endif 938 #endif
2005 WRAPPED_INSTANTIATE_TEST_CASE_P( 939 WRAPPED_INSTANTIATE_TEST_CASE_P(
2006 MAYBE_VerifyMixed, 940 MAYBE_VerifyMixed,
2007 X509CertificateWeakDigestTest, 941 CertVerifyProcWeakDigestTest,
2008 testing::ValuesIn(kVerifyMixedTestData)); 942 testing::ValuesIn(kVerifyMixedTestData));
2009 943
2010 } // namespace net 944 } // namespace net
OLDNEW
« no previous file with comments | « net/base/cert_verify_proc.cc ('k') | net/base/multi_threaded_cert_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698