factor/extra/io/sockets/secure/secure.factor

69 lines
1.6 KiB
Factor
Raw Normal View History

2008-05-11 18:44:14 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel symbols namespaces continuations
2008-05-17 18:45:56 -04:00
destructors io.sockets sequences inspector ;
2008-05-11 18:44:14 -04:00
IN: io.sockets.secure
2008-05-17 18:45:56 -04:00
SYMBOL: secure-socket-backend
2008-05-11 18:44:14 -04:00
SINGLETONS: SSLv2 SSLv23 SSLv3 TLSv1 ;
2008-05-17 18:45:56 -04:00
TUPLE: secure-config
method
key-file password
ca-file ca-path
dh-file
ephemeral-key-bits ;
2008-05-11 18:44:14 -04:00
2008-05-17 18:45:56 -04:00
: <secure-config> ( -- config )
secure-config new
SSLv23 >>method
512 >>ephemeral-key-bits ;
2008-05-11 18:44:14 -04:00
2008-05-17 18:45:56 -04:00
TUPLE: secure-context config handle disposed ;
2008-05-11 18:44:14 -04:00
2008-05-17 18:45:56 -04:00
HOOK: <secure-context> secure-socket-backend ( config -- context )
2008-05-11 18:44:14 -04:00
2008-05-17 18:45:56 -04:00
: with-secure-context ( config quot -- )
2008-05-11 18:44:14 -04:00
[
2008-05-17 18:45:56 -04:00
[ <secure-context> ] [ [ secure-context set ] prepose ] bi*
2008-05-11 18:44:14 -04:00
with-disposal
] with-scope ; inline
2008-05-17 18:45:56 -04:00
TUPLE: secure addrspec ;
2008-05-17 18:45:56 -04:00
C: <secure> secure
: resolve-secure-host ( host port passive? -- seq )
resolve-host [ <secure> ] map ;
HOOK: check-certificate secure-socket-backend ( host handle -- )
<PRIVATE
2008-05-17 18:45:56 -04:00
PREDICATE: secure-inet < secure addrspec>> inet? ;
2008-05-17 18:45:56 -04:00
M: secure-inet (client)
[
addrspec>>
[ [ host>> ] [ port>> ] bi f resolve-secure-host (client) >r |dispose r> ] keep
host>> pick handle>> check-certificate
] with-destructors ;
PRIVATE>
2008-05-17 18:45:56 -04:00
ERROR: premature-close ;
M: premature-close summary
drop "Connection closed prematurely - potential truncation attack" ;
ERROR: certificate-verify-error result ;
M: certificate-verify-error summary
drop "Certificate verification failed" ;
ERROR: common-name-verify-error expected got ;
M: common-name-verify-error summary
drop "Common name verification failed" ;