2014-03-06 12:41:37 -05:00
|
|
|
USING: accessors alien continuations http.client http.server io.servers
|
|
|
|
io.sockets io.sockets.private io.sockets.secure io.sockets.secure.openssl
|
|
|
|
kernel openssl.libcrypto openssl.libssl sequences system tools.test urls
|
2014-04-03 00:11:52 -04:00
|
|
|
vocabs.parser ;
|
2013-09-14 15:18:13 -04:00
|
|
|
IN: io.sockets.secure.openssl.tests
|
|
|
|
|
2014-04-02 11:44:19 -04:00
|
|
|
<< os windows? [ "windows.winsock" ] [ "unix.ffi" ] if use-vocab >>
|
|
|
|
|
2013-10-10 11:03:17 -04:00
|
|
|
: new-ssl ( -- ssl )
|
|
|
|
SSLv23_client_method SSL_CTX_new SSL_new ;
|
|
|
|
|
2014-03-06 12:41:37 -05:00
|
|
|
! This word creates blocking sockets for testing purposes. Factor by
|
|
|
|
! default prefers to use non-blocking ones.
|
|
|
|
: inet-socket ( -- socket )
|
|
|
|
AF_INET SOCK_STREAM IPPROTO_TCP socket ;
|
|
|
|
|
2013-10-10 11:03:17 -04:00
|
|
|
: socket-connect ( remote -- socket )
|
2014-03-06 12:41:37 -05:00
|
|
|
inet-socket swap dupd make-sockaddr/size connect drop ;
|
2013-10-10 11:03:17 -04:00
|
|
|
|
|
|
|
: ssl-socket-connect ( remote -- ssl-socket )
|
2014-03-06 12:41:37 -05:00
|
|
|
socket-connect os windows? [ alien-address ] when
|
|
|
|
BIO_NOCLOSE BIO_new_socket ;
|
2013-10-10 11:03:17 -04:00
|
|
|
|
2013-09-14 15:18:13 -04:00
|
|
|
[ 200 ] [ "https://www.google.se" http-get drop code>> ] unit-test
|
2013-10-10 11:03:17 -04:00
|
|
|
|
2014-04-18 12:46:12 -04:00
|
|
|
: remote ( url -- remote )
|
|
|
|
url-addr addrspec>> resolve-host first ;
|
|
|
|
|
|
|
|
! These tests break if any of the sites change their certs or go
|
|
|
|
! down. But that should never ever happen. :)
|
2013-10-10 11:03:17 -04:00
|
|
|
[ "www.google.com" ] [
|
2014-04-18 12:46:12 -04:00
|
|
|
new-ssl dup URL" https://www.google.com" remote
|
|
|
|
ssl-socket-connect dup SSL_set_bio
|
|
|
|
dup do-ssl-connect-once f assert=
|
|
|
|
SSL_get_peer_certificate subject-name
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "*.facebook.com" ] [
|
|
|
|
new-ssl dup URL" https://www.facebook.com" remote
|
|
|
|
ssl-socket-connect dup SSL_set_bio
|
|
|
|
dup do-ssl-connect-once f assert=
|
|
|
|
SSL_get_peer_certificate subject-name
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "github.com" ] [
|
|
|
|
new-ssl dup URL" https://www.github.com" remote
|
|
|
|
ssl-socket-connect dup SSL_set_bio
|
|
|
|
dup do-ssl-connect-once f assert=
|
|
|
|
SSL_get_peer_certificate subject-name
|
2013-10-10 11:03:17 -04:00
|
|
|
] unit-test
|
2013-10-10 12:41:33 -04:00
|
|
|
|
2014-03-06 12:41:37 -05:00
|
|
|
[ t ] [
|
|
|
|
<http-server> 8887 >>insecure f >>secure [
|
|
|
|
[
|
|
|
|
"https://localhost:8887" http-get
|
|
|
|
] [ certificate-missing-error? ] recover
|
|
|
|
] with-threaded-server
|
2013-10-10 12:41:33 -04:00
|
|
|
] unit-test
|
2013-10-11 12:26:44 -04:00
|
|
|
|
2014-03-06 12:41:37 -05:00
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
"test" 33 <ssl-handle> handle>> check-subject-name
|
|
|
|
] [ certificate-missing-error? ] recover
|
2013-10-11 12:26:44 -04:00
|
|
|
] unit-test
|