| OLD | NEW |
| (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/android/policy/policy_auditor.h" |
| 6 |
| 7 #include "content/public/browser/navigation_entry.h" |
| 8 #include "content/public/browser/render_process_host.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/common/ssl_status.h" |
| 11 #include "jni/PolicyAuditor_jni.h" |
| 12 #include "net/cert/cert_status_flags.h" |
| 13 |
| 14 int GetCertificateFailure(JNIEnv* env, |
| 15 const JavaParamRef<jclass>& obj, |
| 16 const JavaParamRef<jobject>& java_web_contents) { |
| 17 // This function is similar to |
| 18 // ToolbarModelImpl::GetSecurityLevelForWebContents, but has a custom mapping |
| 19 // for policy auditing |
| 20 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.policy |
| 21 // GENERATED_JAVA_PREFIX_TO_STRIP: CERTIFICATE_FAIL_ |
| 22 enum CertificateFailure { |
| 23 NONE = 0, |
| 24 CERTIFICATE_FAIL_UNSPECIFIED = 1, |
| 25 CERTIFICATE_FAIL_UNTRUSTED = 2, |
| 26 CERTIFICATE_FAIL_REVOKED = 3, |
| 27 CERTIFICATE_FAIL_NOT_YET_VALID = 4, |
| 28 CERTIFICATE_FAIL_EXPIRED = 5, |
| 29 CERTIFICATE_FAIL_UNABLE_TO_CHECK_REVOCATION_STATUS = 6, |
| 30 }; |
| 31 |
| 32 content::WebContents* web_contents = |
| 33 content::WebContents::FromJavaWebContents(java_web_contents); |
| 34 content::NavigationEntry* entry = |
| 35 web_contents->GetController().GetVisibleEntry(); |
| 36 if (!entry) |
| 37 return NONE; |
| 38 |
| 39 const content::SSLStatus& ssl = entry->GetSSL(); |
| 40 switch (ssl.security_style) { |
| 41 case content::SECURITY_STYLE_WARNING: |
| 42 case content::SECURITY_STYLE_UNKNOWN: |
| 43 case content::SECURITY_STYLE_UNAUTHENTICATED: |
| 44 return NONE; |
| 45 |
| 46 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| 47 case content::SECURITY_STYLE_AUTHENTICATED: { |
| 48 if (net::IsCertStatusError(ssl.cert_status)) { |
| 49 if (ssl.cert_status & net::CERT_STATUS_AUTHORITY_INVALID) |
| 50 return CERTIFICATE_FAIL_UNTRUSTED; |
| 51 if (ssl.cert_status & net::CERT_STATUS_REVOKED) |
| 52 return CERTIFICATE_FAIL_REVOKED; |
| 53 // No mapping for CERTIFICATE_FAIL_NOT_YET_VALID. |
| 54 if (ssl.cert_status & net::CERT_STATUS_DATE_INVALID) |
| 55 return CERTIFICATE_FAIL_EXPIRED; |
| 56 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) |
| 57 return CERTIFICATE_FAIL_UNABLE_TO_CHECK_REVOCATION_STATUS; |
| 58 return CERTIFICATE_FAIL_UNSPECIFIED; |
| 59 } |
| 60 if (ssl.content_status & |
| 61 content::SSLStatus::DISPLAYED_INSECURE_CONTENT) { |
| 62 return CERTIFICATE_FAIL_UNSPECIFIED; |
| 63 } |
| 64 } |
| 65 } |
| 66 return NONE; |
| 67 } |
| 68 |
| 69 bool RegisterPolicyAuditor(JNIEnv* env) { |
| 70 return RegisterNativesImpl(env); |
| 71 } |
| OLD | NEW |