2020-04-08 20:44:30 +03:00
|
|
|
module websocket
|
2020-04-08 15:22:31 +03:00
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
import net.openssl
|
2020-05-26 13:50:37 +03:00
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
const (
|
|
|
|
is_used = openssl.is_used
|
|
|
|
)
|
2020-04-08 15:22:31 +03:00
|
|
|
|
2020-05-26 13:50:37 +03:00
|
|
|
fn (mut ws Client) connect_ssl() {
|
2020-07-22 17:31:22 +03:00
|
|
|
ws.log.info('Using secure SSL connection')
|
2020-04-08 15:22:31 +03:00
|
|
|
C.SSL_load_error_strings()
|
2020-04-24 08:32:51 +03:00
|
|
|
ws.sslctx = C.SSL_CTX_new(C.SSLv23_client_method())
|
2020-05-26 13:50:37 +03:00
|
|
|
if ws.sslctx == 0 {
|
2020-07-22 17:31:22 +03:00
|
|
|
ws.log.fatal("Couldn't get ssl context")
|
2020-04-08 15:22:31 +03:00
|
|
|
}
|
2020-04-24 08:32:51 +03:00
|
|
|
ws.ssl = C.SSL_new(ws.sslctx)
|
2020-05-26 13:50:37 +03:00
|
|
|
if ws.ssl == 0 {
|
2020-07-22 17:31:22 +03:00
|
|
|
ws.log.fatal("Couldn't create OpenSSL instance.")
|
2020-04-08 15:22:31 +03:00
|
|
|
}
|
2020-04-24 08:32:51 +03:00
|
|
|
if C.SSL_set_fd(ws.ssl, ws.socket.sockfd) != 1 {
|
2020-07-22 17:31:22 +03:00
|
|
|
ws.log.fatal("Couldn't assign ssl to socket.")
|
2020-04-08 15:22:31 +03:00
|
|
|
}
|
2020-04-24 08:32:51 +03:00
|
|
|
if C.SSL_connect(ws.ssl) != 1 {
|
2020-07-22 17:31:22 +03:00
|
|
|
ws.log.fatal("Couldn't connect using SSL.")
|
2020-04-08 15:22:31 +03:00
|
|
|
}
|
2020-05-26 13:50:37 +03:00
|
|
|
}
|