12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758(*
* Copyright (c) 2014 Hannes Mehnert <hannes@mehnert.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*)openLwt.Infixlet_=Nocrypto_entropy_lwt.initialize()moduleClient=structletconnect?srchostsa=Conduit_lwt_server.with_socketsa(funfd->(matchsrcwith|None->Lwt.return_unit|Somesrc_sa->Lwt_unix.bindfdsrc_sa)>>=fun()->X509_lwt.authenticator`No_authentication_I'M_STUPID>>=funauthenticator->letconfig=Tls.Config.client~authenticator()inLwt_unix.connectfdsa>>=fun()->Tls_lwt.Unix.client_of_fdconfig~hostfd>|=funt->letic,oc=Tls_lwt.of_ttin(fd,ic,oc))endmoduleServer=structletinit'?backlog?stop?timeouttlssacallback=sa|>Conduit_lwt_server.listen?backlog>>=Conduit_lwt_server.init?stop(fun(fd,_)->Lwt.try_bind(fun()->Tls_lwt.Unix.server_of_fdtlsfd)(funt->let(ic,oc)=Tls_lwt.of_ttinLwt.return(fd,ic,oc))(funexn->Lwt_unix.closefd>>=fun()->Lwt.failexn)>>=Conduit_lwt_server.process_accept?timeoutcallback)letinit?backlog~certfile~keyfile?stop?timeoutsacallback=X509_lwt.private_of_pems~cert:certfile~priv_key:keyfile>>=funcertificate->letconfig=Tls.Config.server~certificates:(`Singlecertificate)()ininit'?backlog?stop?timeoutconfigsacallbackendletavailable=true