| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "net/base/cert_type.h" |
| 18 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
| 19 #include "net/base/x509_cert_types.h" | 20 #include "net/base/x509_cert_types.h" |
| 20 | 21 |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 #include <windows.h> | 23 #include <windows.h> |
| 23 #include <wincrypt.h> | 24 #include <wincrypt.h> |
| 24 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
| 25 #include <CoreFoundation/CFArray.h> | 26 #include <CoreFoundation/CFArray.h> |
| 26 #include <Security/SecBase.h> | 27 #include <Security/SecBase.h> |
| 27 | 28 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // scoped_refptr<X509Certificate>. | 140 // scoped_refptr<X509Certificate>. |
| 140 static X509Certificate* CreateFromDERCertChain( | 141 static X509Certificate* CreateFromDERCertChain( |
| 141 const std::vector<base::StringPiece>& der_certs); | 142 const std::vector<base::StringPiece>& der_certs); |
| 142 | 143 |
| 143 // Create an X509Certificate from the DER-encoded representation. | 144 // Create an X509Certificate from the DER-encoded representation. |
| 144 // Returns NULL on failure. | 145 // Returns NULL on failure. |
| 145 // | 146 // |
| 146 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. | 147 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. |
| 147 static X509Certificate* CreateFromBytes(const char* data, int length); | 148 static X509Certificate* CreateFromBytes(const char* data, int length); |
| 148 | 149 |
| 150 #if defined(USE_NSS) |
| 151 // Create an X509Certificate from the DER-encoded representation. |
| 152 // |nickname| can be NULL if an auto-generated nickname is desired. |
| 153 // Returns NULL on failure. The returned pointer must be stored in a |
| 154 // scoped_refptr<X509Certificate>. |
| 155 // |
| 156 // This function differs from CreateFromBytes in that it takes a |
| 157 // nickname that will be used when the certificate is imported into PKCS#11. |
| 158 static X509Certificate* CreateFromBytesWithNickname(const char* data, |
| 159 int length, |
| 160 const char* nickname); |
| 161 |
| 162 // The default nickname of the certificate, based on the certificate type |
| 163 // passed in. If this object was created using CreateFromBytesWithNickname, |
| 164 // then this will return the nickname specified upon creation. |
| 165 std::string GetDefaultNickname(CertType type) const; |
| 166 #endif |
| 167 |
| 149 // Create an X509Certificate from the representation stored in the given | 168 // Create an X509Certificate from the representation stored in the given |
| 150 // pickle. The data for this object is found relative to the given | 169 // pickle. The data for this object is found relative to the given |
| 151 // pickle_iter, which should be passed to the pickle's various Read* methods. | 170 // pickle_iter, which should be passed to the pickle's various Read* methods. |
| 152 // Returns NULL on failure. | 171 // Returns NULL on failure. |
| 153 // | 172 // |
| 154 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. | 173 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. |
| 155 static X509Certificate* CreateFromPickle(const Pickle& pickle, | 174 static X509Certificate* CreateFromPickle(const Pickle& pickle, |
| 156 void** pickle_iter, | 175 void** pickle_iter, |
| 157 PickleType type); | 176 PickleType type); |
| 158 | 177 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // Returns the OSCertHandle of this object. Because of caching, this may | 425 // Returns the OSCertHandle of this object. Because of caching, this may |
| 407 // differ from the OSCertHandle originally supplied during initialization. | 426 // differ from the OSCertHandle originally supplied during initialization. |
| 408 // Note: On Windows, CryptoAPI may return unexpected results if this handle | 427 // Note: On Windows, CryptoAPI may return unexpected results if this handle |
| 409 // is used across multiple threads. For more details, see | 428 // is used across multiple threads. For more details, see |
| 410 // CreateOSCertChainForCert(). | 429 // CreateOSCertChainForCert(). |
| 411 OSCertHandle os_cert_handle() const { return cert_handle_; } | 430 OSCertHandle os_cert_handle() const { return cert_handle_; } |
| 412 | 431 |
| 413 // Returns true if two OSCertHandles refer to identical certificates. | 432 // Returns true if two OSCertHandles refer to identical certificates. |
| 414 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); | 433 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); |
| 415 | 434 |
| 416 // Creates an OS certificate handle from the BER-encoded representation. | 435 // Creates an OS certificate handle from the DER-encoded representation. |
| 417 // Returns NULL on failure. | 436 // Returns NULL on failure. |
| 418 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, | 437 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, |
| 419 int length); | 438 int length); |
| 420 | 439 |
| 440 #if defined(USE_NSS) |
| 441 // Creates an OS certificate handle from the DER-encoded representation. |
| 442 // Returns NULL on failure. Sets the default nickname if |nickname| is |
| 443 // non-NULL. |
| 444 static OSCertHandle CreateOSCertHandleFromBytesWithNickname( |
| 445 const char* data, |
| 446 int length, |
| 447 const char* nickname); |
| 448 #endif |
| 449 |
| 421 // Creates all possible OS certificate handles from |data| encoded in a | 450 // Creates all possible OS certificate handles from |data| encoded in a |
| 422 // specific |format|. Returns an empty collection on failure. | 451 // specific |format|. Returns an empty collection on failure. |
| 423 static OSCertHandles CreateOSCertHandlesFromBytes( | 452 static OSCertHandles CreateOSCertHandlesFromBytes( |
| 424 const char* data, int length, Format format); | 453 const char* data, |
| 454 int length, |
| 455 Format format); |
| 425 | 456 |
| 426 // Duplicates (or adds a reference to) an OS certificate handle. | 457 // Duplicates (or adds a reference to) an OS certificate handle. |
| 427 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle); | 458 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle); |
| 428 | 459 |
| 429 // Frees (or releases a reference to) an OS certificate handle. | 460 // Frees (or releases a reference to) an OS certificate handle. |
| 430 static void FreeOSCertHandle(OSCertHandle cert_handle); | 461 static void FreeOSCertHandle(OSCertHandle cert_handle); |
| 431 | 462 |
| 432 // Calculates the SHA-1 fingerprint of the certificate. Returns an empty | 463 // Calculates the SHA-1 fingerprint of the certificate. Returns an empty |
| 433 // (all zero) fingerprint on failure. | 464 // (all zero) fingerprint on failure. |
| 434 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle); | 465 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 // The serial number of this certificate, DER encoded. | 577 // The serial number of this certificate, DER encoded. |
| 547 std::string serial_number_; | 578 std::string serial_number_; |
| 548 | 579 |
| 549 // A handle to the certificate object in the underlying crypto library. | 580 // A handle to the certificate object in the underlying crypto library. |
| 550 OSCertHandle cert_handle_; | 581 OSCertHandle cert_handle_; |
| 551 | 582 |
| 552 // Untrusted intermediate certificates associated with this certificate | 583 // Untrusted intermediate certificates associated with this certificate |
| 553 // that may be needed for chain building. | 584 // that may be needed for chain building. |
| 554 OSCertHandles intermediate_ca_certs_; | 585 OSCertHandles intermediate_ca_certs_; |
| 555 | 586 |
| 587 #if defined(USE_NSS) |
| 588 // This stores any default nickname that has been set on the certificate |
| 589 // at creation time with CreateFromBytesWithNickname. |
| 590 // If this is empty, then GetDefaultNickname will return a generated name |
| 591 // based on the type of the certificate. |
| 592 std::string default_nickname_; |
| 593 #endif |
| 594 |
| 556 #if defined(OS_MACOSX) | 595 #if defined(OS_MACOSX) |
| 557 // Blocks multiple threads from verifying the cert simultaneously. | 596 // Blocks multiple threads from verifying the cert simultaneously. |
| 558 // (Marked mutable because it's used in a const method.) | 597 // (Marked mutable because it's used in a const method.) |
| 559 mutable base::Lock verification_lock_; | 598 mutable base::Lock verification_lock_; |
| 560 #endif | 599 #endif |
| 561 | 600 |
| 562 DISALLOW_COPY_AND_ASSIGN(X509Certificate); | 601 DISALLOW_COPY_AND_ASSIGN(X509Certificate); |
| 563 }; | 602 }; |
| 564 | 603 |
| 565 } // namespace net | 604 } // namespace net |
| 566 | 605 |
| 567 #endif // NET_BASE_X509_CERTIFICATE_H_ | 606 #endif // NET_BASE_X509_CERTIFICATE_H_ |
| OLD | NEW |