This module contains interface functions for the SSL/TLS/DTLS protocol.
For detailed information about the supported standards see
An opaque reference to the TLS/DTLS connection, may be used for equality matching.
The default socket options are
For valid options, see the
When an TLS/DTLS socket is in active mode (the default), data from the socket is delivered to the owner of the socket in the form of messages as described above.
Defaults to
Choose TLS or DTLS protocol for the transport layer security.
Defaults to
Defaults to
The DER-encoded users certificate. If this option
is supplied, it overrides option
Path to a file containing the user certificate on PEM format.
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.
In addition to the signature_algorithms extension from TLS 1.2,
The client will send a signature_algorithms_cert extension (ClientHello), if TLS version 1.3 or later is used, and the signature_algs_cert option is explicitly specified. By default, only the signature_algs extension is sent.
The signature schemes shall be ordered according to the client's preference (favorite choice first).
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.
fun(Chain::[public_key:der_encoded()]) ->
{trusted_ca, DerCert::public_key:der_encoded()} | unknown_ca}
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
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.
Identifies a TLS session.
If set to
Specifies the log level for TLS/DTLS. At verbosity level
When an integer-value is specified,
Integer (24 bits unsigned). Used to limit the size of valid TLS handshake packets to avoid DoS attacks. Defaults to 256*1024.
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
Deprecated since OTP-17, has no affect.
In mode
Reuses a specific session earlier saved with the option
When
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
The special value
Customizes the hostname verification of the peer certificate, as different protocols that use
TLS such as HTTP or LDAP may want to do it differently, for possible options see
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 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
The boolean value true specifies that the server will
agree to reuse sessions. Setting it to false will result in an empty
session table, that is no sessions will be reused.
See also option
Enables the TLS/DTLS 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 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
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
If true, use the server's preference for cipher selection. If false (the default), use the client's preference.
If true, use the server's preference for ECC curve selection. If false (the default), use the client's preference.
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
Make
Deprecated in OTP 21, use
Returns all default or all supported (except anonymous), or all anonymous cipher suites for a TLS version
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
If the option
If the option
Opens an TLS/DTLS 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.
If the option
If the option
Closes an TLS/DTLS connection.
Closes or downgrades an TLS 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.
The legacy
Returns the requested information items about the connection, if they are defined.
If only undefined options are requested the resulting list can be empty.
Removes cipher suites if any of the filter functions returns false for any part of the cipher suite. This function also calls default filter functions to make sure the cipher suites are supported by crypto. If no filter function is supplied for some part the default behaviour is fun(Algorithm) -> true.
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.
Performs the SSL/TLS/DTLS server-side handshake.
Returns a new TLS/DTLS socket if the handshake is successful.
If the option
If
The
If
If option
If the option
Cancel the handshake with a fatal
Continue the SSL/TLS handshake possiby with new, additional or changed 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.
Make
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/DTLS 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
Sets log level for the SSL application.
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
Deprecated in OTP 21, use
handshake/[1,2] always returns a new socket.
Deprecated in OTP 21, use
handshake/[2,3] always returns a new socket.
Returns the local address and port number of socket
Starts the SSL application. Default type
is
Stops the SSL application.
Returns the string representation of a cipher suite.
Accepts an incoming connection request on a listen socket.
Most API functions require that the TLS/DTLS connection is established to work as expected.
The accepted socket inherits the options set for
The default
value for
Returns version information relevant for the SSL application.