ssl.connect now returns the result of the certificate validation.

This commit is contained in:
dom96 2010-10-23 23:35:47 +01:00
commit beb9e3d325
2 changed files with 6 additions and 9 deletions

View file

@ -17,12 +17,10 @@ type
ssl: PSSL ssl: PSSL
bio: PBIO bio: PBIO
proc connect*(sock: var TSecureSocket, address: string, proc connect*(sock: var TSecureSocket, address: string,
port: int, certResult: var Int) = port: int): Int =
## Connects to the specified `address` on the specified `port`. ## 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() SslLoadErrorStrings()
ERR_load_BIO_strings() ERR_load_BIO_strings()
@ -50,7 +48,7 @@ proc connect*(sock: var TSecureSocket, address: string,
ERR_print_errors_fp(stderr) ERR_print_errors_fp(stderr)
OSError() OSError()
certResult = SSL_get_verify_result(sock.ssl) result = SSL_get_verify_result(sock.ssl)
proc recvLine*(sock: TSecureSocket, line: var String): bool = proc recvLine*(sock: TSecureSocket, line: var String): bool =
## Acts in a similar fashion to the `recvLine` in the sockets module. ## Acts in a similar fashion to the `recvLine` in the sockets module.

View file

@ -24,7 +24,7 @@
## smtp.sendmail("username@gmail.com", @["foo@gmail.com"], $msg) ## smtp.sendmail("username@gmail.com", @["foo@gmail.com"], $msg)
## ##
import sockets, strutils, strtabs, ssl, base64 import sockets, strutils, strtabs, ssl, base64, os
type type
TSMTP* = object {.final.} TSMTP* = object {.final.}
@ -62,7 +62,7 @@ proc debugRecv(smtp: TSMTP): String =
echo("S:" & line) echo("S:" & line)
return line return line
else: else:
echo("S-Warning: recvLine failed.") OSError()
return "" return ""
proc quitExcpt(smtp: TSMTP, msg: String) = proc quitExcpt(smtp: TSMTP, msg: String) =
@ -84,8 +84,7 @@ proc connect*(address: String, port: int = 25,
result.sock.connect(address, TPort(port)) result.sock.connect(address, TPort(port))
else: else:
result.ssl = True result.ssl = True
var certResult: int discard result.sslSock.connect(address, port)
result.sslSock.connect(address, port, certResult)
result.debug = debug result.debug = debug