mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 03:14:08 +00:00
ssl.connect now returns the result of the certificate validation.
This commit is contained in:
@@ -17,12 +17,10 @@ type
|
||||
ssl: PSSL
|
||||
bio: PBIO
|
||||
|
||||
|
||||
|
||||
proc connect*(sock: var TSecureSocket, address: string,
|
||||
port: int, certResult: var Int) =
|
||||
port: int): Int =
|
||||
## Connects to the specified `address` on the specified `port`.
|
||||
## `certResult` will become the result of the certificate validation.
|
||||
## Returns the result of the certificate validation.
|
||||
SslLoadErrorStrings()
|
||||
ERR_load_BIO_strings()
|
||||
|
||||
@@ -50,7 +48,7 @@ proc connect*(sock: var TSecureSocket, address: string,
|
||||
ERR_print_errors_fp(stderr)
|
||||
OSError()
|
||||
|
||||
certResult = SSL_get_verify_result(sock.ssl)
|
||||
result = SSL_get_verify_result(sock.ssl)
|
||||
|
||||
proc recvLine*(sock: TSecureSocket, line: var String): bool =
|
||||
## Acts in a similar fashion to the `recvLine` in the sockets module.
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
## smtp.sendmail("username@gmail.com", @["foo@gmail.com"], $msg)
|
||||
##
|
||||
|
||||
import sockets, strutils, strtabs, ssl, base64
|
||||
import sockets, strutils, strtabs, ssl, base64, os
|
||||
|
||||
type
|
||||
TSMTP* = object {.final.}
|
||||
@@ -62,7 +62,7 @@ proc debugRecv(smtp: TSMTP): String =
|
||||
echo("S:" & line)
|
||||
return line
|
||||
else:
|
||||
echo("S-Warning: recvLine failed.")
|
||||
OSError()
|
||||
return ""
|
||||
|
||||
proc quitExcpt(smtp: TSMTP, msg: String) =
|
||||
@@ -84,8 +84,7 @@ proc connect*(address: String, port: int = 25,
|
||||
result.sock.connect(address, TPort(port))
|
||||
else:
|
||||
result.ssl = True
|
||||
var certResult: int
|
||||
result.sslSock.connect(address, port, certResult)
|
||||
discard result.sslSock.connect(address, port)
|
||||
|
||||
result.debug = debug
|
||||
|
||||
|
||||
Reference in New Issue
Block a user