From e2a3cc64781afd45f81530365ab4b134e00847a4 Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Wed, 17 Aug 2016 12:27:39 -0400 Subject: [PATCH] =?UTF-8?q?Backed=20out=20previous=20change=20as=20it=20on?= =?UTF-8?q?ly=20works=20if=20a=20server=20only=20has=20a=20single=20listen?= =?UTF-8?q?er=20socket=20with=20a=20single=20configuration.=20=20If=20ther?= =?UTF-8?q?e=20are=20multiple=20listeners=20and/or=20configurations=20it?= =?UTF-8?q?=E2=80=99s=20not=20going=20to=20work=20properly.=20=C2=A0At=20l?= =?UTF-8?q?east=20the=20way=20it=20was=20it=E2=80=99ll=20work=20regardless?= =?UTF-8?q?=20of=20the=20number=20of=20listeners=20and=20configurations.?= =?UTF-8?q?=20=C2=A0There=E2=80=99s=20a=20more=20efficient=20way=20but=20i?= =?UTF-8?q?t=E2=80=99s=20a=20bit=20more=20involved=20and=20I=20want=20to?= =?UTF-8?q?=20think=20about=20it=20some=20more=20before=20I=20implement=20?= =?UTF-8?q?it.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/SSLService.swift | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Sources/SSLService.swift b/Sources/SSLService.swift index 35d19b7..5671c84 100644 --- a/Sources/SSLService.swift +++ b/Sources/SSLService.swift @@ -32,16 +32,11 @@ public class SSLService : SSLServiceDelegate { // MARK: Statics - /// True if OpenSSL was initialized, false otherwise. - static var openSSLInitialized: Bool = false - - /// SSL Context - static var context: UnsafeMutablePointer? = nil - + static var openSSLInitialized: Bool = false // MARK: Constants - let DEFAULT_VERIFY_DEPTH: Int32 = 2 + let DEFAULT_VERIFY_DEPTH: Int32 = 2 // MARK: Configuration @@ -156,6 +151,9 @@ public class SSLService : SSLServiceDelegate { /// **Note:** We use `SSLv23` which causes negotiation of the highest available SSL/TLS version. private var method: UnsafePointer? = nil + /// SSL Context + private var context: UnsafeMutablePointer? = nil + // MARK: Lifecycle @@ -239,8 +237,8 @@ public class SSLService : SSLServiceDelegate { } // Now the context... - if SSLService.context != nil { - SSL_CTX_free(SSLService.context!) + if self.context != nil { + SSL_CTX_free(self.context!) } // Finally, finish cleanup... @@ -450,11 +448,6 @@ public class SSLService : SSLServiceDelegate { /// private func prepareContext() throws { - // If we've already got a context, skip this... - if SSLService.context != nil { - return - } - // Make sure we've got the method to use... guard let method = self.method else { @@ -463,9 +456,9 @@ public class SSLService : SSLServiceDelegate { } // Now we can create the context... - SSLService.context = SSL_CTX_new(method) + self.context = SSL_CTX_new(method) - guard let context = SSLService.context else { + guard let context = self.context else { let reason = "ERROR: Unable to create SSL context." throw SSLError.fail(Int(ENOMEM), reason) @@ -550,7 +543,7 @@ public class SSLService : SSLServiceDelegate { private func prepareConnection(socket: Socket) throws -> UnsafeMutablePointer { // Make sure our context is valid... - guard let context = SSLService.context else { + guard let context = self.context else { let reason = "ERROR: Unable to access SSL context." throw SSLError.fail(Int(EFAULT), reason)