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

Unified Diff: net/cert/x509_certificate_win.cc

Issue 2761333002: Add a DevTools warning for a missing subjectAltName (Closed)
Patch Set: Feedback & fixes Created 3 years, 9 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 | « net/cert/x509_certificate_unittest.cc ('k') | net/cert/x509_util_nss.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/x509_certificate_win.cc
diff --git a/net/cert/x509_certificate_win.cc b/net/cert/x509_certificate_win.cc
index c67011e06b9c783059b0804c2eb3e97fad473b30..3414734cc7e1dfc86e6e4f1ff3ec834082482c3c 100644
--- a/net/cert/x509_certificate_win.cc
+++ b/net/cert/x509_certificate_win.cc
@@ -151,7 +151,7 @@ void X509Certificate::Initialize() {
reinterpret_cast<char*>(serial_bytes.get()), serial->cbData);
}
-void X509Certificate::GetSubjectAltName(
+bool X509Certificate::GetSubjectAltName(
std::vector<std::string>* dns_names,
std::vector<std::string>* ip_addrs) const {
if (dns_names)
@@ -160,28 +160,39 @@ void X509Certificate::GetSubjectAltName(
ip_addrs->clear();
if (!cert_handle_)
- return;
+ return false;
std::unique_ptr<CERT_ALT_NAME_INFO, base::FreeDeleter> alt_name_info;
GetCertSubjectAltName(cert_handle_, &alt_name_info);
CERT_ALT_NAME_INFO* alt_name = alt_name_info.get();
- if (alt_name) {
- int num_entries = alt_name->cAltEntry;
- for (int i = 0; i < num_entries; i++) {
- // dNSName is an ASN.1 IA5String representing a string of ASCII
- // characters, so we can use UTF16ToASCII here.
- const CERT_ALT_NAME_ENTRY& entry = alt_name->rgAltEntry[i];
-
- if (dns_names && entry.dwAltNameChoice == CERT_ALT_NAME_DNS_NAME) {
+ if (!alt_name)
+ return false;
+
+ bool has_san = false;
+ for (DWORD i = 0, num_entries = alt_name->cAltEntry; i < num_entries; i++) {
+ // dNSName is an ASN.1 IA5String representing a string of ASCII
+ // characters, so we can use UTF16ToASCII here.
+ const CERT_ALT_NAME_ENTRY& entry = alt_name->rgAltEntry[i];
+
+ if (entry.dwAltNameChoice == CERT_ALT_NAME_DNS_NAME) {
+ has_san = true;
+ if (dns_names)
dns_names->push_back(base::UTF16ToASCII(entry.pwszDNSName));
- } else if (ip_addrs &&
- entry.dwAltNameChoice == CERT_ALT_NAME_IP_ADDRESS) {
+ } else if (entry.dwAltNameChoice == CERT_ALT_NAME_IP_ADDRESS) {
+ has_san = true;
+ if (ip_addrs) {
ip_addrs->push_back(std::string(
reinterpret_cast<const char*>(entry.IPAddress.pbData),
entry.IPAddress.cbData));
}
}
+ // Fast path: Found at least one subjectAltName and the caller doesn't
+ // need the actual values.
+ if (has_san && !ip_addrs && !dns_names)
+ return true;
}
+
+ return has_san;
}
PCCERT_CONTEXT X509Certificate::CreateOSCertChainForCert() const {
« no previous file with comments | « net/cert/x509_certificate_unittest.cc ('k') | net/cert/x509_util_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698