caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocaml-ssl
@ 2011-02-24 19:11 Pierre Chopin
  2011-02-25 21:29 ` Tom Wilkie
  2011-02-27 20:48 ` Gregory Bellier
  0 siblings, 2 replies; 3+ messages in thread
From: Pierre Chopin @ 2011-02-24 19:11 UTC (permalink / raw)
  To: caml-list

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-27 20:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-24 19:11 [Caml-list] ocaml-ssl Pierre Chopin
2011-02-25 21:29 ` Tom Wilkie
2011-02-27 20:48 ` Gregory Bellier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).