This module contains interface functions for the SSL/TLS protocol.
For detailed information about the supported standards see
The following data types are used in the functions for SSL:
The default socket options are
For valid options, see the
Defaults to
Used in socket data message.
Used in socket close message.
Represents a file path.
ASN.1 DER-encoded entity as an Erlang binary.
opaque()
According to old API.
The following options have the same meaning in the client and the server:
The DER-encoded users certificate. If this option
is supplied, it overrides option
Path to a file containing the user certificate.
The DER-encoded user's private key. If this option
is supplied, it overrides option
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
String containing the user's password. Only used if the private keyfile is password-protected.
Supported cipher suites. The function
Specifies if to reject renegotiation attempt that does
not live up to
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.
The verification fun is to be defined as follows:
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()}.
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
If the verify callback fun returns
If the verify callback fun returns
If the verify callback fun always returns
If called with an extension unknown to the user application,
return value
Note that if the fun returns
Default option
{fun(_,{bad_cert, _} = Reason, _) ->
{fail, Reason};
(_,{extension, _}, UserState) ->
{unknown, UserState};
(_, valid, UserState) ->
{valid, UserState};
(_, valid_peer, UserState) ->
{valid, UserState}
end, []}
Default option
{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, []}
The possible path validation errors are given on form
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 intermediat CA (trusted anchor does not have to be
self-signed according to X-509) by using option
The chain consisted only of one self-signed certificate.
For possible reasons, see
The CA certificates specified for the connection will be used to construct the certificate chain validating the CRLs.
The CRLs will be fetched from a local or external cache see
Module defaults to ssl_crl_cache with
Enables fetching of CRLs specified as http URIs in
Claim an intermediate CA in the chain as trusted. TLS then
performs
TLS protocol versions supported by started clients and servers.
This option overrides the application environment option
When an integer-value is specified,
The lookup fun is to defined as follows:
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.
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,
For Secure Remote Password (SRP), the fun is only used by the server to
obtain parameters that it uses to generate its session keys.
Affects TLS-1.0 connections only.
If set to
Using
The following options are client-specific or have a slightly different meaning in the client than in the server:
In mode
Specifies if the client is to try to reuse sessions when possible.
The DER-encoded trusted certificates. If this option
is supplied it overrides option
Path to a file containing PEM-encoded CA certificates. The CA certificates are used during server authentication and when building the client certificate chain.
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.
The list of protocols must not contain an empty binary.
The negotiated protocol can be retrieved using the
Indicates that the client is to try to perform Next Protocol Negotiation.
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.
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.
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.
Specifies the identity the client presents to the server.
The matching secret is found by calling
Specifies the username and password to use to authenticate to the server.
Can be specified when upgrading a TCP socket to a TLS socket to use the TLS Server Name Indication extension.
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.
Send special cipher suite TLS_FALLBACK_SCSV to avoid undesired TLS version downgrade. Defaults to false
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
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.
The following options are server-specific or have a slightly different meaning in the server than in the client:
The DER-encoded trusted certificates. If this option
is supplied it overrides option
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.
The DER-encoded Diffie-Hellman parameters. If specified,
it overrides option
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.
A server only does x509-path validation in mode
Used together with
Specifies if the server is to agree to reuse sessions
when requested by the clients. See also option
Enables the SSL server to have a local policy
for deciding if a session is to be reused or not.
Meaningful only if
Indicates the server will try to perform Application-Layer Protocol Negotiation (ALPN).
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.
The negotiated protocol can be retrieved using the
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
Specifies the server identity hint, which the server presents to the client.
If set to
If set to
If the server receives a SNI (Server Name Indication) from the client
matching a host listed in the
If the server receives a SNI (Server Name Indication) from the client,
the given function will be called to retrive
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:
A
Returns a list of supported cipher suites.
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.
Upgrades a
Opens an SSL connection to
Closes an SSL connection.
Closes or downgrades an SSL connection, in the later case the transport
connection will be handed over to the
Returns the Negotiated Protocol version and cipher suite.
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.
Return all the connection information containing negotiated protocol version, cipher suite, and the hostname of SNI extension.
Info will be a proplists containing all the connection information on success, otherwise
Returns the connection information you requested. The connection information you can request contains protocol, cipher_suite, and sni_hostname.
Presents the error returned by an SSL function as a printable string.
Gets the values of the specified socket options.
Creates an SSL listen socket.
Returns the protocol negotiated through ALPN or NPN extensions.
The peer certificate is returned as a DER-encoded binary.
The certificate can be decoded with
Returns the address and port number of the peer.
Uses the Pseudo-Random Function (PRF) of a TLS session to generate
extra key material. It either takes user-generated values for
Can only be used with TLS connections;
Receives a packet from a socket in passive
mode. A closed socket is indicated by return value
Argument
Optional argument
Initiates a new handshake. A notable return value is
Writes
A notable return value is
Sets options according to
Immediately closes a socket in one or two directions.
To be able to handle that the peer has done a shutdown on
the write side, option
Performs the SSL/TLS server-side handshake.
If
The listen socket is to be in mode
If
Returns the local address and port number of socket
Starts the SSL application. Default type
is
Stops the SSL application.
Accepts an incoming connection request on a listen socket.
The socket returned can only be used with
The accepted socket inherits the options set for
The default
value for
Returns version information relevant for the SSL application.