Chromium Code Reviews| Index: chrome/browser/ui/android/page_info/certificate_chain_helper.cc |
| diff --git a/chrome/browser/ui/android/page_info/certificate_chain_helper.cc b/chrome/browser/ui/android/page_info/certificate_chain_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f63330b183cbacf8c14c2881d0b85b4129c36b6 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/page_info/certificate_chain_helper.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
Ted C
2016/12/16 17:21:16
2016
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/page_info/certificate_chain_helper.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/ssl_status.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "jni/CertificateChainHelper_jni.h" |
| +#include "net/cert/x509_certificate.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +using base::android::JavaParamRef; |
| +using base::android::ScopedJavaLocalRef; |
| +using content::WebContents; |
| + |
| +static ScopedJavaLocalRef<jobjectArray> GetCertificateChain( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>&, |
| + const JavaParamRef<jobject>& java_web_contents) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromJavaWebContents(java_web_contents); |
| + if (!web_contents) |
| + return ScopedJavaLocalRef<jobjectArray>(); |
| + |
| + scoped_refptr<net::X509Certificate> cert = |
| + web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; |
| + |
| + std::vector<std::string> cert_chain; |
| + net::X509Certificate::OSCertHandles cert_handles = |
| + cert->GetIntermediateCertificates(); |
| + // 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[0] != cert->os_cert_handle()) |
| + cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); |
| + |
| + cert_chain.reserve(cert_handles.size()); |
| + for (net::X509Certificate::OSCertHandles::const_iterator it = |
| + cert_handles.begin(); |
| + it != cert_handles.end(); |
| + ++it) { |
|
Avi (use Gerrit)
2016/12/09 23:59:10
for (const auto& handle : cert_handles) ?
At leas
|
| + std::string cert_bytes; |
| + net::X509Certificate::GetDEREncoded(*it, &cert_bytes); |
| + cert_chain.push_back(cert_bytes); |
| + } |
| + |
| + return base::android::ToJavaArrayOfByteArray(env, cert_chain); |
| +} |
| + |
| +// static |
| +bool RegisterCertificateChainHelper(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |