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:
Choose TLS or DTLS protocol for the transport layer security.
Defaults to
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 or a map refering to a crypto
engine and its key reference that optionally can be password protected,
seealso
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
Allows to specify the order of preference for named curves and to restrict their usage when using a cipher suite supporting them.
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 intermediate 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
Perform CRL (Certificate Revocation List) verification
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
Specify how to perform lookup and caching of certificate revocation lists.
There are two implementations available:
This module maintains a cache of CRLs. CRLs can be
added to the cache using the function
Enables fetching of CRLs specified as http URIs in
This module makes use of a directory where CRLs are stored in files named by the hash of the issuer name.
The file names consist of eight hexadecimal digits
followed by
For a given hash value, this module finds all
consecutive
The following argument is required:
Specifies the directory in which the CRLs can be found.
Integer (24 bits unsigned). Used to limit the size of valid TLS handshake packets to avoid DoS attacks. Defaults to 256*1024.
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
Affects SSL-3.0 and TLS-1.0 connections only. Used to change the BEAST
mitigation strategy to interoperate with legacy software.
Defaults 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.
Specify the hostname to be used in TLS Server Name Indication extension.
If not specified it will default to the
The
Prevents the Server Name Indication extension from being sent and
disables the hostname verification check
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.
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
[
%% SHA2
{sha512, ecdsa},
{sha512, rsa},
{sha384, ecdsa},
{sha384, rsa},
{sha256, ecdsa},
{sha256, rsa},
{sha224, ecdsa},
{sha224, rsa},
%% SHA
{sha, ecdsa},
{sha, rsa},
{sha, dsa},
]
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
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 retrieve
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
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.
Returns a list of supported ECCs.
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
If the option
Opens an SSL connection to
When the option
According to good practices certificates should not use IP-addresses as "server names". It would be very surprising if this happen outside a closed network.
Closes an SSL connection.
Closes or downgrades an SSL connection. In the latter case the transport
connection will be handed over to the
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.
Returns the most relevant information about the connection, ssl options that are undefined will be filtered out. Note that values that affect the security of the connection will only be returned if explicitly requested by connection_information/2.
Returns the requested information items about the connection, if they are defined.
If only undefined options are requested the resulting list can be empty.
Presents the error returned by an SSL function as a printable string.
Gets the values of the specified socket options.
Gets one or more statistic options for the underlying TCP socket.
See inet:getstat/2 for statistic options description.
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.