| OLD | NEW | 
|    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 #include "net/base/x509_certificate.h" |    5 #include "net/base/x509_certificate.h" | 
|    6  |    6  | 
 |    7 #include "base/lazy_instance.h" | 
|    7 #include "base/logging.h" |    8 #include "base/logging.h" | 
|    8 #include "base/pickle.h" |    9 #include "base/pickle.h" | 
|    9 #include "base/singleton.h" |  | 
|   10 #include "base/string_tokenizer.h" |   10 #include "base/string_tokenizer.h" | 
|   11 #include "base/string_util.h" |   11 #include "base/string_util.h" | 
|   12 #include "base/utf_string_conversions.h" |   12 #include "base/utf_string_conversions.h" | 
|   13 #include "net/base/cert_status_flags.h" |   13 #include "net/base/cert_status_flags.h" | 
|   14 #include "net/base/cert_verify_result.h" |   14 #include "net/base/cert_verify_result.h" | 
|   15 #include "net/base/ev_root_ca_metadata.h" |   15 #include "net/base/ev_root_ca_metadata.h" | 
|   16 #include "net/base/net_errors.h" |   16 #include "net/base/net_errors.h" | 
|   17 #include "net/base/scoped_cert_chain_context.h" |   17 #include "net/base/scoped_cert_chain_context.h" | 
|   18  |   18  | 
|   19 #pragma comment(lib, "crypt32.lib") |   19 #pragma comment(lib, "crypt32.lib") | 
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  522     dns_names->push_back(subject_.common_name); |  522     dns_names->push_back(subject_.common_name); | 
|  523 } |  523 } | 
|  524  |  524  | 
|  525 class GlobalCertStore { |  525 class GlobalCertStore { | 
|  526  public: |  526  public: | 
|  527   HCERTSTORE cert_store() { |  527   HCERTSTORE cert_store() { | 
|  528     return cert_store_; |  528     return cert_store_; | 
|  529   } |  529   } | 
|  530  |  530  | 
|  531  private: |  531  private: | 
|  532   friend struct DefaultSingletonTraits<GlobalCertStore>; |  532   friend struct base::DefaultLazyInstanceTraits<GlobalCertStore>; | 
|  533  |  533  | 
|  534   GlobalCertStore() |  534   GlobalCertStore() | 
|  535       : cert_store_(CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 0, NULL)) { |  535       : cert_store_(CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 0, NULL)) { | 
|  536   } |  536   } | 
|  537  |  537  | 
|  538   ~GlobalCertStore() { |  538   ~GlobalCertStore() { | 
|  539     CertCloseStore(cert_store_, 0 /* flags */); |  539     CertCloseStore(cert_store_, 0 /* flags */); | 
|  540   } |  540   } | 
|  541  |  541  | 
|  542   const HCERTSTORE cert_store_; |  542   const HCERTSTORE cert_store_; | 
|  543  |  543  | 
|  544   DISALLOW_COPY_AND_ASSIGN(GlobalCertStore); |  544   DISALLOW_COPY_AND_ASSIGN(GlobalCertStore); | 
|  545 }; |  545 }; | 
|  546  |  546  | 
 |  547 static base::LazyInstance<GlobalCertStore> g_cert_store( | 
 |  548     base::LINKER_INITIALIZED); | 
 |  549  | 
|  547 // static |  550 // static | 
|  548 HCERTSTORE X509Certificate::cert_store() { |  551 HCERTSTORE X509Certificate::cert_store() { | 
|  549   return Singleton<GlobalCertStore>::get()->cert_store(); |  552   return g_cert_store.Get().cert_store(); | 
|  550 } |  553 } | 
|  551  |  554  | 
|  552 int X509Certificate::Verify(const std::string& hostname, |  555 int X509Certificate::Verify(const std::string& hostname, | 
|  553                             int flags, |  556                             int flags, | 
|  554                             CertVerifyResult* verify_result) const { |  557                             CertVerifyResult* verify_result) const { | 
|  555   verify_result->Reset(); |  558   verify_result->Reset(); | 
|  556   if (!cert_handle_) |  559   if (!cert_handle_) | 
|  557     return ERR_UNEXPECTED; |  560     return ERR_UNEXPECTED; | 
|  558  |  561  | 
|  559   // Build and validate certificate chain. |  562   // Build and validate certificate chain. | 
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  857   DWORD sha1_size = sizeof(sha1.data); |  860   DWORD sha1_size = sizeof(sha1.data); | 
|  858   rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, |  861   rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, | 
|  859                             cert->cbCertEncoded, sha1.data, &sha1_size); |  862                             cert->cbCertEncoded, sha1.data, &sha1_size); | 
|  860   DCHECK(rv && sha1_size == sizeof(sha1.data)); |  863   DCHECK(rv && sha1_size == sizeof(sha1.data)); | 
|  861   if (!rv) |  864   if (!rv) | 
|  862     memset(sha1.data, 0, sizeof(sha1.data)); |  865     memset(sha1.data, 0, sizeof(sha1.data)); | 
|  863   return sha1; |  866   return sha1; | 
|  864 } |  867 } | 
|  865  |  868  | 
|  866 }  // namespace net |  869 }  // namespace net | 
| OLD | NEW |