OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ | 5 #ifndef IOS_WEB_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ |
6 #define IOS_WEB_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ | 6 #define IOS_WEB_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <Security/Security.h> |
9 | 10 |
| 11 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "ios/web/public/security_style.h" |
11 | 14 |
12 namespace net { | 15 namespace net { |
13 class SSLInfo; | 16 class SSLInfo; |
14 class X509Certificate; | 17 class X509Certificate; |
15 } | 18 } |
16 | 19 |
17 namespace web { | 20 namespace web { |
18 | 21 |
19 // NSErrorPeerCertificateChainKey from NSError's userInfo dict. | 22 // NSErrorPeerCertificateChainKey from NSError's userInfo dict. |
20 extern NSString* const kNSErrorPeerCertificateChainKey; | 23 extern NSString* const kNSErrorPeerCertificateChainKey; |
21 | 24 |
22 // Creates a certificate from an array of SecCertificateRef objects. | 25 // Creates a certificate from an array of SecCertificateRef objects. |
23 // Returns null if |certs| is nil or empty. | 26 // Returns null if |certs| is nil or empty. |
24 scoped_refptr<net::X509Certificate> CreateCertFromChain(NSArray* certs); | 27 scoped_refptr<net::X509Certificate> CreateCertFromChain(NSArray* certs); |
25 | 28 |
26 // Creates a certificate from a SecTrustRef object. | 29 // Creates a certificate from a SecTrustRef object. |
27 // Returns null if trust is null or does not have any certs. | 30 // Returns null if trust is null or does not have any certs. |
28 scoped_refptr<net::X509Certificate> CreateCertFromTrust(SecTrustRef trust); | 31 scoped_refptr<net::X509Certificate> CreateCertFromTrust(SecTrustRef trust); |
29 | 32 |
| 33 // Creates server trust object from an array of SecCertificateRef objects. |
| 34 // Returns null if |certs| is null or empty. |
| 35 base::ScopedCFTypeRef<SecTrustRef> CreateServerTrustFromChain(NSArray* certs, |
| 36 NSString* host); |
| 37 |
30 // Makes SecTrustEvaluate call to return kSecTrustResultProceed. | 38 // Makes SecTrustEvaluate call to return kSecTrustResultProceed. |
31 // Should be called only if the user expilitely agreed to proceed with |trust| | 39 // Should be called only if the user expilitely agreed to proceed with |trust| |
32 // or trust represents a valid certificate chain. | 40 // or trust represents a valid certificate chain. |
33 void EnsureFutureTrustEvaluationSucceeds(SecTrustRef trust); | 41 void EnsureFutureTrustEvaluationSucceeds(SecTrustRef trust); |
34 | 42 |
35 // Returns YES if given error is an SSL certificate error. | 43 // Returns YES if given error is an SSL certificate error. |
36 BOOL IsWKWebViewSSLCertError(NSError* error); | 44 BOOL IsWKWebViewSSLCertError(NSError* error); |
37 | 45 |
38 // Fills SSLInfo object with information extracted from |error|. Callers are | 46 // Fills SSLInfo object with information extracted from |error|. Callers are |
39 // responsible to ensure that given |error| is an SSL error by calling | 47 // responsible to ensure that given |error| is an SSL error by calling |
40 // |web::IsWKWebViewSSLCertError| function. | 48 // |web::IsWKWebViewSSLCertError| function. |
41 void GetSSLInfoFromWKWebViewSSLCertError(NSError* error, | 49 void GetSSLInfoFromWKWebViewSSLCertError(NSError* error, |
42 net::SSLInfo* ssl_info); | 50 net::SSLInfo* ssl_info); |
43 | 51 |
| 52 // Maps SecTrustResultType value to web::SecurityStyle. |
| 53 SecurityStyle GetSecurityStyleFromTrustResult(SecTrustResultType result); |
| 54 |
44 } // namespace web | 55 } // namespace web |
45 | 56 |
46 #endif // IOS_WEB_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ | 57 #endif // IOS_WEB_WEB_STATE_WK_WEB_VIEW_SECURITY_UTIL_H_ |
OLD | NEW |