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