OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/android/page_info/certificate_chain_helper.h" | 5 #include "chrome/browser/ui/android/page_info/certificate_chain_helper.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 JNIEnv* env, | 23 JNIEnv* env, |
24 const JavaParamRef<jclass>&, | 24 const JavaParamRef<jclass>&, |
25 const JavaParamRef<jobject>& java_web_contents) { | 25 const JavaParamRef<jobject>& java_web_contents) { |
26 content::WebContents* web_contents = | 26 content::WebContents* web_contents = |
27 content::WebContents::FromJavaWebContents(java_web_contents); | 27 content::WebContents::FromJavaWebContents(java_web_contents); |
28 if (!web_contents) | 28 if (!web_contents) |
29 return ScopedJavaLocalRef<jobjectArray>(); | 29 return ScopedJavaLocalRef<jobjectArray>(); |
30 | 30 |
31 scoped_refptr<net::X509Certificate> cert = | 31 scoped_refptr<net::X509Certificate> cert = |
32 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; | 32 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; |
| 33 if (!cert) |
| 34 return ScopedJavaLocalRef<jobjectArray>(); |
33 | 35 |
34 std::vector<std::string> cert_chain; | 36 std::vector<std::string> cert_chain; |
35 net::X509Certificate::OSCertHandles cert_handles = | 37 net::X509Certificate::OSCertHandles cert_handles = |
36 cert->GetIntermediateCertificates(); | 38 cert->GetIntermediateCertificates(); |
37 // Make sure the peer's own cert is the first in the chain, if it's not | 39 // Make sure the peer's own cert is the first in the chain, if it's not |
38 // already there. | 40 // already there. |
39 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) | 41 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) |
40 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); | 42 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); |
41 | 43 |
42 cert_chain.reserve(cert_handles.size()); | 44 cert_chain.reserve(cert_handles.size()); |
43 for (const auto& handle : cert_handles) { | 45 for (const auto& handle : cert_handles) { |
44 std::string cert_bytes; | 46 std::string cert_bytes; |
45 net::X509Certificate::GetDEREncoded(handle, &cert_bytes); | 47 net::X509Certificate::GetDEREncoded(handle, &cert_bytes); |
46 cert_chain.push_back(cert_bytes); | 48 cert_chain.push_back(cert_bytes); |
47 } | 49 } |
48 | 50 |
49 return base::android::ToJavaArrayOfByteArray(env, cert_chain); | 51 return base::android::ToJavaArrayOfByteArray(env, cert_chain); |
50 } | 52 } |
51 | 53 |
52 // static | 54 // static |
53 bool RegisterCertificateChainHelper(JNIEnv* env) { | 55 bool RegisterCertificateChainHelper(JNIEnv* env) { |
54 return RegisterNativesImpl(env); | 56 return RegisterNativesImpl(env); |
55 } | 57 } |
OLD | NEW |