45 lines
1.3 KiB
Scheme
45 lines
1.3 KiB
Scheme
(import (scheme base)
|
|
(scheme write)
|
|
(retropikzel tap)
|
|
(retropikzel tls)
|
|
(chibi crypto rsa)
|
|
(srfi 64)
|
|
(srfi 106))
|
|
|
|
;; tcpbin.com is an TCP echo server service
|
|
;;
|
|
;; - TCP echo server (port 4242)
|
|
;; - TCP echo server with TLS support (port 4243)
|
|
;; - TCP echo server with client authentication or mTLS (port 4244)
|
|
|
|
(test-runner-current (tap-runner))
|
|
|
|
(test-begin "TLS")
|
|
|
|
(test-group
|
|
"Ensuring TCP Socket works without TLS..."
|
|
(let ((client-socket (make-client-socket "tcpbin.com" "4242"))
|
|
(msg "Hello world!\n"))
|
|
(socket-send client-socket (string->utf8 msg))
|
|
(let ((response (utf8->string (socket-recv client-socket (string-length msg)))))
|
|
(test-assert (string=? response msg))
|
|
(when (not (string=? response msg))
|
|
(error "Stopping tests, TCP socket does not work even without TLS"
|
|
response)
|
|
(exit 1)))))
|
|
|
|
|
|
(let* ((client-socket (make-client-socket "tcpbin.com" "4243"))
|
|
(tls-connection
|
|
(tls-client-handshake (lambda (bytes)
|
|
(socket-send client-socket bytes))
|
|
(lambda (count)
|
|
(socket-recv client-socket count)))))
|
|
(display "HERE: ")
|
|
(write tls-connection)
|
|
(newline))
|
|
|
|
|
|
(test-end "TLS")
|
|
|