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

Side by Side Diff: net/base/x509_certificate_nss.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 <cert.h> 7 #include <cert.h>
8 #include <cryptohi.h> 8 #include <cryptohi.h>
9 #include <keyhi.h> 9 #include <keyhi.h>
10 #include <nss.h> 10 #include <nss.h>
11 #include <pk11pub.h> 11 #include <pk11pub.h>
12 #include <prerror.h> 12 #include <prerror.h>
13 #include <prtime.h> 13 #include <prtime.h>
14 #include <secder.h> 14 #include <secder.h>
15 #include <secerr.h> 15 #include <secerr.h>
16 #include <sechash.h> 16 #include <sechash.h>
17 #include <sslerr.h> 17 #include <sslerr.h>
18 18
19 #include "base/crypto/rsa_private_key.h"
20 #include "base/logging.h" 19 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
22 #include "base/pickle.h" 21 #include "base/pickle.h"
23 #include "base/time.h" 22 #include "base/time.h"
24 #include "base/nss_util.h" 23 #include "crypto/nss_util.h"
24 #include "crypto/rsa_private_key.h"
25 #include "net/base/cert_status_flags.h" 25 #include "net/base/cert_status_flags.h"
26 #include "net/base/cert_verify_result.h" 26 #include "net/base/cert_verify_result.h"
27 #include "net/base/ev_root_ca_metadata.h" 27 #include "net/base/ev_root_ca_metadata.h"
28 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
29 29
30 namespace net { 30 namespace net {
31 31
32 namespace { 32 namespace {
33 33
34 class ScopedCERTCertificatePolicies { 34 class ScopedCERTCertificatePolicies {
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 const char* data; 636 const char* data;
637 int length; 637 int length;
638 if (!pickle.ReadData(pickle_iter, &data, &length)) 638 if (!pickle.ReadData(pickle_iter, &data, &length))
639 return NULL; 639 return NULL;
640 640
641 return CreateFromBytes(data, length); 641 return CreateFromBytes(data, length);
642 } 642 }
643 643
644 // static 644 // static
645 X509Certificate* X509Certificate::CreateSelfSigned( 645 X509Certificate* X509Certificate::CreateSelfSigned(
646 base::RSAPrivateKey* key, 646 crypto::RSAPrivateKey* key,
647 const std::string& subject, 647 const std::string& subject,
648 uint32 serial_number, 648 uint32 serial_number,
649 base::TimeDelta valid_duration) { 649 base::TimeDelta valid_duration) {
650 DCHECK(key); 650 DCHECK(key);
651 651
652 // Create info about public key. 652 // Create info about public key.
653 CERTSubjectPublicKeyInfo* spki = 653 CERTSubjectPublicKeyInfo* spki =
654 SECKEY_CreateSubjectPublicKeyInfo(key->public_key()); 654 SECKEY_CreateSubjectPublicKeyInfo(key->public_key());
655 if (!spki) 655 if (!spki)
656 return NULL; 656 return NULL;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 return a->derCert.len == b->derCert.len && 896 return a->derCert.len == b->derCert.len &&
897 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0; 897 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0;
898 } 898 }
899 899
900 // static 900 // static
901 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes( 901 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes(
902 const char* data, int length) { 902 const char* data, int length) {
903 if (length < 0) 903 if (length < 0)
904 return NULL; 904 return NULL;
905 905
906 base::EnsureNSSInit(); 906 crypto::EnsureNSSInit();
907 907
908 if (!NSS_IsInitialized()) 908 if (!NSS_IsInitialized())
909 return NULL; 909 return NULL;
910 910
911 SECItem der_cert; 911 SECItem der_cert;
912 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data)); 912 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data));
913 der_cert.len = length; 913 der_cert.len = length;
914 der_cert.type = siDERCertBuffer; 914 der_cert.type = siDERCertBuffer;
915 915
916 // Parse into a certificate structure. 916 // Parse into a certificate structure.
917 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL, 917 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL,
918 PR_FALSE, PR_TRUE); 918 PR_FALSE, PR_TRUE);
919 } 919 }
920 920
921 // static 921 // static
922 X509Certificate::OSCertHandles X509Certificate::CreateOSCertHandlesFromBytes( 922 X509Certificate::OSCertHandles X509Certificate::CreateOSCertHandlesFromBytes(
923 const char* data, int length, Format format) { 923 const char* data, int length, Format format) {
924 OSCertHandles results; 924 OSCertHandles results;
925 if (length < 0) 925 if (length < 0)
926 return results; 926 return results;
927 927
928 base::EnsureNSSInit(); 928 crypto::EnsureNSSInit();
929 929
930 if (!NSS_IsInitialized()) 930 if (!NSS_IsInitialized())
931 return results; 931 return results;
932 932
933 switch (format) { 933 switch (format) {
934 case FORMAT_SINGLE_CERTIFICATE: { 934 case FORMAT_SINGLE_CERTIFICATE: {
935 OSCertHandle handle = CreateOSCertHandleFromBytes(data, length); 935 OSCertHandle handle = CreateOSCertHandleFromBytes(data, length);
936 if (handle) 936 if (handle)
937 results.push_back(handle); 937 results.push_back(handle);
938 break; 938 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 DCHECK(0 != cert->derCert.len); 976 DCHECK(0 != cert->derCert.len);
977 977
978 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, 978 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data,
979 cert->derCert.data, cert->derCert.len); 979 cert->derCert.data, cert->derCert.len);
980 DCHECK(rv == SECSuccess); 980 DCHECK(rv == SECSuccess);
981 981
982 return sha1; 982 return sha1;
983 } 983 }
984 984
985 } // namespace net 985 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698