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

Unified Diff: chrome/common/net/x509_certificate_model_openssl.cc

Issue 288053003: x509_certificate_model_openssl: implement GetCertNameOrNickname, GetTitle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: exclude unittest on android too Created 6 years, 7 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 | « chrome/chrome_tests_unit.gypi ('k') | chrome/common/net/x509_certificate_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/net/x509_certificate_model_openssl.cc
diff --git a/chrome/common/net/x509_certificate_model_openssl.cc b/chrome/common/net/x509_certificate_model_openssl.cc
index b8f28b34acc0aabc96d2ed68650d1f2f73966894..687d415ee3e086ddf22d45f36b447587303d760f 100644
--- a/chrome/common/net/x509_certificate_model_openssl.cc
+++ b/chrome/common/net/x509_certificate_model_openssl.cc
@@ -4,12 +4,15 @@
#include "chrome/common/net/x509_certificate_model.h"
+#include <openssl/bio.h>
#include <openssl/obj_mac.h>
#include <openssl/sha.h>
#include <openssl/x509v3.h>
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
+#include "crypto/openssl_bio_string.h"
+#include "crypto/openssl_util.h"
#include "net/cert/x509_util_openssl.h"
namespace x509_util = net::x509_util;
@@ -44,8 +47,19 @@ namespace x509_certificate_model {
using net::X509Certificate;
std::string GetCertNameOrNickname(X509Certificate::OSCertHandle cert_handle) {
- // TODO(bulach): implement me.
- return "";
+ std::string name =
+ ProcessIDN(GetSubjectCommonName(cert_handle, std::string()));
+ if (!name.empty())
+ return name;
+
+ crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&name));
+ if (!bio.get())
+ return name;
+ X509_NAME_print_ex(bio.get(),
+ X509_get_subject_name(cert_handle),
+ 0 /* indent */,
+ XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB);
+ return name;
}
std::string GetTokenName(X509Certificate::OSCertHandle cert_handle) {
@@ -140,8 +154,22 @@ bool GetTimes(X509Certificate::OSCertHandle cert_handle,
}
std::string GetTitle(net::X509Certificate::OSCertHandle cert_handle) {
- // TODO(bulach): implement me.
- return "";
+ // TODO(mattm): merge GetTitle and GetCertNameOrNickname?
+ // Is there any reason GetCertNameOrNickname calls ProcessIDN and this
+ // doesn't?
+ std::string title =
+ GetSubjectCommonName(cert_handle, std::string());
+ if (!title.empty())
+ return title;
+
+ crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&title));
+ if (!bio.get())
+ return title;
+ X509_NAME_print_ex(bio.get(),
+ X509_get_subject_name(cert_handle),
+ 0 /* indent */,
+ XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB);
+ return title;
}
std::string GetIssuerName(net::X509Certificate::OSCertHandle cert_handle) {
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | chrome/common/net/x509_certificate_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698