OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_X509_CERTIFICATE_H_ | 5 #ifndef NET_BASE_X509_CERTIFICATE_H_ |
6 #define NET_BASE_X509_CERTIFICATE_H_ | 6 #define NET_BASE_X509_CERTIFICATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // using GetChainDEREncodedBytes below. | 363 // using GetChainDEREncodedBytes below. |
364 void GetChainDEREncodedBytes(std::vector<std::string>* chain_bytes) const; | 364 void GetChainDEREncodedBytes(std::vector<std::string>* chain_bytes) const; |
365 #endif | 365 #endif |
366 | 366 |
367 #if defined(USE_OPENSSL) | 367 #if defined(USE_OPENSSL) |
368 // Returns a handle to a global, in-memory certificate store. We | 368 // Returns a handle to a global, in-memory certificate store. We |
369 // use it for test code, e.g. importing the test server's certificate. | 369 // use it for test code, e.g. importing the test server's certificate. |
370 static X509_STORE* cert_store(); | 370 static X509_STORE* cert_store(); |
371 #endif | 371 #endif |
372 | 372 |
373 // Verifies the certificate against the given hostname. Returns OK if | |
374 // successful or an error code upon failure. | |
375 // | |
376 // The |*verify_result| structure, including the |verify_result->cert_status| | |
377 // bitmask, is always filled out regardless of the return value. If the | |
378 // certificate has multiple errors, the corresponding status flags are set in | |
379 // |verify_result->cert_status|, and the error code for the most serious | |
380 // error is returned. | |
381 // | |
382 // |flags| is bitwise OR'd of VerifyFlags: | |
383 // | |
384 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, online certificate | |
385 // revocation checking is performed (i.e. OCSP and downloading CRLs). CRLSet | |
386 // based revocation checking is always enabled, regardless of this flag, if | |
387 // |crl_set| is given. | |
388 // | |
389 // If VERIFY_EV_CERT is set in |flags| too, EV certificate verification is | |
390 // performed. | |
391 // | |
392 // |crl_set| points to an optional CRLSet structure which can be used to | |
393 // avoid revocation checks over the network. | |
394 int Verify(const std::string& hostname, | |
395 int flags, | |
396 CRLSet* crl_set, | |
397 CertVerifyResult* verify_result) const; | |
398 | |
399 // Verifies that |hostname| matches this certificate. | 373 // Verifies that |hostname| matches this certificate. |
400 // Does not verify that the certificate is valid, only that the certificate | 374 // Does not verify that the certificate is valid, only that the certificate |
401 // matches this host. | 375 // matches this host. |
402 // Returns true if it matches. | 376 // Returns true if it matches. |
403 bool VerifyNameMatch(const std::string& hostname) const; | 377 bool VerifyNameMatch(const std::string& hostname) const; |
404 | 378 |
405 // Obtains the DER encoded certificate data for |cert_handle|. On success, | 379 // Obtains the DER encoded certificate data for |cert_handle|. On success, |
406 // returns true and writes the DER encoded certificate to |*der_encoded|. | 380 // returns true and writes the DER encoded certificate to |*der_encoded|. |
407 static bool GetDEREncoded(OSCertHandle cert_handle, | 381 static bool GetDEREncoded(OSCertHandle cert_handle, |
408 std::string* der_encoded); | 382 std::string* der_encoded); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle); | 443 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle); |
470 | 444 |
471 // Calculates the SHA-1 fingerprint of the intermediate CA certificates. | 445 // Calculates the SHA-1 fingerprint of the intermediate CA certificates. |
472 // Returns an empty (all zero) fingerprint on failure. | 446 // Returns an empty (all zero) fingerprint on failure. |
473 static SHA1Fingerprint CalculateCAFingerprint( | 447 static SHA1Fingerprint CalculateCAFingerprint( |
474 const OSCertHandles& intermediates); | 448 const OSCertHandles& intermediates); |
475 | 449 |
476 private: | 450 private: |
477 friend class base::RefCountedThreadSafe<X509Certificate>; | 451 friend class base::RefCountedThreadSafe<X509Certificate>; |
478 friend class TestRootCerts; // For unit tests | 452 friend class TestRootCerts; // For unit tests |
479 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, Cache); | 453 // TODO(rsleevi): Temporary refactoring - http://crbug.com/114343 |
480 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, IntermediateCertificates); | 454 friend class X509CertificateTest; |
| 455 friend class CertVerifyProcMac; |
| 456 friend class CertVerifyProcNSS; |
| 457 friend class CertVerifyProcOpenSSL; |
| 458 friend class CertVerifyProcWin; |
| 459 |
| 460 FRIEND_TEST_ALL_PREFIXES(X509CertificateNameVerifyTest, VerifyHostname); |
| 461 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, DigiNotarCerts); |
481 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, SerialNumbers); | 462 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, SerialNumbers); |
482 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, DigiNotarCerts); | |
483 FRIEND_TEST_ALL_PREFIXES(X509CertificateNameVerifyTest, VerifyHostname); | |
484 | 463 |
485 // Construct an X509Certificate from a handle to the certificate object | 464 // Construct an X509Certificate from a handle to the certificate object |
486 // in the underlying crypto library. | 465 // in the underlying crypto library. |
487 X509Certificate(OSCertHandle cert_handle, | 466 X509Certificate(OSCertHandle cert_handle, |
488 const OSCertHandles& intermediates); | 467 const OSCertHandles& intermediates); |
489 | 468 |
490 ~X509Certificate(); | 469 ~X509Certificate(); |
491 | 470 |
492 // Common object initialization code. Called by the constructors only. | 471 // Common object initialization code. Called by the constructors only. |
493 void Initialize(); | 472 void Initialize(); |
494 | 473 |
| 474 // Verifies the certificate against the given hostname. Returns OK if |
| 475 // successful or an error code upon failure. |
| 476 // |
| 477 // The |*verify_result| structure, including the |verify_result->cert_status| |
| 478 // bitmask, is always filled out regardless of the return value. If the |
| 479 // certificate has multiple errors, the corresponding status flags are set in |
| 480 // |verify_result->cert_status|, and the error code for the most serious |
| 481 // error is returned. |
| 482 // |
| 483 // |flags| is bitwise OR'd of VerifyFlags: |
| 484 // |
| 485 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, online certificate |
| 486 // revocation checking is performed (i.e. OCSP and downloading CRLs). CRLSet |
| 487 // based revocation checking is always enabled, regardless of this flag, if |
| 488 // |crl_set| is given. |
| 489 // |
| 490 // If VERIFY_EV_CERT is set in |flags| too, EV certificate verification is |
| 491 // performed. |
| 492 // |
| 493 // |crl_set| points to an optional CRLSet structure which can be used to |
| 494 // avoid revocation checks over the network. |
| 495 int Verify(const std::string& hostname, |
| 496 int flags, |
| 497 CRLSet* crl_set, |
| 498 CertVerifyResult* verify_result) const; |
| 499 |
495 #if defined(OS_WIN) | 500 #if defined(OS_WIN) |
496 bool CheckEV(PCCERT_CHAIN_CONTEXT chain_context, | 501 bool CheckEV(PCCERT_CHAIN_CONTEXT chain_context, |
497 int flags, | 502 int flags, |
498 const char* policy_oid) const; | 503 const char* policy_oid) const; |
499 static bool IsIssuedByKnownRoot(PCCERT_CHAIN_CONTEXT chain_context); | 504 static bool IsIssuedByKnownRoot(PCCERT_CHAIN_CONTEXT chain_context); |
500 #endif | 505 #endif |
501 #if defined(OS_MACOSX) | 506 #if defined(OS_MACOSX) |
502 static bool IsIssuedByKnownRoot(CFArrayRef chain); | 507 static bool IsIssuedByKnownRoot(CFArrayRef chain); |
503 #endif | 508 #endif |
504 #if defined(USE_NSS) | 509 #if defined(USE_NSS) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // (Marked mutable because it's used in a const method.) | 607 // (Marked mutable because it's used in a const method.) |
603 mutable base::Lock verification_lock_; | 608 mutable base::Lock verification_lock_; |
604 #endif | 609 #endif |
605 | 610 |
606 DISALLOW_COPY_AND_ASSIGN(X509Certificate); | 611 DISALLOW_COPY_AND_ASSIGN(X509Certificate); |
607 }; | 612 }; |
608 | 613 |
609 } // namespace net | 614 } // namespace net |
610 | 615 |
611 #endif // NET_BASE_X509_CERTIFICATE_H_ | 616 #endif // NET_BASE_X509_CERTIFICATE_H_ |
OLD | NEW |