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 #include "net/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
6 | 6 |
7 #include "base/crypto/rsa_private_key.h" | |
8 #include "base/crypto/scoped_capi_types.h" | |
9 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
11 #include "base/pickle.h" | 9 #include "base/pickle.h" |
12 #include "base/sha1.h" | 10 #include "base/sha1.h" |
13 #include "base/string_tokenizer.h" | 11 #include "base/string_tokenizer.h" |
14 #include "base/string_util.h" | 12 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "crypto/rsa_private_key.h" |
| 15 #include "crypto/scoped_capi_types.h" |
16 #include "net/base/asn1_util.h" | 16 #include "net/base/asn1_util.h" |
17 #include "net/base/cert_status_flags.h" | 17 #include "net/base/cert_status_flags.h" |
18 #include "net/base/cert_verify_result.h" | 18 #include "net/base/cert_verify_result.h" |
19 #include "net/base/ev_root_ca_metadata.h" | 19 #include "net/base/ev_root_ca_metadata.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/scoped_cert_chain_context.h" | 21 #include "net/base/scoped_cert_chain_context.h" |
22 #include "net/base/test_root_certs.h" | 22 #include "net/base/test_root_certs.h" |
23 #include "net/base/x509_certificate_known_roots_win.h" | 23 #include "net/base/x509_certificate_known_roots_win.h" |
24 | 24 |
25 #pragma comment(lib, "crypt32.lib") | 25 #pragma comment(lib, "crypt32.lib") |
26 | 26 |
27 using base::Time; | 27 using base::Time; |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 typedef base::ScopedCAPIHandle< | 33 typedef crypto::ScopedCAPIHandle< |
34 HCERTSTORE, | 34 HCERTSTORE, |
35 base::CAPIDestroyerWithFlags<HCERTSTORE, | 35 crypto::CAPIDestroyerWithFlags<HCERTSTORE, |
36 CertCloseStore, 0> > ScopedHCERTSTORE; | 36 CertCloseStore, 0> > ScopedHCERTSTORE; |
37 | 37 |
38 struct FreeChainEngineFunctor { | 38 struct FreeChainEngineFunctor { |
39 void operator()(HCERTCHAINENGINE engine) const { | 39 void operator()(HCERTCHAINENGINE engine) const { |
40 if (engine) | 40 if (engine) |
41 CertFreeCertificateChainEngine(engine); | 41 CertFreeCertificateChainEngine(engine); |
42 } | 42 } |
43 }; | 43 }; |
44 | 44 |
45 typedef base::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor> | 45 typedef crypto::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor> |
46 ScopedHCERTCHAINENGINE; | 46 ScopedHCERTCHAINENGINE; |
47 | 47 |
48 //----------------------------------------------------------------------------- | 48 //----------------------------------------------------------------------------- |
49 | 49 |
50 // TODO(wtc): This is a copy of the MapSecurityError function in | 50 // TODO(wtc): This is a copy of the MapSecurityError function in |
51 // ssl_client_socket_win.cc. Another function that maps Windows error codes | 51 // ssl_client_socket_win.cc. Another function that maps Windows error codes |
52 // to our network error codes is WinInetUtil::OSErrorToNetError. We should | 52 // to our network error codes is WinInetUtil::OSErrorToNetError. We should |
53 // eliminate the code duplication. | 53 // eliminate the code duplication. |
54 int MapSecurityError(SECURITY_STATUS err) { | 54 int MapSecurityError(SECURITY_STATUS err) { |
55 // There are numerous security error codes, but these are the ones we thus | 55 // There are numerous security error codes, but these are the ones we thus |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 | 567 |
568 X509Certificate* cert = CreateFromHandle(cert_handle, | 568 X509Certificate* cert = CreateFromHandle(cert_handle, |
569 SOURCE_LONE_CERT_IMPORT, | 569 SOURCE_LONE_CERT_IMPORT, |
570 OSCertHandles()); | 570 OSCertHandles()); |
571 FreeOSCertHandle(cert_handle); | 571 FreeOSCertHandle(cert_handle); |
572 return cert; | 572 return cert; |
573 } | 573 } |
574 | 574 |
575 // static | 575 // static |
576 X509Certificate* X509Certificate::CreateSelfSigned( | 576 X509Certificate* X509Certificate::CreateSelfSigned( |
577 base::RSAPrivateKey* key, | 577 crypto::RSAPrivateKey* key, |
578 const std::string& subject, | 578 const std::string& subject, |
579 uint32 serial_number, | 579 uint32 serial_number, |
580 base::TimeDelta valid_duration) { | 580 base::TimeDelta valid_duration) { |
581 // Get the ASN.1 encoding of the certificate subject. | 581 // Get the ASN.1 encoding of the certificate subject. |
582 std::wstring w_subject = ASCIIToWide(subject); | 582 std::wstring w_subject = ASCIIToWide(subject); |
583 DWORD encoded_subject_length = 0; | 583 DWORD encoded_subject_length = 0; |
584 if (!CertStrToName( | 584 if (!CertStrToName( |
585 X509_ASN_ENCODING, | 585 X509_ASN_ENCODING, |
586 w_subject.c_str(), | 586 w_subject.c_str(), |
587 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) { | 587 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 DWORD sha1_size = sizeof(sha1.data); | 1038 DWORD sha1_size = sizeof(sha1.data); |
1039 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, | 1039 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, |
1040 cert->cbCertEncoded, sha1.data, &sha1_size); | 1040 cert->cbCertEncoded, sha1.data, &sha1_size); |
1041 DCHECK(rv && sha1_size == sizeof(sha1.data)); | 1041 DCHECK(rv && sha1_size == sizeof(sha1.data)); |
1042 if (!rv) | 1042 if (!rv) |
1043 memset(sha1.data, 0, sizeof(sha1.data)); | 1043 memset(sha1.data, 0, sizeof(sha1.data)); |
1044 return sha1; | 1044 return sha1; |
1045 } | 1045 } |
1046 | 1046 |
1047 } // namespace net | 1047 } // namespace net |
OLD | NEW |