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

Unified Diff: net/cert/x509_certificate_openssl.cc

Issue 634033002: Check whether or not a certificate is self-signed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iOS implementation. Created 6 years, 2 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
Index: net/cert/x509_certificate_openssl.cc
diff --git a/net/cert/x509_certificate_openssl.cc b/net/cert/x509_certificate_openssl.cc
index 91501f84ecd8cb2d91354cdf47f38c2c54101b71..6fc131ece98a751795c9b80110c787ba3d979112 100644
--- a/net/cert/x509_certificate_openssl.cc
+++ b/net/cert/x509_certificate_openssl.cc
@@ -36,6 +36,7 @@ namespace {
typedef crypto::ScopedOpenSSL<GENERAL_NAMES, GENERAL_NAMES_free>::Type
ScopedGENERAL_NAMES;
+typedef crypto::ScopedOpenSSL<X509, X509_free>::Type ScopedX509;
Ryan Sleevi 2014/10/27 23:33:13 Unnecessary
palmer 2014/10/28 23:13:41 Done.
void CreateOSCertHandlesFromPKCS7Bytes(
const char* data, int length,
@@ -449,4 +450,14 @@ bool X509Certificate::IsIssuedByEncoded(
return false;
}
+// static
+bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) {
+ crypto::ScopedEVP_PKEY scoped_key(X509_get_pubkey(cert_handle));
+ if (!scoped_key)
+ return false;
+
+ // NOTE: X509_verify() returns 1 in case of success, 0 or -1 on error.
+ return X509_verify(cert_handle, scoped_key.get()) == 1;
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698