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

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

Issue 3112013: Move chain building/verification out of X509Certificate (Closed)
Patch Set: Rebase to trunk - Without OpenSSL fixes Created 10 years, 2 months 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #endif 85 #endif
86 86
87 typedef std::vector<OSCertHandle> OSCertHandles; 87 typedef std::vector<OSCertHandle> OSCertHandles;
88 88
89 // Predicate functor used in maps when X509Certificate is used as the key. 89 // Predicate functor used in maps when X509Certificate is used as the key.
90 class LessThan { 90 class LessThan {
91 public: 91 public:
92 bool operator() (X509Certificate* lhs, X509Certificate* rhs) const; 92 bool operator() (X509Certificate* lhs, X509Certificate* rhs) const;
93 }; 93 };
94 94
95 enum VerifyFlags {
96 VERIFY_REV_CHECKING_ENABLED = 1 << 0,
97 VERIFY_EV_CERT = 1 << 1,
98 };
99
100 enum Format { 95 enum Format {
101 // The data contains a single DER-encoded certificate, or a PEM-encoded 96 // The data contains a single DER-encoded certificate, or a PEM-encoded
102 // DER certificate with the PEM encoding block name of "CERTIFICATE". 97 // DER certificate with the PEM encoding block name of "CERTIFICATE".
103 // Any subsequent blocks will be ignored. 98 // Any subsequent blocks will be ignored.
104 FORMAT_SINGLE_CERTIFICATE = 1 << 0, 99 FORMAT_SINGLE_CERTIFICATE = 1 << 0,
105 100
106 // The data contains a sequence of one or more PEM-encoded, DER 101 // The data contains a sequence of one or more PEM-encoded, DER
107 // certificates, with the PEM encoding block name of "CERTIFICATE". 102 // certificates, with the PEM encoding block name of "CERTIFICATE".
108 // All PEM blocks will be parsed, until the first error is encountered. 103 // All PEM blocks will be parsed, until the first error is encountered.
109 FORMAT_PEM_CERT_SEQUENCE = 1 << 1, 104 FORMAT_PEM_CERT_SEQUENCE = 1 << 1,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // one of the given names will be included in the list. 231 // one of the given names will be included in the list.
237 static bool GetSSLClientCertificates( 232 static bool GetSSLClientCertificates(
238 const std::string& server_domain, 233 const std::string& server_domain,
239 const std::vector<CertPrincipal>& valid_issuers, 234 const std::vector<CertPrincipal>& valid_issuers,
240 std::vector<scoped_refptr<X509Certificate> >* certs); 235 std::vector<scoped_refptr<X509Certificate> >* certs);
241 236
242 // Creates the chain of certs to use for this client identity cert. 237 // Creates the chain of certs to use for this client identity cert.
243 CFArrayRef CreateClientCertificateChain() const; 238 CFArrayRef CreateClientCertificateChain() const;
244 #endif 239 #endif
245 240
246 // Verifies the certificate against the given hostname. Returns OK if
247 // successful or an error code upon failure.
248 //
249 // The |*verify_result| structure, including the |verify_result->cert_status|
250 // bitmask, is always filled out regardless of the return value. If the
251 // certificate has multiple errors, the corresponding status flags are set in
252 // |verify_result->cert_status|, and the error code for the most serious
253 // error is returned.
254 //
255 // |flags| is bitwise OR'd of VerifyFlags.
256 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, certificate revocation
257 // checking is performed. If VERIFY_EV_CERT is set in |flags| too,
258 // EV certificate verification is performed.
259 int Verify(const std::string& hostname,
260 int flags,
261 CertVerifyResult* verify_result) const;
262
263 OSCertHandle os_cert_handle() const { return cert_handle_; } 241 OSCertHandle os_cert_handle() const { return cert_handle_; }
264 242
265 // Returns true if two OSCertHandles refer to identical certificates. 243 // Returns true if two OSCertHandles refer to identical certificates.
266 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b); 244 static bool IsSameOSCert(OSCertHandle a, OSCertHandle b);
267 245
268 // Creates an OS certificate handle from the BER-encoded representation. 246 // Creates an OS certificate handle from the BER-encoded representation.
269 // Returns NULL on failure. 247 // Returns NULL on failure.
270 static OSCertHandle CreateOSCertHandleFromBytes(const char* data, 248 static OSCertHandle CreateOSCertHandleFromBytes(const char* data,
271 int length); 249 int length);
272 250
273 // Creates all possible OS certificate handles from |data| encoded in a 251 // Creates all possible OS certificate handles from |data| encoded in a
274 // specific |format|. Returns an empty collection on failure. 252 // specific |format|. Returns an empty collection on failure.
275 static OSCertHandles CreateOSCertHandlesFromBytes( 253 static OSCertHandles CreateOSCertHandlesFromBytes(
276 const char* data, int length, Format format); 254 const char* data, int length, Format format);
277 255
278 // Duplicates (or adds a reference to) an OS certificate handle. 256 // Duplicates (or adds a reference to) an OS certificate handle.
279 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle); 257 static OSCertHandle DupOSCertHandle(OSCertHandle cert_handle);
280 258
281 // Frees (or releases a reference to) an OS certificate handle. 259 // Frees (or releases a reference to) an OS certificate handle.
282 static void FreeOSCertHandle(OSCertHandle cert_handle); 260 static void FreeOSCertHandle(OSCertHandle cert_handle);
283 261
284 // Frees (or releases a reference to) an OS certificate list handle 262 // Frees (or releases a reference to) an OS certificate list handle
285 static void FreeOSCertListHandle(OSCertListHandle cert_list); 263 static void FreeOSCertListHandle(OSCertListHandle cert_list);
286 264
265 // Calculates the SHA-1 fingerprint of the certificate. Returns an empty
266 // (all zero) fingerprint on failure.
267 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle);
268
287 private: 269 private:
288 friend class base::RefCountedThreadSafe<X509Certificate>; 270 friend class base::RefCountedThreadSafe<X509Certificate>;
289 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, Cache); 271 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, Cache);
290 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, IntermediateCertificates); 272 FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, IntermediateCertificates);
291 273
292 class Cache; 274 class Cache;
293 275
294 // Construct an X509Certificate from a handle to the certificate object 276 // Construct an X509Certificate from a handle to the certificate object
295 // in the underlying crypto library. 277 // in the underlying crypto library.
296 X509Certificate(OSCertHandle cert_handle, 278 X509Certificate(OSCertHandle cert_handle,
297 const OSCertHandles& intermediates); 279 const OSCertHandles& intermediates);
298 280
299 ~X509Certificate(); 281 ~X509Certificate();
300 282
301 // Common object initialization code. Called by the constructors only. 283 // Common object initialization code. Called by the constructors only.
302 void Initialize(); 284 void Initialize();
303 285
304 bool VerifyEV() const;
305
306 // Calculates the SHA-1 fingerprint of the certificate. Returns an empty 286 // Calculates the SHA-1 fingerprint of the certificate. Returns an empty
307 // (all zero) fingerprint on failure. 287 // (all zero) fingerprint on failure.
308 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle); 288 static SHA1Fingerprint CalculateFingerprint(OSCertHandle cert_handle);
309 289
310 // Reads a single certificate from |pickle| and returns a platform 290 // Reads a single certificate from |pickle| and returns a platform
311 // specific certificate handle. The format of the certificate stored in 291 // specific certificate handle. The format of the certificate stored in
312 // the Pickle is not guaranteed to be a cross-platform format or acceptable 292 // the Pickle is not guaranteed to be a cross-platform format or acceptable
313 // to CreateFromBytes. Returns an invalid handle (NULL) on failure. 293 // to CreateFromBytes. Returns an invalid handle (NULL) on failure.
314 static OSCertHandle ReadCertHandleFromPickle(const Pickle& pickle, 294 static OSCertHandle ReadCertHandleFromPickle(const Pickle& pickle,
315 void** pickle_iter); 295 void** pickle_iter);
(...skipping 18 matching lines...) Expand all
334 // The fingerprint of this certificate. 314 // The fingerprint of this certificate.
335 SHA1Fingerprint fingerprint_; 315 SHA1Fingerprint fingerprint_;
336 316
337 // A handle to the certificate object in the underlying crypto library. 317 // A handle to the certificate object in the underlying crypto library.
338 OSCertHandle cert_handle_; 318 OSCertHandle cert_handle_;
339 319
340 // Untrusted intermediate certificates associated with this certificate 320 // Untrusted intermediate certificates associated with this certificate
341 // that may be needed for chain building. (NSS impl does not need these.) 321 // that may be needed for chain building. (NSS impl does not need these.)
342 OSCertHandles intermediate_ca_certs_; 322 OSCertHandles intermediate_ca_certs_;
343 323
344 #if defined(OS_MACOSX)
345 // Blocks multiple threads from verifying the cert simultaneously.
346 // (Marked mutable because it's used in a const method.)
347 mutable Lock verification_lock_;
348 #endif
349
350 DISALLOW_COPY_AND_ASSIGN(X509Certificate); 324 DISALLOW_COPY_AND_ASSIGN(X509Certificate);
351 }; 325 };
352 326
353 } // namespace net 327 } // namespace net
354 328
355 #endif // NET_BASE_X509_CERTIFICATE_H_ 329 #endif // NET_BASE_X509_CERTIFICATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698