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

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

Issue 2567673002: Factor getCertificateChain out of ConnectionPopupInfo (Closed)
Patch Set: Strip out Payment changes for now 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 2015 The Chromium Authors. All rights reserved.
Ted C 2016/12/16 17:21:16 2016
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 (net::X509Certificate::OSCertHandles::const_iterator it =
44 cert_handles.begin();
45 it != cert_handles.end();
46 ++it) {
Avi (use Gerrit) 2016/12/09 23:59:10 for (const auto& handle : cert_handles) ? At leas
47 std::string cert_bytes;
48 net::X509Certificate::GetDEREncoded(*it, &cert_bytes);
49 cert_chain.push_back(cert_bytes);
50 }
51
52 return base::android::ToJavaArrayOfByteArray(env, cert_chain);
53 }
54
55 // static
56 bool RegisterCertificateChainHelper(JNIEnv* env) {
57 return RegisterNativesImpl(env);
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698