OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ | 5 #ifndef IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ |
6 #define IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ | 6 #define IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
| 10 #include "base/mac/scoped_cftyperef.h" |
10 #import "base/memory/ref_counted.h" | 11 #import "base/memory/ref_counted.h" |
| 12 #include "ios/web/public/security_style.h" |
11 #include "net/cert/cert_status_flags.h" | 13 #include "net/cert/cert_status_flags.h" |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 class X509Certificate; | 16 class X509Certificate; |
15 } | 17 } |
16 | 18 |
17 namespace web { | 19 namespace web { |
18 | 20 |
19 class BrowserState; | 21 class BrowserState; |
20 | 22 |
21 // Accept policy for valid or invalid SSL cert. | 23 // Accept policy for valid or invalid SSL cert. |
22 typedef NS_ENUM(NSInteger, CertAcceptPolicy) { | 24 typedef NS_ENUM(NSInteger, CertAcceptPolicy) { |
23 // Cert status can't be determined due to an error. Caller should not proceed | 25 // Cert status can't be determined due to an error. Caller should not proceed |
24 // with the load, but show net error page instead. | 26 // with the load, but show net error page instead. |
25 CERT_ACCEPT_POLICY_NON_RECOVERABLE_ERROR = 0, | 27 CERT_ACCEPT_POLICY_NON_RECOVERABLE_ERROR = 0, |
26 // Cert is not valid. Caller may present SSL warning and ask user if they | 28 // Cert is not valid. Caller may present SSL warning and ask user if they |
27 // want to proceed with the load. | 29 // want to proceed with the load. |
28 CERT_ACCEPT_POLICY_RECOVERABLE_ERROR, | 30 CERT_ACCEPT_POLICY_RECOVERABLE_ERROR, |
29 // Cert is valid. Caller should proceed with the load. | 31 // Cert is valid. Caller should proceed with the load. |
30 CERT_ACCEPT_POLICY_ALLOW, | 32 CERT_ACCEPT_POLICY_ALLOW, |
31 }; | 33 }; |
32 | 34 |
33 // Completion handler called by decidePolicyForCert:host:completionHandler:. | 35 // Completion handler called by decidePolicyForCert:host:completionHandler:. |
34 typedef void (^PolicyDecisionHandler)(web::CertAcceptPolicy, net::CertStatus); | 36 typedef void (^PolicyDecisionHandler)(web::CertAcceptPolicy, net::CertStatus); |
| 37 // Completion handler called by querySSLStatusForTrust:host:completionHandler:. |
| 38 typedef void (^StatusQueryHandler)(web::SecurityStyle, net::CertStatus); |
35 | 39 |
36 } // namespace web | 40 } // namespace web |
37 | 41 |
38 // Provides various cert verification API that can be used for blocking requests | 42 // Provides various cert verification API that can be used for blocking requests |
39 // with bad SSL cert, presenting SSL interstitials and determining SSL status | 43 // with bad SSL cert, presenting SSL interstitials and determining SSL status |
40 // for Navigation Items. Must be used on UI thread. | 44 // for Navigation Items. Must be used on UI thread. |
41 @interface CRWCertVerificationController : NSObject | 45 @interface CRWCertVerificationController : NSObject |
42 | 46 |
43 - (instancetype)init NS_UNAVAILABLE; | 47 - (instancetype)init NS_UNAVAILABLE; |
44 | 48 |
45 // Initializes CRWCertVerificationController with the given |browserState| which | 49 // Initializes CRWCertVerificationController with the given |browserState| which |
46 // cannot be null and must outlive CRWCertVerificationController. | 50 // cannot be null and must outlive CRWCertVerificationController. |
47 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState | 51 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState |
48 NS_DESIGNATED_INITIALIZER; | 52 NS_DESIGNATED_INITIALIZER; |
49 | 53 |
50 // TODO(eugenebut): add API for: | 54 // TODO(eugenebut): add API for: |
51 // - accepting bad SSL cert using CertPolicyCache | 55 // - accepting bad SSL cert using CertPolicyCache |
52 // - querying SSL cert status for Navigation Item | |
53 | 56 |
54 // Decides the policy for the given |cert| for the given |host| and calls | 57 // Decides the policy for the given |cert| for the given |host| and calls |
55 // |completionHandler| on completion. |completionHandler| cannot be null and | 58 // |completionHandler| on completion. |host| should be in ASCII compatible form |
56 // will be called synchronously or asynchronously on UI thread. | 59 // (e.g. for "http://名がドメイン.com", it should be "xn--v8jxj3d1dzdz08w.com"). |
| 60 // |completionHandler| cannot be null and will be called asynchronously on the |
| 61 // UI thread. |
57 - (void)decidePolicyForCert:(const scoped_refptr<net::X509Certificate>&)cert | 62 - (void)decidePolicyForCert:(const scoped_refptr<net::X509Certificate>&)cert |
58 host:(NSString*)host | 63 host:(NSString*)host |
59 completionHandler:(web::PolicyDecisionHandler)handler; | 64 completionHandler:(web::PolicyDecisionHandler)completionHandler; |
| 65 |
| 66 // Asynchronously provides web::SecurityStyle and net::CertStatus for the given |
| 67 // |serverTrust| and |host|. |host| should be in ASCII compatible form. |
| 68 // Note: The web::SecurityStyle determines whether the certificate is trusted. |
| 69 // It is possible for an untrusted certificate to return a net::CertStatus with |
| 70 // no errors if the cause could not be determined. Callers must handle this case |
| 71 // gracefully. |
| 72 - (void)querySSLStatusForTrust:(base::ScopedCFTypeRef<SecTrustRef>)serverTrust |
| 73 host:(NSString*)host |
| 74 completionHandler:(web::StatusQueryHandler)completionHandler; |
60 | 75 |
61 // Cancels all pending verification requests. Completion handlers will not be | 76 // Cancels all pending verification requests. Completion handlers will not be |
62 // called after |shutDown| call. Must always be called before object's | 77 // called after |shutDown| call. Must always be called before object's |
63 // deallocation. | 78 // deallocation. |
64 - (void)shutDown; | 79 - (void)shutDown; |
65 | 80 |
66 @end | 81 @end |
67 | 82 |
68 #endif // IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ | 83 #endif // IOS_WEB_NET_CRW_CERT_VERIFICATION_CONTROLLER_H_ |
OLD | NEW |