summaryrefslogtreecommitdiffstats
path: root/net/cert
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-17 23:57:56 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-17 23:57:56 +0000
commitf8cc0eac3d538017f4e9a106f02604815898a2d3 (patch)
treecf29d23f8855e96a2291ee49292cfb12bce96504 /net/cert
parent156720e503c1cc0d01d2c4ac947da8201344b37f (diff)
downloadchromium_src-f8cc0eac3d538017f4e9a106f02604815898a2d3.zip
chromium_src-f8cc0eac3d538017f4e9a106f02604815898a2d3.tar.gz
chromium_src-f8cc0eac3d538017f4e9a106f02604815898a2d3.tar.bz2
X509Certificate::GetDefaultNickname should handle a user certificate
whose Subject field doesn't have a common name (but has an email address). This was previously https://codereview.chromium.org/10341005/ R=rsleevi@chromium.org BUG=126023 TEST=new unit test X509CertificateTest.GetDefaultNickname, only if USE_NSS is defined. Review URL: https://chromiumcodereview.appspot.com/17093010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/cert')
-rw-r--r--net/cert/x509_certificate_nss.cc12
-rw-r--r--net/cert/x509_certificate_unittest.cc14
2 files changed, 23 insertions, 3 deletions
diff --git a/net/cert/x509_certificate_nss.cc b/net/cert/x509_certificate_nss.cc
index 27cb205..bbc448f 100644
--- a/net/cert/x509_certificate_nss.cc
+++ b/net/cert/x509_certificate_nss.cc
@@ -91,13 +91,19 @@ std::string X509Certificate::GetDefaultNickname(CertType type) const {
PORT_Free(nickname);
break;
}
- case USER_CERT:
+ case USER_CERT: {
+ std::string subject_name = subject_.GetDisplayName();
+ if (subject_name.empty()) {
+ const char* email = CERT_GetFirstEmailAddress(cert_handle_);
+ if (email)
+ subject_name = email;
+ }
// TODO(gspencer): Internationalize this. It's wrong to assume English
// here.
- result = base::StringPrintf("%s's %s ID",
- subject_.GetDisplayName().c_str(),
+ result = base::StringPrintf("%s's %s ID", subject_name.c_str(),
issuer_.GetDisplayName().c_str());
break;
+ }
case SERVER_CERT:
result = subject_.GetDisplayName();
break;
diff --git a/net/cert/x509_certificate_unittest.cc b/net/cert/x509_certificate_unittest.cc
index 191e23b..427431d 100644
--- a/net/cert/x509_certificate_unittest.cc
+++ b/net/cert/x509_certificate_unittest.cc
@@ -781,6 +781,20 @@ TEST(X509CertificateTest, IsIssuedByEncodedWithIntermediates) {
EXPECT_FALSE(cert_chain->IsIssuedByEncoded(issuers));
}
+#if defined(USE_NSS)
+TEST(X509CertificateTest, GetDefaultNickname) {
+ base::FilePath certs_dir = GetTestCertsDirectory();
+
+ scoped_refptr<X509Certificate> test_cert(
+ ImportCertFromFile(certs_dir, "no_subject_common_name_cert.pem"));
+ ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
+
+ std::string nickname = test_cert->GetDefaultNickname(USER_CERT);
+ EXPECT_EQ("wtc@google.com's COMODO Client Authentication and "
+ "Secure Email CA ID", nickname);
+}
+#endif
+
#if !defined(OS_IOS) // TODO(ios): Unable to create certificates.
#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