.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "IO::Async::SSL 3pm" .TH IO::Async::SSL 3pm "2020-04-11" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" "IO::Async::SSL" \- use SSL/TLS with IO::Async .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use IO::Async::Loop; \& use IO::Async::SSL; \& \& my $loop = IO::Async::Loop\->new(); \& \& $loop\->SSL_connect( \& host => "www.example.com", \& service => "https", \& \& on_stream => sub { \& my ( $stream ) = @_; \& \& $stream\->configure( \& on_read => sub { \& ... \& }, \& ); \& \& $loop\->add( $stream ); \& \& ... \& }, \& \& on_resolve_error => sub { print STDERR "Cannot resolve \- $_[0]\en"; }, \& on_connect_error => sub { print STDERR "Cannot connect\en"; }, \& on_ssl_error => sub { print STDERR "Cannot negotiate SSL \- $_[\-1]\en"; }, \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module extends existing IO::Async classes with extra methods to allow the use of \s-1SSL\s0 or TLS-based connections using IO::Socket::SSL. It does not directly provide any methods or functions of its own. .PP Primarily, it provides \f(CW\*(C`SSL_connect\*(C'\fR and \f(CW\*(C`SSL_listen\*(C'\fR, which yield \&\f(CW\*(C`IO::Socket::SSL\*(C'\fR\-upgraded socket handles or IO::Async::Stream instances, and two forms of \f(CW\*(C`SSL_upgrade\*(C'\fR to upgrade an existing \s-1TCP\s0 connection to use \s-1SSL.\s0 .PP As an additional convenience, if the \f(CW\*(C`SSL_verify_mode\*(C'\fR and \f(CW\*(C`SSL_ca_*\*(C'\fR options are omitted, the module will attempt to provide them by quering the result of IO::Socket::SSL's \f(CW\*(C`default_ca\*(C'\fR function. Otherwise, the module will print a warning and set \f(CW\*(C`SSL_VERIFY_NONE\*(C'\fR instead. .SH "LOOP METHODS" .IX Header "LOOP METHODS" The following extra methods are added to IO::Async::Loop. .SS "SSL_upgrade" .IX Subsection "SSL_upgrade" .Vb 1 \& ( $stream or $socket ) = $loop\->SSL_upgrade( %params )\->get; .Ve .PP This method upgrades a given stream filehandle into an SSL-wrapped stream, returning a future which will yield the given stream object or socket. .PP Takes the following parameters: .IP "handle => IO::Async::Stream | \s-1IO\s0" 8 .IX Item "handle => IO::Async::Stream | IO" The \f(CW\*(C`IO::Async::Stream\*(C'\fR object containing the \s-1IO\s0 handle of an already-established connection to act as the transport for \s-1SSL\s0; or the plain \&\s-1IO\s0 socket handle itself. .Sp If an \f(CW\*(C`IO::Async::Stream\*(C'\fR is passed it will have the \f(CW\*(C`reader\*(C'\fR and \f(CW\*(C`writer\*(C'\fR functions set on it suitable for \s-1SSL\s0 use, and will be returned as the result from the future. .Sp If a plain socket handle is passed, that will be returned from the future instead. .IP "SSL_server => \s-1BOOL\s0" 8 .IX Item "SSL_server => BOOL" If true, indicates this is the server side of the connection. .PP In addition, any parameter whose name starts \f(CW\*(C`SSL_\*(C'\fR will be passed to the \&\f(CW\*(C`IO::Socket::SSL\*(C'\fR constructor. .PP The following legacy callback arguments are also supported, in case the returned future is not used: .IP "on_upgraded => \s-1CODE\s0" 8 .IX Item "on_upgraded => CODE" A continuation that is invoked when the socket has been successfully upgraded to \s-1SSL.\s0 It will be passed an instance of an \f(CW\*(C`IO::Socket::SSL\*(C'\fR, which will have appropriate SSL-compatible reader/writer functions attached. .Sp .Vb 1 \& $on_upgraded\->( $sslsocket ) .Ve .IP "on_error => \s-1CODE\s0" 8 .IX Item "on_error => CODE" A continuation that is invoked if \f(CW\*(C`IO::Socket::SSL\*(C'\fR detects an error while negotiating the upgrade. .Sp .Vb 1 \& $on_error\->( $! ) .Ve .SS "SSL_connect" .IX Subsection "SSL_connect" .Vb 1 \& $stream = $loop\->SSL_connect( %params )\->get; .Ve .PP This method performs a non-blocking connection to a given address or set of addresses, upgrades the socket to \s-1SSL,\s0 then yields a \f(CW\*(C`IO::Async::Stream\*(C'\fR object when the \s-1SSL\s0 handshake is complete. .PP It takes all the same arguments as \f(CW\*(C`IO::Async::Loop::connect()\*(C'\fR. Any argument whose name starts \f(CW\*(C`SSL_\*(C'\fR will be passed on to the IO::Socket::SSL constructor rather than the Loop's \f(CW\*(C`connect\*(C'\fR method. It is not required to pass the \f(CW\*(C`socktype\*(C'\fR option, as \s-1SSL\s0 implies this will be \f(CW\*(C`stream\*(C'\fR. .PP This method can also upgrade an existing \f(CW\*(C`IO::Async::Stream\*(C'\fR or subclass instance given as the \f(CW\*(C`handle\*(C'\fR argument, by setting the \f(CW\*(C`reader\*(C'\fR and \&\f(CW\*(C`writer\*(C'\fR functions. .SS "SSL_connect (void)" .IX Subsection "SSL_connect (void)" .Vb 4 \& $loop\->SSL_connect( %params, \& on_connected => sub { ... }, \& on_stream => sub { ... }, \& ); .Ve .PP When not returning a future, this method also supports the \f(CW\*(C`on_connected\*(C'\fR and \&\f(CW\*(C`on_stream\*(C'\fR continuations. .PP In addition, the following arguments are then required: .IP "on_ssl_error => \s-1CODE\s0" 8 .IX Item "on_ssl_error => CODE" A continuation that is invoked if \f(CW\*(C`IO::Socket::SSL\*(C'\fR detects an SSL-based error once the actual stream socket is connected. .PP If the \f(CW\*(C`on_connected\*(C'\fR continuation is used, the socket handle it yields will be a \f(CW\*(C`IO::Socket::SSL\*(C'\fR, which must be wrapped in \f(CW\*(C`IO::Async::SSLStream\*(C'\fR to be used by \f(CW\*(C`IO::Async\*(C'\fR. The \f(CW\*(C`on_stream\*(C'\fR continuation will already yield such an instance. .SS "SSL_listen" .IX Subsection "SSL_listen" .Vb 1 \& $loop\->SSL_listen( %params )\->get; .Ve .PP This method sets up a listening socket using the addresses given, and will invoke the callback each time a new connection is accepted on the socket and the \s-1SSL\s0 handshake has been completed. This can be either the \f(CW\*(C`on_accept\*(C'\fR or \&\f(CW\*(C`on_stream\*(C'\fR continuation; \f(CW\*(C`on_socket\*(C'\fR is not supported. .PP It takes all the same arguments as \f(CW\*(C`IO::Async::Loop::listen()\*(C'\fR. Any argument whose name starts \f(CW\*(C`SSL_\*(C'\fR will be passed on to the IO::Socket::SSL constructor rather than the Loop's \f(CW\*(C`listen\*(C'\fR method. It is not required to pass the \f(CW\*(C`socktype\*(C'\fR option, as \s-1SSL\s0 implies this will be \f(CW\*(C`stream\*(C'\fR. .PP In addition, the following arguments are rquired: .IP "on_ssl_error => \s-1CODE\s0" 8 .IX Item "on_ssl_error => CODE" A continuation that is invoked if \f(CW\*(C`IO::Socket::SSL\*(C'\fR detects an SSL-based error once the actual stream socket is connected. .PP The underlying IO::Socket::SSL socket will also require the server key and certificate for a server-mode socket. See its documentation for more details. .PP If the \f(CW\*(C`on_accept\*(C'\fR continuation is used, the socket handle it yields will be a \f(CW\*(C`IO::Socket::SSL\*(C'\fR, which must be wrapped in \f(CW\*(C`IO::Async::SSLStream\*(C'\fR to be used by \f(CW\*(C`IO::Async\*(C'\fR. The \f(CW\*(C`on_stream\*(C'\fR continuation will already yield such an instance. .SH "STREAM PROTOCOL METHODS" .IX Header "STREAM PROTOCOL METHODS" The following extra methods are added to IO::Async::Protocol::Stream. .SS "SSL_upgrade" .IX Subsection "SSL_upgrade" .Vb 1 \& $protocol\->SSL_upgrade( %params )\->get; .Ve .PP A shortcut to calling \f(CW\*(C`$loop\->SSL_upgrade\*(C'\fR. This method will unconfigure the \f(CW\*(C`transport\*(C'\fR of the Protocol, upgrade its underlying filehandle to \s-1SSL,\s0 then reconfigure it again with \s-1SSL\s0 reader and writer functions on it. It takes the same arguments as \f(CW\*(C`$loop\->SSL_upgrade\*(C'\fR, except that the \f(CW\*(C`handle\*(C'\fR argument is not required as it's taken from the Protocol's \f(CW\*(C`transport\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Paul Evans