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

Side by Side Diff: net/base/x509_certificate.h

Issue 8566056: This applies GUIDs to certificate and key nicknames when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor fixes Created 9 years 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
OLDNEW
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
(...skipping 13 matching lines...) Expand all
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 27
28 #include "base/synchronization/lock.h" 28 #include "base/synchronization/lock.h"
29 #elif defined(USE_OPENSSL) 29 #elif defined(USE_OPENSSL)
30 // Forward declaration; real one in <x509.h> 30 // Forward declaration; real one in <x509.h>
31 typedef struct x509_st X509; 31 typedef struct x509_st X509;
32 typedef struct x509_store_st X509_STORE; 32 typedef struct x509_store_st X509_STORE;
33 #elif defined(USE_NSS) 33 #elif defined(USE_NSS)
34 #include <net/base/cert_type.h>
34 // Forward declaration; real one in <cert.h> 35 // Forward declaration; real one in <cert.h>
35 struct CERTCertificateStr; 36 struct CERTCertificateStr;
36 #endif 37 #endif
37 38
38 class Pickle; 39 class Pickle;
39 40
40 namespace crypto { 41 namespace crypto {
41 class StringPiece; 42 class StringPiece;
42 class RSAPrivateKey; 43 class RSAPrivateKey;
43 } // namespace crypto 44 } // namespace crypto
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // |intermediate_ca_certificates_| at the time it was serialized. 122 // |intermediate_ca_certificates_| at the time it was serialized.
122 PICKLETYPE_CERTIFICATE_CHAIN, 123 PICKLETYPE_CERTIFICATE_CHAIN,
123 }; 124 };
124 125
125 // Creates a X509Certificate from the ground up. Used by tests that simulate 126 // Creates a X509Certificate from the ground up. Used by tests that simulate
126 // SSL connections. 127 // SSL connections.
127 X509Certificate(const std::string& subject, const std::string& issuer, 128 X509Certificate(const std::string& subject, const std::string& issuer,
128 base::Time start_date, base::Time expiration_date); 129 base::Time start_date, base::Time expiration_date);
129 130
130 // Create an X509Certificate from a handle to the certificate object in the 131 // Create an X509Certificate from a handle to the certificate object in the
131 // underlying crypto library. The returned pointer must be stored in a 132 // underlying crypto library. The returned pointer MUST be stored in a
132 // scoped_refptr<X509Certificate>. 133 // scoped_refptr<X509Certificate>.
133 static X509Certificate* CreateFromHandle(OSCertHandle cert_handle, 134 static X509Certificate* CreateFromHandle(OSCertHandle cert_handle,
134 const OSCertHandles& intermediates); 135 const OSCertHandles& intermediates);
135 136
136 // Create an X509Certificate from a chain of DER encoded certificates. The 137 // Create an X509Certificate from a chain of DER encoded certificates. The
137 // first certificate in the chain is the end-entity certificate to which a 138 // first certificate in the chain is the end-entity certificate to which a
138 // handle is returned. The other certificates in the chain are intermediate 139 // handle is returned. The other certificates in the chain are intermediate
139 // certificates. The returned pointer must be stored in a 140 // certificates. The returned pointer MUST be stored in a
140 // scoped_refptr<X509Certificate>. 141 // scoped_refptr<X509Certificate>.
141 static X509Certificate* CreateFromDERCertChain( 142 static X509Certificate* CreateFromDERCertChain(
142 const std::vector<base::StringPiece>& der_certs); 143 const std::vector<base::StringPiece>& der_certs);
143 144
144 // Create an X509Certificate from the DER-encoded representation. 145 // Create an X509Certificate from the DER-encoded representation.
145 // Returns NULL on failure. 146 // Returns NULL on failure.
146 // 147 //
147 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. 148 // The returned pointer MUST be stored in a scoped_refptr<X509Certificate>.
148 static X509Certificate* CreateFromBytes(const char* data, int length); 149 static X509Certificate* CreateFromBytes(const char* data, int length);
149 150
151 #if defined(USE_NSS)
152 // Create an X509Certificate from the DER-encoded representation.
153 // |nickname| can be NULL if an auto-generated nickname is desired.
154 // Returns NULL on failure.
155 //
156 // The returned pointer MUST be stored in a scoped_refptr<X509Certificate>.
157 static X509Certificate* CreateFromBytesWithNickname(const char* data,
158 int length,
159 const char* nickname);
160 #endif
161
150 // Create an X509Certificate from the representation stored in the given 162 // Create an X509Certificate from the representation stored in the given
151 // pickle. The data for this object is found relative to the given 163 // pickle. The data for this object is found relative to the given
152 // pickle_iter, which should be passed to the pickle's various Read* methods. 164 // pickle_iter, which should be passed to the pickle's various Read* methods.
153 // Returns NULL on failure. 165 // Returns NULL on failure.
154 // 166 //
155 // The returned pointer must be stored in a scoped_refptr<X509Certificate>. 167 // The returned pointer MUST be stored in a scoped_refptr<X509Certificate>.
156 static X509Certificate* CreateFromPickle(const Pickle& pickle, 168 static X509Certificate* CreateFromPickle(const Pickle& pickle,
157 void** pickle_iter, 169 void** pickle_iter,
158 PickleType type); 170 PickleType type);
159 171
160 // Parses all of the certificates possible from |data|. |format| is a 172 // Parses all of the certificates possible from |data|. |format| is a
161 // bit-wise OR of Format, indicating the possible formats the 173 // bit-wise OR of Format, indicating the possible formats the
162 // certificates may have been serialized as. If an error occurs, an empty 174 // certificates may have been serialized as. If an error occurs, an empty
163 // collection will be returned. 175 // collection will be returned.
164 static CertificateList CreateCertificateListFromBytes(const char* data, 176 static CertificateList CreateCertificateListFromBytes(const char* data,
165 int length, 177 int length,
(...skipping 26 matching lines...) Expand all
192 void Persist(Pickle* pickle); 204 void Persist(Pickle* pickle);
193 205
194 // The subject of the certificate. For HTTPS server certificates, this 206 // The subject of the certificate. For HTTPS server certificates, this
195 // represents the web server. The common name of the subject should match 207 // represents the web server. The common name of the subject should match
196 // the host name of the web server. 208 // the host name of the web server.
197 const CertPrincipal& subject() const { return subject_; } 209 const CertPrincipal& subject() const { return subject_; }
198 210
199 // The issuer of the certificate. 211 // The issuer of the certificate.
200 const CertPrincipal& issuer() const { return issuer_; } 212 const CertPrincipal& issuer() const { return issuer_; }
201 213
214 #if defined(USE_NSS)
215 // Set/get the label of this certificate (the equivalent of NSS's
216 // CKA_LABEL attribute, which is the nickname or friendly name of
217 // the certificate).
218 bool SetLabel(const std::string& label);
219 std::string GetLabel();
220
221 // Gets the type of certificate this is, based on the certificate's
222 // properties.
223 CertType GetCertificateType() const;
224 #endif // defined(USE_NSS)
225
202 // Time period during which the certificate is valid. More precisely, this 226 // Time period during which the certificate is valid. More precisely, this
203 // certificate is invalid before the |valid_start| date and invalid after 227 // certificate is invalid before the |valid_start| date and invalid after
204 // the |valid_expiry| date. 228 // the |valid_expiry| date.
205 // If we were unable to parse either date from the certificate (or if the cert 229 // If we were unable to parse either date from the certificate (or if the cert
206 // lacks either date), the date will be null (i.e., is_null() will be true). 230 // lacks either date), the date will be null (i.e., is_null() will be true).
207 const base::Time& valid_start() const { return valid_start_; } 231 const base::Time& valid_start() const { return valid_start_; }
208 const base::Time& valid_expiry() const { return valid_expiry_; } 232 const base::Time& valid_expiry() const { return valid_expiry_; }
209 233
210 // The fingerprint of this certificate. 234 // The fingerprint of this certificate.
211 const SHA1Fingerprint& fingerprint() const { return fingerprint_; } 235 const SHA1Fingerprint& fingerprint() const { return fingerprint_; }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // Returns the OSCertHandle of this object. Because of caching, this may 431 // Returns the OSCertHandle of this object. Because of caching, this may
408 // differ from the OSCertHandle originally supplied during initialization. 432 // differ from the OSCertHandle originally supplied during initialization.
409 // Note: On Windows, CryptoAPI may return unexpected results if this handle 433 // Note: On Windows, CryptoAPI may return unexpected results if this handle
410 // is used across multiple threads. For more details, see 434 // is used across multiple threads. For more details, see
411 // CreateOSCertChainForCert(). 435 // CreateOSCertChainForCert().
412 OSCertHandle os_cert_handle() const { return cert_handle_; } 436 OSCertHandle os_cert_handle() const { return cert_handle_; }
413 437
414 // Returns true if two OSCertHandles refer to identical certificates. 438 // Returns true if two OSCertHandles refer to identical certificates.
415 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); 439 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b);
416 440
417 // Creates an OS certificate handle from the BER-encoded representation. 441 // Creates an OS certificate handle from the DER-encoded representation.
418 // Returns NULL on failure. 442 // Returns NULL on failure.
419 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, 443 static OSCertHandle CreateOSCertHandleFromBytes(const char* data,
420 int length); 444 int length);
421 445
446 #if defined(USE_NSS)
447 // Creates an OS certificate handle from the DER-encoded representation,
448 // with the given nickname. NULL nickname will do the same thing as
449 // CreateOSCertHandleFromBytes. Returns NULL on failure.
450 static OSCertHandle CreateOSCertHandleFromBytesWithNickname(
451 const char* data, int length, const char* nickname);
452 #endif
453
422 // Creates all possible OS certificate handles from |data| encoded in a 454 // Creates all possible OS certificate handles from |data| encoded in a
423 // specific |format|. Returns an empty collection on failure. 455 // specific |format|. Returns an empty collection on failure.
424 static OSCertHandles CreateOSCertHandlesFromBytes( 456 static OSCertHandles CreateOSCertHandlesFromBytes(
425 const char* data, int length, Format format); 457 const char* data, int length, Format format);
426 458
427 // Duplicates (or adds a reference to) an OS certificate handle. 459 // Duplicates (or adds a reference to) an OS certificate handle.
428 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle); 460 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle);
429 461
430 // Frees (or releases a reference to) an OS certificate handle. 462 // Frees (or releases a reference to) an OS certificate handle.
431 static void FreeOSCertHandle(OSCertHandle cert_handle); 463 static void FreeOSCertHandle(OSCertHandle cert_handle);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // (Marked mutable because it's used in a const method.) 591 // (Marked mutable because it's used in a const method.)
560 mutable base::Lock verification_lock_; 592 mutable base::Lock verification_lock_;
561 #endif 593 #endif
562 594
563 DISALLOW_COPY_AND_ASSIGN(X509Certificate); 595 DISALLOW_COPY_AND_ASSIGN(X509Certificate);
564 }; 596 };
565 597
566 } // namespace net 598 } // namespace net
567 599
568 #endif // NET_BASE_X509_CERTIFICATE_H_ 600 #endif // NET_BASE_X509_CERTIFICATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698