OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cert/x509_util.h" | 5 #include "net/cert/x509_util.h" |
6 #include "net/cert/x509_util_nss.h" | 6 #include "net/cert/x509_util_nss.h" |
7 | 7 |
8 #include <cert.h> // Must be included before certdb.h | 8 #include <cert.h> // Must be included before certdb.h |
9 #include <certdb.h> | 9 #include <certdb.h> |
10 #include <cryptohi.h> | 10 #include <cryptohi.h> |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace net { | 32 namespace net { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Creates a Certificate object that may be passed to the SignCertificate | 36 // Creates a Certificate object that may be passed to the SignCertificate |
37 // method to generate an X509 certificate. | 37 // method to generate an X509 certificate. |
38 // Returns NULL if an error is encountered in the certificate creation | 38 // Returns NULL if an error is encountered in the certificate creation |
39 // process. | 39 // process. |
40 // Caller responsible for freeing returned certificate object. | 40 // Caller responsible for freeing returned certificate object. |
41 CERTCertificate* CreateCertificate( | 41 CERTCertificate* CreateCertificate(SECKEYPublicKey* public_key, |
42 SECKEYPublicKey* public_key, | 42 const std::string& subject, |
43 const std::string& subject, | 43 uint32_t serial_number, |
44 uint32 serial_number, | 44 base::Time not_valid_before, |
45 base::Time not_valid_before, | 45 base::Time not_valid_after) { |
46 base::Time not_valid_after) { | |
47 // Create info about public key. | 46 // Create info about public key. |
48 CERTSubjectPublicKeyInfo* spki = | 47 CERTSubjectPublicKeyInfo* spki = |
49 SECKEY_CreateSubjectPublicKeyInfo(public_key); | 48 SECKEY_CreateSubjectPublicKeyInfo(public_key); |
50 if (!spki) | 49 if (!spki) |
51 return NULL; | 50 return NULL; |
52 | 51 |
53 // Create the certificate request. | 52 // Create the certificate request. |
54 CERTName* subject_name = | 53 CERTName* subject_name = |
55 CERT_AsciiToName(const_cast<char*>(subject.c_str())); | 54 CERT_AsciiToName(const_cast<char*>(subject.c_str())); |
56 CERTCertificateRequest* cert_request = | 55 CERTCertificateRequest* cert_request = |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return true; | 148 return true; |
150 } | 149 } |
151 | 150 |
152 } // namespace | 151 } // namespace |
153 | 152 |
154 namespace x509_util { | 153 namespace x509_util { |
155 | 154 |
156 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, | 155 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, |
157 DigestAlgorithm alg, | 156 DigestAlgorithm alg, |
158 const std::string& subject, | 157 const std::string& subject, |
159 uint32 serial_number, | 158 uint32_t serial_number, |
160 base::Time not_valid_before, | 159 base::Time not_valid_before, |
161 base::Time not_valid_after, | 160 base::Time not_valid_after, |
162 std::string* der_cert) { | 161 std::string* der_cert) { |
163 DCHECK(key); | 162 DCHECK(key); |
164 DCHECK(!strncmp(subject.c_str(), "CN=", 3U)); | 163 DCHECK(!strncmp(subject.c_str(), "CN=", 3U)); |
165 CERTCertificate* cert = CreateCertificate(key->public_key(), | 164 CERTCertificate* cert = CreateCertificate(key->public_key(), |
166 subject, | 165 subject, |
167 serial_number, | 166 serial_number, |
168 not_valid_before, | 167 not_valid_before, |
169 not_valid_after); | 168 not_valid_after); |
(...skipping 20 matching lines...) Expand all Loading... |
190 if (!validity) | 189 if (!validity) |
191 return false; | 190 return false; |
192 | 191 |
193 CERT_DestroyValidity(validity); | 192 CERT_DestroyValidity(validity); |
194 return true; | 193 return true; |
195 } | 194 } |
196 | 195 |
197 } // namespace x509_util | 196 } // namespace x509_util |
198 | 197 |
199 } // namespace net | 198 } // namespace net |
OLD | NEW |