.TH ssl 3erl "ssl 8.1" "Ericsson AB" "Erlang Module Definition" .SH NAME ssl \- Interface Functions for Secure Socket Layer .SH DESCRIPTION .LP This module contains interface functions for the SSL/TLS protocol\&. For detailed information about the supported standards see \fBssl(7)\fR\&\&. .SH "DATA TYPES" .LP The following data types are used in the functions for SSL: .RS 2 .TP 2 .B \fIboolean() =\fR\&: \fItrue | false\fR\& .TP 2 .B \fIoption() =\fR\&: \fIsocketoption() | ssl_option() | transport_option()\fR\& .TP 2 .B \fIsocketoption() =\fR\&: \fIproplists:property()\fR\& .RS 2 .LP The default socket options are \fI[{mode,list},{packet, 0},{header, 0},{active, true}]\fR\&\&. .RE .RS 2 .LP For valid options, see the \fBinet(3erl)\fR\& and \fBgen_tcp(3erl)\fR\& manual pages in Kernel\&. .RE .TP 2 .B \fIssl_option() =\fR\&: \fI{verify, verify_type()}\fR\& .RS 2 .LP \fI| {verify_fun, {fun(), term()}}\fR\& .RE .RS 2 .LP \fI| {fail_if_no_peer_cert, boolean()}\fR\& .RE .RS 2 .LP \fI| {depth, integer()}\fR\& .RE .RS 2 .LP \fI| {cert, public_key:der_encoded()}\fR\& .RE .RS 2 .LP \fI| {certfile, path()}\fR\& .RE .RS 2 .LP \fI| {key, {\&'RSAPrivateKey\&'| \&'DSAPrivateKey\&' | \&'ECPrivateKey\&' | \&'PrivateKeyInfo\&', public_key:der_encoded()}}\fR\& .RE .RS 2 .LP \fI| {keyfile, path()}\fR\& .RE .RS 2 .LP \fI| {password, string()}\fR\& .RE .RS 2 .LP \fI| {cacerts, [public_key:der_encoded()]}\fR\& .RE .RS 2 .LP \fI| {cacertfile, path()}\fR\& .RE .RS 2 .LP \fI| {dh, public_key:der_encoded()}\fR\& .RE .RS 2 .LP \fI| {dhfile, path()}\fR\& .RE .RS 2 .LP \fI| {ciphers, ciphers()}\fR\& .RE .RS 2 .LP \fI| {user_lookup_fun, {fun(), term()}}, {psk_identity, string()}, {srp_identity, {string(), string()}}\fR\& .RE .RS 2 .LP \fI| {reuse_sessions, boolean()}\fR\& .RE .RS 2 .LP \fI| {reuse_session, fun()} {next_protocols_advertised, [binary()]}\fR\& .RE .RS 2 .LP \fI| {client_preferred_next_protocols, {client | server, [binary()]} | {client | server, [binary()], binary()}}\fR\& .RE .RS 2 .LP \fI| {log_alert, boolean()}\fR\& .RE .RS 2 .LP \fI| {server_name_indication, hostname() | disable}\fR\& .RE .RS 2 .LP \fI| {sni_hosts, [{hostname(), [ssl_option()]}]}\fR\& .RE .RS 2 .LP \fI| {sni_fun, SNIfun::fun()}\fR\& .RE .TP 2 .B \fItransport_option() =\fR\&: \fI{cb_info, {CallbackModule::atom(), DataTag::atom(), ClosedTag::atom(), ErrTag:atom()}}\fR\& .RS 2 .LP Defaults to \fI{gen_tcp, tcp, tcp_closed, tcp_error}\fR\&\&. Can be used to customize the transport layer\&. The callback module must implement a reliable transport protocol, behave as \fIgen_tcp\fR\&, and have functions corresponding to \fIinet:setopts/2\fR\&, \fIinet:getopts/2\fR\&, \fIinet:peername/1\fR\&, \fIinet:sockname/1\fR\&, and \fIinet:port/1\fR\&\&. The callback \fIgen_tcp\fR\& is treated specially and calls \fIinet\fR\& directly\&. .RE .RS 2 .TP 2 .B \fICallbackModule =\fR\&: \fIatom()\fR\& .TP 2 .B \fIDataTag =\fR\&: \fIatom()\fR\& .RS 2 .LP Used in socket data message\&. .RE .TP 2 .B \fIClosedTag =\fR\&: \fIatom()\fR\& .RS 2 .LP Used in socket close message\&. .RE .RE .TP 2 .B \fIverify_type() =\fR\&: \fIverify_none | verify_peer\fR\& .TP 2 .B \fIpath() =\fR\&: \fIstring()\fR\& .RS 2 .LP Represents a file path\&. .RE .TP 2 .B \fIpublic_key:der_encoded() =\fR\&: \fIbinary()\fR\& .RS 2 .LP ASN\&.1 DER-encoded entity as an Erlang binary\&. .RE .TP 2 .B \fIhost() =\fR\&: \fIhostname() | ipaddress()\fR\& .TP 2 .B \fIhostname() =\fR\&: \fIstring()\fR\& .TP 2 .B \fIip_address() =\fR\&: \fI{N1,N2,N3,N4} % IPv4 | {K1,K2,K3,K4,K5,K6,K7,K8} % IPv6 \fR\& .TP 2 .B \fIsslsocket() =\fR\&: opaque() .TP 2 .B \fIprotocol() =\fR\&: \fIsslv3 | tlsv1 | \&'tlsv1\&.1\&' | \&'tlsv1\&.2\&'\fR\& .TP 2 .B \fIciphers() =\fR\&: \fI= [ciphersuite()] | string()\fR\& .RS 2 .LP According to old API\&. .RE .TP 2 .B \fIciphersuite() =\fR\&: \fI{key_exchange(), cipher(), MAC::hash()} | {key_exchange(), cipher(), MAC::hash(), PRF::hash()}\fR\& .TP 2 .B \fIkey_exchange()=\fR\&: \fIrsa | dhe_dss | dhe_rsa | dh_anon | psk | dhe_psk | rsa_psk | srp_anon | srp_dss | srp_rsa | ecdh_anon | ecdh_ecdsa | ecdhe_ecdsa | ecdh_rsa | ecdhe_rsa\fR\& .TP 2 .B \fIcipher() =\fR\&: \fIrc4_128 | des_cbc | \&'3des_ede_cbc\&' | aes_128_cbc | aes_256_cbc | aes_128_gcm | aes_256_gcm | chacha20_poly1305\fR\& .TP 2 .B \fIhash() =\fR\&: \fImd5 | sha | sha224 | sha256 | sha348 | sha512\fR\& .TP 2 .B \fIprf_random() =\fR\&: \fIclient_random | server_random\fR\& .TP 2 .B \fIsrp_param_type() =\fR\&: \fIsrp_1024 | srp_1536 | srp_2048 | srp_3072 | srp_4096 | srp_6144 | srp_8192\fR\& .TP 2 .B \fISNIfun::fun()\fR\&: \fI= fun(ServerName :: string()) -> [ssl_option()]\fR\& .TP 2 .B \fInamed_curve() =\fR\&: \fIsect571r1 | sect571k1 | secp521r1 | brainpoolP512r1 | sect409k1 | sect409r1 | brainpoolP384r1 | secp384r1 | sect283k1 | sect283r1 | brainpoolP256r1 | secp256k1 | secp256r1 | sect239k1 | sect233k1 | sect233r1 | secp224k1 | secp224r1 | sect193r1 | sect193r2 | secp192k1 | secp192r1 | sect163k1 | sect163r1 | sect163r2 | secp160k1 | secp160r1 | secp160r2\fR\& .RE .SH "SSL OPTION DESCRIPTIONS - COMMON FOR SERVER AND CLIENT" .LP The following options have the same meaning in the client and the server: .RS 2 .TP 2 .B \fI{cert, public_key:der_encoded()}\fR\&: The DER-encoded users certificate\&. If this option is supplied, it overrides option \fIcertfile\fR\&\&. .TP 2 .B \fI{certfile, path()}\fR\&: Path to a file containing the user certificate\&. .TP 2 .B \fI{key, {\&'RSAPrivateKey\&'| \&'DSAPrivateKey\&' | \&'ECPrivateKey\&' |\&'PrivateKeyInfo\&', public_key:der_encoded()}}\fR\&: The DER-encoded user\&'s private key\&. If this option is supplied, it overrides option \fIkeyfile\fR\&\&. .TP 2 .B \fI{keyfile, path()}\fR\&: Path to the file containing the user\&'s private PEM-encoded key\&. As PEM-files can contain several entries, this option defaults to the same file as given by option \fIcertfile\fR\&\&. .TP 2 .B \fI{password, string()}\fR\&: String containing the user\&'s password\&. Only used if the private keyfile is password-protected\&. .TP 2 .B \fI{ciphers, ciphers()}\fR\&: Supported cipher suites\&. The function \fIcipher_suites/0\fR\& can be used to find all ciphers that are supported by default\&. \fIcipher_suites(all)\fR\& can be called to find all available cipher suites\&. Pre-Shared Key (RFC 4279 and RFC 5487), Secure Remote Password (RFC 5054), RC4 cipher suites, and anonymous cipher suites only work if explicitly enabled by this option; they are supported/enabled by the peer also\&. Anonymous cipher suites are supported for testing purposes only and are not be used when security matters\&. .TP 2 .B \fI{eccs, [named_curve()]}\fR\&: Allows to specify the order of preference for named curves and to restrict their usage when using a cipher suite supporting them\&. .TP 2 .B \fI{secure_renegotiate, boolean()}\fR\&: Specifies if to reject renegotiation attempt that does not live up to RFC 5746\&. By default \fIsecure_renegotiate\fR\& is set to \fIfalse\fR\&, that is, secure renegotiation is used if possible, but it falls back to insecure renegotiation if the peer does not support RFC 5746\&. .TP 2 .B \fI{depth, integer()}\fR\&: Maximum number of non-self-issued intermediate certificates that can follow the peer certificate in a valid certification path\&. So, if depth is 0 the PEER must be signed by the trusted ROOT-CA directly; if 1 the path can be PEER, CA, ROOT-CA; if 2 the path can be PEER, CA, CA, ROOT-CA, and so on\&. The default value is 1\&. .TP 2 .B \fI{verify_fun, {Verifyfun :: fun(), InitialUserState :: term()}}\fR\&: The verification fun is to be defined as follows: .LP .nf fun(OtpCert :: #'OTPCertificate'{}, Event :: {bad_cert, Reason :: atom() | {revoked, atom()}} | {extension, #'Extension'{}}, InitialUserState :: term()) -> {valid, UserState :: term()} | {valid_peer, UserState :: term()} | {fail, Reason :: term()} | {unknown, UserState :: term()}. .fi .RS 2 .LP The verification fun is called during the X509-path validation when an error or an extension unknown to the SSL application is encountered\&. It is also called when a certificate is considered valid by the path validation to allow access to each certificate in the path to the user application\&. It differentiates between the peer certificate and the CA certificates by using \fIvalid_peer\fR\& or \fIvalid\fR\& as second argument to the verification fun\&. See the \fBpublic_key User\&'s Guide\fR\& for definition of \fI#\&'OTPCertificate\&'{}\fR\& and \fI#\&'Extension\&'{}\fR\&\&. .RE .RS 2 .TP 2 * If the verify callback fun returns \fI{fail, Reason}\fR\&, the verification process is immediately stopped, an alert is sent to the peer, and the TLS/SSL handshake terminates\&. .LP .TP 2 * If the verify callback fun returns \fI{valid, UserState}\fR\&, the verification process continues\&. .LP .TP 2 * If the verify callback fun always returns \fI{valid, UserState}\fR\&, the TLS/SSL handshake does not terminate regarding verification failures and the connection is established\&. .LP .TP 2 * If called with an extension unknown to the user application, return value \fI{unknown, UserState}\fR\& is to be used\&. .RS 2 .LP Note that if the fun returns \fIunknown\fR\& for an extension marked as critical, validation will fail\&. .RE .LP .RE .RS 2 .LP Default option \fIverify_fun\fR\& in \fIverify_peer mode\fR\&: .RE .LP .nf {fun(_,{bad_cert, _} = Reason, _) -> {fail, Reason}; (_,{extension, _}, UserState) -> {unknown, UserState}; (_, valid, UserState) -> {valid, UserState}; (_, valid_peer, UserState) -> {valid, UserState} end, []} .fi .RS 2 .LP Default option \fIverify_fun\fR\& in mode \fIverify_none\fR\&: .RE .LP .nf {fun(_,{bad_cert, _}, UserState) -> {valid, UserState}; (_,{extension, #'Extension'{critical = true}}, UserState) -> {valid, UserState}; (_,{extension, _}, UserState) -> {unknown, UserState}; (_, valid, UserState) -> {valid, UserState}; (_, valid_peer, UserState) -> {valid, UserState} end, []} .fi .RS 2 .LP The possible path validation errors are given on form \fI{bad_cert, Reason}\fR\& where \fIReason\fR\& is: .RE .RS 2 .TP 2 .B \fIunknown_ca\fR\&: No trusted CA was found in the trusted store\&. The trusted CA is normally a so called ROOT CA, which is a self-signed certificate\&. Trust can be claimed for an intermediate CA (trusted anchor does not have to be self-signed according to X-509) by using option \fIpartial_chain\fR\&\&. .TP 2 .B \fIselfsigned_peer\fR\&: The chain consisted only of one self-signed certificate\&. .TP 2 .B \fIPKIX X-509-path validation error\fR\&: For possible reasons, see \fBpublic_key:pkix_path_validation/3\fR\& .RE .TP 2 .B \fI{crl_check, boolean() | peer | best_effort }\fR\&: Perform CRL (Certificate Revocation List) verification \fB (public_key:pkix_crls_validate/3)\fR\& on all the certificates during the path validation \fB(public_key:pkix_path_validation/3) \fR\& of the certificate chain\&. Defaults to \fIfalse\fR\&\&. .RS 2 .TP 2 .B \fIpeer\fR\&: check is only performed on the peer certificate\&. .TP 2 .B \fIbest_effort\fR\&: if certificate revocation status can not be determined it will be accepted as valid\&. .RE .RS 2 .LP The CA certificates specified for the connection will be used to construct the certificate chain validating the CRLs\&. .RE .RS 2 .LP The CRLs will be fetched from a local or external cache\&. See \fBssl_crl_cache_api(3erl)\fR\&\&. .RE .TP 2 .B \fI{crl_cache, {Module :: atom(), {DbHandle :: internal | term(), Args :: list()}}}\fR\&: Specify how to perform lookup and caching of certificate revocation lists\&. \fIModule\fR\& defaults to \fBssl_crl_cache\fR\& with \fI DbHandle \fR\& being \fIinternal\fR\& and an empty argument list\&. .RS 2 .LP There are two implementations available: .RE .RS 2 .TP 2 .B \fIssl_crl_cache\fR\&: This module maintains a cache of CRLs\&. CRLs can be added to the cache using the function \fBssl_crl_cache:insert/1\fR\&, and optionally automatically fetched through HTTP if the following argument is specified: .RS 2 .TP 2 .B \fI{http, timeout()}\fR\&: Enables fetching of CRLs specified as http URIs in\fBX509 certificate extensions\fR\&\&. Requires the OTP inets application\&. .RE .TP 2 .B \fIssl_crl_hash_dir\fR\&: This module makes use of a directory where CRLs are stored in files named by the hash of the issuer name\&. .RS 2 .LP The file names consist of eight hexadecimal digits followed by \fI\&.rN\fR\&, where \fIN\fR\& is an integer, e\&.g\&. \fI1a2b3c4d\&.r0\fR\&\&. For the first version of the CRL, \fIN\fR\& starts at zero, and for each new version, \fIN\fR\& is incremented by one\&. The OpenSSL utility \fIc_rehash\fR\& creates symlinks according to this pattern\&. .RE .RS 2 .LP For a given hash value, this module finds all consecutive \fI\&.r*\fR\& files starting from zero, and those files taken together make up the revocation list\&. CRL files whose \fInextUpdate\fR\& fields are in the past, or that are issued by a different CA that happens to have the same name hash, are excluded\&. .RE .RS 2 .LP The following argument is required: .RE .RS 2 .TP 2 .B \fI{dir, string()}\fR\&: Specifies the directory in which the CRLs can be found\&. .RE .RE .TP 2 .B \fI{partial_chain, fun(Chain::[DerCert]) -> {trusted_ca, DerCert} | unknown_ca }\fR\&: Claim an intermediate CA in the chain as trusted\&. TLS then performs \fBpublic_key:pkix_path_validation/3\fR\& with the selected CA as trusted anchor and the rest of the chain\&. .TP 2 .B \fI{versions, [protocol()]}\fR\&: TLS protocol versions supported by started clients and servers\&. This option overrides the application environment option \fIprotocol_version\fR\&\&. If the environment option is not set, it defaults to all versions, except SSL-3\&.0, supported by the SSL application\&. See also \fBssl(7)\&.\fR\& .TP 2 .B \fI{hibernate_after, integer()|undefined}\fR\&: When an integer-value is specified, \fIssl_connection\fR\& goes into hibernation after the specified number of milliseconds of inactivity, thus reducing its memory footprint\&. When \fIundefined\fR\& is specified (this is the default), the process never goes into hibernation\&. .TP 2 .B \fI{user_lookup_fun, {Lookupfun :: fun(), UserState :: term()}}\fR\&: The lookup fun is to defined as follows: .LP .nf fun(psk, PSKIdentity ::string(), UserState :: term()) -> {ok, SharedSecret :: binary()} | error; fun(srp, Username :: string(), UserState :: term()) -> {ok, {SRPParams :: srp_param_type(), Salt :: binary(), DerivedKey :: binary()}} | error. .fi .RS 2 .LP For Pre-Shared Key (PSK) cipher suites, the lookup fun is called by the client and server to determine the shared secret\&. When called by the client, \fIPSKIdentity\fR\& is set to the hint presented by the server or to undefined\&. When called by the server, \fIPSKIdentity\fR\& is the identity presented by the client\&. .RE .RS 2 .LP For Secure Remote Password (SRP), the fun is only used by the server to obtain parameters that it uses to generate its session keys\&. \fIDerivedKey\fR\& is to be derived according to RFC 2945 and RFC 5054: \fIcrypto:sha([Salt, crypto:sha([Username, <<$:>>, Password])])\fR\& .RE .TP 2 .B \fI{padding_check, boolean()}\fR\&: Affects TLS-1\&.0 connections only\&. If set to \fIfalse\fR\&, it disables the block cipher padding check to be able to interoperate with legacy software\&. .LP .RS -4 .B Warning: .RE Using \fI{padding_check, boolean()}\fR\& makes TLS vulnerable to the Poodle attack\&. .TP 2 .B \fI{beast_mitigation, one_n_minus_one | zero_n | disabled}\fR\&: Affects SSL-3\&.0 and TLS-1\&.0 connections only\&. Used to change the BEAST mitigation strategy to interoperate with legacy software\&. Defaults to \fIone_n_minus_one\fR\&\&. .RS 2 .LP \fIone_n_minus_one\fR\& - Perform 1/n-1 BEAST mitigation\&. .RE .RS 2 .LP \fIzero_n\fR\& - Perform 0/n BEAST mitigation\&. .RE .RS 2 .LP \fIdisabled\fR\& - Disable BEAST mitigation\&. .RE .LP .RS -4 .B Warning: .RE Using \fI{beast_mitigation, disabled}\fR\& makes SSL or TLS vulnerable to the BEAST attack\&. .RE .SH "SSL OPTION DESCRIPTIONS - CLIENT SIDE" .LP The following options are client-specific or have a slightly different meaning in the client than in the server: .RS 2 .TP 2 .B \fI{verify, verify_type()}\fR\&: In mode \fIverify_none\fR\& the default behavior is to allow all x509-path validation errors\&. See also option \fIverify_fun\fR\&\&. .TP 2 .B \fI{reuse_sessions, boolean()}\fR\&: Specifies if the client is to try to reuse sessions when possible\&. .TP 2 .B \fI{cacerts, [public_key:der_encoded()]}\fR\&: The DER-encoded trusted certificates\&. If this option is supplied it overrides option \fIcacertfile\fR\&\&. .TP 2 .B \fI{cacertfile, path()}\fR\&: Path to a file containing PEM-encoded CA certificates\&. The CA certificates are used during server authentication and when building the client certificate chain\&. .TP 2 .B \fI{alpn_advertised_protocols, [binary()]}\fR\&: The list of protocols supported by the client to be sent to the server to be used for an Application-Layer Protocol Negotiation (ALPN)\&. If the server supports ALPN then it will choose a protocol from this list; otherwise it will fail the connection with a "no_application_protocol" alert\&. A server that does not support ALPN will ignore this value\&. .RS 2 .LP The list of protocols must not contain an empty binary\&. .RE .RS 2 .LP The negotiated protocol can be retrieved using the \fInegotiated_protocol/1\fR\& function\&. .RE .TP 2 .B \fI{client_preferred_next_protocols, {Precedence :: server | client, ClientPrefs :: [binary()]}}\fR\& .br \fI{client_preferred_next_protocols, {Precedence :: server | client, ClientPrefs :: [binary()], Default :: binary()}}\fR\&: Indicates that the client is to try to perform Next Protocol Negotiation\&. .RS 2 .LP If precedence is server, the negotiated protocol is the first protocol to be shown on the server advertised list, which is also on the client preference list\&. .RE .RS 2 .LP If precedence is client, the negotiated protocol is the first protocol to be shown on the client preference list, which is also on the server advertised list\&. .RE .RS 2 .LP If the client does not support any of the server advertised protocols or the server does not advertise any protocols, the client falls back to the first protocol in its list or to the default protocol (if a default is supplied)\&. If the server does not support Next Protocol Negotiation, the connection terminates if no default protocol is supplied\&. .RE .TP 2 .B \fI{psk_identity, string()}\fR\&: Specifies the identity the client presents to the server\&. The matching secret is found by calling \fIuser_lookup_fun\fR\&\&. .TP 2 .B \fI{srp_identity, {Username :: string(), Password :: string()} \fR\&: Specifies the username and password to use to authenticate to the server\&. .TP 2 .B \fI{server_name_indication, hostname()}\fR\&: Can be specified when upgrading a TCP socket to a TLS socket to use the TLS Server Name Indication extension\&. .TP 2 .B \fI{server_name_indication, disable}\fR\&: When starting a TLS connection without upgrade, the Server Name Indication extension is sent if possible\&. This option can be used to disable that behavior\&. .TP 2 .B \fI{fallback, boolean()}\fR\&: Send special cipher suite TLS_FALLBACK_SCSV to avoid undesired TLS version downgrade\&. Defaults to false .LP .RS -4 .B Warning: .RE Note this option is not needed in normal TLS usage and should not be used to implement new clients\&. But legacy clients that retries connections in the following manner .LP \fI ssl:connect(Host, Port, [\&.\&.\&.{versions, [\&'tlsv2\&', \&'tlsv1\&.1\&', \&'tlsv1\&', \&'sslv3\&']}])\fR\& .LP \fI ssl:connect(Host, Port, [\&.\&.\&.{versions, [tlsv1\&.1\&', \&'tlsv1\&', \&'sslv3\&']}, {fallback, true}])\fR\& .LP \fI ssl:connect(Host, Port, [\&.\&.\&.{versions, [\&'tlsv1\&', \&'sslv3\&']}, {fallback, true}]) \fR\& .LP \fI ssl:connect(Host, Port, [\&.\&.\&.{versions, [\&'sslv3\&']}, {fallback, true}]) \fR\& .LP may use it to avoid undesired TLS version downgrade\&. Note that TLS_FALLBACK_SCSV must also be supported by the server for the prevention to work\&. .TP 2 .B \fI{signature_algs, [{hash(), ecdsa | rsa | dsa}]}\fR\&: In addition to the algorithms negotiated by the cipher suite used for key exchange, payload encryption, message authentication and pseudo random calculation, the TLS signature algorithm extension Section 7\&.4\&.1\&.4\&.1 in RFC 5246 may be used, from TLS 1\&.2, to negotiate which signature algorithm to use during the TLS handshake\&. If no lower TLS versions than 1\&.2 are supported, the client will send a TLS signature algorithm extension with the algorithms specified by this option\&. Defaults to .LP .nf [ %% SHA2 {sha512, ecdsa}, {sha512, rsa}, {sha384, ecdsa}, {sha384, rsa}, {sha256, ecdsa}, {sha256, rsa}, {sha224, ecdsa}, {sha224, rsa}, %% SHA {sha, ecdsa}, {sha, rsa}, {sha, dsa}, ] .fi .RS 2 .LP The algorithms should be in the preferred order\&. Selected signature algorithm can restrict which hash functions that may be selected\&. Default support for {md5, rsa} removed in ssl-8\&.0 .RE .RE .SH "SSL OPTION DESCRIPTIONS - SERVER SIDE" .LP The following options are server-specific or have a slightly different meaning in the server than in the client: .RS 2 .TP 2 .B \fI{cacerts, [public_key:der_encoded()]}\fR\&: The DER-encoded trusted certificates\&. If this option is supplied it overrides option \fIcacertfile\fR\&\&. .TP 2 .B \fI{cacertfile, path()}\fR\&: Path to a file containing PEM-encoded CA certificates\&. The CA certificates are used to build the server certificate chain and for client authentication\&. The CAs are also used in the list of acceptable client CAs passed to the client when a certificate is requested\&. Can be omitted if there is no need to verify the client and if there are no intermediate CAs for the server certificate\&. .TP 2 .B \fI{dh, public_key:der_encoded()}\fR\&: The DER-encoded Diffie-Hellman parameters\&. If specified, it overrides option \fIdhfile\fR\&\&. .TP 2 .B \fI{dhfile, path()}\fR\&: Path to a file containing PEM-encoded Diffie Hellman parameters to be used by the server if a cipher suite using Diffie Hellman key exchange is negotiated\&. If not specified, default parameters are used\&. .TP 2 .B \fI{verify, verify_type()}\fR\&: A server only does x509-path validation in mode \fIverify_peer\fR\&, as it then sends a certificate request to the client (this message is not sent if the verify option is \fIverify_none\fR\&)\&. You can then also want to specify option \fIfail_if_no_peer_cert\fR\&\&. .TP 2 .B \fI{fail_if_no_peer_cert, boolean()}\fR\&: Used together with \fI{verify, verify_peer}\fR\& by an SSL server\&. If set to \fItrue\fR\&, the server fails if the client does not have a certificate to send, that is, sends an empty certificate\&. If set to \fIfalse\fR\&, it fails only if the client sends an invalid certificate (an empty certificate is considered valid)\&. Defaults to false\&. .TP 2 .B \fI{reuse_sessions, boolean()}\fR\&: Specifies if the server is to agree to reuse sessions when requested by the clients\&. See also option \fIreuse_session\fR\&\&. .TP 2 .B \fI{reuse_session, fun(SuggestedSessionId, PeerCert, Compression, CipherSuite) -> boolean()}\fR\&: Enables the SSL server to have a local policy for deciding if a session is to be reused or not\&. Meaningful only if \fIreuse_sessions\fR\& is set to \fItrue\fR\&\&. \fISuggestedSessionId\fR\& is a \fIbinary()\fR\&, \fIPeerCert\fR\& is a DER-encoded certificate, \fICompression\fR\& is an enumeration integer, and \fICipherSuite\fR\& is of type \fIciphersuite()\fR\&\&. .TP 2 .B \fI{alpn_preferred_protocols, [binary()]}\fR\&: Indicates the server will try to perform Application-Layer Protocol Negotiation (ALPN)\&. .RS 2 .LP The list of protocols is in order of preference\&. The protocol negotiated will be the first in the list that matches one of the protocols advertised by the client\&. If no protocol matches, the server will fail the connection with a "no_application_protocol" alert\&. .RE .RS 2 .LP The negotiated protocol can be retrieved using the \fInegotiated_protocol/1\fR\& function\&. .RE .TP 2 .B \fI{next_protocols_advertised, Protocols :: [binary()]}\fR\&: List of protocols to send to the client if the client indicates that it supports the Next Protocol extension\&. The client can select a protocol that is not on this list\&. The list of protocols must not contain an empty binary\&. If the server negotiates a Next Protocol, it can be accessed using the \fInegotiated_next_protocol/1\fR\& method\&. .TP 2 .B \fI{psk_identity, string()}\fR\&: Specifies the server identity hint, which the server presents to the client\&. .TP 2 .B \fI{log_alert, boolean()}\fR\&: If set to \fIfalse\fR\&, error reports are not displayed\&. .TP 2 .B \fI{honor_cipher_order, boolean()}\fR\&: If set to \fItrue\fR\&, use the server preference for cipher selection\&. If set to \fIfalse\fR\& (the default), use the client preference\&. .TP 2 .B \fI{sni_hosts, [{hostname(), [ssl_option()]}]}\fR\&: If the server receives a SNI (Server Name Indication) from the client matching a host listed in the \fIsni_hosts\fR\& option, the specific options for that host will override previously specified options\&. The option \fIsni_fun\fR\&, and \fIsni_hosts\fR\& are mutually exclusive\&. .TP 2 .B \fI{sni_fun, SNIfun::fun()}\fR\&: If the server receives a SNI (Server Name Indication) from the client, the given function will be called to retrieve \fI[ssl_option()]\fR\& for the indicated server\&. These options will be merged into predefined \fI[ssl_option()]\fR\&\&. The function should be defined as: \fIfun(ServerName :: string()) -> [ssl_option()]\fR\& and can be specified as a fun or as named \fIfun module:function/1\fR\& The option \fIsni_fun\fR\&, and \fIsni_hosts\fR\& are mutually exclusive\&. .TP 2 .B \fI{client_renegotiation, boolean()}\fR\&: In protocols that support client-initiated renegotiation, the cost of resources of such an operation is higher for the server than the client\&. This can act as a vector for denial of service attacks\&. The SSL application already takes measures to counter-act such attempts, but client-initiated renegotiation can be strictly disabled by setting this option to \fIfalse\fR\&\&. The default value is \fItrue\fR\&\&. Note that disabling renegotiation can result in long-lived connections becoming unusable due to limits on the number of messages the underlying cipher suite can encipher\&. .TP 2 .B \fI{honor_cipher_order, boolean()}\fR\&: If true, use the server\&'s preference for cipher selection\&. If false (the default), use the client\&'s preference\&. .TP 2 .B \fI{honor_ecc_order, boolean()}\fR\&: If true, use the server\&'s preference for ECC curve selection\&. If false (the default), use the client\&'s preference\&. .TP 2 .B \fI{signature_algs, [{hash(), ecdsa | rsa | dsa}]}\fR\&: The algorithms specified by this option will be the ones accepted by the server in a signature algorithm negotiation, introduced in TLS-1\&.2\&. The algorithms will also be offered to the client if a client certificate is requested\&. For more details see the \fBcorresponding client option\fR\&\&. .TP 2 .B \fI{v2_hello_compatible, boolean()}\fR\&: If true, the server accepts clients that send hello messages on SSL-2\&.0 format but offers supported SSL/TLS versions\&. Defaults to false, that is the server will not interoperate with clients that offers SSL-2\&.0\&. .RE .SH "GENERAL" .LP When an SSL socket is in active mode (the default), data from the socket is delivered to the owner of the socket in the form of messages: .RS 2 .TP 2 * \fI{ssl, Socket, Data}\fR\& .LP .TP 2 * \fI{ssl_closed, Socket}\fR\& .LP .TP 2 * \fI{ssl_error, Socket, Reason}\fR\& .LP .RE .LP A \fITimeout\fR\& argument specifies a time-out in milliseconds\&. The default value for argument \fITimeout\fR\& is \fIinfinity\fR\&\&. .SH EXPORTS .LP .B cipher_suites() -> .br .B cipher_suites(Type) -> ciphers() .br .RS .LP Types: .RS 3 Type = erlang | openssl | all .br .RE .RE .RS .LP Returns a list of supported cipher suites\&. \fIcipher_suites()\fR\& is equivalent to \fIcipher_suites(erlang)\&.\fR\& Type \fIopenssl\fR\& is provided for backwards compatibility with the old SSL, which used OpenSSL\&. \fIcipher_suites(all)\fR\& returns all available cipher suites\&. The cipher suites not present in \fIcipher_suites(erlang)\fR\& but included in \fIcipher_suites(all)\fR\& are not used unless explicitly configured by the user\&. .RE .LP .B eccs() -> .br .B eccs(protocol()) -> [named_curve()] .br .RS .LP Returns a list of supported ECCs\&. \fIeccs()\fR\& is equivalent to calling \fIeccs(Protocol)\fR\& with all supported protocols and then deduplicating the output\&. .RE .LP .B clear_pem_cache() -> ok .br .RS .LP PEM files, used by ssl API-functions, are cached\&. The cache is regularly checked to see if any cache entries should be invalidated, however this function provides a way to unconditionally clear the whole cache\&. .RE .LP .B connect(Socket, SslOptions) -> .br .B connect(Socket, SslOptions, Timeout) -> {ok, SslSocket} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = socket() .br SslOptions = [ssl_option()] .br Timeout = integer() | infinity .br SslSocket = sslsocket() .br Reason = term() .br .RE .RE .RS .LP Upgrades a \fIgen_tcp\fR\&, or equivalent, connected socket to an SSL socket, that is, performs the client-side ssl handshake\&. .RE .LP .B connect(Host, Port, Options) -> .br .B connect(Host, Port, Options, Timeout) -> {ok, SslSocket} | {error, Reason} .br .RS .LP Types: .RS 3 Host = host() .br Port = integer() .br Options = [option()] .br Timeout = integer() | infinity .br SslSocket = sslsocket() .br Reason = term() .br .RE .RE .RS .LP Opens an SSL connection to \fIHost\fR\&, \fIPort\fR\&\&. .RE .LP .B close(SslSocket) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 SslSocket = sslsocket() .br Reason = term() .br .RE .RE .RS .LP Closes an SSL connection\&. .RE .LP .B close(SslSocket, How) -> ok | {ok, port()} | {error, Reason} .br .RS .LP Types: .RS 3 SslSocket = sslsocket() .br How = timeout() | {NewController::pid(), timeout()} .br Reason = term() .br .RE .RE .RS .LP Closes or downgrades an SSL connection\&. In the latter case the transport connection will be handed over to the \fINewController\fR\& process after receiving the TLS close alert from the peer\&. The returned transport socket will have the following options set: \fI[{active, false}, {packet, 0}, {mode, binary}]\fR\& .RE .LP .B controlling_process(SslSocket, NewOwner) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 SslSocket = sslsocket() .br NewOwner = pid() .br Reason = term() .br .RE .RE .RS .LP Assigns a new controlling process to the SSL socket\&. A controlling process is the owner of an SSL socket, and receives all messages from the socket\&. .RE .LP .B connection_information(SslSocket) -> {ok, Result} | {error, Reason} .br .RS .LP Types: .RS 3 Item = protocol | cipher_suite | sni_hostname | ecc | atom() .br .RS 2 Meaningful atoms, not specified above, are the ssl option names\&. .RE Result = [{Item::atom(), Value::term()}] .br Reason = term() .br .RE .RE .RS .LP Returns all relevant information about the connection, ssl options that are undefined will be filtered out\&. .RE .LP .B connection_information(SslSocket, Items) -> {ok, Result} | {error, Reason} .br .RS .LP Types: .RS 3 Items = [Item] .br Item = protocol | cipher_suite | sni_hostname | atom() .br .RS 2 Meaningful atoms, not specified above, are the ssl option names\&. .RE Result = [{Item::atom(), Value::term()}] .br Reason = term() .br .RE .RE .RS .LP Returns the requested information items about the connection, if they are defined\&. .LP .RS -4 .B Note: .RE If only undefined options are requested the resulting list can be empty\&. .RE .LP .B format_error(Reason) -> string() .br .RS .LP Types: .RS 3 Reason = term() .br .RE .RE .RS .LP Presents the error returned by an SSL function as a printable string\&. .RE .LP .B getopts(Socket, OptionNames) -> {ok, [socketoption()]} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br OptionNames = [atom()] .br .RE .RE .RS .LP Gets the values of the specified socket options\&. .RE .LP .B getstat(Socket) -> {ok, OptionValues} | {error, inet:posix()} .br .B getstat(Socket, OptionNames) -> {ok, OptionValues} | {error, inet:posix()} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br OptionNames = [atom()] .br OptionValues = [{inet:stat_option(), integer()}] .br .RE .RE .RS .LP Gets one or more statistic options for the underlying TCP socket\&. .LP See inet:getstat/2 for statistic options description\&. .RE .LP .B listen(Port, Options) -> {ok, ListenSocket} | {error, Reason} .br .RS .LP Types: .RS 3 Port = integer() .br Options = options() .br ListenSocket = sslsocket() .br .RE .RE .RS .LP Creates an SSL listen socket\&. .RE .LP .B negotiated_protocol(Socket) -> {ok, Protocol} | {error, protocol_not_negotiated} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Protocol = binary() .br .RE .RE .RS .LP Returns the protocol negotiated through ALPN or NPN extensions\&. .RE .LP .B peercert(Socket) -> {ok, Cert} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Cert = binary() .br .RE .RE .RS .LP The peer certificate is returned as a DER-encoded binary\&. The certificate can be decoded with \fIpublic_key:pkix_decode_cert/2\fR\&\&. .RE .LP .B peername(Socket) -> {ok, {Address, Port}} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Address = ipaddress() .br Port = integer() .br .RE .RE .RS .LP Returns the address and port number of the peer\&. .RE .LP .B prf(Socket, Secret, Label, Seed, WantedLength) -> {ok, binary()} | {error, reason()} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Secret = binary() | master_secret .br Label = binary() .br Seed = [binary() | prf_random()] .br WantedLength = non_neg_integer() .br .RE .RE .RS .LP Uses the Pseudo-Random Function (PRF) of a TLS session to generate extra key material\&. It either takes user-generated values for \fISecret\fR\& and \fISeed\fR\& or atoms directing it to use a specific value from the session security parameters\&. .LP Can only be used with TLS connections; \fI{error, undefined}\fR\& is returned for SSLv3 connections\&. .RE .LP .B recv(Socket, Length) -> .br .B recv(Socket, Length, Timeout) -> {ok, Data} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Length = integer() .br Timeout = integer() .br Data = [char()] | binary() .br .RE .RE .RS .LP Receives a packet from a socket in passive mode\&. A closed socket is indicated by return value \fI{error, closed}\fR\&\&. .LP Argument \fILength\fR\& is meaningful only when the socket is in mode \fIraw\fR\& and denotes the number of bytes to read\&. If \fILength\fR\& = 0, all available bytes are returned\&. If \fILength\fR\& > 0, exactly \fILength\fR\& bytes are returned, or an error; possibly discarding less than \fILength\fR\& bytes of data when the socket gets closed from the other side\&. .LP Optional argument \fITimeout\fR\& specifies a time-out in milliseconds\&. The default value is \fIinfinity\fR\&\&. .RE .LP .B renegotiate(Socket) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br .RE .RE .RS .LP Initiates a new handshake\&. A notable return value is \fI{error, renegotiation_rejected}\fR\& indicating that the peer refused to go through with the renegotiation, but the connection is still active using the previously negotiated session\&. .RE .LP .B send(Socket, Data) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Data = iodata() .br .RE .RE .RS .LP Writes \fIData\fR\& to \fISocket\fR\&\&. .LP A notable return value is \fI{error, closed}\fR\& indicating that the socket is closed\&. .RE .LP .B setopts(Socket, Options) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Options = [socketoption]() .br .RE .RE .RS .LP Sets options according to \fIOptions\fR\& for socket \fISocket\fR\&\&. .RE .LP .B shutdown(Socket, How) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br How = read | write | read_write .br Reason = reason() .br .RE .RE .RS .LP Immediately closes a socket in one or two directions\&. .LP \fIHow == write\fR\& means closing the socket for writing, reading from it is still possible\&. .LP To be able to handle that the peer has done a shutdown on the write side, option \fI{exit_on_close, false}\fR\& is useful\&. .RE .LP .B ssl_accept(Socket) -> .br .B ssl_accept(Socket, Timeout) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Timeout = integer() .br Reason = term() .br .RE .RE .RS .LP Performs the SSL/TLS server-side handshake\&. .LP \fISocket\fR\& is a socket as returned by \fBssl:transport_accept/[1,2]\fR\& .RE .LP .B ssl_accept(Socket, SslOptions) -> .br .B ssl_accept(Socket, SslOptions, Timeout) -> {ok, Socket} | ok | {error, Reason} .br .RS .LP Types: .RS 3 Socket = socket() | sslsocket() .br SslOptions = [ssl_option()] .br Timeout = integer() .br Reason = term() .br .RE .RE .RS .LP If \fISocket\fR\& is a \fIsocket()\fR\&: upgrades a \fIgen_tcp\fR\&, or equivalent, socket to an SSL socket, that is, performs the SSL/TLS server-side handshake and returns the SSL socket\&. .LP .RS -4 .B Warning: .RE The listen socket is to be in mode \fI{active, false}\fR\& before telling the client that the server is ready to upgrade by calling this function, else the upgrade succeeds or does not succeed depending on timing\&. .LP If \fISocket\fR\& is an \fIsslsocket()\fR\&: provides extra SSL/TLS options to those specified in \fBssl:listen/2 \fR\& and then performs the SSL/TLS handshake\&. .RE .LP .B sockname(Socket) -> {ok, {Address, Port}} | {error, Reason} .br .RS .LP Types: .RS 3 Socket = sslsocket() .br Address = ipaddress() .br Port = integer() .br .RE .RE .RS .LP Returns the local address and port number of socket \fISocket\fR\&\&. .RE .LP .B start() -> .br .B start(Type) -> ok | {error, Reason} .br .RS .LP Types: .RS 3 Type = permanent | transient | temporary .br .RE .RE .RS .LP Starts the SSL application\&. Default type is \fItemporary\fR\&\&. .RE .LP .B stop() -> ok .br .RS .LP Stops the SSL application\&. .RE .LP .B transport_accept(ListenSocket) -> .br .B transport_accept(ListenSocket, Timeout) -> {ok, NewSocket} | {error, Reason} .br .RS .LP Types: .RS 3 ListenSocket = NewSocket = sslsocket() .br Timeout = integer() .br Reason = reason() .br .RE .RE .RS .LP Accepts an incoming connection request on a listen socket\&. \fIListenSocket\fR\& must be a socket returned from \fB ssl:listen/2\fR\&\&. The socket returned is to be passed to \fB ssl:ssl_accept[2,3]\fR\& to complete handshaking, that is, establishing the SSL/TLS connection\&. .LP .RS -4 .B Warning: .RE The socket returned can only be used with \fB ssl:ssl_accept[2,3]\fR\&\&. No traffic can be sent or received before that call\&. .LP The accepted socket inherits the options set for \fIListenSocket\fR\& in \fB ssl:listen/2\fR\&\&. .LP The default value for \fITimeout\fR\& is \fIinfinity\fR\&\&. If \fITimeout\fR\& is specified and no connection is accepted within the given time, \fI{error, timeout}\fR\& is returned\&. .RE .LP .B versions() -> [versions_info()] .br .RS .LP Types: .RS 3 versions_info() = {app_vsn, string()} | {supported | available, [protocol()] .br .RE .RE .RS .LP Returns version information relevant for the SSL application\&. .RS 2 .TP 2 .B \fIapp_vsn\fR\&: The application version of the SSL application\&. .TP 2 .B \fIsupported\fR\&: TLS/SSL versions supported by default\&. Overridden by a version option on \fB connect/[2,3,4]\fR\&, \fB listen/2\fR\&, and \fBssl_accept/[1,2,3]\fR\&\&. For the negotiated TLS/SSL version, see \fBssl:connection_information/1 \fR\&\&. .TP 2 .B \fIavailable\fR\&: All TLS/SSL versions supported by the SSL application\&. TLS 1\&.2 requires sufficient support from the Crypto application\&. .RE .RE .SH "SEE ALSO" .LP \fBinet(3erl)\fR\& and \fBgen_tcp(3erl)\fR\&