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

DEPRECATIONS

1951       The following functions are deprecated and are only retained for
1952       compatibility:
1953
1954       context_init()
1955         use the SSL_reuse_ctx option if you want to re-use a context
1956
1957       socketToSSL() and socket_to_SSL()
1958         use IO::Socket::SSL->start_SSL() instead
1959
1960       kill_socket()
1961         use close() instead
1962
1963       get_peer_certificate()
1964         use the peer_certificate() function instead.  Used to return
1965         X509_Certificate with methods subject_name and issuer_name.  Now
1966         simply returns $self which has these methods (although deprecated).
1967
1968       issuer_name()
1969         use peer_certificate( 'issuer' ) instead
1970
1971       subject_name()
1972         use peer_certificate( 'subject' ) instead
1973

EXAMPLES

1975       See the 'example' directory, the tests in 't' and also the tools in
1976       'util'.
1977

BUGS

1979       If you use IO::Socket::SSL together with threads you should load it
1980       (e.g. use or require) inside the main thread before creating any other
1981       threads which use it.  This way it is much faster because it will be
1982       initialized only once. Also there are reports that it might crash the
1983       other way.
1984
1985       Creating an IO::Socket::SSL object in one thread and closing it in
1986       another thread will not work.
1987
1988       IO::Socket::SSL does not work together with
1989       Storable::fd_retrieve/fd_store.  See BUGS file for more information and
1990       how to work around the problem.
1991
1992       Non-blocking and timeouts (which are based on non-blocking) are not
1993       supported on Win32, because the underlying IO::Socket::INET does not
1994       support non-blocking on this platform.
1995
1996       If you have a server and it looks like you have a memory leak you might
1997       check the size of your session cache. Default for Net::SSLeay seems to
1998       be 20480, see the example for SSL_create_ctx_callback for how to limit
1999       it.
2000
2001       TLS 1.3 support regarding session reuse is incomplete.
2002

SEE ALSO

2004       IO::Socket::INET, IO::Socket::INET6, IO::Socket::IP, Net::SSLeay.
2005

THANKS

2007       Many thanks to all who added patches or reported bugs or helped
2008       IO::Socket::SSL another way. Please keep reporting bugs and help with
2009       patches, even if they just fix the documentation.
2010
2011       Special thanks to the team of Net::SSLeay for the good cooperation.
2012

AUTHORS

2014       Steffen Ullrich, <sullr at cpan.org> is the current maintainer.
2015
2016       Peter Behroozi, <behrooz at fas.harvard.edu> (Note the lack of an "i"
2017       at the end of "behrooz")
2018
2019       Marko Asplund, <marko.asplund at kronodoc.fi>, was the original author
2020       of IO::Socket::SSL.
2021
2022       Patches incorporated from various people, see file Changes.
2023
2025       The original versions of this module are Copyright (C) 1999-2002 Marko
2026       Asplund.
2027
2028       The rewrite of this module is Copyright (C) 2002-2005 Peter Behroozi.
2029
2030       Versions 0.98 and newer are Copyright (C) 2006-2014 Steffen Ullrich.
2031
2032       This module is free software; you can redistribute it and/or modify it
2033       under the same terms as Perl itself.
2034
2035
2036
2037perl v5.32.1                      2021-03-19                IO::Socket::SSL(3)
Impressum