Skip to content

Commit

Permalink
Backed out previous change as it only works if a server only has a si…
Browse files Browse the repository at this point in the history
…ngle listener socket with a single configuration. If there are multiple listeners and/or configurations it’s not going to work properly.  At least the way it was it’ll work regardless of the number of listeners and configurations.  There’s a more efficient way but it’s a bit more involved and I want to think about it some more before I implement it.
  • Loading branch information
Bill Abt committed Aug 17, 2016
1 parent da4db75 commit e2a3cc6
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions Sources/SSLService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<SSL_CTX>? = nil

static var openSSLInitialized: Bool = false

// MARK: Constants

let DEFAULT_VERIFY_DEPTH: Int32 = 2
let DEFAULT_VERIFY_DEPTH: Int32 = 2

// MARK: Configuration

Expand Down Expand Up @@ -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<SSL_METHOD>? = nil

/// SSL Context
private var context: UnsafeMutablePointer<SSL_CTX>? = nil


// MARK: Lifecycle

Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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 {

Expand All @@ -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)
Expand Down Expand Up @@ -550,7 +543,7 @@ public class SSLService : SSLServiceDelegate {
private func prepareConnection(socket: Socket) throws -> UnsafeMutablePointer<SSL> {

// 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)
Expand Down

0 comments on commit e2a3cc6

Please sign in to comment.