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_CERT_X509_CERTIFICATE_H_ | 5 #ifndef NET_CERT_X509_CERTIFICATE_H_ |
6 #define NET_CERT_X509_CERTIFICATE_H_ | 6 #define NET_CERT_X509_CERTIFICATE_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
22 #include <windows.h> | 22 #include <windows.h> |
23 #include "crypto/wincrypt_shim.h" | 23 #include "crypto/wincrypt_shim.h" |
24 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
25 #include <CoreFoundation/CFArray.h> | 25 #include <CoreFoundation/CFArray.h> |
26 #include <Security/SecBase.h> | 26 #include <Security/SecBase.h> |
27 #elif defined(USE_OPENSSL_CERTS) | 27 #elif defined(USE_OPENSSL_CERTS) |
28 // Forward declaration; real one in <x509.h> | 28 // Forward declaration; real one in <x509.h> |
29 typedef struct x509_st X509; | 29 typedef struct x509_st X509; |
30 typedef struct x509_store_st X509_STORE; | 30 typedef struct x509_store_st X509_STORE; |
31 #elif defined(USE_NSS) | 31 #elif defined(USE_NSS_CERTS) |
32 // Forward declaration; real one in <cert.h> | 32 // Forward declaration; real one in <cert.h> |
33 struct CERTCertificateStr; | 33 struct CERTCertificateStr; |
34 #endif | 34 #endif |
35 | 35 |
36 class Pickle; | 36 class Pickle; |
37 class PickleIterator; | 37 class PickleIterator; |
38 | 38 |
39 namespace net { | 39 namespace net { |
40 | 40 |
41 class CRLSet; | 41 class CRLSet; |
(...skipping 10 matching lines...) Expand all Loading... |
52 public: | 52 public: |
53 // An OSCertHandle is a handle to a certificate object in the underlying | 53 // An OSCertHandle is a handle to a certificate object in the underlying |
54 // crypto library. We assume that OSCertHandle is a pointer type on all | 54 // crypto library. We assume that OSCertHandle is a pointer type on all |
55 // platforms and that NULL represents an invalid OSCertHandle. | 55 // platforms and that NULL represents an invalid OSCertHandle. |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 typedef PCCERT_CONTEXT OSCertHandle; | 57 typedef PCCERT_CONTEXT OSCertHandle; |
58 #elif defined(OS_MACOSX) | 58 #elif defined(OS_MACOSX) |
59 typedef SecCertificateRef OSCertHandle; | 59 typedef SecCertificateRef OSCertHandle; |
60 #elif defined(USE_OPENSSL_CERTS) | 60 #elif defined(USE_OPENSSL_CERTS) |
61 typedef X509* OSCertHandle; | 61 typedef X509* OSCertHandle; |
62 #elif defined(USE_NSS) | 62 #elif defined(USE_NSS_CERTS) |
63 typedef struct CERTCertificateStr* OSCertHandle; | 63 typedef struct CERTCertificateStr* OSCertHandle; |
64 #else | 64 #else |
65 // TODO(ericroman): not implemented | 65 // TODO(ericroman): not implemented |
66 typedef void* OSCertHandle; | 66 typedef void* OSCertHandle; |
67 #endif | 67 #endif |
68 | 68 |
69 typedef std::vector<OSCertHandle> OSCertHandles; | 69 typedef std::vector<OSCertHandle> OSCertHandles; |
70 | 70 |
71 enum PublicKeyType { | 71 enum PublicKeyType { |
72 kPublicKeyTypeUnknown, | 72 kPublicKeyTypeUnknown, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // scoped_refptr<X509Certificate>. | 148 // scoped_refptr<X509Certificate>. |
149 static X509Certificate* CreateFromDERCertChain( | 149 static X509Certificate* CreateFromDERCertChain( |
150 const std::vector<base::StringPiece>& der_certs); | 150 const std::vector<base::StringPiece>& der_certs); |
151 | 151 |
152 // Create an X509Certificate from the DER-encoded representation. | 152 // Create an X509Certificate from the DER-encoded representation. |
153 // Returns NULL on failure. | 153 // Returns NULL on failure. |
154 // | 154 // |
155 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. | 155 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. |
156 static X509Certificate* CreateFromBytes(const char* data, int length); | 156 static X509Certificate* CreateFromBytes(const char* data, int length); |
157 | 157 |
158 #if defined(USE_NSS) | 158 #if defined(USE_NSS_CERTS) |
159 // Create an X509Certificate from the DER-encoded representation. | 159 // Create an X509Certificate from the DER-encoded representation. |
160 // |nickname| can be NULL if an auto-generated nickname is desired. | 160 // |nickname| can be NULL if an auto-generated nickname is desired. |
161 // Returns NULL on failure. The returned pointer must be stored in a | 161 // Returns NULL on failure. The returned pointer must be stored in a |
162 // scoped_refptr<X509Certificate>. | 162 // scoped_refptr<X509Certificate>. |
163 // | 163 // |
164 // This function differs from CreateFromBytes in that it takes a | 164 // This function differs from CreateFromBytes in that it takes a |
165 // nickname that will be used when the certificate is imported into PKCS#11. | 165 // nickname that will be used when the certificate is imported into PKCS#11. |
166 static X509Certificate* CreateFromBytesWithNickname(const char* data, | 166 static X509Certificate* CreateFromBytesWithNickname(const char* data, |
167 int length, | 167 int length, |
168 const char* nickname); | 168 const char* nickname); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 OSCertHandle os_cert_handle() const { return cert_handle_; } | 355 OSCertHandle os_cert_handle() const { return cert_handle_; } |
356 | 356 |
357 // Returns true if two OSCertHandles refer to identical certificates. | 357 // Returns true if two OSCertHandles refer to identical certificates. |
358 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); | 358 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); |
359 | 359 |
360 // Creates an OS certificate handle from the DER-encoded representation. | 360 // Creates an OS certificate handle from the DER-encoded representation. |
361 // Returns NULL on failure. | 361 // Returns NULL on failure. |
362 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, | 362 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, |
363 int length); | 363 int length); |
364 | 364 |
365 #if defined(USE_NSS) | 365 #if defined(USE_NSS_CERTS) |
366 // Creates an OS certificate handle from the DER-encoded representation. | 366 // Creates an OS certificate handle from the DER-encoded representation. |
367 // Returns NULL on failure. Sets the default nickname if |nickname| is | 367 // Returns NULL on failure. Sets the default nickname if |nickname| is |
368 // non-NULL. | 368 // non-NULL. |
369 static OSCertHandle CreateOSCertHandleFromBytesWithNickname( | 369 static OSCertHandle CreateOSCertHandleFromBytesWithNickname( |
370 const char* data, | 370 const char* data, |
371 int length, | 371 int length, |
372 const char* nickname); | 372 const char* nickname); |
373 #endif | 373 #endif |
374 | 374 |
375 // Creates all possible OS certificate handles from |data| encoded in a | 375 // Creates all possible OS certificate handles from |data| encoded in a |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // The serial number of this certificate, DER encoded. | 501 // The serial number of this certificate, DER encoded. |
502 std::string serial_number_; | 502 std::string serial_number_; |
503 | 503 |
504 // A handle to the certificate object in the underlying crypto library. | 504 // A handle to the certificate object in the underlying crypto library. |
505 OSCertHandle cert_handle_; | 505 OSCertHandle cert_handle_; |
506 | 506 |
507 // Untrusted intermediate certificates associated with this certificate | 507 // Untrusted intermediate certificates associated with this certificate |
508 // that may be needed for chain building. | 508 // that may be needed for chain building. |
509 OSCertHandles intermediate_ca_certs_; | 509 OSCertHandles intermediate_ca_certs_; |
510 | 510 |
511 #if defined(USE_NSS) | 511 #if defined(USE_NSS_CERTS) |
512 // This stores any default nickname that has been set on the certificate | 512 // This stores any default nickname that has been set on the certificate |
513 // at creation time with CreateFromBytesWithNickname. | 513 // at creation time with CreateFromBytesWithNickname. |
514 // If this is empty, then GetDefaultNickname will return a generated name | 514 // If this is empty, then GetDefaultNickname will return a generated name |
515 // based on the type of the certificate. | 515 // based on the type of the certificate. |
516 std::string default_nickname_; | 516 std::string default_nickname_; |
517 #endif | 517 #endif |
518 | 518 |
519 DISALLOW_COPY_AND_ASSIGN(X509Certificate); | 519 DISALLOW_COPY_AND_ASSIGN(X509Certificate); |
520 }; | 520 }; |
521 | 521 |
522 } // namespace net | 522 } // namespace net |
523 | 523 |
524 #endif // NET_CERT_X509_CERTIFICATE_H_ | 524 #endif // NET_CERT_X509_CERTIFICATE_H_ |
OLD | NEW |