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

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: 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 const char* data; 624 const char* data;
625 int length; 625 int length;
626 if (!pickle.ReadData(pickle_iter, &data, &length)) 626 if (!pickle.ReadData(pickle_iter, &data, &length))
627 return NULL; 627 return NULL;
628 628
629 return CreateFromBytes(data, length); 629 return CreateFromBytes(data, length);
630 } 630 }
631 631
632 // static 632 // static
633 X509Certificate* X509Certificate::CreateSelfSigned( 633 X509Certificate* X509Certificate::CreateSelfSigned(
634 base::RSAPrivateKey* key, 634 crypto::RSAPrivateKey* key,
635 const std::string& subject, 635 const std::string& subject,
636 uint32 serial_number, 636 uint32 serial_number,
637 base::TimeDelta valid_duration) { 637 base::TimeDelta valid_duration) {
638 DCHECK(key); 638 DCHECK(key);
639 639
640 // Create info about public key. 640 // Create info about public key.
641 CERTSubjectPublicKeyInfo* spki = 641 CERTSubjectPublicKeyInfo* spki =
642 SECKEY_CreateSubjectPublicKeyInfo(key->public_key()); 642 SECKEY_CreateSubjectPublicKeyInfo(key->public_key());
643 if (!spki) 643 if (!spki)
644 return NULL; 644 return NULL;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 return a->derCert.len == b->derCert.len && 878 return a->derCert.len == b->derCert.len &&
879 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0; 879 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0;
880 } 880 }
881 881
882 // static 882 // static
883 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes( 883 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes(
884 const char* data, int length) { 884 const char* data, int length) {
885 if (length < 0) 885 if (length < 0)
886 return NULL; 886 return NULL;
887 887
888 base::EnsureNSSInit(); 888 crypto::EnsureNSSInit();
889 889
890 if (!NSS_IsInitialized()) 890 if (!NSS_IsInitialized())
891 return NULL; 891 return NULL;
892 892
893 SECItem der_cert; 893 SECItem der_cert;
894 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data)); 894 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data));
895 der_cert.len = length; 895 der_cert.len = length;
896 der_cert.type = siDERCertBuffer; 896 der_cert.type = siDERCertBuffer;
897 897
898 // Parse into a certificate structure. 898 // Parse into a certificate structure.
899 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL, 899 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL,
900 PR_FALSE, PR_TRUE); 900 PR_FALSE, PR_TRUE);
901 } 901 }
902 902
903 // static 903 // static
904 X509Certificate::OSCertHandles X509Certificate::CreateOSCertHandlesFromBytes( 904 X509Certificate::OSCertHandles X509Certificate::CreateOSCertHandlesFromBytes(
905 const char* data, int length, Format format) { 905 const char* data, int length, Format format) {
906 OSCertHandles results; 906 OSCertHandles results;
907 if (length < 0) 907 if (length < 0)
908 return results; 908 return results;
909 909
910 base::EnsureNSSInit(); 910 crypto::EnsureNSSInit();
911 911
912 if (!NSS_IsInitialized()) 912 if (!NSS_IsInitialized())
913 return results; 913 return results;
914 914
915 switch (format) { 915 switch (format) {
916 case FORMAT_SINGLE_CERTIFICATE: { 916 case FORMAT_SINGLE_CERTIFICATE: {
917 OSCertHandle handle = CreateOSCertHandleFromBytes(data, length); 917 OSCertHandle handle = CreateOSCertHandleFromBytes(data, length);
918 if (handle) 918 if (handle)
919 results.push_back(handle); 919 results.push_back(handle);
920 break; 920 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 DCHECK(0 != cert->derCert.len); 958 DCHECK(0 != cert->derCert.len);
959 959
960 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, 960 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data,
961 cert->derCert.data, cert->derCert.len); 961 cert->derCert.data, cert->derCert.len);
962 DCHECK(rv == SECSuccess); 962 DCHECK(rv == SECSuccess);
963 963
964 return sha1; 964 return sha1;
965 } 965 }
966 966
967 } // namespace net 967 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698