Skip to content

Commit 657ae89

Browse files
authored
Merge pull request vapor-community#46 from vapor/ssl-errors
Extract error messages from the SSL error queue
2 parents f364aa9 + e77e062 commit 657ae89

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Sources/TLS/Error.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ extension Socket {
5252
reason = "The operation did not complete because an application callback set by SSL_CTX_set_client_cert_cb() has asked to be called again."
5353
case SSL_ERROR_SYSCALL:
5454
reason = String(validatingUTF8: strerror(errno)) ?? "System call error"
55+
case SSL_ERROR_SSL:
56+
let bio = BIO_new(BIO_s_mem())
57+
58+
defer {
59+
BIO_free(bio)
60+
}
61+
62+
ERR_print_errors(bio)
63+
let written = BIO_number_written(bio)
64+
65+
var buffer: [Int8] = Array(repeating: 0, count: Int(written) + 1)
66+
reason = buffer.withUnsafeMutableBufferPointer { buf in
67+
BIO_read(bio, buf.baseAddress, Int32(written))
68+
return String(validatingUTF8: buf.baseAddress!)
69+
}
5570
default:
5671
reason = "A failure in the SSL library occurred."
5772
}

0 commit comments

Comments
 (0)