1IO::Socket::SSL(3)    User Contributed Perl Documentation   IO::Socket::SSL(3)
2
3
4

NAME

6       IO::Socket::SSL - SSL sockets with IO::Socket interface
7

SYNOPSIS

9           use strict;
10           use IO::Socket::SSL;
11
12           # simple client
13           my $cl = IO::Socket::SSL->new('www.google.com:443');
14           print $cl "GET / HTTP/1.0\r\n\r\n";
15           print <$cl>;
16
17           # simple server
18           my $srv = IO::Socket::SSL->new(
19               LocalAddr => '0.0.0.0:1234',
20               Listen => 10,
21               SSL_cert_file => 'server-cert.pem',
22               SSL_key_file => 'server-key.pem',
23           );
24           $srv->accept;
25

DESCRIPTION

27       IO::Socket::SSL makes using SSL/TLS much easier by wrapping the
28       necessary functionality into the familiar IO::Socket interface and
29       providing secure defaults whenever possible.  This way, existing
30       applications can be made SSL-aware without much effort, at least if you
31       do blocking I/O and don't use select or poll.
32
33       But, under the hood, SSL is a complex beast.  So there are lots of
34       methods to make it do what you need if the default behavior is not
35       adequate.  Because it is easy to inadvertently introduce critical
36       security bugs or just hard to debug problems, I would recommend
37       studying the following documentation carefully.
38
39       The documentation consists of the following parts:
40
41       •   "Essential Information About SSL/TLS"
42
43       •   "Basic SSL Client"
44
45       •   "Basic SSL Server"
46
47       •   "Common Usage Errors"
48
49       •   "Common Problems with SSL"
50
51       •   "Using Non-Blocking Sockets"
52
53       •   "Advanced Usage"
54
55       •   "Integration Into Own Modules"
56
57       •   "Description Of Methods"
58
59       Additional documentation can be found in
60
61       •   IO::Socket::SSL::Intercept - Doing Man-In-The-Middle with SSL
62
63       •   IO::Socket::SSL::Utils - Useful functions for certificates etc
64

Essential Information About SSL/TLS

66       SSL (Secure Socket Layer) or its successor TLS (Transport Layer
67       Security) are protocols to facilitate end-to-end security. These
68       protocols are used when accessing web sites (https), delivering or
69       retrieving email, and in lots of other use cases.  In the following
70       documentation we will refer to both SSL and TLS as simply 'SSL'.
71
72       SSL enables end-to-end security by providing two essential functions:
73
74       Encryption
75           This part encrypts the data for transit between the communicating
76           parties, so that nobody in between can read them. It also provides
77           tamper resistance so that nobody in between can manipulate the
78           data.
79
80       Identification
81           This part makes sure that you talk to the right peer.  If the
82           identification is done incorrectly it is easy to mount man-in-the-
83           middle attacks, e.g. if Alice wants to talk to Bob it would be
84           possible for Mallory to put itself in the middle, so that Alice
85           talks to Mallory and Mallory to Bob.  All the data would still be
86           encrypted, but not end-to-end between Alice and Bob, but only
87           between Alice and Mallory and then between Mallory and Bob.  Thus
88           Mallory would be able to read and modify all traffic between Alice
89           and Bob.
90
91       Identification is the part which is the hardest to understand and the
92       easiest to get wrong.
93
94       With SSL, the Identification is usually done with certificates inside a
95       PKI (Public Key Infrastructure).  These Certificates are comparable to
96       an identity card, which contains information about the owner of the
97       card. The card then is somehow signed by the issuer of the card, the CA
98       (Certificate Agency).
99
100       To verify the identity of the peer the following must be done inside
101       SSL:
102
103       •   Get the certificate from the peer.  If the peer does not present a
104           certificate we cannot verify it.
105
106       •   Check if we trust the certificate, e.g. make sure it's not a
107           forgery.
108
109           We believe that a certificate is not a fake if we either know the
110           certificate already or if we trust the issuer (the CA) and can
111           verify the issuers signature on the certificate.  In reality there
112           is often a hierarchy of certificate agencies and we only directly
113           trust the root of this hierarchy.  In this case the peer not only
114           sends his own certificate, but also all intermediate certificates.
115           Verification will be done by building a trust path from the trusted
116           root up to the peers certificate and checking in each step if the
117           we can verify the issuer's signature.
118
119           This step often causes problems because the client does not know
120           the necessary trusted root certificates. These are usually stored
121           in a system dependent CA store, but often the browsers have their
122           own CA store.
123
124       •   Check if the certificate is still valid.  Each certificate has a
125           lifetime and should not be used after that time because it might be
126           compromised or the underlying cryptography got broken in the mean
127           time.
128
129       •   Check if the subject of the certificate matches the peer.  This is
130           like comparing the picture on the identity card against the person
131           representing the identity card.
132
133           When connecting to a server this is usually done by comparing the
134           hostname used for connecting against the names represented in the
135           certificate.  A certificate might contain multiple names or
136           wildcards, so that it can be used for multiple hosts (e.g.
137           *.example.com and *.example.org).
138
139           Although nobody sane would accept an identity card where the
140           picture does not match the person we see, it is a common
141           implementation error with SSL to omit this check or get it wrong.
142
143       •   Check if the certificate was revoked by the issuer.  This might be
144           the case if the certificate was compromised somehow and now
145           somebody else might use it to claim the wrong identity.  Such
146           revocations happened a lot after the heartbleed attack.
147
148           For SSL there are two ways to verify a revocation, CRL and OCSP.
149           With CRLs (Certificate Revocation List) the CA provides a list of
150           serial numbers for revoked certificates. The client somehow has to
151           download the list (which can be huge) and keep it up to date.  With
152           OCSP (Online Certificate Status Protocol) the client can check a
153           single certificate directly by asking the issuer.
154
155           Revocation is the hardest part of the verification and none of
156           today's browsers get it fully correct. But, they are still better
157           than most other implementations which don't implement revocation
158           checks or leave the hard parts to the developer.
159
160       When accessing a web site with SSL or delivering mail in a secure way
161       the identity is usually only checked one way, e.g. the client wants to
162       make sure it talks to the right server, but the server usually does not
163       care which client it talks to.  But, sometimes the server wants to
164       identify the client too and will request a certificate from the client
165       which the server must verify in a similar way.
166

Basic SSL Client

168       A basic SSL client is simple:
169
170           my $client = IO::Socket::SSL->new('www.example.com:443')
171               or die "error=$!, ssl_error=$SSL_ERROR";
172
173       This will take the OpenSSL default CA store as the store for the
174       trusted CA.  This usually works on UNIX systems.  If there are no
175       certificates in the store it will try use Mozilla::CA which provides
176       the default CAs of Firefox.
177
178       In the default settings, IO::Socket::SSL will use a safer cipher set
179       and SSL version, do a proper hostname check against the certificate,
180       and use SNI (server name indication) to send the hostname inside the
181       SSL handshake. This is necessary to work with servers which have
182       different certificates behind the same IP address.  It will also check
183       the revocation of the certificate with OCSP, but currently only if the
184       server provides OCSP stapling (for deeper checks see "ocsp_resolver"
185       method).
186
187       Lots of options can be used to change ciphers, SSL version, location of
188       CA and much more. See documentation of methods for details.
189
190       With protocols like SMTP it is necessary to upgrade an existing socket
191       to SSL.  This can be done like this:
192
193           my $client = IO::Socket::INET->new('mx.example.com:25') or die $!;
194           # .. read greeting from server
195           # .. send EHLO and read response
196           # .. send STARTTLS command and read response
197           # .. if response was successful we can upgrade the socket to SSL now:
198           IO::Socket::SSL->start_SSL($client,
199               # explicitly set hostname we should use for SNI
200               SSL_hostname => 'mx.example.com'
201           ) or die $SSL_ERROR;
202
203       A more complete example for a simple HTTP client:
204
205           my $client = IO::Socket::SSL->new(
206               # where to connect
207               PeerHost => "www.example.com",
208               PeerPort => "https",
209
210               # certificate verification - VERIFY_PEER is default
211               SSL_verify_mode => SSL_VERIFY_PEER,
212
213               # location of CA store
214               # need only be given if default store should not be used
215               SSL_ca_path => '/etc/ssl/certs', # typical CA path on Linux
216               SSL_ca_file => '/etc/ssl/cert.pem', # typical CA file on BSD
217
218               # or just use default path on system:
219               IO::Socket::SSL::default_ca(), # either explicitly
220               # or implicitly by not giving SSL_ca_*
221
222               # easy hostname verification
223               # It will use PeerHost as default name a verification
224               # scheme as default, which is safe enough for most purposes.
225               SSL_verifycn_name => 'foo.bar',
226               SSL_verifycn_scheme => 'http',
227
228               # SNI support - defaults to PeerHost
229               SSL_hostname => 'foo.bar',
230
231           ) or die "failed connect or ssl handshake: $!,$SSL_ERROR";
232
233           # send and receive over SSL connection
234           print $client "GET / HTTP/1.0\r\n\r\n";
235           print <$client>;
236
237       And to do revocation checks with OCSP (only available with OpenSSL
238       1.0.0 or higher and Net::SSLeay 1.59 or higher):
239
240           # default will try OCSP stapling and check only leaf certificate
241           my $client = IO::Socket::SSL->new($dst);
242
243           # better yet: require checking of full chain
244           my $client = IO::Socket::SSL->new(
245               PeerAddr => $dst,
246               SSL_ocsp_mode => SSL_OCSP_FULL_CHAIN,
247           );
248
249           # even better: make OCSP errors fatal
250           # (this will probably fail with lots of sites because of bad OCSP setups)
251           # also use common OCSP response cache
252           my $ocsp_cache = IO::Socket::SSL::OCSP_Cache->new;
253           my $client = IO::Socket::SSL->new(
254               PeerAddr => $dst,
255               SSL_ocsp_mode => SSL_OCSP_FULL_CHAIN|SSL_OCSP_FAIL_HARD,
256               SSL_ocsp_cache => $ocsp_cache,
257           );
258
259           # disable OCSP stapling in case server has problems with it
260           my $client = IO::Socket::SSL->new(
261               PeerAddr => $dst,
262               SSL_ocsp_mode => SSL_OCSP_NO_STAPLE,
263           );
264
265           # check any certificates which are not yet checked by OCSP stapling or
266           # where we have already cached results. For your own resolving combine
267           # $ocsp->requests with $ocsp->add_response(uri,response).
268           my $ocsp = $client->ocsp_resolver();
269           my $errors = $ocsp->resolve_blocking();
270           if ($errors) {
271               warn "OCSP verification failed: $errors";
272               close($client);
273           }
274

Basic SSL Server

276       A basic SSL server looks similar to other IO::Socket servers, only that
277       it also contains settings for certificate and key:
278
279           # simple server
280           my $server = IO::Socket::SSL->new(
281               # where to listen
282               LocalAddr => '127.0.0.1',
283               LocalPort => 8080,
284               Listen => 10,
285
286               # which certificate to offer
287               # with SNI support there can be different certificates per hostname
288               SSL_cert_file => 'cert.pem',
289               SSL_key_file => 'key.pem',
290           ) or die "failed to listen: $!";
291
292           # accept client
293           my $client = $server->accept or die
294               "failed to accept or ssl handshake: $!,$SSL_ERROR";
295
296       This will automatically use a secure set of ciphers and SSL version and
297       also supports Forward Secrecy with (Elliptic-Curve) Diffie-Hellmann Key
298       Exchange.
299
300       If you are doing a forking or threading server, we recommend that you
301       do the SSL handshake inside the new process/thread so that the master
302       is free for new connections.  We recommend this because a client with
303       improper or slow SSL handshake could make the server block in the
304       handshake which would be bad to do on the listening socket:
305
306           # inet server
307           my $server = IO::Socket::INET->new(
308               # where to listen
309               LocalAddr => '127.0.0.1',
310               LocalPort => 8080,
311               Listen => 10,
312           );
313
314           # accept client
315           my $client = $server->accept or die;
316
317           # SSL upgrade client (in new process/thread)
318           IO::Socket::SSL->start_SSL($client,
319               SSL_server => 1,
320               SSL_cert_file => 'cert.pem',
321               SSL_key_file => 'key.pem',
322           ) or die "failed to ssl handshake: $SSL_ERROR";
323
324       Like with normal sockets, neither forking nor threading servers scale
325       well.  It is recommended to use non-blocking sockets instead, see
326       "Using Non-Blocking Sockets"
327

Common Usage Errors

329       This is a list of typical errors seen with the use of IO::Socket::SSL:
330
331       •   Disabling verification with "SSL_verify_mode".
332
333           As described in "Essential Information About SSL/TLS", a proper
334           identification of the peer is essential and failing to verify makes
335           Man-In-The-Middle attacks possible.
336
337           Nevertheless, lots of scripts and even public modules or
338           applications disable verification, because it is probably the
339           easiest way to make the thing work and usually nobody notices any
340           security problems anyway.
341
342           If the verification does not succeed with the default settings, one
343           can do the following:
344
345           •       Make sure the needed CAs are in the store, maybe use
346                   "SSL_ca_file" or "SSL_ca_path" to specify a different CA
347                   store.
348
349           •       If the validation fails because the certificate is self-
350                   signed and that's what you expect, you can use the
351                   "SSL_fingerprint" option to accept specific leaf
352                   certificates by their certificate or pubkey fingerprint.
353
354           •       If the validation failed because the hostname does not
355                   match and you cannot access the host with the name given in
356                   the certificate, you can use "SSL_verifycn_name" to specify
357                   the hostname you expect in the certificate.
358
359           A common error pattern is also to disable verification if they
360           found no CA store (different modules look at different "default"
361           places).  Because IO::Socket::SSL is now able to provide a usable
362           CA store on most platforms (UNIX, Mac OSX and Windows) it is better
363           to use the defaults provided by IO::Socket::SSL.  If necessary
364           these can be checked with the "default_ca" method.
365
366       •   Polling of SSL sockets (e.g. select, poll and other event loops).
367
368           If you sysread one byte on a normal socket it will result in a
369           syscall to read one byte. Thus, if more than one byte is available
370           on the socket it will be kept in the network stack of your OS and
371           the next select or poll call will return the socket as readable.
372           But, with SSL you don't deliver single bytes. Multiple data bytes
373           are packaged and encrypted together in an SSL frame. Decryption can
374           only be done on the whole frame, so a sysread for one byte actually
375           reads the complete SSL frame from the socket, decrypts it and
376           returns the first decrypted byte. Further sysreads will return more
377           bytes from the same frame until all bytes are returned and the next
378           SSL frame will be read from the socket.
379
380           Thus, in order to decide if you can read more data (e.g. if sysread
381           will block) you must check if there are still data in the current
382           SSL frame by calling "pending" and if there are no data pending you
383           might check the underlying socket with select or poll.  Another way
384           might be if you try to sysread at least 16kByte all the time.
385           16kByte is the maximum size of an SSL frame and because sysread
386           returns data from only a single SSL frame you can guarantee that
387           there are no pending data.
388
389           Additionally, contrary to plain sockets the  data delivered on the
390           socket are not necessarily application payload.  It might be a TLS
391           handshake, it might just be the beginning of a TLS record or it
392           might be TLS session tickets which are send after the TLS handshake
393           in TLS 1.3.  In such situations select will return that data are
394           available for read since it only looks at the plain socket.  A
395           sysread on the IO::Socket::SSL socket will not return any data
396           though since it is an abstraction which only returns application
397           data.  This causes the sysread to hang in case the socket was
398           blocking or to return an error with EAGAIN on non-blocking sockets.
399           Applications using select or similar should therefore set the
400           socket to non-blocking and also expect that the sysread might
401           temporarily fail with EAGAIN.
402
403           See also "Using Non-Blocking Sockets".
404
405       •   Expecting exactly the same behavior as plain sockets.
406
407           IO::Socket::SSL tries to emulate the usual socket behavior as good
408           as possible, but full emulation can not be done. Specifically a
409           read on the SSL socket might also result in a write on the TCP
410           socket or a write on the SSL socket might result in a read on the
411           TCP socket. Also "accept" and close on the SSL socket will result
412           in writing and reading data to the TCP socket too.
413
414           Especially the hidden writes might result in a connection reset if
415           the underlying TCP socket is already closed by the peer. Unless
416           signal PIPE is explicitly handled by the application this will
417           usually result in the application crashing. It is thus recommended
418           to explicitly IGNORE signal PIPE so that the errors get propagated
419           as EPIPE instead of causing a crash of the application.
420
421       •   Set 'SSL_version' or 'SSL_cipher_list' to a "better" value.
422
423           IO::Socket::SSL tries to set these values to reasonable, secure
424           values which are compatible with the rest of the world.  But, there
425           are some scripts or modules out there which tried to be smart and
426           get more secure or compatible settings.  Unfortunately, they did
427           this years ago and never updated these values, so they are still
428           forced to do only 'TLSv1' (instead of also using TLSv12 or TLSv11).
429           Or they set 'HIGH' as the cipher list and thought they were secure,
430           but did not notice that 'HIGH' includes anonymous ciphers, e.g.
431           without identification of the peer.
432
433           So it is recommended to leave the settings at the secure defaults
434           which IO::Socket::SSL sets and which get updated from time to time
435           to better fit the real world.
436
437       •   Make SSL settings inaccessible by the user, together with bad
438           builtin settings.
439
440           Some modules use IO::Socket::SSL, but don't make the SSL settings
441           available to the user. This is often combined with bad builtin
442           settings or defaults (like switching verification off).
443
444           Thus the user needs to hack around these restrictions by using
445           "set_args_filter_hack" or similar.
446
447       •   Use of constants as strings.
448
449           Constants like "SSL_VERIFY_PEER" or "SSL_WANT_READ" should be used
450           as constants and not be put inside quotes, because they represent
451           numerical values.
452
453       •   Forking and handling the socket in parent and child.
454
455           A fork of the process will duplicate the internal user space SSL
456           state of the socket. If both master and child interact with the
457           socket by using their own SSL state strange error messages will
458           happen. Such interaction includes explicit or implicit close of the
459           SSL socket. To avoid this the socket should be explicitly closed
460           with SSL_no_shutdown.
461
462       •   Forking and executing a new process.
463
464           Since the SSL state is stored in user space it will be duplicated
465           by a fork but it will be lost when doing exec. This means it is not
466           possible to simply redirect stdin and stdout for the new process to
467           the SSL socket by duplicating the relevant file handles. Instead
468           explicitly exchanging plain data between child-process and SSL
469           socket are needed.
470

Common Problems with SSL

472       SSL is a complex protocol with multiple implementations and each of
473       these has their own quirks. While most of these implementations work
474       together, it often gets problematic with older versions, minimal
475       versions in load balancers, or plain wrong setups.
476
477       Unfortunately these problems are hard to debug.  Helpful for debugging
478       are a knowledge of SSL internals, wireshark and the use of the debug
479       settings of IO::Socket::SSL and Net::SSLeay, which can both be set with
480       $IO::Socket::SSL::DEBUG.  The following debugs levels are defined, but
481       used not in any consistent way:
482
483       •   0 - No debugging (default).
484
485       •   1 - Print out errors from IO::Socket::SSL and ciphers from
486           Net::SSLeay.
487
488       •   2 - Print also information about call flow from IO::Socket::SSL and
489           progress information from Net::SSLeay.
490
491       •   3 - Print also some data dumps from IO::Socket::SSL and from
492           Net::SSLeay.
493
494       Also, "analyze-ssl.pl" from the ssl-tools repository at
495       <https://github.com/noxxi/p5-ssl-tools>  might be a helpful tool when
496       debugging SSL problems, as do the "openssl" command line tool and a
497       check with a different SSL implementation (e.g. a web browser).
498
499       The following problems are not uncommon:
500
501       •   Bad server setup: missing intermediate certificates.
502
503           It is a regular problem that administrators fail to include all
504           necessary certificates into their server setup, e.g. everything
505           needed to build the trust chain from the trusted root.  If they
506           check the setup with the browser everything looks ok, because
507           browsers work around these problems by caching any intermediate
508           certificates and apply them to new connections if certificates are
509           missing.
510
511           But, fresh browser profiles which have never seen these
512           intermediates cannot fill in the missing certificates and fail to
513           verify; the same is true with IO::Socket::SSL.
514
515       •   Old versions of servers or load balancers which do not understand
516           specific TLS versions or croak on specific data.
517
518           From time to time one encounters an SSL peer, which just closes the
519           connection inside the SSL handshake. This can usually be worked
520           around by downgrading the SSL version, e.g. by setting
521           "SSL_version". Modern Browsers usually deal with such servers by
522           automatically downgrading the SSL version and repeat the connection
523           attempt until they succeed.
524
525           Worse servers do not close the underlying TCP connection but
526           instead just drop the relevant packet. This is harder to detect
527           because it looks like a stalled connection. But downgrading the SSL
528           version often works here too.
529
530           A cause of such problems are often load balancers or security
531           devices, which have hardware acceleration and only a minimal (and
532           less robust) SSL stack. They can often be detected because they
533           support much fewer ciphers than other implementations.
534
535       •   Bad or old OpenSSL versions.
536
537           IO::Socket::SSL uses OpenSSL with the help of the Net::SSLeay
538           library. It is recommend to have a recent version of this library,
539           because it has more features and usually fewer known bugs.
540
541       •   Validation of client certificates fail.
542
543           Make sure that the purpose of the certificate allows use as ssl
544           client (check with "openssl x509 -purpose", that the necessary root
545           certificate is in the path specified by "SSL_ca*" (or the default
546           path) and that any intermediate certificates needed to build the
547           trust chain are sent by the client.
548
549       •   Validation of self-signed certificate fails even if it is given
550           with "SSL_ca*" argument.
551
552           The "SSL_ca*" arguments do not give a general trust store for
553           arbitrary certificates but only specify a store for CA certificates
554           which then can be used to verify other certificates.  This
555           especially means that certificates which are not a CA get simply
556           ignored, notably self-signed certificates which do not also have
557           the CA-flag set.
558
559           This behavior of OpenSSL differs from the more general trust-store
560           concept which can be found in browsers and where it is possible to
561           simply added arbitrary certificates (CA or not) as trusted.
562

Using Non-Blocking Sockets

564       If you have a non-blocking socket, the expected behavior on read,
565       write, accept or connect is to set $! to EWOULDBLOCK if the operation
566       cannot be completed immediately. Note that EWOULDBLOCK is the same as
567       EAGAIN on UNIX systems, but is different on Windows.
568
569       With SSL, handshakes might occur at any time, even within an
570       established connection. In these cases it is necessary to finish the
571       handshake before you can read or write data. This might result in
572       situations where you want to read but must first finish the write of a
573       handshake or where you want to write but must first finish a read.  In
574       these cases $! is set to EAGAIN like expected, and additionally
575       $SSL_ERROR is set to either SSL_WANT_READ or SSL_WANT_WRITE.  Thus if
576       you get EWOULDBLOCK on a SSL socket you must check $SSL_ERROR for
577       SSL_WANT_* and adapt your event mask accordingly.
578
579       Using readline on non-blocking sockets does not make much sense and I
580       would advise against using it.  And, while the behavior is not
581       documented for other IO::Socket classes, it will try to emulate the
582       behavior seen there, e.g. to return the received data instead of
583       blocking, even if the line is not complete. If an unrecoverable error
584       occurs it will return nothing, even if it already received some data.
585
586       Also, I would advise against using "accept" with a non-blocking SSL
587       object because it might block and this is not what most would expect.
588       The reason for this is that "accept" on a non-blocking TCP socket (e.g.
589       IO::Socket::IP, IO::Socket::INET..) results in a new TCP socket which
590       does not inherit the non-blocking behavior of the master socket. And
591       thus, the initial SSL handshake on the new socket inside
592       "IO::Socket::SSL::accept" will be done in a blocking way. To work
593       around this you are safer by doing a TCP accept and later upgrade the
594       TCP socket in a non-blocking way with "start_SSL" and "accept_SSL".
595
596           my $cl = IO::Socket::SSL->new($dst);
597           $cl->blocking(0);
598           my $sel = IO::Select->new($cl);
599           while (1) {
600               # with SSL a call for reading n bytes does not result in reading of n
601               # bytes from the socket, but instead it must read at least one full SSL
602               # frame. If the socket has no new bytes, but there are unprocessed data
603               # from the SSL frame can_read will block!
604
605               # wait for data on socket
606               $sel->can_read();
607
608               # new data on socket or eof
609               READ:
610               # this does not read only 1 byte from socket, but reads the complete SSL
611               # frame and then just returns one byte. On subsequent calls it than
612               # returns more byte of the same SSL frame until it needs to read the
613               # next frame.
614               my $n = sysread( $cl,my $buf,1);
615               if ( ! defined $n ) {
616                   die $! if not $!{EWOULDBLOCK};
617                   next if $SSL_ERROR == SSL_WANT_READ;
618                   if ( $SSL_ERROR == SSL_WANT_WRITE ) {
619                       # need to write data on renegotiation
620                       $sel->can_write;
621                       next;
622                   }
623                   die "something went wrong: $SSL_ERROR";
624               } elsif ( ! $n ) {
625                   last; # eof
626               } else {
627                   # read next bytes
628                   # we might have still data within the current SSL frame
629                   # thus first process these data instead of waiting on the underlying
630                   # socket object
631                   goto READ if $cl->pending;    # goto sysread
632                   next;                         # goto $sel->can_read
633               }
634           }
635
636       Additionally there are differences to plain sockets when using select,
637       poll, kqueue or similar technologies to get notified if data are
638       available.  Relying only on these calls is not sufficient in all cases
639       since unread data might be internally buffered in the SSL stack. To
640       detect such buffering pending() need to be used. Alternatively the
641       buffering can be avoided by using sysread with the maximum size of an
642       SSL frame. See "Common Usage Errors" for details.
643

Advanced Usage

645   SNI Support
646       Newer extensions to SSL can distinguish between multiple hostnames on
647       the same IP address using Server Name Indication (SNI).
648
649       Support for SNI on the client side was added somewhere in the OpenSSL
650       0.9.8 series, but with 1.0 a bug was fixed when the server could not
651       decide about its hostname. Therefore client side SNI is only supported
652       with OpenSSL 1.0 or higher in IO::Socket::SSL.  With a supported
653       version, SNI is used automatically on the client side, if it can
654       determine the hostname from "PeerAddr" or "PeerHost" (which are
655       synonyms in the underlying IO::Socket:: classes and thus should never
656       be set both or at least not to different values).  On unsupported
657       OpenSSL versions it will silently not use SNI.  The hostname can also
658       be given explicitly given with "SSL_hostname", but in this case it will
659       throw in error, if SNI is not supported.  To check for support you
660       might call "IO::Socket::SSL->can_client_sni()".
661
662       On the server side, earlier versions of OpenSSL are supported, but only
663       together with Net::SSLeay version >= 1.50.  To check for support you
664       might call "IO::Socket::SSL->can_server_sni()".  If server side SNI is
665       supported, you might specify different certificates per host with
666       "SSL_cert*" and "SSL_key*", and check the requested name using
667       "get_servername".
668
669   Talk Plain and SSL With The Same Socket
670       It is often required to first exchange some plain data and then upgrade
671       the socket to SSL after some kind of STARTTLS command. Protocols like
672       FTPS even need a way to downgrade the socket again back to plain.
673
674       The common way to do this would be to create a normal socket and use
675       "start_SSL" to upgrade and stop_SSL to downgrade:
676
677           my $sock = IO::Socket::INET->new(...) or die $!;
678           ... exchange plain data on $sock until starttls command ...
679           IO::Socket::SSL->start_SSL($sock,%sslargs) or die $SSL_ERROR;
680           ... now $sock is an IO::Socket::SSL object ...
681           ... exchange data with SSL on $sock until stoptls command ...
682           $sock->stop_SSL or die $SSL_ERROR;
683           ... now $sock is again an IO::Socket::INET object ...
684
685       But, lots of modules just derive directly from IO::Socket::INET.  While
686       this base class can be replaced with IO::Socket::SSL, these modules
687       cannot easily support different base classes for SSL and plain data and
688       switch between these classes on a starttls command.
689
690       To help in this case, IO::Socket::SSL can be reduced to a plain socket
691       on startup, and connect_SSL/accept_SSL/start_SSL can be used to enable
692       SSL and "stop_SSL" to talk plain again:
693
694           my $sock = IO::Socket::SSL->new(
695               PeerAddr => ...
696               SSL_startHandshake => 0,
697               %sslargs
698           ) or die $!;
699           ... exchange plain data on $sock until starttls command ...
700           $sock->connect_SSL or die $SSL_ERROR;
701           ... now $sock is an IO::Socket::SSL object ...
702           ... exchange data with SSL on $sock until stoptls command ...
703           $sock->stop_SSL or die $SSL_ERROR;
704           ... $sock is still an IO::Socket::SSL object ...
705           ... but data exchanged again in plain ...
706

Integration Into Own Modules

708       IO::Socket::SSL behaves similarly to other IO::Socket modules and thus
709       could be integrated in the same way, but you have to take special care
710       when using non-blocking I/O (like for handling timeouts) or using
711       select or poll.  Please study the documentation on how to deal with
712       these differences.
713
714       Also, it is recommended to not set or touch most of the "SSL_*"
715       options, so that they keep their secure defaults. It is also
716       recommended to let the user override these SSL specific settings
717       without the need of global settings or hacks like
718       "set_args_filter_hack".
719
720       The notable exception is "SSL_verifycn_scheme".  This should be set to
721       the hostname verification scheme required by the module or protocol.
722

Description Of Methods

724       IO::Socket::SSL inherits from another IO::Socket module.  The choice of
725       the super class depends on the installed modules:
726
727       •   If IO::Socket::IP with at least version 0.20 is installed it will
728           use this module as super class, transparently providing IPv6 and
729           IPv4 support.
730
731       •   If IO::Socket::INET6 is installed it will use this module as super
732           class, transparently providing IPv6 and IPv4 support.
733
734       •   Otherwise it will fall back to IO::Socket::INET, which is a perl
735           core module.  With IO::Socket::INET you only get IPv4 support.
736
737       Please be aware that with the IPv6 capable super classes, it will look
738       first for the IPv6 address of a given hostname. If the resolver
739       provides an IPv6 address, but the host cannot be reached by IPv6, there
740       will be no automatic fallback to IPv4.  To avoid these problems you can
741       enforce IPv4 for a specific socket by using the "Domain" or "Family"
742       option with the value AF_INET as described in IO::Socket::IP.
743       Alternatively you can enforce IPv4 globally by loading IO::Socket::SSL
744       with the option 'inet4', in which case it will use the IPv4 only class
745       IO::Socket::INET as the super class.
746
747       IO::Socket::SSL will provide all of the methods of its super class, but
748       sometimes it will override them to match the behavior expected from SSL
749       or to provide additional arguments.
750
751       The new or changed methods are described below, but please also read
752       the section about SSL specific error handling.
753
754       Error Handling
755           If an SSL specific error occurs, the global variable $SSL_ERROR
756           will be set.  If the error occurred on an existing SSL socket, the
757           method "errstr" will give access to the latest socket specific
758           error.  Both $SSL_ERROR and the "errstr" method give a dualvar
759           similar to $!, e.g.  providing an error number in numeric context
760           or an error description in string context.
761
762       new(...)
763           Creates a new IO::Socket::SSL object.  You may use all the friendly
764           options that came bundled with the super class (e.g.
765           IO::Socket::IP, IO::Socket::INET, ...) plus (optionally) the ones
766           described below.  If you don't specify any SSL related options it
767           will do its best in using secure defaults, e.g. choosing good
768           ciphers, enabling proper verification, etc.
769
770           SSL_server
771             Set this option to a true value if the socket should be used as a
772             server.  If this is not explicitly set it is assumed if the
773             "Listen" parameter is given when creating the socket.
774
775           SSL_hostname
776             This can be given to specify the hostname used for SNI, which is
777             needed if you have multiple SSL hostnames on the same IP address.
778             If not given it will try to determine the hostname from
779             "PeerAddr", which will fail if only an IP was given or if this
780             argument is used within "start_SSL".
781
782             If you want to disable SNI, set this argument to ''.
783
784             Currently only supported for the client side and will be ignored
785             for the server side.
786
787             See section "SNI Support" for details of SNI the support.
788
789           SSL_startHandshake
790             If this option is set to false (defaults to true) it will not
791             start the SSL handshake yet. This has to be done later with
792             "accept_SSL" or "connect_SSL".  Before the handshake is started
793             read/write/etc. can be used to exchange plain data.
794
795           SSL_keepSocketOnError
796             If this option is set to true (defaults to false) it will not
797             close the underlying TCP socket on errors. In most cases there is
798             no real use for this behavior since both sides of the TCP
799             connection will probably have a different idea of the current
800             state of the connection.
801
802           SSL_ca | SSL_ca_file | SSL_ca_path
803             Usually you want to verify that the peer certificate has been
804             signed by a trusted certificate authority. In this case you
805             should use this option to specify the file ("SSL_ca_file") or
806             directory ("SSL_ca_path") containing the certificate(s) of the
807             trusted certificate authorities.
808
809             "SSL_ca_path" can also be an array or a string containing
810             multiple path, where the path are separated by the platform
811             specific separator. This separator is ";" on DOS, Windows,
812             Netware, "," on VMS and ":" for all the other systems.  If
813             multiple path are given at least one of these must be accessible.
814
815             You can also give a list of X509* certificate handles (like you
816             get from Net::SSLeay or IO::Socket::SSL::Utils::PEM_xxx2cert)
817             with "SSL_ca". These will be added to the CA store before path
818             and file and thus take precedence.  If neither SSL_ca, nor
819             SSL_ca_file or SSL_ca_path are set it will use "default_ca()" to
820             determine the user-set or system defaults.  If you really don't
821             want to set a CA set SSL_ca_file or SSL_ca_path to "\undef" or
822             SSL_ca to an empty list. (unfortunately '' is used by some
823             modules using IO::Socket::SSL when CA is not explicitly given).
824
825           SSL_client_ca | SSL_client_ca_file
826             If verify_mode is VERIFY_PEER on the server side these options
827             can be used to set the list of acceptable CAs for the client.
828             This way the client can select they required certificate from a
829             list of certificates.  The value for these options is similar to
830             "SSL_ca" and "SSL_ca_file".
831
832           SSL_fingerprint
833             Sometimes you have a self-signed certificate or a certificate
834             issued by an unknown CA and you really want to accept it, but
835             don't want to disable verification at all. In this case you can
836             specify the fingerprint of the certificate as
837             'algo$hex_fingerprint'. "algo" is a fingerprint algorithm
838             supported by OpenSSL, e.g. 'sha1','sha256'... and
839             "hex_fingerprint" is the hexadecimal representation of the binary
840             fingerprint. Any colons inside the hex string will be ignored.
841
842             If you want to use the fingerprint of the pubkey inside the
843             certificate instead of the certificate use the syntax
844             'algo$pub$hex_fingerprint' instead.  To get the fingerprint of an
845             established connection you can use "get_fingerprint".
846
847             It is also possible to skip "algo$", i.e. only specify the
848             fingerprint. In this case the likely algorithms will be
849             automatically detected based on the length of the digest string.
850
851             You can specify a list of fingerprints in case you have several
852             acceptable certificates.  If a fingerprint matches the topmost
853             (i.e. leaf) certificate no additional validations can make the
854             verification fail.
855
856           SSL_cert_file | SSL_cert | SSL_key_file | SSL_key
857             If you create a server you usually need to specify a server
858             certificate which should be verified by the client. Same is true
859             for client certificates, which should be verified by the server.
860             The certificate can be given as a file with SSL_cert_file or as
861             an internal representation of an X509* object (like you get from
862             Net::SSLeay or IO::Socket::SSL::Utils::PEM_xxx2cert) with
863             SSL_cert.  If given as a file it will automatically detect the
864             format.  Supported file formats are PEM, DER and PKCS#12, where
865             PEM and PKCS#12 can contain the certificate and the chain to use,
866             while DER can only contain a single certificate.
867
868             If given as a list of X509* please note, that the all the chain
869             certificates (e.g. all except the first) will be "consumed" by
870             openssl and will be freed if the SSL context gets destroyed - so
871             you should never free them yourself. But the servers certificate
872             (e.g. the first) will not be consumed by openssl and thus must be
873             freed by the application.
874
875             For each certificate a key is need, which can either be given as
876             a file with SSL_key_file or as an internal representation of an
877             EVP_PKEY* object with SSL_key (like you get from Net::SSLeay or
878             IO::Socket::SSL::Utils::PEM_xxx2key).  If a key was already given
879             within the PKCS#12 file specified by SSL_cert_file it will ignore
880             any SSL_key or SSL_key_file.  If no SSL_key or SSL_key_file was
881             given it will try to use the PEM file given with SSL_cert_file
882             again, maybe it contains the key too.
883
884             If your SSL server should be able to use different certificates
885             on the same IP address, depending on the name given by SNI, you
886             can use a hash reference instead of a file with "<hostname ="
887             cert_file>>.
888
889             If your SSL server should be able to use both RSA and ECDSA
890             certificates for the same domain/IP a similar hash reference like
891             with SNI is given. The domain names used to specify the
892             additional certificates should be "hostname%whatever", i.e.
893             "hostname%ecc" or similar. This needs at least OpenSSL 1.0.2. To
894             let the server pick the certificate based on the clients cipher
895             preference "SSL_honor_cipher_order" should be set to false.
896
897             In case certs and keys are needed but not given it might fall
898             back to builtin defaults, see "Defaults for Cert, Key and CA".
899
900             Examples:
901
902              SSL_cert_file => 'mycert.pem',
903              SSL_key_file => 'mykey.pem',
904
905              SSL_cert_file => {
906                 "foo.example.org" => 'foo-cert.pem',
907                 "foo.example.org%ecc" => 'foo-ecc-cert.pem',
908                 "bar.example.org" => 'bar-cert.pem',
909                 # used when nothing matches or client does not support SNI
910                 '' => 'default-cert.pem',
911                 '%ecc' => 'default-ecc-cert.pem',
912              },
913              SSL_key_file => {
914                 "foo.example.org" => 'foo-key.pem',
915                 "foo.example.org%ecc" => 'foo-ecc-key.pem',
916                 "bar.example.org" => 'bar-key.pem',
917                 # used when nothing matches or client does not support SNI
918                 '' => 'default-key.pem',
919                 '%ecc' => 'default-ecc-key.pem',
920              }
921
922           SSL_passwd_cb
923             If your private key is encrypted, you might not want the default
924             password prompt from Net::SSLeay.  This option takes a reference
925             to a subroutine that should return the password required to
926             decrypt your private key.
927
928           SSL_use_cert
929             If this is true, it forces IO::Socket::SSL to use a certificate
930             and key, even if you are setting up an SSL client.  If this is
931             set to 0 (the default), then you will only need a certificate and
932             key if you are setting up a server.
933
934             SSL_use_cert will implicitly be set if SSL_server is set.  For
935             convenience it is also set if it was not given but a cert was
936             given for use (SSL_cert_file or similar).
937
938           SSL_version
939             Sets the version of the SSL protocol used to transmit data.
940             'SSLv23' uses a handshake compatible with SSL2.0, SSL3.0 and
941             TLS1.x, while 'SSLv2', 'SSLv3', 'TLSv1', 'TLSv1_1', 'TLSv1_2', or
942             'TLSv1_3' restrict handshake and protocol to the specified
943             version.  All values are case-insensitive.  Instead of 'TLSv1_1',
944             'TLSv1_2', and 'TLSv1_3' one can also use 'TLSv11', 'TLSv12', and
945             'TLSv13'.  Support for 'TLSv1_1', 'TLSv1_2', and 'TLSv1_3'
946             requires recent versions of Net::SSLeay and openssl.  The default
947             SSL_version is defined by the underlying cryptographic library.
948
949             Independent from the handshake format you can limit to set of
950             accepted SSL versions by adding !version separated by ':'.
951
952             For example, 'SSLv23:!SSLv3:!SSLv2' means that the handshake
953             format is compatible to SSL2.0 and higher, but that the
954             successful handshake is limited to TLS1.0 and higher, that is no
955             SSL2.0 or SSL3.0 because both of these versions have serious
956             security issues and should not be used anymore.  You can also use
957             !TLSv1_1 and !TLSv1_2 to disable TLS versions 1.1 and 1.2 while
958             still allowing TLS version 1.0.
959
960             Setting the version instead to 'TLSv1' might break interaction
961             with older clients, which need and SSL2.0 compatible handshake.
962             On the other side some clients just close the connection when
963             they receive a TLS version 1.1 request. In this case setting the
964             version to 'SSLv23:!SSLv2:!SSLv3:!TLSv1_1:!TLSv1_2' might help.
965
966           SSL_cipher_list
967             If this option is set the cipher list for the connection will be
968             set to the given value, e.g. something like
969             'ALL:!LOW:!EXP:!aNULL'. This will only affect ciphers for TLS 1.2
970             and lower. See the OpenSSL documentation
971             (<https://www.openssl.org/docs/manmaster/man1/openssl-ciphers.html#CIPHER-STRINGS>)
972             for more details.
973
974             Unless you fail to contact your peer because of no shared ciphers
975             it is recommended to leave this option at the default setting,
976             which honors the system-wide PROFILE=SYSTEM cipher list.
977
978             In case different cipher lists are needed for different SNI hosts
979             a hash can be given with the host as key and the cipher suite as
980             value, similar to SSL_cert*.
981
982           SSL_ciphersuites
983             If this option is set the TLS 1.3 ciphersuites for the connection
984             will be set to the given value. This is similar to
985             SSL_cipher_list, but only for TLS 1.3 ciphers. See argument
986             "-ciphersuits" in the OpenSSL documentation
987             (<https://www.openssl.org/docs/manmaster/man1/openssl-ciphers.html>)
988             for details.
989
990             Unless you fail to contact your peer because of no shared ciphers
991             it is recommended to leave this option at the default setting,
992             which uses the system default.
993
994             In case different cipher lists are needed for different SNI hosts
995             a hash can be given with the host as key and the cipher suite as
996             value, similar to SSL_cert*.
997
998           SSL_honor_cipher_order
999             If this option is true the cipher order the server specified is
1000             used instead of the order proposed by the client. This option
1001             defaults to true to make use of our secure cipher list setting.
1002
1003           SSL_dh_file
1004             To create a server which provides forward secrecy you need to
1005             either give the DH parameters or (better, because faster) the
1006             ECDH curve. This setting cares about DH parameters.
1007
1008             To support non-elliptic Diffie-Hellman key exchange a suitable
1009             file needs to be given here or the SSL_dh should be used with an
1010             appropriate value.  See dhparam command in openssl for more
1011             information.
1012
1013             If neither "SSL_dh_file" nor "SSL_dh" are set a builtin DH
1014             parameter with a length of 2048 bit is used to offer DH key
1015             exchange by default. If you don't want this (e.g. disable DH key
1016             exchange) explicitly set this or the "SSL_dh" parameter to undef.
1017
1018           SSL_dh
1019             Like SSL_dh_file, but instead of giving a file you use a
1020             preloaded or generated DH*.
1021
1022           SSL_ecdh_curve
1023             To create a server which provides forward secrecy you need to
1024             either give the DH parameters or (better, because faster) the
1025             ECDH curve. This setting cares about the ECDH curve(s).
1026
1027             To support Elliptic Curve Diffie-Hellmann key exchange the OID or
1028             NID of at least one suitable curve needs to be provided here.
1029
1030             With OpenSSL 1.1.0+ this parameter defaults to "auto", which
1031             means that it lets OpenSSL pick the best settings. If support for
1032             CTX_set_ecdh_auto is implemented in Net::SSLeay (needs at least
1033             version 1.86) it will use this to implement the same default.
1034             Otherwise it will default to "prime256v1" (builtin of OpenSSL) in
1035             order to offer ECDH key exchange by default.
1036
1037             If setting groups or curves is supported by Net::SSLeay (needs at
1038             least version 1.86) then multiple curves can be given here in the
1039             order of the preference, i.e.  "P-521:P-384:P-256". When used at
1040             the client side this will include the supported curves as
1041             extension in the TLS handshake.
1042
1043             If you don't want to have ECDH key exchange this could be set to
1044             undef or set "SSL_ciphers" to exclude all of these ciphers.
1045
1046             You can check if ECDH support is available by calling
1047             "IO::Socket::SSL->can_ecdh".
1048
1049           SSL_verify_mode
1050             This option sets the verification mode for the peer certificate.
1051             You may combine SSL_VERIFY_PEER (verify_peer),
1052             SSL_VERIFY_FAIL_IF_NO_PEER_CERT (fail verification if no peer
1053             certificate exists; ignored for clients), SSL_VERIFY_CLIENT_ONCE
1054             (verify client once; ignored for clients).  See OpenSSL man page
1055             for SSL_CTX_set_verify for more information.
1056
1057             The default is SSL_VERIFY_NONE for server  (e.g. no check for
1058             client certificate) and SSL_VERIFY_PEER for client (check server
1059             certificate).
1060
1061           SSL_verify_callback
1062             If you want to verify certificates yourself, you can pass a sub
1063             reference along with this parameter to do so.  When the callback
1064             is called, it will be passed:
1065
1066             1. a true/false value that indicates what OpenSSL thinks of the
1067             certificate,
1068             2. a C-style memory address of the certificate store,
1069             3. a string containing the certificate's issuer attributes and
1070             owner attributes, and
1071             4. a string containing any errors encountered (0 if no errors).
1072             5. a C-style memory address of the peer's own certificate
1073             (convertible to PEM form with
1074             Net::SSLeay::PEM_get_string_X509()).
1075             6. The depth of the certificate in the chain. Depth 0 is the leaf
1076             certificate.
1077
1078             The function should return 1 or 0, depending on whether it thinks
1079             the certificate is valid or invalid.  The default is to let
1080             OpenSSL do all of the busy work.
1081
1082             The callback will be called for each element in the certificate
1083             chain.
1084
1085             See the OpenSSL documentation for SSL_CTX_set_verify for more
1086             information.
1087
1088           SSL_verifycn_scheme
1089             The scheme is used to correctly verify the identity inside the
1090             certificate by using the hostname of the peer.  See the
1091             information about the verification schemes in verify_hostname.
1092
1093             If you don't specify a scheme it will use 'default', but only
1094             complain loudly if the name verification fails instead of letting
1095             the whole certificate verification fail. THIS WILL CHANGE, e.g.
1096             it will let the certificate verification fail in the future if
1097             the hostname does not match the certificate !!!!  To override the
1098             name used in verification use SSL_verifycn_name.
1099
1100             The scheme 'default' is a superset of the usual schemes, which
1101             will accept the hostname in common name and subjectAltName and
1102             allow wildcards everywhere.  While using this scheme is way more
1103             secure than no name verification at all you better should use the
1104             scheme specific to your application protocol, e.g. 'http',
1105             'ftp'...
1106
1107             If you are really sure, that you don't want to verify the
1108             identity using the hostname  you can use 'none' as a scheme. In
1109             this case you'd better have alternative forms of verification,
1110             like a certificate fingerprint or do a manual verification later
1111             by calling verify_hostname yourself.
1112
1113           SSL_verifycn_publicsuffix
1114             This option is used to specify the behavior when checking
1115             wildcards certificates for public suffixes, e.g. no wildcard
1116             certificates for *.com or *.co.uk should be accepted, while
1117             *.example.com or *.example.co.uk is ok.
1118
1119             If not specified it will simply use the builtin default of
1120             IO::Socket::SSL::PublicSuffix, you can create another object with
1121             from_string or from_file of this module.
1122
1123             To disable verification of public suffix set this option to ''.
1124
1125           SSL_verifycn_name
1126             Set the name which is used in verification of hostname. If
1127             SSL_verifycn_scheme is set and no SSL_verifycn_name is given it
1128             will try to use SSL_hostname or PeerHost and PeerAddr settings
1129             and fail if no name can be determined.  If SSL_verifycn_scheme is
1130             not set it will use a default scheme and warn if it cannot
1131             determine a hostname, but it will not fail.
1132
1133             Using PeerHost or PeerAddr works only if you create the
1134             connection directly with "IO::Socket::SSL->new", if an
1135             IO::Socket::INET object is upgraded with start_SSL the name has
1136             to be given in SSL_verifycn_name or SSL_hostname.
1137
1138           SSL_check_crl
1139             If you want to verify that the peer certificate has not been
1140             revoked by the signing authority, set this value to true. OpenSSL
1141             will search for the CRL in your SSL_ca_path, or use the file
1142             specified by SSL_crl_file.  See the Net::SSLeay documentation for
1143             more details.  Note that this functionality appears to be broken
1144             with OpenSSL < v0.9.7b, so its use with lower versions will
1145             result in an error.
1146
1147           SSL_crl_file
1148             If you want to specify the CRL file to be used, set this value to
1149             the pathname to be used.  This must be used in addition to
1150             setting SSL_check_crl.
1151
1152           SSL_ocsp_mode
1153             Defines how certificate revocation is done using OCSP (Online
1154             Status Revocation Protocol). The default is to send a request for
1155             OCSP stapling to the server and if the server sends an OCSP
1156             response back the result will be used.
1157
1158             Any other OCSP checking needs to be done manually with
1159             "ocsp_resolver".
1160
1161             The following flags can be combined with "|":
1162
1163             SSL_OCSP_NO_STAPLE
1164                     Don't ask for OCSP stapling.  This is the default if
1165                     SSL_verify_mode is VERIFY_NONE.
1166
1167             SSL_OCSP_TRY_STAPLE
1168                     Try OCSP stapling, but don't complain if it gets no
1169                     stapled response back.  This is the default if
1170                     SSL_verify_mode is VERIFY_PEER (the default).
1171
1172             SSL_OCSP_MUST_STAPLE
1173                     Consider it a hard error, if the server does not send a
1174                     stapled OCSP response back. Most servers currently send
1175                     no stapled OCSP response back.
1176
1177             SSL_OCSP_FAIL_HARD
1178                     Fail hard on response errors, default is to fail soft
1179                     like the browsers do.  Soft errors mean, that the OCSP
1180                     response is not usable, e.g. no response, error response,
1181                     no valid signature etc.  Certificate revocations inside a
1182                     verified response are considered hard errors in any case.
1183
1184                     Soft errors inside a stapled response are never
1185                     considered hard, e.g. it is expected that in this case an
1186                     OCSP request will be send to the responsible OCSP
1187                     responder.
1188
1189             SSL_OCSP_FULL_CHAIN
1190                     This will set up the "ocsp_resolver" so that all
1191                     certificates from the peer chain will be checked,
1192                     otherwise only the leaf certificate will be checked
1193                     against revocation.
1194
1195           SSL_ocsp_staple_callback
1196             If this callback is defined, it will be called with the SSL
1197             object and the OCSP response handle obtained from the peer, e.g.
1198             "<$cb-"($ssl,$resp)>>.  If the peer did not provide a stapled
1199             OCSP response the function will be called with "$resp=undef".
1200             Because the OCSP response handle is no longer valid after leaving
1201             this function it should not by copied or freed. If access to the
1202             response is necessary after leaving this function it can be
1203             serialized with "Net::SSLeay::i2d_OCSP_RESPONSE".
1204
1205             If no such callback is provided, it will use the default one,
1206             which verifies the response and uses it to check if the
1207             certificate(s) of the connection got revoked.
1208
1209           SSL_ocsp_cache
1210             With this option a cache can be given for caching OCSP responses,
1211             which could be shared between different SSL contexts. If not
1212             given a cache specific to the SSL context only will be used.
1213
1214             You can either create a new cache with
1215             "IO::Socket::SSL::OCSP_Cache->new([size])" or implement your own
1216             cache, which needs to have methods "put($key,\%entry)" and
1217             "get($key)" (returning "\%entry") where entry is the hash
1218             representation of the OCSP response with fields like
1219             "nextUpdate". The default implementation of the cache will
1220             consider responses valid as long as "nextUpdate" is less then the
1221             current time.
1222
1223           SSL_reuse_ctx
1224             If you have already set the above options for a previous instance
1225             of IO::Socket::SSL, then you can reuse the SSL context of that
1226             instance by passing it as the value for the SSL_reuse_ctx
1227             parameter.  You may also create a new instance of the
1228             IO::Socket::SSL::SSL_Context class, using any context options
1229             that you desire without specifying connection options, and pass
1230             that here instead.
1231
1232             If you use this option, all other context-related options that
1233             you pass in the same call to new() will be ignored unless the
1234             context supplied was invalid.  Note that, contrary to versions of
1235             IO::Socket::SSL below v0.90, a global SSL context will not be
1236             implicitly used unless you use the set_default_context()
1237             function.
1238
1239           SSL_create_ctx_callback
1240             With this callback you can make individual settings to the
1241             context after it got created and the default setup was done.  The
1242             callback will be called with the CTX object from Net::SSLeay as
1243             the single argument.
1244
1245             Example for limiting the server session cache size:
1246
1247               SSL_create_ctx_callback => sub {
1248                   my $ctx = shift;
1249                   Net::SSLeay::CTX_sess_set_cache_size($ctx,128);
1250               }
1251
1252           SSL_session_cache_size
1253             If you make repeated connections to the same host/port and the
1254             SSL renegotiation time is an issue, you can turn on client-side
1255             session caching with this option by specifying a positive cache
1256             size.  For successive connections, pass the SSL_reuse_ctx option
1257             to the new() calls (or use set_default_context()) to make use of
1258             the cached sessions.  The session cache size refers to the number
1259             of unique host/port pairs that can be stored at one time; the
1260             oldest sessions in the cache will be removed if new ones are
1261             added.
1262
1263             This option does not effect the session cache a server has for
1264             it's clients, e.g. it does not affect SSL objects with SSL_server
1265             set.
1266
1267             Note that session caching with TLS 1.3 needs at least Net::SSLeay
1268             1.86.
1269
1270           SSL_session_cache
1271             Specifies session cache object which should be used instead of
1272             creating a new.  Overrules SSL_session_cache_size.  This option
1273             is useful if you want to reuse the cache, but not the rest of the
1274             context.
1275
1276             A session cache object can be created using
1277             "IO::Socket::SSL::Session_Cache->new( cachesize )".
1278
1279             Use set_default_session_cache() to set a global cache object.
1280
1281           SSL_session_key
1282             Specifies a key to use for lookups and inserts into client-side
1283             session cache.  Per default ip:port of destination will be used,
1284             but sometimes you want to share the same session over multiple
1285             ports on the same server (like with FTPS).
1286
1287           SSL_session_id_context
1288             This gives an id for the servers session cache. It's necessary if
1289             you want clients to connect with a client certificate. If not
1290             given but SSL_verify_mode specifies the need for client
1291             certificate a context unique id will be picked.
1292
1293           SSL_error_trap
1294             When using the accept() or connect() methods, it may be the case
1295             that the actual socket connection works but the SSL negotiation
1296             fails, as in the case of an HTTP client connecting to an HTTPS
1297             server.  Passing a subroutine ref attached to this parameter
1298             allows you to gain control of the orphaned socket instead of
1299             having it be closed forcibly.  The subroutine, if called, will be
1300             passed two parameters: a reference to the socket on which the SSL
1301             negotiation failed and the full text of the error message.
1302
1303           SSL_npn_protocols
1304             If used on the server side it specifies list of protocols
1305             advertised by SSL server as an array ref, e.g.
1306             ['spdy/2','http1.1'].  On the client side it specifies the
1307             protocols offered by the client for NPN as an array ref.  See
1308             also method "next_proto_negotiated".
1309
1310             Next Protocol Negotiation (NPN) is available with Net::SSLeay
1311             1.46+ and openssl-1.0.1+. NPN is unavailable in TLSv1.3 protocol.
1312             To check support you might call "IO::Socket::SSL->can_npn()".  If
1313             you use this option with an unsupported Net::SSLeay/OpenSSL it
1314             will throw an error.
1315
1316           SSL_alpn_protocols
1317             If used on the server side it specifies list of protocols
1318             supported by the SSL server as an array ref, e.g. ['http/2.0',
1319             'spdy/3.1','http/1.1'].  On the client side it specifies the
1320             protocols advertised by the client for ALPN as an array ref.  See
1321             also method "alpn_selected".
1322
1323             Application-Layer Protocol Negotiation (ALPN) is available with
1324             Net::SSLeay 1.56+ and openssl-1.0.2+. More details about the
1325             extension are in RFC7301. To check support you might call
1326             "IO::Socket::SSL->can_alpn()". If you use this option with an
1327             unsupported Net::SSLeay/OpenSSL it will throw an error.
1328
1329             Note that some client implementations may encounter problems if
1330             both NPN and ALPN are specified. Since ALPN is intended as a
1331             replacement for NPN, try providing ALPN protocols then fall back
1332             to NPN if that fails.
1333
1334           SSL_ticket_keycb => [$sub,$data] | $sub
1335             This is a callback used for stateless session reuse (Session
1336             Tickets, RFC 5077).
1337
1338             This callback will be called as "$sub->($data,[$key_name])" where
1339             $data is the argument given to SSL_ticket_keycb (or undef) and
1340             $key_name depends on the mode:
1341
1342             encrypt ticket
1343                     If a ticket needs to be encrypted the callback will be
1344                     called without $key_name. In this case it should return
1345                     "($current_key,$current_key_name") where $current_key is
1346                     the current key (32 byte random data) and
1347                     $current_key_name the name associated with this key
1348                     (exactly 16 byte). This $current_key_name will be
1349                     incorporated into the ticket.
1350
1351             decrypt ticket
1352                     If a ticket needs to be decrypted the callback will be
1353                     called with $key_name as found in the ticket. It should
1354                     return "($key,$current_key_name") where $key is the key
1355                     associated with the given $key_name and $current_key_name
1356                     the name associated with the currently active key.  If
1357                     $current_key_name is different from the given $key_name
1358                     the callback will be called again to re-encrypt the
1359                     ticket with the currently active key.
1360
1361                     If no key can be found which matches the given $key_name
1362                     then this function should return nothing (empty list).
1363
1364                     This mechanism should be used to limit the life time for
1365                     each key encrypting the ticket. Compromise of a ticket
1366                     encryption key might lead to decryption of SSL sessions
1367                     which used session tickets protected by this key.
1368
1369             Example:
1370
1371                 Net::SSLeay::RAND_bytes(my $oldkey,32);
1372                 Net::SSLeay::RAND_bytes(my $newkey,32);
1373                 my $oldkey_name = pack("a16",'oldsecret');
1374                 my $newkey_name = pack("a16",'newsecret');
1375
1376                 my @keys = (
1377                    [ $newkey_name, $newkey ], # current active key
1378                    [ $oldkey_name, $oldkey ], # already expired
1379                 );
1380
1381                 my $keycb = [ sub {
1382                    my ($mykeys,$name) = @_;
1383
1384                    # return (current_key, current_key_name) if no name given
1385                    return ($mykeys->[0][1],$mykeys->[0][0]) if ! $name;
1386
1387                    # return (matching_key, current_key_name) if we find a key matching
1388                    # the given name
1389                    for(my $i = 0; $i<@$mykeys; $i++) {
1390                        next if $name ne $mykeys->[$i][0];
1391                        return ($mykeys->[$i][1],$mykeys->[0][0]);
1392                    }
1393
1394                    # no matching key found
1395                    return;
1396                 },\@keys ];
1397
1398                 my $srv = IO::Socket::SSL->new(..., SSL_ticket_keycb => $keycb);
1399
1400           SSL_mode_release_buffers 1|0
1401             This enables or disables the SSL_MODE_RELEASE_BUFFERS option on
1402             the SSL object.  With this option the read buffer will be
1403             released after each SSL_read but will need to be reallocated for
1404             each new SSL_read. If memory usage is a concern this might save
1405             lots of memory in the mean time though, about 34k per idle SSL
1406             connection according to the documentation in
1407             SSL_CTX_set_mode(3ssl).
1408
1409       accept
1410           This behaves similar to the accept function of the underlying
1411           socket class, but additionally does the initial SSL handshake. But
1412           because the underlying socket class does return a blocking file
1413           handle even when accept is called on a non-blocking socket, the SSL
1414           handshake on the new file object will be done in a blocking way.
1415           Please see the section about non-blocking I/O for details.  If you
1416           don't like this behavior you should do accept on the TCP socket and
1417           then upgrade it with "start_SSL" later.
1418
1419       connect(...)
1420           This behaves similar to the connect function but also does an SSL
1421           handshake.  Because you cannot give SSL specific arguments to this
1422           function, you should better either use "new" to create a connect
1423           SSL socket or "start_SSL" to upgrade an established TCP socket to
1424           SSL.
1425
1426       close(...)
1427           Contrary to a close for a simple INET socket a close in SSL also
1428           mandates a proper shutdown of the SSL part. This is done by sending
1429           a close notify message by both peers.
1430
1431           A naive implementation would thus wait until it receives the close
1432           notify message from the peer - which conflicts with the commonly
1433           expected semantic that a close will not block. The default behavior
1434           is thus to only send a close notify but not  wait for the close
1435           notify of the peer. If this is required "SSL_fast_shutdown" need to
1436           be explicitly set to false.
1437
1438           There are also cases where a SSL shutdown should not be done at
1439           all. This is true for example when forking to let a child deal with
1440           the socket and closing the socket in the parent process. A naive
1441           explicit "close" or an implicit close when destroying the socket in
1442           the parent would send a close notify to the peer which would make
1443           the SSL socket in the client process unusable. In this case an
1444           explicit "close" with "SSL_no_shutdown" set to true should be done
1445           in the parent process.
1446
1447           For more details and other arguments see "stop_SSL" which gets
1448           called from "close" to shutdown the SSL state of the socket.
1449
1450       sysread( BUF, LEN, [ OFFSET ] )
1451           This function behaves from the outside the same as sysread in other
1452           IO::Socket objects, e.g. it returns at most LEN bytes of data.  But
1453           in reality it reads not only LEN bytes from the underlying socket,
1454           but at a single SSL frame. It then returns up to LEN bytes it
1455           decrypted from this SSL frame. If the frame contained more data
1456           than requested it will return only LEN data, buffer the rest and
1457           return it on further read calls.  This means, that it might be
1458           possible to read data, even if the underlying socket is not
1459           readable, so using poll or select might not be sufficient.
1460
1461           sysread will only return data from a single SSL frame, e.g. either
1462           the pending data from the already buffered frame or it will read a
1463           frame from the underlying socket and return the decrypted data. It
1464           will not return data spanning several SSL frames in a single call.
1465
1466           Also, calls to sysread might fail, because it must first finish an
1467           SSL handshake.
1468
1469           To understand these behaviors is essential, if you write
1470           applications which use event loops and/or non-blocking sockets.
1471           Please read the specific sections in this documentation.
1472
1473       syswrite( BUF, [ LEN, [ OFFSET ]] )
1474           This functions behaves from the outside the same as syswrite in
1475           other IO::Socket objects, e.g. it will write at most LEN bytes to
1476           the socket, but there is no guarantee, that all LEN bytes are
1477           written. It will return the number of bytes written.  Because it
1478           basically just calls SSL_write from OpenSSL syswrite will write at
1479           most a single SSL frame. This means, that no more than 16.384
1480           bytes, which is the maximum size of an SSL frame, will be written
1481           at once.
1482
1483           For non-blocking sockets SSL specific behavior applies.  Pease read
1484           the specific section in this documentation.
1485
1486       peek( BUF, LEN, [ OFFSET ])
1487           This function has exactly the same syntax as sysread, and performs
1488           nearly the same task but will not advance the read position so that
1489           successive calls to peek() with the same arguments will return the
1490           same results.  This function requires OpenSSL 0.9.6a or later to
1491           work.
1492
1493       pending()
1494           This function gives you the number of bytes available without
1495           reading from the underlying socket object. This function is
1496           essential if you work with event loops, please see the section
1497           about polling SSL sockets.
1498
1499       get_fingerprint([algo,certificate,pubkey])
1500           This methods returns the fingerprint of the given certificate in
1501           the form "algo$digest_hex", where "algo" is the used algorithm,
1502           default 'sha256'.  If no certificate is given the peer certificate
1503           of the connection is used.  If "pubkey" is true it will not return
1504           the fingerprint of the certificate but instead the fingerprint of
1505           the pubkey inside the certificate as "algo$pub$digest_hex".
1506
1507       get_fingerprint_bin([algo,certificate,pubkey])
1508           This methods returns the binary fingerprint of the given
1509           certificate by using the algorithm "algo", default 'sha256'.  If no
1510           certificate is given the peer certificate of the connection is
1511           used.  If "pubkey" is true it will not return the fingerprint of
1512           the certificate but instead the fingerprint of the pubkey inside
1513           the certificate.
1514
1515       get_cipher()
1516           Returns the string form of the cipher that the IO::Socket::SSL
1517           object is using.
1518
1519       get_sslversion()
1520           Returns the string representation of the SSL version of an
1521           established connection.
1522
1523       get_sslversion_int()
1524           Returns the integer representation of the SSL version of an
1525           established connection.
1526
1527       get_session_reused()
1528           This returns true if the session got reused and false otherwise.
1529           Note that with a reused session no certificates are send within the
1530           handshake and no ciphers are offered and thus functions which rely
1531           on this might not work.
1532
1533       dump_peer_certificate()
1534           Returns a parsable string with select fields from the peer SSL
1535           certificate.  This method directly returns the result of the
1536           dump_peer_certificate() method of Net::SSLeay.
1537
1538       peer_certificate($field;[$refresh])
1539           If a peer certificate exists, this function can retrieve values
1540           from it.  If no field is given the internal representation of
1541           certificate from Net::SSLeay is returned.  If refresh is true it
1542           will not used a cached version, but check again in case the
1543           certificate of the connection has changed due to renegotiation.
1544
1545           The following fields can be queried:
1546
1547           authority (alias issuer)
1548                   The certificate authority which signed the certificate.
1549
1550           owner (alias subject)
1551                   The owner of the certificate.
1552
1553           commonName (alias cn) - only for Net::SSLeay version >=1.30
1554                   The common name, usually the server name for SSL
1555                   certificates.
1556
1557           subjectAltNames - only for Net::SSLeay version >=1.33
1558                   Alternative names for the subject, usually different names
1559                   for the same server, like example.org, example.com,
1560                   *.example.com.
1561
1562                   It returns a list of (typ,value) with typ GEN_DNS,
1563                   GEN_IPADD etc (these constants are exported from
1564                   IO::Socket::SSL).  See
1565                   Net::SSLeay::X509_get_subjectAltNames.
1566
1567       sock_certificate($field)
1568           This is similar to "peer_certificate" but will return the sites own
1569           certificate. The same arguments for $field can be used.  If no
1570           $field is given the certificate handle from the underlying OpenSSL
1571           will be returned. This handle will only be valid as long as the SSL
1572           connection exists and if used afterwards it might result in strange
1573           crashes of the application.
1574
1575       peer_certificates
1576           This returns all the certificates send by the peer, e.g. first the
1577           peers own certificate and then the rest of the chain. You might use
1578           CERT_asHash from IO::Socket::SSL::Utils to inspect each of the
1579           certificates.
1580
1581           This function depends on a version of Net::SSLeay >= 1.58 .
1582
1583       get_servername
1584           This gives the name requested by the client if Server Name
1585           Indication (SNI) was used.
1586
1587       verify_hostname($hostname,$scheme,$publicsuffix)
1588           This verifies the given hostname against the peer certificate using
1589           the given scheme. Hostname is usually what you specify within the
1590           PeerAddr.  See the "SSL_verifycn_publicsuffix" parameter for an
1591           explanation of suffix checking and for the possible values.
1592
1593           Verification of hostname against a certificate is different between
1594           various applications and RFCs. Some scheme allow wildcards for
1595           hostnames, some only in subjectAltNames, and even their different
1596           wildcard schemes are possible.  RFC 6125 provides a good overview.
1597
1598           To ease the verification the following schemes are predefined (both
1599           protocol name and rfcXXXX name can be used):
1600
1601           rfc2818, xmpp (rfc3920), ftp (rfc4217)
1602                   Extended wildcards in subjectAltNames and common name are
1603                   possible, e.g.  *.example.org or even www*.example.org. The
1604                   common name will be only checked if no DNS names are given
1605                   in subjectAltNames.
1606
1607           http (alias www)
1608                   While name checking is defined in rfc2818 the current
1609                   browsers usually accept also an IP address (w/o wildcards)
1610                   within the common name as long as no subjectAltNames are
1611                   defined. Thus this is rfc2818 extended with this feature.
1612
1613           smtp (rfc2595), imap, pop3, acap (rfc4642), netconf (rfc5538),
1614           syslog (rfc5425), snmp (rfc5953)
1615                   Simple wildcards in subjectAltNames are possible, e.g.
1616                   *.example.org matches www.example.org but not
1617                   lala.www.example.org. If nothing from subjectAltNames match
1618                   it checks against the common name, where wildcards are also
1619                   allowed to match the full leftmost label.
1620
1621           ldap (rfc4513)
1622                   Simple wildcards are allowed in subjectAltNames, but not in
1623                   common name.  Common name will be checked even if
1624                   subjectAltNames exist.
1625
1626           sip (rfc5922)
1627                   No wildcards are allowed and common name is checked even if
1628                   subjectAltNames exist.
1629
1630           gist (rfc5971)
1631                   Simple wildcards are allowed in subjectAltNames and common
1632                   name, but common name will only be checked if their are no
1633                   DNS names in subjectAltNames.
1634
1635           default This is a superset of all the rules and is automatically
1636                   used if no scheme is given but a hostname (instead of IP)
1637                   is known.  Extended wildcards are allowed in
1638                   subjectAltNames and common name and common name is checked
1639                   always.
1640
1641           none    No verification will be done.  Actually is does not make
1642                   any sense to call verify_hostname in this case.
1643
1644           The scheme can be given either by specifying the name for one of
1645           the above predefined schemes, or by using a hash which can have the
1646           following keys and values:
1647
1648           check_cn:  0|'always'|'when_only'
1649                   Determines if the common name gets checked. If 'always' it
1650                   will always be checked (like in ldap), if 'when_only' it
1651                   will only be checked if no names are given in
1652                   subjectAltNames (like in http), for any other values the
1653                   common name will not be checked.
1654
1655           wildcards_in_alt: 0|'full_label'|'anywhere'
1656                   Determines if and where wildcards in subjectAltNames are
1657                   possible. If 'full_label' only cases like *.example.org
1658                   will be possible (like in ldap), for 'anywhere'
1659                   www*.example.org is possible too (like http), dangerous
1660                   things like but www.*.org or even '*' will not be allowed.
1661                   For compatibility with older versions 'leftmost' can be
1662                   given instead of 'full_label'.
1663
1664           wildcards_in_cn: 0|'full_label'|'anywhere'
1665                   Similar to wildcards_in_alt, but checks the common name.
1666                   There is no predefined scheme which allows wildcards in
1667                   common names.
1668
1669           ip_in_cn: 0|1|4|6
1670                   Determines if an IP address is allowed in the common name
1671                   (no wildcards are allowed). If set to 4 or 6 it only allows
1672                   IPv4 or IPv6 addresses, any other true value allows both.
1673
1674           callback: \&coderef
1675                   If you give a subroutine for verification it will be called
1676                   with the arguments
1677                   ($hostname,$commonName,@subjectAltNames), where hostname is
1678                   the name given for verification, commonName is the result
1679                   from peer_certificate('cn') and subjectAltNames is the
1680                   result from peer_certificate('subjectAltNames').
1681
1682                   All other arguments for the verification scheme will be
1683                   ignored in this case.
1684
1685       next_proto_negotiated()
1686           This method returns the name of negotiated protocol - e.g.
1687           'http/1.1'. It works for both client and server side of SSL
1688           connection.
1689
1690           NPN support is available with Net::SSLeay 1.46+ and openssl-1.0.1+.
1691           To check support you might call "IO::Socket::SSL->can_npn()".
1692
1693       alpn_selected()
1694           Returns the protocol negotiated via ALPN as a string, e.g.
1695           'http/1.1', 'http/2.0' or 'spdy/3.1'.
1696
1697           ALPN support is available with Net::SSLeay 1.56+ and
1698           openssl-1.0.2+.  To check support, use
1699           "IO::Socket::SSL->can_alpn()".
1700
1701       errstr()
1702           Returns the last error (in string form) that occurred. If you do
1703           not have a real object to perform this method on, call
1704           IO::Socket::SSL::errstr() instead.
1705
1706           For read and write errors on non-blocking sockets, this method may
1707           include the string "SSL wants a read first!" or "SSL wants a write
1708           first!" meaning that the other side is expecting to read from or
1709           write to the socket and wants to be satisfied before you get to do
1710           anything. But with version 0.98 you are better comparing the global
1711           exported variable $SSL_ERROR against the exported symbols
1712           SSL_WANT_READ and SSL_WANT_WRITE.
1713
1714       opened()
1715           This returns false if the socket could not be opened, 1 if the
1716           socket could be opened and the SSL handshake was successful done
1717           and -1 if the underlying IO::Handle is open, but the SSL handshake
1718           failed.
1719
1720       IO::Socket::SSL->start_SSL($socket, ... )
1721           This will convert a glob reference or a socket that you provide to
1722           an IO::Socket::SSL object.   You may also pass parameters to
1723           specify context or connection options as with a call to new().  If
1724           you are using this function on an accept()ed socket, you must set
1725           the parameter "SSL_server" to 1, i.e.
1726           IO::Socket::SSL->start_SSL($socket, SSL_server => 1).  If you have
1727           a class that inherits from IO::Socket::SSL and you want the $socket
1728           to be blessed into your own class instead, use
1729           MyClass->start_SSL($socket) to achieve the desired effect.
1730
1731           Note that if start_SSL() fails in SSL negotiation, $socket will
1732           remain blessed in its original class.    For non-blocking sockets
1733           you better just upgrade the socket to IO::Socket::SSL and call
1734           accept_SSL or connect_SSL and the upgraded object. To just upgrade
1735           the socket set SSL_startHandshake explicitly to 0. If you call
1736           start_SSL w/o this parameter it will revert to blocking behavior
1737           for accept_SSL and connect_SSL.
1738
1739           If given the parameter "Timeout" it will stop if after the timeout
1740           no SSL connection was established. This parameter is only used for
1741           blocking sockets, if it is not given the default Timeout from the
1742           underlying IO::Socket will be used.
1743
1744       stop_SSL(...)
1745           This is the opposite of start_SSL(), connect_SSL() and
1746           accept_SSL(), e.g. it will shutdown the SSL connection and return
1747           to the class before start_SSL(). It gets the same arguments as
1748           close(), in fact close() calls stop_SSL() (but without downgrading
1749           the class).
1750
1751           Will return true if it succeeded and undef if failed. This might be
1752           the case for non-blocking sockets. In this case $! is set to
1753           EWOULDBLOCK and the ssl error to SSL_WANT_READ or SSL_WANT_WRITE.
1754           In this case the call should be retried again with the same
1755           arguments once the socket is ready.
1756
1757           For calling from "stop_SSL" "SSL_fast_shutdown" default to false,
1758           e.g. it waits for the close_notify of the peer. This is necessary
1759           in case you want to downgrade the socket and continue to use it as
1760           a plain socket.
1761
1762           After stop_SSL the socket can again be used to exchange plain data.
1763
1764       connect_SSL, accept_SSL
1765           These functions should be used to do the relevant handshake, if the
1766           socket got created with "new" or upgraded with "start_SSL" and
1767           "SSL_startHandshake" was set to false.  They will return undef
1768           until the handshake succeeded or an error got thrown.  As long as
1769           the function returns undef and $! is set to EWOULDBLOCK one could
1770           retry the call after the socket got readable (SSL_WANT_READ) or
1771           writeable (SSL_WANT_WRITE).
1772
1773       ocsp_resolver
1774           This will create an OCSP resolver object, which can be used to
1775           create OCSP requests for the certificates of the SSL connection.
1776           Which certificates are verified depends on the setting of
1777           "SSL_ocsp_mode": by default only the leaf certificate will be
1778           checked, but with SSL_OCSP_FULL_CHAIN all chain certificates will
1779           be checked.
1780
1781           Because to create an OCSP request the certificate and its issuer
1782           certificate need to be known it is not possible to check
1783           certificates when the trust chain is incomplete or if the
1784           certificate is self-signed.
1785
1786           The OCSP resolver gets created by calling "$ssl->ocsp_resolver" and
1787           provides the following methods:
1788
1789           hard_error
1790                   This returns the hard error when checking the OCSP
1791                   response.  Hard errors are certificate revocations. With
1792                   the "SSL_ocsp_mode" of SSL_OCSP_FAIL_HARD any soft error
1793                   (e.g. failures to get signed information about the
1794                   certificates) will be considered a hard error too.
1795
1796                   The OCSP resolving will stop on the first hard error.
1797
1798                   The method will return undef as long as no hard errors
1799                   occurred and still requests to be resolved. If all requests
1800                   got resolved and no hard errors occurred the method will
1801                   return ''.
1802
1803           soft_error
1804                   This returns the soft error(s) which occurred when asking
1805                   the OCSP responders.
1806
1807           requests
1808                   This will return a hash consisting of
1809                   "(url,request)"-tuples, e.g. which contain the OCSP request
1810                   string and the URL where it should be sent too. The usual
1811                   way to send such a request is as HTTP POST request with a
1812                   content-type of "application/ocsp-request" or as a GET
1813                   request with the base64 and url-encoded request is added to
1814                   the path of the URL.
1815
1816                   After you've handled all these requests and added the
1817                   response with "add_response" you should better call this
1818                   method again to make sure, that no more requests are
1819                   outstanding. IO::Socket::SSL will combine multiple OCSP
1820                   requests for the same server inside a single request, but
1821                   some server don't give a response to all these requests, so
1822                   that one has to ask again with the remaining requests.
1823
1824           add_response($uri,$response)
1825                   This method takes the HTTP body of the response which got
1826                   received when sending the OCSP request to $uri. If no
1827                   response was received or an error occurred one should
1828                   either retry or consider $response as empty which will
1829                   trigger a soft error.
1830
1831                   The method returns the current value of "hard_error", e.g.
1832                   a defined value when no more requests need to be done.
1833
1834           resolve_blocking(%args)
1835                   This combines "requests" and "add_response" which
1836                   HTTP::Tiny to do all necessary requests in a blocking way.
1837                   %args will be given to HTTP::Tiny so that you can put proxy
1838                   settings etc here. HTTP::Tiny will be called with
1839                   "verify_SSL" of false, because the OCSP responses have
1840                   their own signatures so no extra SSL verification is
1841                   needed.
1842
1843                   If you don't want to use blocking requests you need to roll
1844                   your own user agent with "requests" and "add_response".
1845
1846       IO::Socket::SSL->new_from_fd($fd, [mode], %sslargs)
1847           This will convert a socket identified via a file descriptor into an
1848           SSL socket.  Note that the argument list does not include a "MODE"
1849           argument; if you supply one, it will be thoughtfully ignored (for
1850           compatibility with IO::Socket::INET).  Instead, a mode of '+<' is
1851           assumed, and the file descriptor passed must be able to handle such
1852           I/O because the initial SSL handshake requires bidirectional
1853           communication.
1854
1855           Internally the given $fd will be upgraded to a socket object using
1856           the "new_from_fd" method of the super class (IO::Socket::INET or
1857           similar) and then "start_SSL" will be called using the given
1858           %sslargs.  If $fd is already an IO::Socket object you should better
1859           call "start_SSL" directly.
1860
1861       IO::Socket::SSL::default_ca([ path|dir| SSL_ca_file = ..., SSL_ca_path
1862       => ... ])>
1863           Determines or sets the default CA path.  If existing path or dir or
1864           a hash is given it will set the default CA path to this value and
1865           never try to detect it automatically.  If "undef" is given it will
1866           forget any stored defaults and continue with detection of system
1867           defaults.  If no arguments are given it will start detection of
1868           system defaults, unless it has already stored user-set or
1869           previously detected values.
1870
1871           The detection of system defaults works similar to OpenSSL, e.g. it
1872           will check the directory specified in environment variable
1873           SSL_CERT_DIR or the path OPENSSLDIR/certs (SSLCERTS: on VMS) and
1874           the file specified in environment variable SSL_CERT_FILE or the
1875           path OPENSSLDIR/cert.pem (SSLCERTS:cert.pem on VMS). Contrary to
1876           OpenSSL it will check if the SSL_ca_path contains PEM files with
1877           the hash as file name and if the SSL_ca_file looks like PEM.  If no
1878           usable system default can be found it will try to load and use
1879           Mozilla::CA and if not available give up detection.  The result of
1880           the detection will be saved to speed up future calls.
1881
1882           The function returns the saved default CA as hash with SSL_ca_file
1883           and SSL_ca_path.
1884
1885       IO::Socket::SSL::set_default_context(...)
1886           You may use this to make IO::Socket::SSL automatically re-use a
1887           given context (unless specifically overridden in a call to new()).
1888           It accepts one argument, which should be either an IO::Socket::SSL
1889           object or an IO::Socket::SSL::SSL_Context object.  See the
1890           SSL_reuse_ctx option of new() for more details.  Note that this
1891           sets the default context globally, so use with caution (esp. in
1892           mod_perl scripts).
1893
1894       IO::Socket::SSL::set_default_session_cache(...)
1895           You may use this to make IO::Socket::SSL automatically re-use a
1896           given session cache (unless specifically overridden in a call to
1897           new()).  It accepts one argument, which should be an
1898           IO::Socket::SSL::Session_Cache object or similar (e.g. something
1899           which implements get_session, add_session and del_session like
1900           IO::Socket::SSL::Session_Cache does).  See the SSL_session_cache
1901           option of new() for more details.  Note that this sets the default
1902           cache globally, so use with caution.
1903
1904       IO::Socket::SSL::set_defaults(%args)
1905           With this function one can set defaults for all SSL_* parameter
1906           used for creation of the context, like the SSL_verify* parameter.
1907           Any SSL_* parameter can be given or the following short versions:
1908
1909           mode - SSL_verify_mode
1910           callback - SSL_verify_callback
1911           scheme - SSL_verifycn_scheme
1912           name - SSL_verifycn_name
1913       IO::Socket::SSL::set_client_defaults(%args)
1914           Similar to "set_defaults", but only sets the defaults for client
1915           mode.
1916
1917       IO::Socket::SSL::set_server_defaults(%args)
1918           Similar to "set_defaults", but only sets the defaults for server
1919           mode.
1920
1921       IO::Socket::SSL::set_args_filter_hack(\&code|'use_defaults')
1922           Sometimes one has to use code which uses unwanted or invalid
1923           arguments for SSL, typically disabling SSL verification or setting
1924           wrong ciphers or SSL versions.  With this hack it is possible to
1925           override these settings and restore sanity.  Example:
1926
1927               IO::Socket::SSL::set_args_filter_hack( sub {
1928                   my ($is_server,$args) = @_;
1929                   if ( ! $is_server ) {
1930                       # client settings - enable verification with default CA
1931                       # and fallback hostname verification etc
1932                       delete @{$args}{qw(
1933                           SSL_verify_mode
1934                           SSL_ca_file
1935                           SSL_ca_path
1936                           SSL_verifycn_scheme
1937                           SSL_version
1938                       )};
1939                       # and add some fingerprints for known certs which are signed by
1940                       # unknown CAs or are self-signed
1941                       $args->{SSL_fingerprint} = ...
1942                   }
1943               });
1944
1945           With the short setting "set_args_filter_hack('use_defaults')" it
1946           will prefer the default settings in all cases. These default
1947           settings can be modified with "set_defaults", "set_client_defaults"
1948           and "set_server_defaults".
1949
1950       The following methods are unsupported (not to mention futile!) and
1951       IO::Socket::SSL will emit a large CROAK() if you are silly enough to
1952       use them:
1953
1954       truncate
1955       stat
1956       ungetc
1957       setbuf
1958       setvbuf
1959       fdopen
1960       send/recv
1961           Note that send() and recv() cannot be reliably trapped by a tied
1962           filehandle (such as that used by IO::Socket::SSL) and so may send
1963           unencrypted data over the socket.    Object-oriented calls to these
1964           functions will fail, telling you to use the print/printf/syswrite
1965           and read/sysread families instead.
1966

DEPRECATIONS

1968       The following functions are deprecated and are only retained for
1969       compatibility:
1970
1971       context_init()
1972         use the SSL_reuse_ctx option if you want to re-use a context
1973
1974       socketToSSL() and socket_to_SSL()
1975         use IO::Socket::SSL->start_SSL() instead
1976
1977       kill_socket()
1978         use close() instead
1979
1980       get_peer_certificate()
1981         use the peer_certificate() function instead.  Used to return
1982         X509_Certificate with methods subject_name and issuer_name.  Now
1983         simply returns $self which has these methods (although deprecated).
1984
1985       issuer_name()
1986         use peer_certificate( 'issuer' ) instead
1987
1988       subject_name()
1989         use peer_certificate( 'subject' ) instead
1990

EXAMPLES

1992       See the 'example' directory, the tests in 't' and also the tools in
1993       'util'.
1994

BUGS

1996       If you use IO::Socket::SSL together with threads you should load it
1997       (e.g. use or require) inside the main thread before creating any other
1998       threads which use it.  This way it is much faster because it will be
1999       initialized only once. Also there are reports that it might crash the
2000       other way.
2001
2002       Creating an IO::Socket::SSL object in one thread and closing it in
2003       another thread will not work.
2004
2005       IO::Socket::SSL does not work together with
2006       Storable::fd_retrieve/fd_store.  See BUGS file for more information and
2007       how to work around the problem.
2008
2009       Non-blocking and timeouts (which are based on non-blocking) are not
2010       supported on Win32, because the underlying IO::Socket::INET does not
2011       support non-blocking on this platform.
2012
2013       If you have a server and it looks like you have a memory leak you might
2014       check the size of your session cache. Default for Net::SSLeay seems to
2015       be 20480, see the example for SSL_create_ctx_callback for how to limit
2016       it.
2017
2018       TLS 1.3 support regarding session reuse is incomplete.
2019

SEE ALSO

2021       IO::Socket::INET, IO::Socket::INET6, IO::Socket::IP, Net::SSLeay.
2022

THANKS

2024       Many thanks to all who added patches or reported bugs or helped
2025       IO::Socket::SSL another way. Please keep reporting bugs and help with
2026       patches, even if they just fix the documentation.
2027
2028       Special thanks to the team of Net::SSLeay for the good cooperation.
2029

AUTHORS

2031       Steffen Ullrich, <sullr at cpan.org> is the current maintainer.
2032
2033       Peter Behroozi, <behrooz at fas.harvard.edu> (Note the lack of an "i"
2034       at the end of "behrooz")
2035
2036       Marko Asplund, <marko.asplund at kronodoc.fi>, was the original author
2037       of IO::Socket::SSL.
2038
2039       Patches incorporated from various people, see file Changes.
2040
2042       The original versions of this module are Copyright (C) 1999-2002 Marko
2043       Asplund.
2044
2045       The rewrite of this module is Copyright (C) 2002-2005 Peter Behroozi.
2046
2047       Versions 0.98 and newer are Copyright (C) 2006-2014 Steffen Ullrich.
2048
2049       This module is free software; you can redistribute it and/or modify it
2050       under the same terms as Perl itself.
2051
2052
2053
2054perl v5.34.0                      2022-01-21                IO::Socket::SSL(3)
Impressum