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

Side by Side Diff: chrome/browser/ui/android/page_info/certificate_chain_helper.cc

Issue 2567673002: Factor getCertificateChain out of ConnectionPopupInfo (Closed)
Patch Set: Address review comments Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/android/page_info/certificate_chain_helper.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/ssl_status.h"
13 #include "content/public/browser/web_contents.h"
14 #include "jni/CertificateChainHelper_jni.h"
15 #include "net/cert/x509_certificate.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 using base::android::JavaParamRef;
19 using base::android::ScopedJavaLocalRef;
20 using content::WebContents;
21
22 static ScopedJavaLocalRef<jobjectArray> GetCertificateChain(
23 JNIEnv* env,
24 const JavaParamRef<jclass>&,
25 const JavaParamRef<jobject>& java_web_contents) {
26 content::WebContents* web_contents =
27 content::WebContents::FromJavaWebContents(java_web_contents);
28 if (!web_contents)
29 return ScopedJavaLocalRef<jobjectArray>();
30
31 scoped_refptr<net::X509Certificate> cert =
32 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate;
33
34 std::vector<std::string> cert_chain;
35 net::X509Certificate::OSCertHandles cert_handles =
36 cert->GetIntermediateCertificates();
37 // Make sure the peer's own cert is the first in the chain, if it's not
38 // already there.
39 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle())
40 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle());
41
42 cert_chain.reserve(cert_handles.size());
43 for (const auto& handle : cert_handles) {
44 std::string cert_bytes;
45 net::X509Certificate::GetDEREncoded(handle, &cert_bytes);
46 cert_chain.push_back(cert_bytes);
47 }
48
49 return base::android::ToJavaArrayOfByteArray(env, cert_chain);
50 }
51
52 // static
53 bool RegisterCertificateChainHelper(JNIEnv* env) {
54 return RegisterNativesImpl(env);
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698