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

Unified Diff: net/cert/x509_util_unittest.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_unittest.cc
===================================================================
--- net/cert/x509_util_unittest.cc (revision 229411)
+++ net/cert/x509_util_unittest.cc (working copy)
@@ -9,6 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
+#include "crypto/hmac.h"
#include "crypto/rsa_private_key.h"
#include "net/cert/x509_certificate.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -52,32 +53,34 @@
ASSERT_FALSE(certs[5].get());
}
-// This test creates a self-signed cert from a private key and then verify the
+// This test creates a self-signed cert and a private key and then verifies the
// content of the certificate.
-TEST(X509UtilTest, CreateSelfSigned) {
- scoped_ptr<crypto::RSAPrivateKey> private_key(
- crypto::RSAPrivateKey::Create(1024));
+TEST(X509UtilTest, CreateKeyAndSelfSigned) {
+ crypto::RSAPrivateKey* raw_key;
- ASSERT_TRUE(private_key.get());
-
std::string der_cert;
- ASSERT_TRUE(x509_util::CreateSelfSignedCert(
- private_key.get(),
+ ASSERT_TRUE(x509_util::CreateKeyAndSelfSignedCert(
"CN=subject",
1,
base::Time::Now(),
base::Time::Now() + base::TimeDelta::FromDays(1),
+ &raw_key,
&der_cert));
+ scoped_ptr<crypto::RSAPrivateKey> key(raw_key);
+ ASSERT_TRUE(key.get());
+
scoped_refptr<X509Certificate> cert(X509Certificate::CreateFromBytes(
der_cert.data(), der_cert.size()));
ASSERT_TRUE(cert.get());
EXPECT_EQ("subject", cert->subject().GetDisplayName());
EXPECT_FALSE(cert->HasExpired());
+}
- cert = NULL;
-
+// This test creates a self-signed cert from a private key and then verifies the
+// content of the certificate.
+TEST(X509UtilTest, CreateSelfSignedInternal) {
const uint8 private_key_info[] = {
0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
@@ -165,18 +168,22 @@
input.resize(sizeof(private_key_info));
memcpy(&input.front(), private_key_info, sizeof(private_key_info));
- private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
+ scoped_ptr<crypto::RSAPrivateKey> private_key(
+ crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
ASSERT_TRUE(private_key.get());
- ASSERT_TRUE(x509_util::CreateSelfSignedCert(
+ std::string der_cert;
+ ASSERT_TRUE(x509_util::CreateSelfSignedCertInternal(
private_key.get(),
+ crypto::HMAC::SHA1,
"CN=subject",
1,
base::Time::Now(),
base::Time::Now() + base::TimeDelta::FromDays(1),
&der_cert));
- cert = X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
+ scoped_refptr<X509Certificate> cert =
+ X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size());
ASSERT_TRUE(cert.get());
EXPECT_EQ("subject", cert->subject().GetDisplayName());

Powered by Google App Engine
This is Rietveld 408576698