123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143openCoreopenAsyncopenPrivate_ssl.V2type_addr=|OpenSSL:Socket.Address.Inet.t*Ssl.Config.t->Socket.Address.Inet.taddr|Inet:Socket.Address.Inet.t->Socket.Address.Inet.taddr|Unix:Socket.Address.Unix.t->Socket.Address.Unix.taddr[@@derivingsexp_of]type_tcp_sock=|Inet_sock:([`Active],Socket.Address.Inet.t)Socket.t->Socket.Address.Inet.ttcp_sock|Unix_sock:([`Active],Socket.Address.Unix.t)Socket.t->Socket.Address.Unix.ttcp_sockletssl_schemes=["https";"wss"]letmem_schemes=List.memssl_schemes~equal:String.equalsletresolve_uri?(options=[])uri=lethost=Option.value_exn~here:[%here]~message:"no host in URL"(Uri.hosturi)inletservice=match(Uri.porturi,Uri_services.tcp_port_of_uriuri)with|Somep,_->Some(string_of_intp)|None,Somep->Some(string_of_intp)|_->Nonein(* Async_extra does not yet support IPv6 *)letoptions=Unix.Addr_info.AI_FAMILYPF_INET::optionsinUnix.Addr_info.get~host?serviceoptions>>=function|[]->failwithf"unable to resolve %s"(Uri.to_stringuri)()|{ai_addr;_}::_->(match(Uri.schemeuri,ai_addr)with|_,ADDR_UNIX_->invalid_arg"uri must resolve to inet address"|Somes,ADDR_INET(h,p)whenmem_schemes->return(OpenSSL(`Inet(h,p),Ssl.Config.create()))|_,ADDR_INET(h,p)->return(Inet(`Inet(h,p))))letconnect(typea)?interrupt(addr:aaddr):(atcp_sock*Reader.t*Writer.t)Deferred.t=matchaddrwith|Inetaddr->Tcp.connect?interrupt(Tcp.Where_to_connect.of_inet_addressaddr)>>|fun(s,r,w)->(Inet_socks,r,w)|OpenSSL(addr,cfg)->Tcp.connect?interrupt(Tcp.Where_to_connect.of_inet_addressaddr)>>=fun(s,rd,wr)->Ssl.connect~cfgrdwr>>|fun(rd,wr)->(Inet_socks,rd,wr)|Unixaddr->Tcp.connect?interrupt(Tcp.Where_to_connect.of_unix_addressaddr)>>|fun(s,r,w)->(Unix_socks,r,w)letwith_connection(typea)?interrupt(addr:aaddr)(f:atcp_sock->Reader.t->Writer.t->'aDeferred.t)=matchaddrwith|Inetaddr->Tcp.with_connection?interrupt(Tcp.Where_to_connect.of_inet_addressaddr)(funsrdwr->f(Inet_socks)rdwr)|OpenSSL(addr,cfg)->Tcp.with_connection?interrupt(Tcp.Where_to_connect.of_inet_addressaddr)(funsrdwr->Ssl.connect~cfgrdwr>>=fun(rd,wr)->Monitor.protect(fun()->f(Inet_socks)rdwr)~finally:(fun()->Deferred.all_unit[Reader.closerd;Writer.closewr]))|Unixaddr->Tcp.with_connection?interrupt(Tcp.Where_to_connect.of_unix_addressaddr)(funsrdwr->f(Unix_socks)rdwr)letconnect_uri?options?interrupturi=resolve_uri?optionsuri>>=funaddr->connect?interruptaddrletwith_connection_uri?options?interrupturif=resolve_uri?optionsuri>>=funaddr->with_connection?interruptaddrftypetrust_chain=[`Ca_fileofstring|`Ca_pathofstring|`Search_file_first_then_pathof[`Fileofstring]*[`Pathofstring]][@@derivingsexp]typeopenssl=[`OpenSSLof[`Crt_file_pathofstring]*[`Key_file_pathofstring]][@@derivingsexp]typerequires_async_ssl=[openssl|`OpenSSL_with_trust_chainofopenssl*trust_chain][@@derivingsexp]typeserver=[`TCP|requires_async_ssl][@@derivingsexp]letserve?max_connections?backlog?buffer_age_limit~on_handler_errormodewhere_to_listenhandle_request=lethandle_clienthandle_requestsockrdwr=matchmodewith|`TCP->handle_requestsockrdwr|#requires_async_sslasasync_ssl->letcrt_file,key_file,ca_file,ca_path=matchasync_sslwith|`OpenSSL(`Crt_file_pathcrt_file,`Key_file_pathkey_file)->(crt_file,key_file,None,None)|`OpenSSL_with_trust_chain(`OpenSSL(`Crt_file_pathcrt,`Key_file_pathkey),trust_chain)->letca_file,ca_path=matchtrust_chainwith|`Ca_fileca_file->(Someca_file,None)|`Ca_pathca_path->(None,Someca_path)|`Search_file_first_then_path(`Fileca_file,`Pathca_path)->(Someca_file,Someca_path)in(crt,key,ca_file,ca_path)inletcfg=Ssl.Config.create?ca_file?ca_path~crt_file~key_file()inSsl.listencfgrdwr>>=fun(rd,wr)->Monitor.protect(fun()->handle_requestsockrdwr)~finally:(fun()->Deferred.all_unit[Reader.closerd;Writer.closewr])inTcp.Server.create?max_connections?backlog?buffer_age_limit~on_handler_errorwhere_to_listen(handle_clienthandle_request)typessl_version=Ssl.version[@@derivingsexp]typessl_opt=Ssl.opt[@@derivingsexp]typessl_conn=Ssl.connection[@@derivingsexp_of]typeallowed_ciphers=[`Onlyofstringlist|`Openssl_default|`Secure][@@derivingsexp]typeverify_mode=Ssl.verify_mode[@@derivingsexp_of]typesession=Ssl.session[@@derivingsexp_of]moduleSsl=structmoduleConfig=Ssl.Configend