| Index: net/cert/x509_util_unittest.cc
|
| ===================================================================
|
| --- net/cert/x509_util_unittest.cc (revision 228925)
|
| +++ 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"
|
| @@ -53,32 +54,34 @@
|
| }
|
|
|
| #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
|
| -// 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,
|
| @@ -166,18 +169,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());
|
|
|