1ssl(3)                     Erlang Module Definition                     ssl(3)
2
3
4

NAME

6       ssl - Interface Functions for Secure Socket Layer
7

DESCRIPTION

9       This module contains interface functions for the SSL/TLS/DTLS protocol.
10       For detailed information about the supported standards see ssl(6).
11

DATA TYPES

13   Types used in SSL/TLS/DTLS
14       socket() = gen_tcp:socket()
15
16       sslsocket() = any()
17
18              An opaque reference to the TLS/DTLS connection, may be used  for
19              equality matching.
20
21       tls_option() = tls_client_option() | tls_server_option()
22
23       tls_client_option() =
24           client_option() |
25           common_option() |
26           socket_option() |
27           transport_option()
28
29       tls_server_option() =
30           server_option() |
31           common_option() |
32           socket_option() |
33           transport_option()
34
35       socket_option() =
36           gen_tcp:connect_option() |
37           gen_tcp:listen_option() |
38           gen_udp:option()
39
40              The default socket options are [{mode,list},{packet, 0},{header,
41              0},{active, true}].
42
43              For valid options, see the inet(3),  gen_tcp(3)  and  gen_udp(3)
44              manual  pages  in Kernel. Note that stream oriented options such
45              as packet are only relevant for SSL/TLS and not DTLS
46
47       active_msgs() =
48           {ssl, sslsocket(), Data :: binary() | list()} |
49           {ssl_closed, sslsocket()} |
50           {ssl_error, sslsocket(), Reason :: any()} |
51           {ssl_passive, sslsocket()}
52
53              When a TLS/DTLS socket is in active  mode  (the  default),  data
54              from  the  socket is delivered to the owner of the socket in the
55              form of messages as described above.
56
57              The ssl_passive message is sent  only  when  the  socket  is  in
58              {active, N} mode and the counter dropped to 0. It indicates that
59              the socket has transitioned to passive ({active, false}) mode.
60
61       transport_option() =
62           {cb_info,
63            {CallbackModule :: atom(),
64             DataTag :: atom(),
65             ClosedTag :: atom(),
66             ErrTag :: atom()}} |
67           {cb_info,
68            {CallbackModule :: atom(),
69             DataTag :: atom(),
70             ClosedTag :: atom(),
71             ErrTag :: atom(),
72             PassiveTag :: atom()}}
73
74              Defaults to {gen_tcp, tcp, tcp_closed,  tcp_error,  tcp_passive}
75              for  TLS  (for  backward compatibility a four tuple will be con‐
76              verted to a  five  tuple  with  the  last  element  "second_ele‐
77              ment"_passive)  and  {gen_udp,  udp,  udp_closed, udp_error} for
78              DTLS (might also be changed to five tuple in the future). Can be
79              used  to customize the transport layer. The tag values should be
80              the values used by the underlying transport in its  active  mode
81              messages.  For TLS the callback module must implement a reliable
82              transport protocol, behave as gen_tcp, and have functions corre‐
83              sponding  to  inet:setopts/2,  inet:getopts/2,  inet:peername/1,
84              inet:sockname/1,  and  inet:port/1.  The  callback  gen_tcp   is
85              treated specially and calls inet directly. For DTLS this feature
86              must be considered exprimental.
87
88       host() = hostname() | ip_address()
89
90       hostname() = string()
91
92       ip_address() = inet:ip_address()
93
94       protocol_version() = tls_version() | dtls_version()
95
96       tls_version() =
97           tlsv1 | 'tlsv1.1' | 'tlsv1.2' | 'tlsv1.3' | legacy_version()
98
99       dtls_version() = dtlsv1 | 'dtlsv1.2'
100
101       legacy_version() = sslv3
102
103       prf_random() = client_random | server_random
104
105       verify_type() = verify_none | verify_peer
106
107       ciphers() = [erl_cipher_suite()] | string()
108
109       erl_cipher_suite() =
110           #{key_exchange := kex_algo(),
111             cipher := cipher(),
112             mac := hash() | aead,
113             prf := hash() | default_prf}
114
115       cipher() =
116           aes_128_cbc |
117           aes_256_cbc |
118           aes_128_gcm |
119           aes_256_gcm |
120           chacha20_poly1305 |
121           legacy_cipher()
122
123       legacy_cipher() = rc4_128 | des_cbc | '3des_ede_cbc'
124
125       cipher_filters() =
126           [{key_exchange | cipher | mac | prf, algo_filter()}]
127
128       hash() = sha | sha2() | legacy_hash()
129
130       sha2() = sha224 | sha256 | sha384 | sha512
131
132       legacy_hash() = md5
133
134       old_cipher_suite() =
135           {kex_algo(), cipher(), hash()} |
136           {kex_algo(), cipher(), hash() | aead, hash()}
137
138       signature_algs() = [{hash(), sign_algo()}]
139
140       sign_algo() = rsa | dsa | ecdsa
141
142       kex_algo() =
143           rsa |
144           dhe_rsa |
145           dhe_dss |
146           ecdhe_ecdsa |
147           ecdh_ecdsa |
148           ecdh_rsa |
149           srp_rsa |
150           srp_dss |
151           psk |
152           dhe_psk |
153           rsa_psk |
154           dh_anon |
155           ecdh_anon |
156           srp_anon
157
158       algo_filter() =
159           fun((kex_algo() | cipher() | hash() | aead | default_prf) ->
160                   true | false)
161
162       named_curve() =
163           sect571r1 |
164           sect571k1 |
165           secp521r1 |
166           brainpoolP512r1 |
167           sect409k1 |
168           sect409r1 |
169           brainpoolP384r1 |
170           secp384r1 |
171           sect283k1 |
172           sect283r1 |
173           brainpoolP256r1 |
174           secp256k1 |
175           secp256r1 |
176           sect239k1 |
177           sect233k1 |
178           sect233r1 |
179           secp224k1 |
180           secp224r1 |
181           sect193r1 |
182           sect193r2 |
183           secp192k1 |
184           secp192r1 |
185           sect163k1 |
186           sect163r1 |
187           sect163r2 |
188           secp160k1 |
189           secp160r1 |
190           secp160r2
191
192       psk_identity() = string()
193
194       srp_identity() = {Username :: string(), Password :: string()}
195
196       srp_param_type() =
197           srp_1024 |
198           srp_1536 |
199           srp_2048 |
200           srp_3072 |
201           srp_4096 |
202           srp_6144 |
203           srp_8192
204
205       app_level_protocol() = binary()
206
207       protocol_extensions() =
208           #{renegotiation_info => binary(),
209             signature_algs => signature_algs(),
210             alpn => app_level_protocol(),
211             srp => binary(),
212             next_protocol => app_level_protocol(),
213             ec_point_formats => [0..2],
214             elliptic_curves => [public_key:oid()],
215             sni => hostname()}
216
217       error_alert() =
218           {tls_alert, {tls_alert(), Description :: string()}}
219
220       tls_alert() =
221           close_notify |
222           unexpected_message |
223           bad_record_mac |
224           record_overflow |
225           handshake_failure |
226           bad_certificate |
227           unsupported_certificate |
228           certificate_revoked |
229           certificate_expired |
230           certificate_unknown |
231           illegal_parameter |
232           unknown_ca |
233           access_denied |
234           decode_error |
235           decrypt_error |
236           export_restriction |
237           protocol_version |
238           insufficient_security |
239           internal_error |
240           inappropriate_fallback |
241           user_canceled |
242           no_renegotiation |
243           unsupported_extension |
244           certificate_unobtainable |
245           unrecognized_name |
246           bad_certificate_status_response |
247           bad_certificate_hash_value |
248           unknown_psk_identity |
249           no_application_protocol
250
251       reason() = any()
252
253   TLS/DTLS OPTION DESCRIPTIONS - COMMON for SERVER and CLIENT
254       common_option() =
255           {protocol, protocol()} |
256           {handshake, handshake_completion()} |
257           {cert, cert()} |
258           {certfile, cert_pem()} |
259           {key, key()} |
260           {keyfile, key_pem()} |
261           {password, key_password()} |
262           {ciphers, cipher_suites()} |
263           {secure_renegotiate, secure_renegotiation()} |
264           {depth, allowed_cert_chain_length()} |
265           {verify_fun, custom_verify()} |
266           {crl_check, crl_check()} |
267           {crl_cache, crl_cache_opts()} |
268           {max_handshake_size, handshake_size()} |
269           {partial_chain, root_fun()} |
270           {versions, protocol_versions()} |
271           {user_lookup_fun, custom_user_lookup()} |
272           {log_alert, log_alert()} |
273           {hibernate_after, hibernate_after()} |
274           {padding_check, padding_check()} |
275           {beast_mitigation, beast_mitigation()} |
276           {ssl_imp, ssl_imp()}
277
278       protocol() = tls | dtls
279
280              Choose TLS or DTLS protocol for the  transport  layer  security.
281              Defaults  to tls. For DTLS other transports than UDP are not yet
282              supported.
283
284       handshake_completion() = hello | full
285
286              Defaults to full. If hello is specified the handshake will pause
287              after  the  hello  message  and give the user a possibility make
288              decisions based on hello extensions before continuing or  abort‐
289              ing  the  handshake  by  calling  handshake_continue/3 or  hand‐
290              shake_cancel/1
291
292       cert() = public_key:der_encoded()
293
294              The DER-encoded users certificate. If this option  is  supplied,
295              it overrides option certfile.
296
297       cert_pem() = file:filename()
298
299              Path to a file containing the user certificate on PEM format.
300
301       key() =
302           {'RSAPrivateKey' |
303            'DSAPrivateKey' |
304            'ECPrivateKey' |
305            'PrivateKeyInfo',
306            public_key:der_encoded()} |
307           #{algorithm := rsa | dss | ecdsa,
308             engine := crypto:engine_ref(),
309             key_id := crypto:key_id(),
310             password => crypto:password()}
311
312              The DER-encoded user's private key or a map refering to a crypto
313              engine and its key reference that  optionally  can  be  password
314              protected,  seealso   crypto:engine_load/4   and  Crypto's Users
315              Guide. If this option is supplied, it overrides option keyfile.
316
317       key_pem() = file:filename()
318
319              Path to the file containing the user's private PEM-encoded  key.
320              As  PEM-files  can contain several entries, this option defaults
321              to the same file as given by option certfile.
322
323       key_password() = string()
324
325              String containing the user's password. Only used if the  private
326              keyfile is password-protected.
327
328       cipher_suites() = ciphers()
329
330              Supported  cipher  suites.  The  function cipher_suites/2 can be
331              used  to  find  all  ciphers  that  are  supported  by  default.
332              cipher_suites(all,  'tlsv1.2')  can be called to find all avail‐
333              able cipher suites. Pre-Shared Key  (RFC  4279  and  RFC  5487),
334              Secure Remote Password (RFC 5054), RC4, 3DES, DES cipher suites,
335              and anonymous cipher suites only work if explicitly  enabled  by
336              this option; they are supported/enabled by the peer also. Anony‐
337              mous cipher suites are supported for testing purposes  only  and
338              are not be used when security matters.
339
340       secure_renegotiation() = boolean()
341
342              Specifies  if to reject renegotiation attempt that does not live
343              up to RFC 5746. By default secure_renegotiate is  set  to  true,
344              that  is,  secure  renegotiation  is  enforced.  If set to false
345              secure renegotiation will still be  used  if  possible,  but  it
346              falls  back  to insecure renegotiation if the peer does not sup‐
347              port RFC 5746.
348
349       allowed_cert_chain_length() = integer()
350
351              Maximum number of non-self-issued intermediate certificates that
352              can  follow  the peer certificate in a valid certification path.
353              So, if depth is 0 the PEER must be signed by the trusted ROOT-CA
354              directly;  if 1 the path can be PEER, CA, ROOT-CA; if 2 the path
355              can be PEER, CA, CA, ROOT-CA, and so on. The default value is 1.
356
357       custom_verify() =
358           {Verifyfun :: function(), InitialUserState :: term()}
359
360              The verification fun is to be defined as follows:
361
362              fun(OtpCert :: #'OTPCertificate'{}, Event :: {bad_cert, Reason :: atom() |
363                           {revoked, atom()}} |
364                        {extension, #'Extension'{}}, InitialUserState :: term()) ->
365                   {valid, UserState :: term()} | {valid_peer, UserState :: term()} |
366                   {fail, Reason :: term()} | {unknown, UserState :: term()}.
367
368
369              The verification fun is called during the  X509-path  validation
370              when  an error or an extension unknown to the SSL application is
371              encountered. It is also called when a certificate is  considered
372              valid by the path validation to allow access to each certificate
373              in the path to the user application. It  differentiates  between
374              the peer certificate and the CA certificates by using valid_peer
375              or valid as second argument to the  verification  fun.  See  the
376              public_key  User's  Guide  for definition of #'OTPCertificate'{}
377              and #'Extension'{}.
378
379                * If the verify callback fun returns {fail, Reason}, the veri‐
380                  fication process is immediately stopped, an alert is sent to
381                  the peer, and the TLS/DTLS handshake terminates.
382
383                * If the verify callback fun returns {valid,  UserState},  the
384                  verification process continues.
385
386                * If  the  verify  callback  fun  always returns {valid, User‐
387                  State}, the TLS/DTLS handshake does not terminate  regarding
388                  verification failures and the connection is established.
389
390                * If called with an extension unknown to the user application,
391                  return value {unknown, UserState} is to be used.
392
393                  Note that if the fun returns unknown for an extension marked
394                  as critical, validation will fail.
395
396              Default option verify_fun in verify_peer mode:
397
398              {fun(_,{bad_cert, _} = Reason, _) ->
399                    {fail, Reason};
400                  (_,{extension, _}, UserState) ->
401                    {unknown, UserState};
402                  (_, valid, UserState) ->
403                    {valid, UserState};
404                  (_, valid_peer, UserState) ->
405                       {valid, UserState}
406               end, []}
407
408
409              Default option verify_fun in mode verify_none:
410
411              {fun(_,{bad_cert, _}, UserState) ->
412                    {valid, UserState};
413                  (_,{extension, #'Extension'{critical = true}}, UserState) ->
414                    {valid, UserState};
415                  (_,{extension, _}, UserState) ->
416                    {unknown, UserState};
417                  (_, valid, UserState) ->
418                    {valid, UserState};
419                  (_, valid_peer, UserState) ->
420                       {valid, UserState}
421               end, []}
422
423
424              The possible path validation errors are given on form {bad_cert,
425              Reason} where Reason is:
426
427                unknown_ca:
428                  No trusted CA was found in the trusted store. The trusted CA
429                  is normally a so called ROOT CA, which is a self-signed cer‐
430                  tificate. Trust  can  be  claimed  for  an  intermediate  CA
431                  (trusted anchor does not have to be self-signed according to
432                  X-509) by using option partial_chain.
433
434                selfsigned_peer:
435                  The chain consisted only of one self-signed certificate.
436
437                PKIX X-509-path validation error:
438                  For possible reasons, see public_key:pkix_path_validation/3
439
440       crl_check() = boolean() | peer | best_effort
441
442              Perform CRL (Certificate Revocation  List)  verification   (pub‐
443              lic_key:pkix_crls_validate/3) on all the certificates during the
444              path validation (public_key:pkix_path_validation/3)  of the cer‐
445              tificate chain. Defaults to false.
446
447                peer:
448                  check is only performed on the peer certificate.
449
450                best_effort:
451                  if  certificate  revocation  status can not be determined it
452                  will be accepted as valid.
453
454              The CA certificates specified for the connection will be used to
455              construct the certificate chain validating the CRLs.
456
457              The  CRLs  will  be  fetched from a local or external cache. See
458              ssl_crl_cache_api(3).
459
460       crl_cache_opts() = [term()]
461
462              Specify how to perform lookup and caching of certificate revoca‐
463              tion  lists.  Module  defaults  to ssl_crl_cache with  DbHandle
464              being internal and an empty argument list.
465
466              There are two implementations available:
467
468                ssl_crl_cache:
469                  This module maintains a cache of CRLs. CRLs can be added  to
470                  the  cache  using  the  function ssl_crl_cache:insert/1, and
471                  optionally automatically fetched through HTTP if the follow‐
472                  ing argument is specified:
473
474                  {http, timeout()}:
475                    Enables  fetching  of  CRLs  specified as http URIs inX509
476                    certificate extensions. Requires the  OTP  inets  applica‐
477                    tion.
478
479                ssl_crl_hash_dir:
480                  This  module  makes use of a directory where CRLs are stored
481                  in files named by the hash of the issuer name.
482
483                  The file names consist of eight hexadecimal digits  followed
484                  by  .rN,  where  N  is an integer, e.g. 1a2b3c4d.r0. For the
485                  first version of the CRL, N starts at zero, and for each new
486                  version,  N  is  incremented  by  one.  The  OpenSSL utility
487                  c_rehash creates symlinks according to this pattern.
488
489                  For a given hash value, this module  finds  all  consecutive
490                  .r* files starting from zero, and those files taken together
491                  make up the revocation  list.  CRL  files  whose  nextUpdate
492                  fields are in the past, or that are issued by a different CA
493                  that happens to have the same name hash, are excluded.
494
495                  The following argument is required:
496
497                  {dir, string()}:
498                    Specifies the directory in which the CRLs can be found.
499
500       root_fun() = function()
501
502              fun(Chain::[public_key:der_encoded()]) ->
503                   {trusted_ca, DerCert::public_key:der_encoded()} | unknown_ca}
504
505
506              Claim an intermediate CA in the chain as trusted. TLS then  per‐
507              forms  public_key:pkix_path_validation/3 with the selected CA as
508              trusted anchor and the rest of the chain.
509
510       protocol_versions() = [protocol_version()]
511
512              TLS protocol versions supported by started clients and  servers.
513              This  option overrides the application environment option proto‐
514              col_version and dtls_protocol_version. If the environment option
515              is  not  set,  it defaults to all versions, except SSL-3.0, sup‐
516              ported by the SSL application. See also ssl(6).
517
518       custom_user_lookup() =
519           {Lookupfun :: function(), UserState :: term()}
520
521              The lookup fun is to defined as follows:
522
523              fun(psk, PSKIdentity ::string(), UserState :: term()) ->
524                   {ok, SharedSecret :: binary()} | error;
525              fun(srp, Username :: string(), UserState :: term()) ->
526                   {ok, {SRPParams :: srp_param_type(), Salt :: binary(),
527                         DerivedKey :: binary()}} | error.
528
529
530              For Pre-Shared Key (PSK) cipher suites, the lookup fun is called
531              by  the  client  and server to determine the shared secret. When
532              called by the client, PSKIdentity is set to the  hint  presented
533              by  the server or to undefined. When called by the server, PSKI‐
534              dentity is the identity presented by the client.
535
536              For Secure Remote Password (SRP), the fun is only  used  by  the
537              server to obtain parameters that it uses to generate its session
538              keys. DerivedKey is to be derived according  to   RFC  2945  and
539              RFC  5054: crypto:sha([Salt, crypto:sha([Username, <<$:>>, Pass‐
540              word])])
541
542       session_id() = binary()
543
544              Identifies a TLS session.
545
546       log_alert() = boolean()
547
548              If set to false, error reports are not displayed.
549
550       hibernate_after() = timeout()
551
552              When an integer-value  is  specified,  TLS/DTLS-connection  goes
553              into  hibernation  after the specified number of milliseconds of
554              inactivity, thus reducing its memory footprint.  When  undefined
555              is  specified (this is the default), the process never goes into
556              hibernation.
557
558       handshake_size() = integer()
559
560              Integer (24 bits unsigned). Used to limit the size of valid  TLS
561              handshake packets to avoid DoS attacks. Defaults to 256*1024.
562
563       padding_check() = boolean()
564
565              Affects  TLS-1.0  connections only. If set to false, it disables
566              the block cipher padding check to be able to  interoperate  with
567              legacy software.
568
569          Warning:
570              Using  {padding_check,  boolean()}  makes  TLS vulnerable to the
571              Poodle attack.
572
573
574       beast_mitigation() = one_n_minus_one | zero_n | disabled
575
576              Affects SSL-3.0 and TLS-1.0 connections only. Used to change the
577              BEAST  mitigation strategy to interoperate with legacy software.
578              Defaults to one_n_minus_one.
579
580              one_n_minus_one - Perform 1/n-1 BEAST mitigation.
581
582              zero_n - Perform 0/n BEAST mitigation.
583
584              disabled - Disable BEAST mitigation.
585
586          Warning:
587              Using {beast_mitigation, disabled} makes SSL-3.0 or TLS-1.0 vul‐
588              nerable to the BEAST attack.
589
590
591       ssl_imp() = new | old
592
593              Deprecated since OTP-17, has no affect.
594
595   TLS/DTLS OPTION DESCRIPTIONS - CLIENT
596       client_option() =
597           {verify, client_verify_type()} |
598           {reuse_session, client_reuse_session()} |
599           {reuse_sessions, client_reuse_sessions()} |
600           {cacerts, client_cacerts()} |
601           {cacertfile, client_cafile()} |
602           {alpn_advertised_protocols, client_alpn()} |
603           {client_preferred_next_protocols,
604            client_preferred_next_protocols()} |
605           {psk_identity, client_psk_identity()} |
606           {srp_identity, client_srp_identity()} |
607           {server_name_indication, sni()} |
608           {customize_hostname_check, customize_hostname_check()} |
609           {signature_algs, client_signature_algs()} |
610           {fallback, fallback()}
611
612       client_verify_type() = verify_type()
613
614              In  mode  verify_none  the  default  behavior  is  to  allow all
615              x509-path validation errors. See also option verify_fun.
616
617       client_reuse_session() = session_id()
618
619              Reuses a specific session earlier saved  with  the  option  {re‐
620              use_sessions, save} since OTP-21.3
621
622       client_reuse_sessions() = boolean() | save
623
624              When  save  is specified a new connection will be negotiated and
625              saved for later reuse. The session ID can be fetched  with  con‐
626              nection_information/2 and used with the client option reuse_ses‐
627              sion The boolean value true specifies that if possible,  automa‐
628              tized  session reuse will be performed. If a new session is cre‐
629              ated, and is unique in regard to previous  stored  sessions,  it
630              will be saved for possible later reuse. Since OTP-21.3
631
632       client_cacerts() = [public_key:der_encoded()]
633
634              The DER-encoded trusted certificates. If this option is supplied
635              it overrides option cacertfile.
636
637       client_cafile() = file:filename()
638
639              Path to a file containing PEM-encoded CA  certificates.  The  CA
640              certificates  are  used  during  server  authentication and when
641              building the client certificate chain.
642
643       client_alpn() = [app_level_protocol()]
644
645              The list of protocols supported by the client to be sent to  the
646              server  to be used for an Application-Layer Protocol Negotiation
647              (ALPN). If the server supports ALPN then it will choose a proto‐
648              col from this list; otherwise it will fail the connection with a
649              "no_application_protocol" alert. A server that does not  support
650              ALPN will ignore this value.
651
652              The list of protocols must not contain an empty binary.
653
654              The  negotiated  protocol  can  be  retrieved  using the negoti‐
655              ated_protocol/1 function.
656
657       client_preferred_next_protocols() =
658           {Precedence :: server | client,
659            ClientPrefs :: [app_level_protocol()]} |
660           {Precedence :: server | client,
661            ClientPrefs :: [app_level_protocol()],
662            Default :: app_level_protocol()}
663
664              Indicates that the client is to try  to  perform  Next  Protocol
665              Negotiation.
666
667              If  precedence  is  server, the negotiated protocol is the first
668              protocol to be shown on the server  advertised  list,  which  is
669              also on the client preference list.
670
671              If  precedence  is  client, the negotiated protocol is the first
672              protocol to be shown on the client  preference  list,  which  is
673              also on the server advertised list.
674
675              If the client does not support any of the server advertised pro‐
676              tocols or the server  does  not  advertise  any  protocols,  the
677              client  falls  back  to the first protocol in its list or to the
678              default protocol (if a default is supplied). If the server  does
679              not support Next Protocol Negotiation, the connection terminates
680              if no default protocol is supplied.
681
682       client_psk_identity() = psk_identity()
683
684              Specifies the identity the client presents to  the  server.  The
685              matching secret is found by calling user_lookup_fun
686
687       client_srp_identity() = srp_identity()
688
689              Specifies  the  username  and password to use to authenticate to
690              the server.
691
692       sni() = hostname() | disable
693
694              Specify the hostname to be used in TLS  Server  Name  Indication
695              extension. If not specified it will default to the Host argument
696              of connect/[3,4] unless it is of type inet:ipaddress().
697
698              The HostName will also be used in the hostname  verification  of
699              the peer certificate using public_key:pkix_verify_hostname/2.
700
701              The  special  value  disable prevents the Server Name Indication
702              extension from being sent and disables the hostname verification
703              check public_key:pkix_verify_hostname/2
704
705       customize_hostname_check() = list()
706
707              Customizes the hostname verification of the peer certificate, as
708              different protocols that use TLS such as HTTP or LDAP  may  want
709              to   do   it   differently,   for   possible  options  see  pub‐
710              lic_key:pkix_verify_hostname/3
711
712       fallback() = boolean()
713
714              Send special cipher suite TLS_FALLBACK_SCSV to  avoid  undesired
715              TLS version downgrade. Defaults to false
716
717          Warning:
718              Note  this  option  is not needed in normal TLS usage and should
719              not be used to implement new clients. But  legacy  clients  that
720              retries connections in the following manner
721
722               ssl:connect(Host,  Port,  [...{versions,  ['tlsv2',  'tlsv1.1',
723              'tlsv1', 'sslv3']}])
724
725               ssl:connect(Host,  Port,  [...{versions,  [tlsv1.1',   'tlsv1',
726              'sslv3']}, {fallback, true}])
727
728               ssl:connect(Host,  Port,  [...{versions,  ['tlsv1',  'sslv3']},
729              {fallback, true}])
730
731               ssl:connect(Host, Port, [...{versions,  ['sslv3']},  {fallback,
732              true}])
733
734              may  use  it to avoid undesired TLS version downgrade. Note that
735              TLS_FALLBACK_SCSV must also be supported by the server  for  the
736              prevention to work.
737
738
739       client_signature_algs() = signature_algs()
740
741              In  addition  to  the  algorithms negotiated by the cipher suite
742              used for key exchange, payload encryption,  message  authentica‐
743              tion  and pseudo random calculation, the TLS signature algorithm
744              extension Section 7.4.1.4.1 in RFC 5246 may be  used,  from  TLS
745              1.2,  to  negotiate  which signature algorithm to use during the
746              TLS handshake. If no lower TLS versions than 1.2 are  supported,
747              the  client  will  send a TLS signature algorithm extension with
748              the algorithms specified by this option. Defaults to
749
750              [
751              %% SHA2
752              {sha512, ecdsa},
753              {sha512, rsa},
754              {sha384, ecdsa},
755              {sha384, rsa},
756              {sha256, ecdsa},
757              {sha256, rsa},
758              {sha224, ecdsa},
759              {sha224, rsa},
760              %% SHA
761              {sha, ecdsa},
762              {sha, rsa},
763              {sha, dsa},
764              ]
765
766              The algorithms should be in the preferred order. Selected signa‐
767              ture  algorithm  can  restrict  which hash functions that may be
768              selected. Default support for {md5, rsa} removed in ssl-8.0
769
770   TLS/DTLS OPTION DESCRIPTIONS - SERVER
771       server_option() =
772           {cacerts, server_cacerts()} |
773           {cacertfile, server_cafile()} |
774           {dh, dh_der()} |
775           {dhfile, dh_file()} |
776           {verify, server_verify_type()} |
777           {fail_if_no_peer_cert, fail_if_no_peer_cert()} |
778           {reuse_sessions, server_reuse_sessions()} |
779           {reuse_session, server_reuse_session()} |
780           {alpn_preferred_protocols, server_alpn()} |
781           {next_protocols_advertised, server_next_protocol()} |
782           {psk_identity, server_psk_identity()} |
783           {honor_cipher_order, boolean()} |
784           {sni_hosts, sni_hosts()} |
785           {sni_fun, sni_fun()} |
786           {honor_cipher_order, honor_cipher_order()} |
787           {honor_ecc_order, honor_ecc_order()} |
788           {client_renegotiation, client_renegotiation()} |
789           {signature_algs, server_signature_algs()}
790
791       server_cacerts() = [public_key:der_encoded()]
792
793              The DER-encoded trusted certificates. If this option is supplied
794              it overrides option cacertfile.
795
796       server_cafile() = file:filename()
797
798              Path  to  a  file containing PEM-encoded CA certificates. The CA
799              certificates are used to build the server certificate chain  and
800              for  client authentication. The CAs are also used in the list of
801              acceptable client CAs passed to the client when a certificate is
802              requested.  Can  be  omitted  if  there is no need to verify the
803              client and if there are no intermediate CAs for the server  cer‐
804              tificate.
805
806       dh_der() = binary()
807
808              The  DER-encoded  Diffie-Hellman  parameters.  If  specified, it
809              overrides option dhfile.
810
811       dh_file() = file:filename()
812
813              Path to a file containing PEM-encoded Diffie Hellman  parameters
814              to  be used by the server if a cipher suite using Diffie Hellman
815              key exchange is negotiated. If not specified, default parameters
816              are used.
817
818       server_verify_type() = verify_type()
819
820              A  server only does x509-path validation in mode verify_peer, as
821              it then sends a certificate request to the client (this  message
822              is  not  sent if the verify option is verify_none). You can then
823              also want to specify option fail_if_no_peer_cert.
824
825       fail_if_no_peer_cert() = boolean()
826
827              Used together with {verify, verify_peer} by an TLS/DTLS  server.
828              If  set  to true, the server fails if the client does not have a
829              certificate to send, that is, sends an empty certificate. If set
830              to  false, it fails only if the client sends an invalid certifi‐
831              cate (an empty certificate is  considered  valid).  Defaults  to
832              false.
833
834       server_reuse_sessions() = boolean()
835
836              The  boolean  value true specifies that the server will agree to
837              reuse sessions. Setting it to false will result in an empty ses‐
838              sion  table, that is no sessions will be reused. See also option
839              reuse_session
840
841       server_reuse_session() = function()
842
843              Enables the TLS/DTLS server to have a local policy for  deciding
844              if  a  session  is  to  be reused or not. Meaningful only if re‐
845              use_sessions is set to true. SuggestedSessionId is  a  binary(),
846              PeerCert is a DER-encoded certificate, Compression is an enumer‐
847              ation integer, and CipherSuite is of type ciphersuite().
848
849       server_alpn() = [app_level_protocol()]
850
851              Indicates the server will try to perform Application-Layer  Pro‐
852              tocol Negotiation (ALPN).
853
854              The  list  of  protocols is in order of preference. The protocol
855              negotiated will be the first in the list that matches one of the
856              protocols  advertised by the client. If no protocol matches, the
857              server will fail the connection with a "no_application_protocol"
858              alert.
859
860              The  negotiated  protocol  can  be  retrieved  using the negoti‐
861              ated_protocol/1 function.
862
863       server_next_protocol() = [app_level_protocol()]
864
865              List of protocols to send to the client if the client  indicates
866              that  it  supports  the  Next Protocol extension. The client can
867              select a protocol that is not on this list. The list  of  proto‐
868              cols  must not contain an empty binary. If the server negotiates
869              a  Next  Protocol,  it  can  be  accessed  using   the   negoti‐
870              ated_next_protocol/1 method.
871
872       server_psk_identity() = psk_identity()
873
874              Specifies the server identity hint, which the server presents to
875              the client.
876
877       honor_cipher_order() = boolean()
878
879              If set to true, use the server preference for cipher  selection.
880              If set to false (the default), use the client preference.
881
882       sni_hosts() =
883           [{hostname(), [server_option() | common_option()]}]
884
885              If  the  server receives a SNI (Server Name Indication) from the
886              client matching a host listed in the sni_hosts option, the  spe‐
887              cific  options  for that host will override previously specified
888              options. The option sni_fun, and sni_hosts are  mutually  exclu‐
889              sive.
890
891       sni_fun() = function()
892
893              If  the  server receives a SNI (Server Name Indication) from the
894              client,  the  given  function  will  be   called   to   retrieve
895              [server_option()]   for the indicated server. These options will
896              be merged into predefined [server_option()]  list. The  function
897              should   be   defined   as:   fun(ServerName   ::  string())  ->
898              [server_option()]  and can be specified as a fun or as named fun
899              module:function/1 The option sni_fun, and sni_hosts are mutually
900              exclusive.
901
902       client_renegotiation() = boolean()
903
904              In protocols that support  client-initiated  renegotiation,  the
905              cost  of resources of such an operation is higher for the server
906              than the client. This can act as a vector for denial of  service
907              attacks.  The SSL application already takes measures to counter-
908              act such attempts, but  client-initiated  renegotiation  can  be
909              strictly  disabled  by setting this option to false. The default
910              value is true. Note that disabling renegotiation can  result  in
911              long-lived  connections  becoming  unusable due to limits on the
912              number of messages the underlying cipher suite can encipher.
913
914       honor_cipher_order() = boolean()
915
916              If true, use the server's preference for  cipher  selection.  If
917              false (the default), use the client's preference.
918
919       honor_ecc_order() = boolean()
920
921              If true, use the server's preference for ECC curve selection. If
922              false (the default), use the client's preference.
923
924       server_signature_algs() = signature_algs()
925
926              The algorithms  specified  by  this  option  will  be  the  ones
927              accepted  by  the  server  in a signature algorithm negotiation,
928              introduced in TLS-1.2. The algorithms will also  be  offered  to
929              the  client  if  a  client  certificate  is  requested. For more
930              details see the corresponding client option.
931

EXPORTS

933       append_cipher_suites(Deferred, Suites) -> ciphers()
934
935              Types:
936
937                 Deferred = ciphers() | cipher_filters()
938                 Suites = ciphers()
939
940              Make Deferred suites become the least preferred suites, that  is
941              put them at the end of the cipher suite list Suites after remov‐
942              ing them from Suites if present.  Deferred  may  be  a  list  of
943              cipher  suits or a list of filters in which case the filters are
944              use on Suites to extract the Deferred cipher list.
945
946       cipher_suites() -> [old_cipher_suite()] | [string()]
947
948       cipher_suites(Type) -> [old_cipher_suite() | string()]
949
950              Types:
951
952                 Type = erlang | openssl | all
953
954              Deprecated in OTP 21, use cipher_suites/2 instead.
955
956       cipher_suites(Supported, Version) -> ciphers()
957
958              Types:
959
960                 Supported = default | all | anonymous
961                 Version = protocol_version()
962
963              Returns all default or all supported (except anonymous), or  all
964              anonymous cipher suites for a TLS version
965
966       eccs() -> NamedCurves
967
968       eccs(Version) -> NamedCurves
969
970              Types:
971
972                 Version = protocol_version()
973                 NamedCurves = [named_curve()]
974
975              Returns  a list of supported ECCs. eccs() is equivalent to call‐
976              ing eccs(Protocol) with all supported protocols and  then  dedu‐
977              plicating the output.
978
979       clear_pem_cache() -> ok
980
981              PEM  files,  used by ssl API-functions, are cached. The cache is
982              regularly checked to see if any cache entries should be  invali‐
983              dated,  however  this function provides a way to unconditionally
984              clear the whole cache.
985
986       connect(TCPSocket, TLSOptions) ->
987                  {ok, sslsocket()} |
988                  {error, reason()} |
989                  {option_not_a_key_value_tuple, any()}
990
991       connect(TCPSocket, TLSOptions, Timeout) ->
992                  {ok, sslsocket()} | {error, reason()}
993
994              Types:
995
996                 TCPSocket = socket()
997                 TLSOptions = [tls_client_option()]
998                 Timeout = timeout()
999
1000              Upgrades a gen_tcp, or equivalent, connected socket  to  an  TLS
1001              socket, that is, performs the client-side TLS handshake.
1002
1003          Note:
1004              If   the   option  verify  is  set  to  verify_peer  the  option
1005              server_name_indication shall also be specified, if it is not  no
1006              Server   Name  Indication  extension  will  be  sent,  and  pub‐
1007              lic_key:pkix_verify_hostname/2  will  be  called  with  the  IP-
1008              address  of  the connection as ReferenceID, which is proably not
1009              what you want.
1010
1011
1012              If the option {handshake, hello} is used the handshake is paused
1013              after  receiving  the  server  hello  message  and  the  success
1014              response is {ok, SslSocket, Ext}  instead  of  {ok,  SslSocket}.
1015              Thereafter  the  handshake  is  continued or canceled by calling
1016              handshake_continue/3 or handshake_cancel/1.
1017
1018              If the option active is set to once, true or an  integer  value,
1019              the  process  owning the sslsocket will receive messages of type
1020              active_msgs()
1021
1022       connect(Host, Port, TLSOptions) ->
1023                  {ok, sslsocket()} |
1024                  {ok, sslsocket(), Ext :: protocol_extensions()} |
1025                  {error, reason()} |
1026                  {option_not_a_key_value_tuple, any()}
1027
1028       connect(Host, Port, TLSOptions, Timeout) ->
1029                  {ok, sslsocket()} |
1030                  {ok, sslsocket(), Ext :: protocol_extensions()} |
1031                  {error, reason()} |
1032                  {option_not_a_key_value_tuple, any()}
1033
1034              Types:
1035
1036                 Host = host()
1037                 Port = inet:port_number()
1038                 TLSOptions = [tls_client_option()]
1039                 Timeout = timeout()
1040
1041              Opens an TLS/DTLS connection to Host, Port.
1042
1043              When the option verify is set  to  verify_peer  the  check  pub‐
1044              lic_key:pkix_verify_hostname/2  will be performed in addition to
1045              the usual x509-path validation checks. If the  check  fails  the
1046              error  {bad_cert,  hostname_check_failed}  will be propagated to
1047              the path validation fun verify_fun, where it is possible  to  do
1048              customized  checks  by  using the full possibilities of the pub‐
1049              lic_key:pkix_verify_hostname/3    API.    When    the     option
1050              server_name_indication  is  provided,  its  value (the DNS name)
1051              will be  used  as  ReferenceID  to  public_key:pkix_verify_host‐
1052              name/2. When no server_name_indication option is given, the Host
1053              argument will be used as Server Name Indication  extension.  The
1054              Host  argument  will  also  be used for the public_key:pkix_ver‐
1055              ify_hostname/2  check  and  if   the   Host   argument   is   an
1056              inet:ip_address()  the  ReferenceID  used  for the check will be
1057              {ip, Host} otherwise dns_id will be assumed with a  fallback  to
1058              ip if that fails.
1059
1060          Note:
1061              According  to  good  practices  certificates  should not use IP-
1062              addresses as "server names". It would be very surprising if this
1063              happen outside a closed network.
1064
1065
1066              If the option {handshake, hello} is used the handshake is paused
1067              after  receiving  the  server  hello  message  and  the  success
1068              response  is  {ok,  SslSocket,  Ext} instead of {ok, SslSocket}.
1069              Thereafter the handshake is continued  or  canceled  by  calling
1070              handshake_continue/3 or handshake_cancel/1.
1071
1072              If  the  option active is set to once, true or an integer value,
1073              the process owning the sslsocket will receive messages  of  type
1074              active_msgs()
1075
1076       close(SslSocket) -> ok | {error, Reason}
1077
1078              Types:
1079
1080                 SslSocket = sslsocket()
1081                 Reason = any()
1082
1083              Closes an TLS/DTLS connection.
1084
1085       close(SslSocket, How) -> ok | {ok, port()} | {error, Reason}
1086
1087              Types:
1088
1089                 SslSocket = sslsocket()
1090                 How = timeout() | {NewController :: pid(), timeout()}
1091                 Reason = any()
1092
1093              Closes  or  downgrades an TLS connection. In the latter case the
1094              transport connection will be handed over  to  the  NewController
1095              process  after  receiving the TLS close alert from the peer. The
1096              returned transport socket will have the following  options  set:
1097              [{active, false}, {packet, 0}, {mode, binary}]
1098
1099       controlling_process(SslSocket, NewOwner) -> ok | {error, Reason}
1100
1101              Types:
1102
1103                 SslSocket = sslsocket()
1104                 NewOwner = pid()
1105                 Reason = any()
1106
1107              Assigns  a new controlling process to the SSL socket. A control‐
1108              ling process is the owner of an SSL  socket,  and  receives  all
1109              messages from the socket.
1110
1111       connection_information(SslSocket) ->
1112                                 {ok, Result} | {error, reason()}
1113
1114              Types:
1115
1116                 SslSocket = sslsocket()
1117                 Result = [{OptionName, OptionValue}]
1118                 OptionName = atom()
1119                 OptionValue = any()
1120
1121              Returns  the most relevant information about the connection, ssl
1122              options that are undefined will be filtered out. Note that  val‐
1123              ues  that  affect  the  security  of the connection will only be
1124              returned if explicitly requested by connection_information/2.
1125
1126          Note:
1127              The legacy Item = cipher_suite is still  supported  and  returns
1128              the  cipher suite on its (undocumented) legacy format. It should
1129              be replaced by selected_cipher_suite.
1130
1131
1132       connection_information(SslSocket, Items) ->
1133                                 {ok, Result} | {error, reason()}
1134
1135              Types:
1136
1137                 SslSocket = sslsocket()
1138                 Items = [OptionName]
1139                 Result = [{OptionName, OptionValue}]
1140                 OptionName = atom()
1141                 OptionValue = any()
1142
1143              Returns the requested information items about the connection, if
1144              they are defined.
1145
1146              Note  that  client_random,  server_random  and master_secret are
1147              values that affect the security of connection. Meaningful atoms,
1148              not specified above, are the ssl option names.
1149
1150          Note:
1151              If  only  undefined options are requested the resulting list can
1152              be empty.
1153
1154
1155       filter_cipher_suites(Suites, Filters) -> Ciphers
1156
1157              Types:
1158
1159                 Suites = ciphers()
1160                 Filters = cipher_filters()
1161                 Ciphers = ciphers()
1162
1163              Removes cipher suites if any of  the  filter  functions  returns
1164              false for any part of the cipher suite. This function also calls
1165              default filter functions to make sure the cipher suites are sup‐
1166              ported  by  crypto.  If  no filter function is supplied for some
1167              part the default behaviour is fun(Algorithm) -> true.
1168
1169       format_error(Reason :: {error, Reason}) -> string()
1170
1171              Types:
1172
1173                 Reason = any()
1174
1175              Presents the error returned by an SSL function  as  a  printable
1176              string.
1177
1178       getopts(SslSocket, OptionNames) ->
1179                  {ok, [gen_tcp:option()]} | {error, reason()}
1180
1181              Types:
1182
1183                 SslSocket = sslsocket()
1184                 OptionNames = [gen_tcp:option_name()]
1185
1186              Gets the values of the specified socket options.
1187
1188       getstat(SslSocket) -> {ok, OptionValues} | {error, inet:posix()}
1189
1190       getstat(SslSocket, Options) ->
1191                  {ok, OptionValues} | {error, inet:posix()}
1192
1193              Types:
1194
1195                 SslSocket = sslsocket()
1196                 Options = [inet:stat_option()]
1197                 OptionValues = [{inet:stat_option(), integer()}]
1198
1199              Gets  one  or  more  statistic  options  for  the underlying TCP
1200              socket.
1201
1202              See inet:getstat/2 for statistic options description.
1203
1204       handshake(HsSocket) ->
1205                    {ok, SslSocket} |
1206                    {ok, SslSocket, Ext} |
1207                    {error, Reason}
1208
1209       handshake(HsSocket, Timeout) ->
1210                    {ok, SslSocket} |
1211                    {ok, SslSocket, Ext} |
1212                    {error, Reason}
1213
1214              Types:
1215
1216                 HsSocket = sslsocket()
1217                 Timeout = timeout()
1218                 SslSocket = sslsocket()
1219                 Ext = protocol_extensions()
1220                 Reason = closed | timeout | error_alert()
1221
1222              Performs the SSL/TLS/DTLS server-side handshake.
1223
1224              Returns a new TLS/DTLS socket if the handshake is successful.
1225
1226              If the option active is set to once, true or an  integer  value,
1227              the  process  owning the sslsocket will receive messages of type
1228              active_msgs()
1229
1230       handshake(Socket, Options) ->
1231                    {ok, SslSocket} |
1232                    {ok, SslSocket, Ext} |
1233                    {error, Reason}
1234
1235       handshake(Socket, Options, Timeout) ->
1236                    {ok, SslSocket} |
1237                    {ok, SslSocket, Ext} |
1238                    {error, Reason}
1239
1240              Types:
1241
1242                 Socket = socket() | sslsocket()
1243                 SslSocket = sslsocket()
1244                 Options = [server_option()]
1245                 Timeout = timeout()
1246                 Ext = protocol_extensions()
1247                 Reason = closed | timeout | {options, any()} | error_alert()
1248
1249              If Socket is a ordinary socket(): upgrades a gen_tcp, or equiva‐
1250              lent,  socket  to  an  SSL socket, that is, performs the SSL/TLS
1251              server-side handshake and returns a TLS socket.
1252
1253          Warning:
1254              The Socket shall be in passive  mode  ({active,  false})  before
1255              calling  this  function or else the behavior of this function is
1256              undefined.
1257
1258
1259              If Socket is  an   sslsocket()  :  provides  extra  SSL/TLS/DTLS
1260              options  to  those  specified in listen/2  and then performs the
1261              SSL/TLS/DTLS handshake. Returns a new  TLS/DTLS  socket  if  the
1262              handshake is successful.
1263
1264              If  option  {handshake,  hello}  is  specified  the handshake is
1265              paused after receiving the client hello message and the  success
1266              response  is  {ok,  SslSocket,  Ext} instead of {ok, SslSocket}.
1267              Thereafter the handshake is continued  or  canceled  by  calling
1268              handshake_continue/3 or handshake_cancel/1.
1269
1270              If  the  option active is set to once, true or an integer value,
1271              the process owning the sslsocket will receive messages  of  type
1272              active_msgs()
1273
1274       handshake_cancel(Sslsocket :: #sslsocket{}) -> any()
1275
1276              Cancel the handshake with a fatal USER_CANCELED alert.
1277
1278       handshake_continue(HsSocket, Options) ->
1279                             {ok, SslSocket} | {error, Reason}
1280
1281       handshake_continue(HsSocket, Options, Timeout) ->
1282                             {ok, SslSocket} | {error, Reason}
1283
1284              Types:
1285
1286                 HsSocket = sslsocket()
1287                 Options = [tls_client_option() | tls_server_option()]
1288                 Timeout = timeout()
1289                 SslSocket = sslsocket()
1290                 Reason = closed | timeout | error_alert()
1291
1292              Continue  the  SSL/TLS handshake possiby with new, additional or
1293              changed options.
1294
1295       listen(Port, Options) -> {ok, ListenSocket} | {error, reason()}
1296
1297              Types:
1298
1299                 Port = inet:port_number()
1300                 Options = [tls_server_option()]
1301                 ListenSocket = sslsocket()
1302
1303              Creates an SSL listen socket.
1304
1305       negotiated_protocol(SslSocket) -> {ok, Protocol} | {error, Reason}
1306
1307              Types:
1308
1309                 SslSocket = sslsocket()
1310                 Protocol = binary()
1311                 Reason = protocol_not_negotiated
1312
1313              Returns the protocol negotiated through ALPN or NPN extensions.
1314
1315       peercert(SslSocket) -> {ok, Cert} | {error, reason()}
1316
1317              Types:
1318
1319                 SslSocket = sslsocket()
1320                 Cert = binary()
1321
1322              The peer certificate is returned as a  DER-encoded  binary.  The
1323              certificate can be decoded with public_key:pkix_decode_cert/2
1324
1325       peername(SslSocket) -> {ok, {Address, Port}} | {error, reason()}
1326
1327              Types:
1328
1329                 SslSocket = sslsocket()
1330                 Address = inet:ip_address()
1331                 Port = inet:port_number()
1332
1333              Returns the address and port number of the peer.
1334
1335       prepend_cipher_suites(Preferred, Suites) -> ciphers()
1336
1337              Types:
1338
1339                 Preferred = ciphers() | cipher_filters()
1340                 Suites = ciphers()
1341
1342              Make  Preferred  suites become the most preferred suites that is
1343              put them at the head of  the  cipher  suite  list  Suites  after
1344              removing them from Suites if present. Preferred may be a list of
1345              cipher suits or a list of filters in which case the filters  are
1346              use on Suites to extract the preferred cipher list.
1347
1348       prf(SslSocket, Secret, Label, Seed, WantedLength) ->
1349              {ok, binary()} | {error, reason()}
1350
1351              Types:
1352
1353                 SslSocket = sslsocket()
1354                 Secret = binary() | master_secret
1355                 Label = binary()
1356                 Seed = [binary() | prf_random()]
1357                 WantedLength = integer() >= 0
1358
1359              Uses the Pseudo-Random Function (PRF) of a TLS session to gener‐
1360              ate extra key material. It either  takes  user-generated  values
1361              for  Secret  and  Seed  or  atoms directing it to use a specific
1362              value from the session security parameters.
1363
1364              Can only be used with TLS/DTLS connections;  {error,  undefined}
1365              is returned for SSLv3 connections.
1366
1367       recv(SslSocket, Length) -> {ok, Data} | {error, reason()}
1368
1369       recv(SslSocket, Length, Timeout) -> {ok, Data} | {error, reason()}
1370
1371              Types:
1372
1373                 SslSocket = sslsocket()
1374                 Length = integer()
1375                 Data = binary() | list() | HttpPacket
1376                 Timeout = timeout()
1377                 HttpPacket = any()
1378                   See the description of HttpPacket in erlang:decode_packet/3
1379                   in ERTS.
1380
1381              Receives a packet from a socket in passive mode. A closed socket
1382              is indicated by return value {error, closed}.
1383
1384              Argument  Length  is  meaningful only when the socket is in mode
1385              raw and denotes the number of bytes to read. If Length = 0,  all
1386              available  bytes  are  returned.  If  Length > 0, exactly Length
1387              bytes are returned, or an error; possibly discarding  less  than
1388              Length  bytes of data when the socket gets closed from the other
1389              side.
1390
1391              Optional argument Timeout specifies a time-out in  milliseconds.
1392              The default value is infinity.
1393
1394       renegotiate(SslSocket) -> ok | {error, reason()}
1395
1396              Types:
1397
1398                 SslSocket = sslsocket()
1399
1400              Initiates  a  new  handshake.  A notable return value is {error,
1401              renegotiation_rejected} indicating that the peer refused  to  go
1402              through  with  the  renegotiation,  but  the connection is still
1403              active using the previously negotiated session.
1404
1405       send(SslSocket, Data) -> ok | {error, reason()}
1406
1407              Types:
1408
1409                 SslSocket = sslsocket()
1410                 Data = iodata()
1411
1412              Writes Data to SslSocket.
1413
1414              A notable return value is {error, closed}  indicating  that  the
1415              socket is closed.
1416
1417       setopts(SslSocket, Options) -> ok | {error, reason()}
1418
1419              Types:
1420
1421                 SslSocket = sslsocket()
1422                 Options = [gen_tcp:option()]
1423
1424              Sets options according to Options for socket SslSocket.
1425
1426       shutdown(SslSocket, How) -> ok | {error, reason()}
1427
1428              Types:
1429
1430                 SslSocket = sslsocket()
1431                 How = read | write | read_write
1432
1433              Immediately closes a socket in one or two directions.
1434
1435              How  == write means closing the socket for writing, reading from
1436              it is still possible.
1437
1438              To be able to handle that the peer has done a  shutdown  on  the
1439              write side, option {exit_on_close, false} is useful.
1440
1441       ssl_accept(SslSocket) -> ok | {error, Reason}
1442
1443       ssl_accept(Socket, TimeoutOrOptions) ->
1444                     ok | {ok, sslsocket()} | {error, Reason}
1445
1446              Types:
1447
1448                 Socket = sslsocket() | socket()
1449                 TimeoutOrOptions = timeout() | [tls_server_option()]
1450                 Reason = timeout | closed | {options, any()} | error_alert()
1451
1452              Deprecated in OTP 21, use handshake/[1,2] instead.
1453
1454          Note:
1455              handshake/[1,2] always returns a new socket.
1456
1457
1458       ssl_accept(Socket, Options, Timeout) ->
1459                     ok | {ok, sslsocket()} | {error, Reason}
1460
1461              Types:
1462
1463                 Socket = sslsocket() | socket()
1464                 Options = [tls_server_option()]
1465                 Timeout = timeout()
1466                 Reason = timeout | closed | {options, any()} | error_alert()
1467
1468              Deprecated in OTP 21, use handshake/[2,3] instead.
1469
1470          Note:
1471              handshake/[2,3] always returns a new socket.
1472
1473
1474       sockname(SslSocket) -> {ok, {Address, Port}} | {error, reason()}
1475
1476              Types:
1477
1478                 SslSocket = sslsocket()
1479                 Address = inet:ip_address()
1480                 Port = inet:port_number()
1481
1482              Returns the local address and port number of socket SslSocket.
1483
1484       start() -> ok | {error, reason()}
1485       start(Type) -> ok | {error, Reason}
1486
1487              Starts the SSL application. Default type is temporary.
1488
1489       stop() -> ok
1490
1491              Stops the SSL application.
1492
1493       suite_to_str(CipherSuite) -> string()
1494
1495              Types:
1496
1497                 CipherSuite = erl_cipher_suite()
1498
1499              Returns the string representation of a cipher suite.
1500
1501       transport_accept(ListenSocket) ->
1502                           {ok, SslSocket} | {error, reason()}
1503
1504       transport_accept(ListenSocket, Timeout) ->
1505                           {ok, SslSocket} | {error, reason()}
1506
1507              Types:
1508
1509                 ListenSocket = sslsocket()
1510                 Timeout = timeout()
1511                 SslSocket = sslsocket()
1512
1513              Accepts  an incoming connection request on a listen socket. Lis‐
1514              tenSocket must be a socket returned from  listen/2.  The  socket
1515              returned  is  to be passed to  handshake/[2,3] to complete hand‐
1516              shaking, that is, establishing the SSL/TLS/DTLS connection.
1517
1518          Warning:
1519              Most API functions  require  that  the  TLS/DTLS  connection  is
1520              established to work as expected.
1521
1522
1523              The accepted socket inherits the options set for ListenSocket in
1524              listen/2.
1525
1526              The default value for Timeout is infinity. If Timeout is  speci‐
1527              fied  and  no  connection  is  accepted  within  the given time,
1528              {error, timeout} is returned.
1529
1530       versions() -> [VersionInfo]
1531
1532              Types:
1533
1534                 VersionInfo =
1535                     {ssl_app, string()} |
1536                     {supported | available, [tls_version()]} |
1537                     {supported_dtls | available_dtls, [dtls_version()]}
1538
1539              Returns version information relevant for the SSL application.
1540
1541                app_vsn:
1542                  The application version of the SSL application.
1543
1544                supported:
1545                  SSL/TLS versions supported by default. Overridden by a  ver‐
1546                  sion    option    on     connect/[2,3,4],    listen/2,   and
1547                  ssl_accept/[1,2,3]. For the negotiated SSL/TLS version,  see
1548                  connection_information/1 .
1549
1550                supported_dtls:
1551                  DTLS  versions supported by default. Overridden by a version
1552                  option     on      connect/[2,3,4],       listen/2,      and
1553                  ssl_accept/[1,2,3].  For  the  negotiated  DTLS version, see
1554                  connection_information/1 .
1555
1556                available:
1557                  All SSL/TLS versions supported by the SSL  application.  TLS
1558                  1.2 requires sufficient support from the Crypto application.
1559
1560                available_dtls:
1561                  All DTLS versions supported by the SSL application. DTLS 1.2
1562                  requires sufficient support from the Crypto application.
1563

SEE ALSO

1565       inet(3) and gen_tcp(3) gen_udp(3)
1566
1567
1568
1569Ericsson AB                       ssl 9.2.3.2                           ssl(3)
Impressum