0001    // SSLClientContext.swift
0002    //
0003    // The MIT License (MIT)
0004    //
0005    // Copyright (c) 2015 Zewo
0006    //
0007    // Permission is hereby granted, free of charge, to any person obtaining a copy
0008    // of this software and associated documentation files (the "Software"), to deal
0009    // in the Software without restriction, including without limitation the rights
0010    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0011    // copies of the Software, and to permit persons to whom the Software is
0012    // furnished to do so, subject to the following conditions:
0013    //
0014    // The above copyright notice and this permission notice shall be included in all
0015    // copies or substantial portions of the Software.
0016    //
0017    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018    // IMPLIED, INCLUDINbG BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0020    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0021    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0022    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0023    // SOFTWARE.
0024    
0025    import COpenSSL
0026    
0027    public final class SSLClientContext
ClientStream.swift:30
    private let context: SSLClientContext
ClientStream.swift:38
	public init(context: SSLClientContext, rawStream: StreamType) throws {
: Context { 0028 public init(verifyBundle: String? = nil, certificate: String? = nil, privateKey: String? = nil, certificateChain: String? = nil) throws { 0029 try super.init(method: .SSLv23, type: .Client) 0030 0031 SSL_CTX_set_verify(context, SSL_VERIFY_PEER, nil) 0032 0033 if SSL_CTX_set_default_verify_paths(context) != 1 { 0034 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0035 } 0036 0037 if let verifyBundle = verifyBundle { 0038 if SSL_CTX_load_verify_locations(context, verifyBundle, nil) != 1 { 0039 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0040 } 0041 } 0042 0043 if let certificateChain = certificateChain { 0044 if SSL_CTX_use_certificate_chain_file(context, certificateChain) != 1 { 0045 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0046 } 0047 } 0048 0049 if let certificate = certificate { 0050 if SSL_CTX_use_certificate_file(context, certificate, SSL_FILETYPE_PEM) != 1 { 0051 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0052 } 0053 } 0054 0055 if let privateKey = privateKey { 0056 if SSL_CTX_use_PrivateKey_file(context, privateKey, SSL_FILETYPE_PEM) != 1 { 0057 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0058 } 0059 0060 if SSL_CTX_check_private_key(context) != 1 { 0061 throw Context.Error.Certificate(description: lastSSLErrorDescription) 0062 } 0063 } 0064 } 0065 } 0066