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

Unified Diff: net/cert/x509_util.cc

Issue 27832002: Sign self-signed certs with SHA256. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 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
Index: net/cert/x509_util.cc
===================================================================
--- net/cert/x509_util.cc (revision 231602)
+++ net/cert/x509_util.cc (working copy)
@@ -4,13 +4,24 @@
#include "net/cert/x509_util.h"
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
+#include "crypto/ec_private_key.h"
+#include "crypto/rsa_private_key.h"
#include "net/cert/x509_certificate.h"
namespace net {
namespace x509_util {
+// RSA keys created by CreateKeyAndSelfSignedCert will be of this length.
+static const uint16 kRSAKeyLength = 1024;
+
+// Certificates made by CreateKeyAndSelfSignedCert and
+// CreateKeyAndDomainBoundCertEC will be signed using this digest algorithm.
+static const DigestAlgorithm kSignatureDigestAlgorithm = DIGEST_SHA256;
+
ClientCertSorter::ClientCertSorter() : now_(base::Time::Now()) {}
bool ClientCertSorter::operator()(
@@ -44,6 +55,53 @@
return a_intermediates.size() < b_intermediates.size();
}
+bool CreateKeyAndDomainBoundCertEC(const std::string& domain,
+ uint32 serial_number,
+ base::Time not_valid_before,
+ base::Time not_valid_after,
+ scoped_ptr<crypto::ECPrivateKey>* key,
+ std::string* der_cert) {
+ scoped_ptr<crypto::ECPrivateKey> new_key(crypto::ECPrivateKey::Create());
+ if (!new_key.get())
+ return false;
+
+ bool success = CreateDomainBoundCertEC(new_key.get(),
+ kSignatureDigestAlgorithm,
+ domain,
+ serial_number,
+ not_valid_before,
+ not_valid_after,
+ der_cert);
+ if (success)
+ key->reset(new_key.release());
+
+ return success;
+}
+
+bool CreateKeyAndSelfSignedCert(const std::string& subject,
+ uint32 serial_number,
+ base::Time not_valid_before,
+ base::Time not_valid_after,
+ scoped_ptr<crypto::RSAPrivateKey>* key,
+ std::string* der_cert) {
+ scoped_ptr<crypto::RSAPrivateKey> new_key(
+ crypto::RSAPrivateKey::Create(kRSAKeyLength));
+ if (!new_key.get())
+ return false;
+
+ bool success = CreateSelfSignedCert(new_key.get(),
+ kSignatureDigestAlgorithm,
+ subject,
+ serial_number,
+ not_valid_before,
+ not_valid_after,
+ der_cert);
+ if (success)
+ key->reset(new_key.release());
+
+ return success;
+}
+
} // namespace x509_util
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698