Index: net/base/x509_certificate_openssl.cc |
diff --git a/net/base/x509_certificate_openssl.cc b/net/base/x509_certificate_openssl.cc |
index 5612d61ab49445ec1b3b9acf646be1f5e2ddbd02..1c95fab59cc384767d6149ca3397931c67ff5f2e 100644 |
--- a/net/base/x509_certificate_openssl.cc |
+++ b/net/base/x509_certificate_openssl.cc |
@@ -25,6 +25,11 @@ |
#include "net/base/net_errors.h" |
#include "net/base/x509_util_openssl.h" |
+#if defined(OS_ANDROID) |
+#include "base/logging.h" |
+#include "net/android/network_library.h" |
+#endif |
+ |
namespace net { |
namespace { |
@@ -512,8 +517,44 @@ X509_STORE* X509Certificate::cert_store() { |
return X509InitSingleton::GetInstance()->store(); |
} |
-#if !defined(OS_ANDROID) |
+#if defined(OS_ANDROID) |
+int X509Certificate::VerifyInternal(const std::string& hostname, |
+ int flags, |
+ CRLSet* crl_set, |
+ CertVerifyResult* verify_result) const { |
+ if (!VerifyNameMatch(hostname)) |
+ verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; |
+ |
+ std::vector<std::string> cert_bytes; |
+ GetChainDEREncodedBytes(&cert_bytes); |
+ // TODO(joth): Fetch the authentication type from SSL rather than hardcode. |
+ // TODO(jingzhao): Recover the original implementation once we support JNI. |
+#if 0 |
+ android::VerifyResult result = |
+ android::VerifyX509CertChain(cert_bytes, hostname, "RSA"); |
+#else |
+ android::VerifyResult result = android::VERIFY_INVOCATION_ERROR; |
+ NOTIMPLEMENTED(); |
+#endif |
+ switch (result) { |
+ case android::VERIFY_OK: |
+ return OK; |
Ryan Sleevi
2011/11/06 02:39:48
random drive by:
What does it mean if android::Ve
Jing Zhao
2011/11/07 03:42:49
I think Joth is the original author of this functi
joth
2011/11/07 10:42:20
oh yes, good spot.
To be consistent with the !ANDR
jingzhao
2011/11/08 02:02:17
Fixed as you said.
|
+ case android::VERIFY_BAD_HOSTNAME: |
+ verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; |
+ break; |
+ case android::VERIFY_NO_TRUSTED_ROOT: |
+ verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; |
+ break; |
+ case android::VERIFY_INVOCATION_ERROR: |
+ default: |
+ verify_result->cert_status |= ERR_CERT_INVALID; |
+ break; |
+ } |
+ return MapCertStatusToNetError(verify_result->cert_status); |
+} |
+ |
+#else |
int X509Certificate::VerifyInternal(const std::string& hostname, |
int flags, |
CRLSet* crl_set, |
@@ -565,7 +606,7 @@ int X509Certificate::VerifyInternal(const std::string& hostname, |
return OK; |
} |
-#endif // !defined(OS_ANDROID) |
+#endif // defined(OS_ANDROID) |
// static |
bool X509Certificate::GetDEREncoded(X509Certificate::OSCertHandle cert_handle, |
@@ -620,4 +661,25 @@ bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, |
der_cache.data_length); |
} |
+#if defined(OS_ANDROID) |
+void X509Certificate::GetChainDEREncodedBytes( |
+ std::vector<std::string>* chain_bytes) const { |
+ OSCertHandles cert_handles(intermediate_ca_certs_); |
Ryan Sleevi
2011/11/06 02:39:48
Two things:
1) Why not implement this in terms of
joth
2011/11/07 10:42:20
I think it's just GetDEREncoded didn't exist when
jingzhao
2011/11/08 02:02:17
This change seems small so I made it.. Please take
joth
2011/11/08 10:05:23
Thanks, this looks OK.
For my own record, when we
Ryan Sleevi
2011/11/08 15:03:23
Even if not unlined to the callsite, you can move
|
+ // Make sure the peer's own cert is the first in the chain, if it's not |
+ // already there. |
+ if (cert_handles.empty()) |
+ cert_handles.insert(cert_handles.begin(), cert_handle_); |
Ryan Sleevi
2011/11/06 02:39:48
2) This isn't correct how X509Certificate stores i
joth
2011/11/07 10:42:20
Good spot, thank you. This was broken when it was
jingzhao
2011/11/08 02:02:17
Fixed as you said.
|
+ |
+ chain_bytes->reserve(cert_handles.size()); |
+ for (OSCertHandles::const_iterator it = cert_handles.begin(); |
+ it != cert_handles.end(); ++it) { |
+ DERCache der_cache = {0}; |
+ GetDERAndCacheIfNeeded(*it, &der_cache); |
+ std::string cert_bytes ( |
+ reinterpret_cast<const char*>(der_cache.data), der_cache.data_length); |
+ chain_bytes->push_back(cert_bytes); |
+ } |
+} |
+#endif |
+ |
} // namespace net |