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

Unified Diff: net/cert/x509_certificate_mac.cc

Issue 17265013: Remove platform-specific implementations of RSAPrivateKey and SignatureCreator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix colliding serial numbers Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/x509_certificate_ios.cc ('k') | net/cert/x509_certificate_nss.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/x509_certificate_mac.cc
diff --git a/net/cert/x509_certificate_mac.cc b/net/cert/x509_certificate_mac.cc
index fd9aaca69b32e12ba135e85857d395c06145cc8c..2f8ce438afd3c8213ba3063f513be54b71596a38 100644
--- a/net/cert/x509_certificate_mac.cc
+++ b/net/cert/x509_certificate_mac.cc
@@ -25,7 +25,6 @@
#include "crypto/cssm_init.h"
#include "crypto/mac_security_services_lock.h"
#include "crypto/nss_util.h"
-#include "crypto/rsa_private_key.h"
#include "net/cert/x509_util_mac.h"
using base::ScopedCFTypeRef;
@@ -326,144 +325,6 @@ bool X509Certificate::IsIssuedByEncoded(
return false;
}
-// static
-X509Certificate* X509Certificate::CreateSelfSigned(
- crypto::RSAPrivateKey* key,
- const std::string& subject,
- uint32 serial_number,
- base::TimeDelta valid_duration) {
- DCHECK(key);
- DCHECK(!subject.empty());
-
- if (valid_duration.InSeconds() > kuint32max) {
- LOG(ERROR) << "valid_duration too big " << valid_duration.InSeconds();
- valid_duration = base::TimeDelta::FromSeconds(kuint32max);
- }
-
- // There is a comment in
- // http://www.opensource.apple.com/source/security_certtool/security_certtool-31828/src/CertTool.cpp
- // that serial_numbers being passed into CSSM_TP_SubmitCredRequest can't have
- // their high bit set. We will continue though and mask it out below.
- if (serial_number & 0x80000000)
- LOG(ERROR) << "serial_number has high bit set " << serial_number;
-
- // NSS is used to parse the subject string into a set of
- // CSSM_OID/string pairs. There doesn't appear to be a system routine for
- // parsing Distinguished Name strings.
- crypto::EnsureNSSInit();
-
- CSSMOIDStringVector subject_name_oids;
- ScopedCertName subject_name(
- CERT_AsciiToName(const_cast<char*>(subject.c_str())));
- if (!CERTNameToCSSMOIDVector(subject_name, &subject_name_oids)) {
- DLOG(ERROR) << "Unable to generate CSSMOIDMap from " << subject;
- return NULL;
- }
-
- // Convert the map of oid/string pairs into an array of
- // CSSM_APPLE_TP_NAME_OIDs.
- std::vector<CSSM_APPLE_TP_NAME_OID> cssm_subject_names;
- for (CSSMOIDStringVector::iterator iter = subject_name_oids.begin();
- iter != subject_name_oids.end(); ++iter) {
- CSSM_APPLE_TP_NAME_OID cssm_subject_name;
- cssm_subject_name.oid = iter->oid_;
- cssm_subject_name.string = iter->string_.c_str();
- cssm_subject_names.push_back(cssm_subject_name);
- }
-
- if (cssm_subject_names.empty()) {
- DLOG(ERROR) << "cssm_subject_names.size() == 0. Input: " << subject;
- return NULL;
- }
-
- // Set up a certificate request.
- CSSM_APPLE_TP_CERT_REQUEST certReq;
- memset(&certReq, 0, sizeof(certReq));
- certReq.cspHand = crypto::GetSharedCSPHandle();
- certReq.clHand = crypto::GetSharedCLHandle();
- // See comment about serial numbers above.
- certReq.serialNumber = serial_number & 0x7fffffff;
- certReq.numSubjectNames = cssm_subject_names.size();
- certReq.subjectNames = &cssm_subject_names[0];
- certReq.numIssuerNames = 0; // Root.
- certReq.issuerNames = NULL;
- certReq.issuerNameX509 = NULL;
- certReq.certPublicKey = key->public_key();
- certReq.issuerPrivateKey = key->key();
- // These are the Apple defaults.
- certReq.signatureAlg = CSSM_ALGID_SHA1WithRSA;
- certReq.signatureOid = CSSMOID_SHA1WithRSA;
- certReq.notBefore = 0;
- certReq.notAfter = static_cast<uint32>(valid_duration.InSeconds());
- certReq.numExtensions = 0;
- certReq.extensions = NULL;
- certReq.challengeString = NULL;
-
- CSSM_TP_REQUEST_SET reqSet;
- reqSet.NumberOfRequests = 1;
- reqSet.Requests = &certReq;
-
- CSSM_FIELD policyId;
- memset(&policyId, 0, sizeof(policyId));
- policyId.FieldOid = CSSMOID_APPLE_TP_LOCAL_CERT_GEN;
-
- CSSM_TP_CALLERAUTH_CONTEXT callerAuthContext;
- memset(&callerAuthContext, 0, sizeof(callerAuthContext));
- callerAuthContext.Policy.NumberOfPolicyIds = 1;
- callerAuthContext.Policy.PolicyIds = &policyId;
-
- CSSM_TP_HANDLE tp_handle = crypto::GetSharedTPHandle();
- CSSM_DATA refId;
- memset(&refId, 0, sizeof(refId));
- sint32 estTime;
- CSSM_RETURN crtn = CSSM_TP_SubmitCredRequest(tp_handle, NULL,
- CSSM_TP_AUTHORITY_REQUEST_CERTISSUE, &reqSet, &callerAuthContext,
- &estTime, &refId);
- if (crtn) {
- DLOG(ERROR) << "CSSM_TP_SubmitCredRequest failed " << crtn;
- return NULL;
- }
-
- CSSM_BOOL confirmRequired;
- CSSM_TP_RESULT_SET* resultSet = NULL;
- crtn = CSSM_TP_RetrieveCredResult(tp_handle, &refId, NULL, &estTime,
- &confirmRequired, &resultSet);
- ScopedEncodedCertResults scopedResults(resultSet);
- crypto::CSSMFree(refId.Data);
- if (crtn) {
- DLOG(ERROR) << "CSSM_TP_RetrieveCredResult failed " << crtn;
- return NULL;
- }
-
- if (confirmRequired) {
- // Potential leak here of resultSet. |confirmRequired| should never be
- // true.
- DLOG(ERROR) << "CSSM_TP_RetrieveCredResult required confirmation";
- return NULL;
- }
-
- if (resultSet->NumberOfResults != 1) {
- DLOG(ERROR) << "Unexpected number of results: "
- << resultSet->NumberOfResults;
- return NULL;
- }
-
- CSSM_ENCODED_CERT* encCert =
- reinterpret_cast<CSSM_ENCODED_CERT*>(resultSet->Results);
- ScopedCFTypeRef<SecCertificateRef> scoped_cert;
- SecCertificateRef certificate_ref = NULL;
- OSStatus os_status =
- SecCertificateCreateFromData(&encCert->CertBlob, encCert->CertType,
- encCert->CertEncoding, &certificate_ref);
- if (os_status != 0) {
- OSSTATUS_DLOG(ERROR, os_status) << "SecCertificateCreateFromData failed";
- return NULL;
- }
- scoped_cert.reset(certificate_ref);
-
- return CreateFromHandle(scoped_cert, X509Certificate::OSCertHandles());
-}
-
void X509Certificate::GetSubjectAltName(
std::vector<std::string>* dns_names,
std::vector<std::string>* ip_addrs) const {
« no previous file with comments | « net/cert/x509_certificate_ios.cc ('k') | net/cert/x509_certificate_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698