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

Side by Side Diff: chrome/browser/android/policy/policy_auditor.cc

Issue 1930963002: 🌈 Upstream some code related to PolicyAuditing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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/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,
Bernhard Bauer 2016/04/28 16:33:08 Just to check: the generated JNI binding declares
Yaron 2016/04/28 19:30:49 yep (cause it was static in java): static jint Ge
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 enum CertificateFailure {
Bernhard Bauer 2016/04/28 16:33:08 You could put this into a header and generate the
Yaron 2016/04/28 19:30:49 Done.
21 NONE = 0,
22 CERTIFICATE_FAIL_UNSPECIFIED = 1,
23 CERTIFICATE_FAIL_UNTRUSTED = 2,
24 CERTIFICATE_FAIL_REVOKED = 3,
25 CERTIFICATE_FAIL_NOT_YET_VALID = 4,
26 CERTIFICATE_FAIL_EXPIRED = 5,
27 CERTIFICATE_FAIL_UNABLE_TO_CHECK_REVOCATION_STATUS = 6,
28 };
29
30 content::WebContents* web_contents =
31 content::WebContents::FromJavaWebContents(java_web_contents);
32 content::NavigationEntry* entry =
33 web_contents->GetController().GetVisibleEntry();
34 if (!entry)
35 return NONE;
36
37 const content::SSLStatus& ssl = entry->GetSSL();
38 switch (ssl.security_style) {
39 case content::SECURITY_STYLE_UNKNOWN:
40 case content::SECURITY_STYLE_UNAUTHENTICATED:
41 return NONE;
42
43 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN:
44 case content::SECURITY_STYLE_AUTHENTICATED: {
45 if (net::IsCertStatusError(ssl.cert_status)) {
46 if (ssl.cert_status & net::CERT_STATUS_AUTHORITY_INVALID)
47 return CERTIFICATE_FAIL_UNTRUSTED;
48 if (ssl.cert_status & net::CERT_STATUS_REVOKED)
49 return CERTIFICATE_FAIL_REVOKED;
50 // No mapping for CERTIFICATE_FAIL_NOT_YET_VALID.
51 if (ssl.cert_status & net::CERT_STATUS_DATE_INVALID)
52 return CERTIFICATE_FAIL_EXPIRED;
53 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION)
54 return CERTIFICATE_FAIL_UNABLE_TO_CHECK_REVOCATION_STATUS;
55 return CERTIFICATE_FAIL_UNSPECIFIED;
56 }
57 if (!!(ssl.content_status &
Bernhard Bauer 2016/04/28 16:33:08 Is the cast to bool necessary if we're using this
Yaron 2016/04/28 19:30:49 Just copied from internal tree
58 content::SSLStatus::DISPLAYED_INSECURE_CONTENT))
59 return CERTIFICATE_FAIL_UNSPECIFIED;
Bernhard Bauer 2016/04/28 16:33:08 I think if the condition is long enough to require
Yaron 2016/04/28 19:30:49 Done.
60 // Secure content, no certificate errors.
61 return NONE;
62 }
63 default:
Bernhard Bauer 2016/04/28 16:33:08 What other values are there? Could we remove the d
Yaron 2016/04/28 19:30:49 Done.
64 NOTREACHED();
65 return NONE;
66 }
67 }
68
69 bool RegisterPolicyAuditor(JNIEnv* env) {
70 return RegisterNativesImpl(env);
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698