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

Unified Diff: net/base/x509_util_nss.cc

Issue 11579002: Add X509Certificate::IsIssuedByEncoded() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix ios formatting Created 8 years 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
« net/base/x509_util_nss.h ('K') | « net/base/x509_util_nss.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_util_nss.cc
diff --git a/net/base/x509_util_nss.cc b/net/base/x509_util_nss.cc
index c86b9c5db8b9e013d0bbd4eb4c2795ab77554d11..d1bfdbda9c7efedbc515dc1b815f51aad675995d 100644
--- a/net/base/x509_util_nss.cc
+++ b/net/base/x509_util_nss.cc
@@ -273,6 +273,36 @@ SECStatus PR_CALLBACK CollectCertsCallback(void* arg,
return SECSuccess;
}
+
+typedef scoped_ptr_malloc<CERTName,
+ crypto::NSSDestroyer<CERTName, CERT_DestroyName> > ScopedCERTName;
Ryan Sleevi 2012/12/21 22:09:50 style nit: This indenting is wrong typedef scoped
digit1 2013/01/07 13:58:40 Done.
+
+// Create a new CERTName object from its encoded representation.
+// |arena| is the allocation pool to use.
+// |data| points to a DER-encoded X.509 DistinguishedName.
+// Return a new CERTName pointer on success, or NULL.
+CERTName* CreateCertNameFromEncoded(PLArenaPool* arena,
+ const base::StringPiece& data) {
+ if (!arena)
+ return NULL;
+
+ ScopedCERTName name(PORT_ArenaZNew(arena, CERTName));
+ if (!name.get())
+ return NULL;
+
+ SECItem item;
+ item.len = static_cast<unsigned int>(data.length());
+ item.data = reinterpret_cast<unsigned char*>(
+ const_cast<char*>(data.data()));
+
+ SECStatus rv = SEC_ASN1DecodeItem(arena, name.get(),
+ SEC_ASN1_GET(CERT_NameTemplate), &item);
Ryan Sleevi 2012/12/21 22:09:50 style: This indent is incorrect (minimally, should
digit1 2013/01/07 13:58:40 Done.
+ if (rv != SECSuccess)
+ return NULL;
+
+ return name.release();
+}
+
#endif // defined(USE_NSS) || defined(OS_IOS)
} // namespace
@@ -527,6 +557,36 @@ void GetPublicKeyInfo(CERTCertificate* handle,
break;
}
}
+
+bool GetIssuersFromEncodedList(
+ const std::vector<std::string>& encoded_issuers,
+ PLArenaPool* arena,
+ std::vector<CERTName*>* out) {
+
+ out->clear();
+ for (size_t n = 0; n < encoded_issuers.size(); ++n) {
+ CERTName* name = CreateCertNameFromEncoded(arena, encoded_issuers[n]);
+ if (name == NULL)
+ return false;
+
+ out->push_back(name);
+ }
Ryan Sleevi 2012/12/21 22:09:50 RAII-safe alternative: std::vector<CERTName*> res
digit1 2013/01/07 13:58:40 Done.
+ return true;
+}
+
+
+bool IsCertificateIssuedBy(const std::vector<CERTCertificate*>& cert_chain,
+ const std::vector<CERTName*>& valid_issuers) {
+ for (size_t n = 0; n < cert_chain.size(); ++n) {
+ CERTName* cert_issuer = &cert_chain[n]->issuer;
+ for (size_t i = 0; i < valid_issuers.size(); ++i) {
+ if (CERT_CompareName(valid_issuers[i], cert_issuer))
+ return true;
+ }
+ }
+ return false;
+}
+
#endif // defined(USE_NSS) || defined(OS_IOS)
} // namespace x509_util
« net/base/x509_util_nss.h ('K') | « net/base/x509_util_nss.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698