1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
source [file dirname [info script]]/testing.tcl
needs constraint jim
needs cmd socket
needs cmd os.fork
needs cmd load_ssl_certs
# Note that we don't actually need to load certificates with load_ssl_certs
# since the openssl installation should generally automatically load
# root certs
# Let's set up a client and a server where the client
# simply echos everything back to the server
set s [socket stream.server 127.0.0.1:1443]
if {[os.fork] == 0} {
# child
set c [[socket stream 127.0.0.1:1443] ssl]
$s close
$c ndelay 1
sleep 0.25
$c readable {
# read everything available and echo it back
set buf [$c read]
$c puts -nonewline $buf
$c flush
if {[$c eof]} {
incr ssldone
$c close
}
}
vwait ssldone
exit 99
}
# Now set up the server
set certpath [file dirname [info script]]
set cs [[$s accept addr] ssl -server $certpath/certificate.pem $certpath/key.pem]
$s close
defer {
$cs close
}
# At this point, $cs is the server connection to the client in the child process
$cs buffering line
test ssl-1.1 {puts/gets} {
$cs puts hello
$cs gets
} hello
test ssl-1.2 {puts/gets} {
$cs puts -nonewline again
$cs flush
lmap p [range 5] {
set c [$cs read 1]
set c
}
} {a g a i n}
testreport
|