From: Pierre Chopin <pierrchp@free.fr>
To: caml-list@inria.fr
Subject: [Caml-list] ocaml-ssl
Date: Thu, 24 Feb 2011 14:11:40 -0500 [thread overview]
Message-ID: <72F1256E-1783-45EC-8A18-EA286B290E51@free.fr> (raw)
Hi,
I am trying to get familiar with the ocaml-ssl bindings for Opensll.
Thus, I am trying to establish an SSL connection between a server and a client which are on my computer.
I therefore create two sockets, establish a tcp connection between then, and then fail to establish SSL communication.
The function Ssl.accept on the server will return Accept_error Error_want_read, which I believe is due to the fact that somehow the socket is used in non-blocking mode.
I therefore made a loop to constantly check for accepting connection. I am not familiar with non blocking mode so I don't know if it is right. Here is the code for the server.
(*
#directory "/opt/local/lib/ocaml/site-lib/ssl/";;
#load "ssl.cma" ;;
#load "unix.cma"
*)
open Ssl ;;
open Unix;;
init () ;;
let domain = PF_INET ;;
let ty = SOCK_STREAM ;;
let usock = socket domain ty 0;;
let name =Unix.gethostname () ;;
let h = Unix.gethostbyname name ;;
let inet = h.h_addr_list.(0) ;;
let cont = create_context SSLv3 Server_context ;;
let sock_addr = Unix.ADDR_INET (inet,22211) ;;
bind usock sock_addr ;;
listen usock 3 ;;
accept usock ;;
print_string "TCP connection established\n" ;;
Pervasives.flush Pervasives.stdout ;;
let sock = embed_socket usock cont ;;
while true do
try
Ssl.accept sock ;;
print_endline "bing" ;
Pervasives.flush Pervasives.stdout
with Ssl.Accept_error Error_want_read ->
sleep 1;
print_endline "looping" ;Pervasives.flush Pervasives.stdout
done;
Concerning the client, it's pretty much a mirror of the server, except for the loop:
#directory "/opt/local/lib/ocaml/site-lib/ssl/";;
#load "/opt/local/lib/ocaml/site-lib/ssl/ssl.cma" ;;
#load "unix.cma"
open Ssl ;;
open Unix;;
init () ;;
let domain = PF_INET ;;
let ty = SOCK_STREAM ;;
let usock = socket domain ty 0;;
let name =Unix.gethostname () ;;
let h = Unix.gethostbyname name ;;
let inet = h.h_addr_list.(0) ;;
let cont = create_context SSLv3 Client_context ;;
let sock_addr = Unix.ADDR_INET (inet,22211) ;;
connect usock sock_addr;;
let sock =embed_socket usock cont ;;
let usock2 = file_descr_of_socket sock ;;
Ssl.connect sock ;;
That last function never returns, and the server keeps "looping", until i kill the process. Any idea why?
Sincerly, Pierre
next reply other threads:[~2011-02-24 19:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-24 19:11 Pierre Chopin [this message]
2011-02-25 21:29 ` Tom Wilkie
2011-02-27 20:48 ` Gregory Bellier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=72F1256E-1783-45EC-8A18-EA286B290E51@free.fr \
--to=pierrchp@free.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox