|
4 | 4 | // |
5 | 5 | // Created by Lukas Schmidt on 24.09.17. |
6 | 6 | // |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to deal |
| 9 | +// in the Software without restriction, including without limitation the rights |
| 10 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +// copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +// THE SOFTWARE. |
7 | 24 |
|
8 | 25 | import Foundation |
9 | 26 | import Starscream |
10 | 27 |
|
11 | | -public class SSLSecurity: NSObject { |
| 28 | +/// A wrapper around Starscream's SSLSecurity that provides a minimal Objective-C interface. |
| 29 | +open class SSLSecurity : NSObject { |
| 30 | + /// The internal Starscream SSLSecurity. |
12 | 31 | public let security: Starscream.SSLSecurity |
13 | 32 |
|
14 | 33 | init(security: Starscream.SSLSecurity) { |
15 | 34 | self.security = security |
16 | 35 | } |
17 | 36 |
|
| 37 | + /// Creates a new SSLSecurity that specifies whether to use publicKeys or certificates should be used for SSL |
| 38 | + /// pinning validation |
| 39 | + /// |
| 40 | + /// - parameter usePublicKeys: is to specific if the publicKeys or certificates should be used for SSL pinning |
| 41 | + /// validation |
18 | 42 | @objc |
19 | 43 | public convenience init(usePublicKeys: Bool = true) { |
20 | 44 | let security = Starscream.SSLSecurity(usePublicKeys: usePublicKeys) |
21 | 45 | self.init(security: security) |
22 | 46 | } |
23 | 47 |
|
| 48 | + |
| 49 | + /// Designated init |
| 50 | + /// |
| 51 | + /// - parameter certs: is the certificates or public keys to use |
| 52 | + /// - parameter usePublicKeys: is to specific if the publicKeys or certificates should be used for SSL pinning |
| 53 | + /// validation |
| 54 | + /// - returns: a representation security object to be used with |
24 | 55 | public convenience init(certs: [SSLCert], usePublicKeys: Bool) { |
25 | 56 | let security = Starscream.SSLSecurity(certs: certs, usePublicKeys: usePublicKeys) |
26 | 57 | self.init(security: security) |
27 | 58 | } |
28 | 59 |
|
| 60 | + /// Returns whether or not the given trust is valid. |
| 61 | + /// |
| 62 | + /// - parameter trust: The trust to validate. |
| 63 | + /// - parameter domain: The CN domain to validate. |
| 64 | + /// - returns: Whether or not this is valid. |
29 | 65 | public func isValid(_ trust: SecTrust, domain: String?) -> Bool { |
30 | 66 | return security.isValid(trust, domain: domain) |
31 | 67 | } |
|
0 commit comments