-USING: arrays kernel math openssl.libssl sequences tools.test ;
+USING: arrays destructors kernel math openssl openssl.libssl sequences
+tools.test ;
USING: openssl ;
IN: openssl.libssl.tests
: has-opt ( ctx op -- ? )
swap SSL_CTRL_OPTIONS 0 f SSL_CTX_ctrl bitand 0 > ;
-: new-ctx ( -- ctx )
- TLSv1_client_method SSL_CTX_new ;
+: new-ctx ( method -- ctx )
+ SSL_CTX_new &SSL_CTX_free ;
-: new-ssl ( -- ssl )
- new-ctx SSL_new ;
+: new-tls1-ctx ( -- ctx )
+ TLSv1_client_method new-ctx ;
+
+: new-ssl ( ctx -- ssl )
+ SSL_new &SSL_free ;
{
{ f f f }
} [
- new-ctx tls-opts [ has-opt ] with map
+ [
+ new-tls1-ctx tls-opts [ has-opt ] with map
+ ] with-destructors
] unit-test
! Test setting options
{ 3 } [
- new-ctx tls-opts [ [ set-opt ] [ has-opt ] 2bi ] with map [ t = ] count
+ [
+ new-tls1-ctx tls-opts [ [ set-opt ] [ has-opt ] 2bi ] with map
+ [ t = ] count
+ ] with-destructors
] unit-test
! Initial state
{ { "before/connect initialization" "read header" 1 f } } [
- new-ssl {
- SSL_state_string_long
- SSL_rstate_string_long
- SSL_want
- SSL_get_peer_certificate
- } [ execute( x -- x ) ] with map
+ [
+ new-tls1-ctx new-ssl {
+ SSL_state_string_long
+ SSL_rstate_string_long
+ SSL_want
+ SSL_get_peer_certificate
+ } [ execute( x -- x ) ] with map
+ ] with-destructors
+] unit-test
+
+: method>version-string ( method -- str )
+ new-ctx new-ssl SSL_get_version ;
+
+! SSL_get_version
+{ { "TLSv1" "TLSv1.1" "TLSv1.2" } } [
+ [
+ TLSv1_method TLSv1_1_method TLSv1_2_method 3array
+ [ method>version-string ] map
+ ] with-destructors
] unit-test
FUNCTION: void SSL_set_connect_state ( SSL* ssl )
FUNCTION: void SSL_set_accept_state ( SSL* ssl )
-
FUNCTION: void SSL_free ( SSL* ssl )
+DESTRUCTOR: SSL_free
+
FUNCTION: int SSL_accept ( SSL* ssl )
FUNCTION: int SSL_connect ( SSL* ssl )
FUNCTION: int SSL_read ( SSL* ssl, void* buf, int num )
! ------------------------------------------------------------------------------
FUNCTION: SSL_CTX* SSL_CTX_new ( ssl-method method )
FUNCTION: void SSL_CTX_free ( SSL_CTX* ctx )
+DESTRUCTOR: SSL_CTX_free
! Load the certificates and private keys into the SSL_CTX
FUNCTION: int SSL_CTX_use_certificate_chain_file ( SSL_CTX* ctx,