OLD | NEW |
1 // Copyright (c) 2006-2008 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/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
13 #include "base/string_util.h" | 11 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "crypto/rsa_private_key.h" |
| 14 #include "crypto/scoped_capi_types.h" |
15 #include "net/base/cert_status_flags.h" | 15 #include "net/base/cert_status_flags.h" |
16 #include "net/base/cert_verify_result.h" | 16 #include "net/base/cert_verify_result.h" |
17 #include "net/base/ev_root_ca_metadata.h" | 17 #include "net/base/ev_root_ca_metadata.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/scoped_cert_chain_context.h" | 19 #include "net/base/scoped_cert_chain_context.h" |
20 #include "net/base/test_root_certs.h" | 20 #include "net/base/test_root_certs.h" |
21 | 21 |
22 #pragma comment(lib, "crypt32.lib") | 22 #pragma comment(lib, "crypt32.lib") |
23 | 23 |
24 using base::Time; | 24 using base::Time; |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 typedef base::ScopedCAPIHandle< | 30 typedef crypto::ScopedCAPIHandle< |
31 HCERTSTORE, | 31 HCERTSTORE, |
32 base::CAPIDestroyerWithFlags<HCERTSTORE, | 32 crypto::CAPIDestroyerWithFlags<HCERTSTORE, |
33 CertCloseStore, 0> > ScopedHCERTSTORE; | 33 CertCloseStore, 0> > ScopedHCERTSTORE; |
34 | 34 |
35 struct FreeChainEngineFunctor { | 35 struct FreeChainEngineFunctor { |
36 void operator()(HCERTCHAINENGINE engine) const { | 36 void operator()(HCERTCHAINENGINE engine) const { |
37 if (engine) | 37 if (engine) |
38 CertFreeCertificateChainEngine(engine); | 38 CertFreeCertificateChainEngine(engine); |
39 } | 39 } |
40 }; | 40 }; |
41 | 41 |
42 typedef base::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor> | 42 typedef crypto::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor> |
43 ScopedHCERTCHAINENGINE; | 43 ScopedHCERTCHAINENGINE; |
44 | 44 |
45 //----------------------------------------------------------------------------- | 45 //----------------------------------------------------------------------------- |
46 | 46 |
47 // TODO(wtc): This is a copy of the MapSecurityError function in | 47 // TODO(wtc): This is a copy of the MapSecurityError function in |
48 // ssl_client_socket_win.cc. Another function that maps Windows error codes | 48 // ssl_client_socket_win.cc. Another function that maps Windows error codes |
49 // to our network error codes is WinInetUtil::OSErrorToNetError. We should | 49 // to our network error codes is WinInetUtil::OSErrorToNetError. We should |
50 // eliminate the code duplication. | 50 // eliminate the code duplication. |
51 int MapSecurityError(SECURITY_STATUS err) { | 51 int MapSecurityError(SECURITY_STATUS err) { |
52 // There are numerous security error codes, but these are the ones we thus | 52 // There are numerous security error codes, but these are the ones we thus |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 522 |
523 X509Certificate* cert = CreateFromHandle(cert_handle, | 523 X509Certificate* cert = CreateFromHandle(cert_handle, |
524 SOURCE_LONE_CERT_IMPORT, | 524 SOURCE_LONE_CERT_IMPORT, |
525 OSCertHandles()); | 525 OSCertHandles()); |
526 FreeOSCertHandle(cert_handle); | 526 FreeOSCertHandle(cert_handle); |
527 return cert; | 527 return cert; |
528 } | 528 } |
529 | 529 |
530 // static | 530 // static |
531 X509Certificate* X509Certificate::CreateSelfSigned( | 531 X509Certificate* X509Certificate::CreateSelfSigned( |
532 base::RSAPrivateKey* key, | 532 crypto::RSAPrivateKey* key, |
533 const std::string& subject, | 533 const std::string& subject, |
534 uint32 serial_number, | 534 uint32 serial_number, |
535 base::TimeDelta valid_duration) { | 535 base::TimeDelta valid_duration) { |
536 // Get the ASN.1 encoding of the certificate subject. | 536 // Get the ASN.1 encoding of the certificate subject. |
537 std::wstring w_subject = ASCIIToWide(subject); | 537 std::wstring w_subject = ASCIIToWide(subject); |
538 DWORD encoded_subject_length = 0; | 538 DWORD encoded_subject_length = 0; |
539 if (!CertStrToName( | 539 if (!CertStrToName( |
540 X509_ASN_ENCODING, | 540 X509_ASN_ENCODING, |
541 w_subject.c_str(), | 541 w_subject.c_str(), |
542 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) { | 542 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) { |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 DWORD sha1_size = sizeof(sha1.data); | 990 DWORD sha1_size = sizeof(sha1.data); |
991 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, | 991 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, |
992 cert->cbCertEncoded, sha1.data, &sha1_size); | 992 cert->cbCertEncoded, sha1.data, &sha1_size); |
993 DCHECK(rv && sha1_size == sizeof(sha1.data)); | 993 DCHECK(rv && sha1_size == sizeof(sha1.data)); |
994 if (!rv) | 994 if (!rv) |
995 memset(sha1.data, 0, sizeof(sha1.data)); | 995 memset(sha1.data, 0, sizeof(sha1.data)); |
996 return sha1; | 996 return sha1; |
997 } | 997 } |
998 | 998 |
999 } // namespace net | 999 } // namespace net |
OLD | NEW |