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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 DLOG(ERROR) << "DerSignData: " << PORT_GetError(); | 187 DLOG(ERROR) << "DerSignData: " << PORT_GetError(); |
188 return false; | 188 return false; |
189 } | 189 } |
190 | 190 |
191 // Save the signed result to the cert. | 191 // Save the signed result to the cert. |
192 cert->derCert = result; | 192 cert->derCert = result; |
193 | 193 |
194 return true; | 194 return true; |
195 } | 195 } |
196 | 196 |
197 #if defined(USE_NSS) || defined(OS_IOS) | 197 #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
198 // Callback for CERT_DecodeCertPackage(), used in | 198 // Callback for CERT_DecodeCertPackage(), used in |
199 // CreateOSCertHandlesFromBytes(). | 199 // CreateOSCertHandlesFromBytes(). |
200 SECStatus PR_CALLBACK CollectCertsCallback(void* arg, | 200 SECStatus PR_CALLBACK CollectCertsCallback(void* arg, |
201 SECItem** certs, | 201 SECItem** certs, |
202 int num_certs) { | 202 int num_certs) { |
203 X509Certificate::OSCertHandles* results = | 203 X509Certificate::OSCertHandles* results = |
204 reinterpret_cast<X509Certificate::OSCertHandles*>(arg); | 204 reinterpret_cast<X509Certificate::OSCertHandles*>(arg); |
205 | 205 |
206 for (int i = 0; i < num_certs; ++i) { | 206 for (int i = 0; i < num_certs; ++i) { |
207 X509Certificate::OSCertHandle handle = | 207 X509Certificate::OSCertHandle handle = |
(...skipping 29 matching lines...) Expand all Loading... |
237 const_cast<char*>(data.data())); | 237 const_cast<char*>(data.data())); |
238 | 238 |
239 SECStatus rv = SEC_ASN1DecodeItem( | 239 SECStatus rv = SEC_ASN1DecodeItem( |
240 arena, name.get(), SEC_ASN1_GET(CERT_NameTemplate), &item); | 240 arena, name.get(), SEC_ASN1_GET(CERT_NameTemplate), &item); |
241 if (rv != SECSuccess) | 241 if (rv != SECSuccess) |
242 return NULL; | 242 return NULL; |
243 | 243 |
244 return name.release(); | 244 return name.release(); |
245 } | 245 } |
246 | 246 |
247 #endif // defined(USE_NSS) || defined(OS_IOS) | 247 #endif // defined(USE_NSS_CERTS) || defined(OS_IOS) |
248 | 248 |
249 } // namespace | 249 } // namespace |
250 | 250 |
251 namespace x509_util { | 251 namespace x509_util { |
252 | 252 |
253 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, | 253 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, |
254 DigestAlgorithm alg, | 254 DigestAlgorithm alg, |
255 const std::string& subject, | 255 const std::string& subject, |
256 uint32 serial_number, | 256 uint32 serial_number, |
257 base::Time not_valid_before, | 257 base::Time not_valid_before, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 DCHECK(cert->derCert.len); | 362 DCHECK(cert->derCert.len); |
363 // XXX copied from X509Certificate::GetDEREncoded | 363 // XXX copied from X509Certificate::GetDEREncoded |
364 der_cert->clear(); | 364 der_cert->clear(); |
365 der_cert->append(reinterpret_cast<char*>(cert->derCert.data), | 365 der_cert->append(reinterpret_cast<char*>(cert->derCert.data), |
366 cert->derCert.len); | 366 cert->derCert.len); |
367 CERT_DestroyCertificate(cert); | 367 CERT_DestroyCertificate(cert); |
368 return true; | 368 return true; |
369 } | 369 } |
370 | 370 |
371 #if defined(USE_NSS) || defined(OS_IOS) | 371 #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
372 void ParsePrincipal(CERTName* name, CertPrincipal* principal) { | 372 void ParsePrincipal(CERTName* name, CertPrincipal* principal) { |
373 // Starting in NSS 3.15, CERTGetNameFunc takes a const CERTName* argument. | 373 // Starting in NSS 3.15, CERTGetNameFunc takes a const CERTName* argument. |
374 #if NSS_VMINOR >= 15 | 374 #if NSS_VMINOR >= 15 |
375 typedef char* (*CERTGetNameFunc)(const CERTName* name); | 375 typedef char* (*CERTGetNameFunc)(const CERTName* name); |
376 #else | 376 #else |
377 typedef char* (*CERTGetNameFunc)(CERTName* name); | 377 typedef char* (*CERTGetNameFunc)(CERTName* name); |
378 #endif | 378 #endif |
379 | 379 |
380 // TODO(jcampan): add business_category and serial_number. | 380 // TODO(jcampan): add business_category and serial_number. |
381 // TODO(wtc): NSS has the CERT_GetOrgName, CERT_GetOrgUnitName, and | 381 // TODO(wtc): NSS has the CERT_GetOrgName, CERT_GetOrgUnitName, and |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 while (SEC_CertNicknameConflict(temp_nickname.c_str(), | 624 while (SEC_CertNicknameConflict(temp_nickname.c_str(), |
625 const_cast<SECItem*>(subject), | 625 const_cast<SECItem*>(subject), |
626 CERT_GetDefaultCertDB())) { | 626 CERT_GetDefaultCertDB())) { |
627 base::SStringPrintf(&new_name, "%s #%d", nickname.c_str(), index++); | 627 base::SStringPrintf(&new_name, "%s #%d", nickname.c_str(), index++); |
628 temp_nickname = token_name + new_name; | 628 temp_nickname = token_name + new_name; |
629 } | 629 } |
630 | 630 |
631 return new_name; | 631 return new_name; |
632 } | 632 } |
633 | 633 |
634 #endif // defined(USE_NSS) || defined(OS_IOS) | 634 #endif // defined(USE_NSS_CERTS) || defined(OS_IOS) |
635 | 635 |
636 } // namespace x509_util | 636 } // namespace x509_util |
637 | 637 |
638 } // namespace net | 638 } // namespace net |
OLD | NEW |