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

Side by Side Diff: net/base/x509_certificate_win.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Chrome, webkit, remoting and crypto/owners Created 9 years, 8 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 | 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 #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/cert_status_flags.h" 16 #include "net/base/cert_status_flags.h"
17 #include "net/base/cert_verify_result.h" 17 #include "net/base/cert_verify_result.h"
18 #include "net/base/ev_root_ca_metadata.h" 18 #include "net/base/ev_root_ca_metadata.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/base/scoped_cert_chain_context.h" 20 #include "net/base/scoped_cert_chain_context.h"
21 #include "net/base/test_root_certs.h" 21 #include "net/base/test_root_certs.h"
22 #include "net/base/x509_certificate_known_roots_win.h" 22 #include "net/base/x509_certificate_known_roots_win.h"
23 23
24 #pragma comment(lib, "crypt32.lib") 24 #pragma comment(lib, "crypt32.lib")
25 25
26 using base::Time; 26 using base::Time;
27 27
28 namespace net { 28 namespace net {
29 29
30 namespace { 30 namespace {
31 31
32 typedef base::ScopedCAPIHandle< 32 typedef crypto::ScopedCAPIHandle<
33 HCERTSTORE, 33 HCERTSTORE,
34 base::CAPIDestroyerWithFlags<HCERTSTORE, 34 crypto::CAPIDestroyerWithFlags<HCERTSTORE,
35 CertCloseStore, 0> > ScopedHCERTSTORE; 35 CertCloseStore, 0> > ScopedHCERTSTORE;
36 36
37 struct FreeChainEngineFunctor { 37 struct FreeChainEngineFunctor {
38 void operator()(HCERTCHAINENGINE engine) const { 38 void operator()(HCERTCHAINENGINE engine) const {
39 if (engine) 39 if (engine)
40 CertFreeCertificateChainEngine(engine); 40 CertFreeCertificateChainEngine(engine);
41 } 41 }
42 }; 42 };
43 43
44 typedef base::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor> 44 typedef crypto::ScopedCAPIHandle<HCERTCHAINENGINE, FreeChainEngineFunctor>
45 ScopedHCERTCHAINENGINE; 45 ScopedHCERTCHAINENGINE;
46 46
47 //----------------------------------------------------------------------------- 47 //-----------------------------------------------------------------------------
48 48
49 // TODO(wtc): This is a copy of the MapSecurityError function in 49 // TODO(wtc): This is a copy of the MapSecurityError function in
50 // ssl_client_socket_win.cc. Another function that maps Windows error codes 50 // ssl_client_socket_win.cc. Another function that maps Windows error codes
51 // to our network error codes is WinInetUtil::OSErrorToNetError. We should 51 // to our network error codes is WinInetUtil::OSErrorToNetError. We should
52 // eliminate the code duplication. 52 // eliminate the code duplication.
53 int MapSecurityError(SECURITY_STATUS err) { 53 int MapSecurityError(SECURITY_STATUS err) {
54 // There are numerous security error codes, but these are the ones we thus 54 // There are numerous security error codes, but these are the ones we thus
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 540
541 X509Certificate* cert = CreateFromHandle(cert_handle, 541 X509Certificate* cert = CreateFromHandle(cert_handle,
542 SOURCE_LONE_CERT_IMPORT, 542 SOURCE_LONE_CERT_IMPORT,
543 OSCertHandles()); 543 OSCertHandles());
544 FreeOSCertHandle(cert_handle); 544 FreeOSCertHandle(cert_handle);
545 return cert; 545 return cert;
546 } 546 }
547 547
548 // static 548 // static
549 X509Certificate* X509Certificate::CreateSelfSigned( 549 X509Certificate* X509Certificate::CreateSelfSigned(
550 base::RSAPrivateKey* key, 550 crypto::RSAPrivateKey* key,
551 const std::string& subject, 551 const std::string& subject,
552 uint32 serial_number, 552 uint32 serial_number,
553 base::TimeDelta valid_duration) { 553 base::TimeDelta valid_duration) {
554 // Get the ASN.1 encoding of the certificate subject. 554 // Get the ASN.1 encoding of the certificate subject.
555 std::wstring w_subject = ASCIIToWide(subject); 555 std::wstring w_subject = ASCIIToWide(subject);
556 DWORD encoded_subject_length = 0; 556 DWORD encoded_subject_length = 0;
557 if (!CertStrToName( 557 if (!CertStrToName(
558 X509_ASN_ENCODING, 558 X509_ASN_ENCODING,
559 w_subject.c_str(), 559 w_subject.c_str(),
560 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) { 560 CERT_X500_NAME_STR, NULL, NULL, &encoded_subject_length, NULL)) {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 DWORD sha1_size = sizeof(sha1.data); 1010 DWORD sha1_size = sizeof(sha1.data);
1011 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, 1011 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded,
1012 cert->cbCertEncoded, sha1.data, &sha1_size); 1012 cert->cbCertEncoded, sha1.data, &sha1_size);
1013 DCHECK(rv && sha1_size == sizeof(sha1.data)); 1013 DCHECK(rv && sha1_size == sizeof(sha1.data));
1014 if (!rv) 1014 if (!rv)
1015 memset(sha1.data, 0, sizeof(sha1.data)); 1015 memset(sha1.data, 0, sizeof(sha1.data));
1016 return sha1; 1016 return sha1;
1017 } 1017 }
1018 1018
1019 } // namespace net 1019 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698