aboutsummaryrefslogtreecommitdiff
path: root/test_ssl.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-01 11:21:05 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-01 11:21:05 -0400
commitc7a908cc5adede6ca34519059f2e324dc6737ff6 (patch)
tree98a32e703bac397e37c38d1fdbfa16123e2d46af /test_ssl.f90
parent690395a50cd55401a9cfee598638bef482d164bd (diff)
downloadLR-87-c7a908cc5adede6ca34519059f2e324dc6737ff6.tar.gz
LR-87-c7a908cc5adede6ca34519059f2e324dc6737ff6.zip
SSL network connections now seem to work, including on windows
Diffstat (limited to 'test_ssl.f90')
-rw-r--r--test_ssl.f9060
1 files changed, 56 insertions, 4 deletions
diff --git a/test_ssl.f90 b/test_ssl.f90
index 04386d4..9c22895 100644
--- a/test_ssl.f90
+++ b/test_ssl.f90
@@ -1,28 +1,44 @@
program test_ssl
+use iso_c_binding
use jessl
use network
+use request
use wsa_network, only: windows_network_startup => startup
implicit none
type(sockaddr_in), target::sa
integer::s
+ character(*), parameter:: request_attempt = &
+ "gemini://gemini.circumlinar.space/"//C_CARRIAGE_RETURN//C_NEW_LINE
+
+ !"GET / HTTP/1.1"//C_CARRIAGE_RETURN//C_NEW_LINE&
+ !//"Host: rainbow-100.com"//C_CARRIAGE_RETURN//C_NEW_LINE&
+ !//C_CARRIAGE_RETURN//C_NEW_LINE
+
type(simple_hostent)::hent
+ type(c_ptr)::ssl_method, ssl_ctx, ssl
+
+ character, dimension(bufsize)::buffer
+ integer::bytes_received, i
+
call windows_network_startup()
- hent = gethostbyname("google.com")
+ hent = gethostbyname("gemini.circumlunar.space")
+ !"rainbow-100.com")
+
if(allocated(hent%h_name)) then
Print *, "host: ", hent%h_name
- Print *, "addr: ", hent%h_addr4
+ Print *, "addr: ", inet_ntoa(hent%h_addr4)
else
Print *, "Failure"
stop
end if
sa%sin_family = AF_INET
- sa%sin_addr%s_addr = hent%h_addr4 !inet_addr("192.168.2.90")
- sa%sin_port = htons(80)
+ sa%sin_addr%s_addr = hent%h_addr4
+ sa%sin_port = htons(1965) !443)
s = socket(AF_INET, SOCK_STREAM, 0);
if(.not. connect(s, sa)) then
@@ -32,5 +48,41 @@ implicit none
Print *, "socket opened!"
+ call library_init()
+ ssl_method = tls_v1_3_client_method()
+ ssl_ctx = ctx_new(ssl_method)
+ ssl = ssl_new(ssl_ctx)
+
+ if(set_fd(ssl, s) == 1) then
+ Print *, "FD set"
+ if(ssl_connect(ssl) == 1) then
+ Print *, "Connected via SSL"
+
+
+ if(send_string(ssl, request_attempt, trimming=.false.)) then
+ Print *, "Message sent"
+
+ bytes_received = retrieve_characters(ssl, buffer)
+ do while(bytes_received > 0)
+ do i=1, bytes_received
+ write(*, '(A1)', advance='no') buffer(i)
+ end do
+ bytes_received = retrieve_characters(ssl, buffer)
+ end do
+
+ Print *, " "
+ Print *, "DONE"
+ else
+ Print *, "Could not send request"
+ end if
+
+ else
+ Print *, "Did not complete the ssl handshake..."
+ end if
+ else
+ Print *, "No fd set"
+ end if
+
+ call close_socket(s)
end program test_ssl \ No newline at end of file