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("gemini.circumlunar.space") !"rainbow-100.com") if(allocated(hent%h_name)) then Print *, "host: ", hent%h_name 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 sa%sin_port = htons(1965) !443) s = socket(AF_INET, SOCK_STREAM, 0); if(.not. connect(s, sa)) then Print *, "Connection failed", IERRNO() stop end if 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