1 ! Copyright (C) 2007 Elie CHAFTARI
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Tested with OpenSSL 0.9.8a_0 on Mac OS X 10.4.9 PowerPC
6 ! export LD_LIBRARY_PATH=/opt/local/lib
8 USING: alien alien.syntax combinators kernel system ;
13 { [ win32? ] [ "ssleay32.dll" "stdcall" ] }
14 { [ macosx? ] [ "libssl.dylib" "cdecl" ] }
15 { [ unix? ] [ "$LD_LIBRARY_PATH/libssl.so" "cdecl" ] }
18 : X509_FILETYPE_PEM 1 ; inline
19 : X509_FILETYPE_ASN1 2 ; inline
20 : X509_FILETYPE_DEFAULT 3 ; inline
22 : SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 ; inline
23 : SSL_FILETYPE_PEM X509_FILETYPE_PEM ; inline
25 : SSL_CTRL_NEED_TMP_RSA 1 ; inline
26 : SSL_CTRL_SET_TMP_RSA 2 ; inline
27 : SSL_CTRL_SET_TMP_DH 3 ; inline
28 : SSL_CTRL_SET_TMP_RSA_CB 4 ; inline
29 : SSL_CTRL_SET_TMP_DH_CB 5 ; inline
31 : SSL_ERROR_NONE 0 ; inline
32 : SSL_ERROR_SSL 1 ; inline
33 : SSL_ERROR_WANT_READ 2 ; inline
34 : SSL_ERROR_WANT_WRITE 3 ; inline
35 : SSL_ERROR_WANT_X509_LOOKUP 4 ; inline
36 : SSL_ERROR_SYSCALL 5 ; inline ! consult errno for details
37 : SSL_ERROR_ZERO_RETURN 6 ; inline
38 : SSL_ERROR_WANT_CONNECT 7 ; inline
39 : SSL_ERROR_WANT_ACCEPT 8 ; inline
41 ! Error messages table
42 : error-messages ( -- hash )
44 { 0 "SSL_ERROR_NONE" }
46 { 2 "SSL_ERROR_WANT_READ" }
47 { 3 "SSL_ERROR_WANT_WRITE" }
48 { 4 "SSL_ERROR_WANT_X509_LOOKUP" }
49 { 5 "SSL_ERROR_SYSCALL" }
50 { 6 "SSL_ERROR_ZERO_RETURN" }
51 { 7 "SSL_ERROR_WANT_CONNECT" }
52 { 8 "SSL_ERROR_WANT_ACCEPT" }
55 TYPEDEF: void* ssl-method
56 TYPEDEF: void* ssl-ctx
57 TYPEDEF: void* ssl-pointer
61 ! ===============================================
63 ! ===============================================
65 FUNCTION: char* SSL_get_version ( ssl-pointer ssl ) ;
67 ! Maps OpenSSL errors to strings
68 FUNCTION: void SSL_load_error_strings ( ) ;
70 ! Must be called before any other action takes place
71 FUNCTION: int SSL_library_init ( ) ;
73 ! Sets the default SSL version
74 FUNCTION: ssl-method SSLv2_client_method ( ) ;
76 FUNCTION: ssl-method SSLv23_client_method ( ) ;
78 FUNCTION: ssl-method SSLv23_server_method ( ) ;
80 FUNCTION: ssl-method SSLv23_method ( ) ; ! SSLv3 but can rollback to v2
82 FUNCTION: ssl-method SSLv3_client_method ( ) ;
84 FUNCTION: ssl-method SSLv3_server_method ( ) ;
86 FUNCTION: ssl-method SSLv3_method ( ) ;
88 FUNCTION: ssl-method TLSv1_client_method ( ) ;
90 FUNCTION: ssl-method TLSv1_server_method ( ) ;
92 FUNCTION: ssl-method TLSv1_method ( ) ;
95 FUNCTION: ssl-ctx SSL_CTX_new ( ssl-method method ) ;
97 ! Load the certificates and private keys into the SSL_CTX
98 FUNCTION: int SSL_CTX_use_certificate_chain_file ( ssl-ctx ctx,
99 char* file ) ; ! PEM type
100 FUNCTION: ssl-pointer SSL_new ( ssl-ctx ctx ) ;
102 FUNCTION: int SSL_set_fd ( ssl-pointer ssl, int fd ) ;
104 FUNCTION: void SSL_set_bio ( ssl-pointer ssl, void* rbio, void* wbio ) ;
106 FUNCTION: int SSL_get_error ( ssl-pointer ssl, int ret ) ;
108 FUNCTION: void SSL_set_connect_state ( ssl-pointer ssl ) ;
110 FUNCTION: void SSL_set_accept_state ( ssl-pointer ssl ) ;
112 FUNCTION: int SSL_connect ( ssl-pointer ssl ) ;
114 FUNCTION: int SSL_accept ( ssl-pointer ssl ) ;
116 FUNCTION: int SSL_write ( ssl-pointer ssl, void* buf, int num ) ;
118 FUNCTION: int SSL_read ( ssl-pointer ssl, void* buf, int num ) ;
120 FUNCTION: void SSL_shutdown ( ssl-pointer ssl ) ;
122 FUNCTION: void SSL_free ( ssl-pointer ssl ) ;
124 FUNCTION: void SSL_CTX_free ( ssl-ctx ctx ) ;
126 FUNCTION: void RAND_seed ( void* buf, int num ) ;
128 FUNCTION: int SSL_set_cipher_list ( ssl-pointer ssl, char* str ) ;
130 FUNCTION: int SSL_use_RSAPrivateKey_file ( ssl-pointer ssl, char* str ) ;
132 FUNCTION: int SSL_CTX_use_RSAPrivateKey_file ( ssl-ctx ctx, int type ) ;
134 FUNCTION: int SSL_use_certificate_file ( ssl-pointer ssl,
135 char* str, int type ) ;
137 FUNCTION: int SSL_CTX_load_verify_locations ( ssl-ctx ctx, char* CAfile,
140 FUNCTION: void SSL_CTX_set_client_CA_list ( ssl-ctx ctx, ssl-pointer list ) ;
142 FUNCTION: ssl-pointer SSL_load_client_CA_file ( char* file ) ;
144 ! Used to manipulate settings of the SSL_CTX and SSL objects.
145 ! This function should never be called directly
146 FUNCTION: long SSL_CTX_ctrl ( ssl-ctx ctx, int cmd, long larg, void* parg ) ;
148 FUNCTION: void SSL_CTX_set_default_passwd_cb ( ssl-ctx ctx, void* cb ) ;
150 FUNCTION: void SSL_CTX_set_default_passwd_cb_userdata ( ssl-ctx ctx,
153 FUNCTION: int SSL_CTX_use_PrivateKey_file ( ssl-ctx ctx, char* file,
156 ! Sets the maximum depth for the allowed ctx certificate chain verification
157 FUNCTION: void SSL_CTX_set_verify_depth ( ssl-ctx ctx, int depth ) ;
159 ! Sets DH parameters to be used to be dh.
160 ! The key is inherited by all ssl objects created from ctx
161 FUNCTION: void SSL_CTX_set_tmp_dh_callback ( ssl-ctx ctx, void* dh ) ;
163 FUNCTION: void SSL_CTX_set_tmp_rsa_callback ( ssl-ctx ctx, void* rsa ) ;
165 FUNCTION: void* BIO_f_ssl ( ) ;
167 ! ===============================================
169 ! ===============================================
171 ! For a high level interface to message digests
172 ! use the EVP digest routines in libcrypto.factor
174 FUNCTION: uchar* SHA1 ( uchar* d, ulong n, uchar* md ) ;