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