| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | USING: alien alien.c-types assocs bit-arrays hashtables io io.files | 
					
						
							|  |  |  | io.sockets kernel mirrors openssl.libcrypto openssl.libssl | 
					
						
							| 
									
										
										
										
											2008-02-06 20:23:39 -05:00
										 |  |  | namespaces math math.parser openssl prettyprint sequences tools.test ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Some crypto functions (still to be turned into words) | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     B{ 201 238 222 100 92 200 182 188 138 255 129 163 115 88 240 136 } | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | [ "Hello world from the openssl binding" >md5 ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     B{ 63 113 237 255 181 5 152 241 136 181 43 95 160 105 44 87 49
 | 
					
						
							|  |  |  |     82 115 0 } | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | [ "Hello world from the openssl binding" >sha1 ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Initialize context | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ init load-error-strings ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ ssl-v23 new-ctx ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx "/extra/openssl/test/server.pem" resource-path use-cert-chain ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! TODO: debug 'Memory protection fault at address 6c' | 
					
						
							|  |  |  | ! get-ctx 1024 "char" malloc-array 1024 0 f password-cb set-default-passwd | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx "password" string>char-alien set-default-passwd-userdata ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Enter PEM pass phrase: password | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx "/extra/openssl/test/server.pem" resource-path | 
					
						
							|  |  |  | SSL_FILETYPE_PEM use-private-key ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx "/extra/openssl/test/root.pem" resource-path f
 | 
					
						
							|  |  |  | verify-load-locations ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx 1 set-verify-depth ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Load Diffie-Hellman parameters | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ "/extra/openssl/test/dh1024.pem" resource-path "r" bio-new-file ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-bio f f f read-pem-dh-params ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-bio bio-free ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! TODO: debug SSL_CTX_set_tmp_dh 'No such symbol' | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx get-dh set-tmp-dh-callback ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Workaround (this function should never be called directly) | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | ! [ ] [ get-ctx SSL_CTRL_SET_TMP_DH 0 get-dh set-ctx-ctrl ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Generate ephemeral RSA key | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ 512 RSA_F4 f f generate-rsa-key ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! TODO: debug SSL_CTX_set_tmp_rsa 'No such symbol' | 
					
						
							|  |  |  | ! get-ctx get-rsa set-tmp-rsa-callback | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Workaround (this function should never be called directly) | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-ctx SSL_CTRL_SET_TMP_RSA 0 get-rsa set-ctx-ctrl ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-rsa free-rsa ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Listen and accept on socket | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! SYMBOL: sock | 
					
						
							|  |  |  | ! SYMBOL: fdset | 
					
						
							|  |  |  | ! SYMBOL: acset | 
					
						
							|  |  |  | ! SYMBOL: sbio | 
					
						
							|  |  |  | ! SYMBOL: ssl | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! : is-set ( seq -- newseq ) | 
					
						
							|  |  |  | !     <enum> >alist [ nip ] assoc-subset >hashtable keys ; | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! ! 1234 server-socket sock set | 
					
						
							|  |  |  | ! "127.0.0.1" 1234 <inet4> SOCK_STREAM server-fd sock set | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! FD_SETSIZE 8 * <bit-array> fdset set | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! FD_SETSIZE 8 * <bit-array> t 8 rot [ set-nth ] keep fdset set | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! fdset get is-set . | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! : loop ( -- ) | 
					
						
							|  |  |  | !     sock get f f accept | 
					
						
							|  |  |  | !     dup -1 = [ drop ] [ | 
					
						
							|  |  |  | !         dup number>string print flush | 
					
						
							|  |  |  | !         ! BIO_NOCLOSE bio-new-socket sbio set | 
					
						
							|  |  |  | !         [ get-ctx new-ssl ssl set ] keep | 
					
						
							|  |  |  | !         ssl get swap set-ssl-fd | 
					
						
							|  |  |  | !         ! ssl get sbio get dup set-ssl-bio | 
					
						
							|  |  |  | !         ! ssl get ssl-accept | 
					
						
							|  |  |  | !         ! dup 0 <= [  | 
					
						
							|  |  |  | !         !     ssl get swap ssl-get-error  | 
					
						
							|  |  |  | !         ! ] [ drop ] if | 
					
						
							|  |  |  | !     ] if | 
					
						
							|  |  |  | !     loop ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! { } acset set | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! : loop ( -- ) | 
					
						
							|  |  |  | !     ! FD_SETSIZE fdset get f f f select . flush | 
					
						
							|  |  |  | !     FD_SETSIZE fdset get f f 10000 make-timeval select  | 
					
						
							|  |  |  | !     0 <= [ acset get [ close ] each "timeout" print ] [ | 
					
						
							|  |  |  | !         fdset get is-set sock get swap member? [  | 
					
						
							|  |  |  | !              sock get f f accept dup . flush  | 
					
						
							|  |  |  | !              acset get swap add acset set | 
					
						
							|  |  |  | !     ] [ ] if | 
					
						
							|  |  |  | !         loop | 
					
						
							|  |  |  | !     ] if ; | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! loop | 
					
						
							|  |  |  | ! 
 | 
					
						
							|  |  |  | ! sock get close | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Dump errors to file | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ "/extra/openssl/test/errors.txt" resource-path "w" bio-new-file ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ 6 ] [ get-bio "Hello\n" bio-print ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ ] [ get-bio bio-free ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | ! Clean-up | 
					
						
							|  |  |  | ! ========================================================= | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! sock get close | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | get-ctx destroy-ctx |