Skip to content

Commit

Permalink
Merge pull request #46 from vapor/ssl-errors
Browse files Browse the repository at this point in the history
Extract error messages from the SSL error queue
  • Loading branch information
loganwright authored May 31, 2017
2 parents f364aa9 + e77e062 commit 657ae89
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/TLS/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ extension Socket {
reason = "The operation did not complete because an application callback set by SSL_CTX_set_client_cert_cb() has asked to be called again."
case SSL_ERROR_SYSCALL:
reason = String(validatingUTF8: strerror(errno)) ?? "System call error"
case SSL_ERROR_SSL:
let bio = BIO_new(BIO_s_mem())

defer {
BIO_free(bio)
}

ERR_print_errors(bio)
let written = BIO_number_written(bio)

var buffer: [Int8] = Array(repeating: 0, count: Int(written) + 1)
reason = buffer.withUnsafeMutableBufferPointer { buf in
BIO_read(bio, buf.baseAddress, Int32(written))
return String(validatingUTF8: buf.baseAddress!)
}
default:
reason = "A failure in the SSL library occurred."
}
Expand Down

0 comments on commit 657ae89

Please sign in to comment.