????
Current Path : /usr/man/man3/ |
Current File : //usr/man/man3/Net::SSLeay.3 |
.\" Automatically generated by Pod::Man 2.26 (Pod::Simple 3.22) .\" .\" 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 turned on, 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 "Net::SSLeay 3" .TH Net::SSLeay 3 "2010-01-30" "perl v5.14.3" "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" Net::SSLeay \- Perl extension for using OpenSSL .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::SSLeay qw(get_https post_https sslcat make_headers make_form); \& \& ($page) = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); # 1 \& \& ($page, $response, %reply_headers) \& = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq, # 2 \& make_headers(User\-Agent => \*(AqCryptozilla/5.0b1\*(Aq, \& Referer => \*(Aqhttps://www.bacus.pt\*(Aq \& )); \& \& ($page, $result, %headers) = # 2b \& = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/protected.html\*(Aq, \& make_headers(Authorization => \& \*(AqBasic \*(Aq . MIME::Base64::encode("$user:$pass",\*(Aq\*(Aq)) \& ); \& \& ($page, $response, %reply_headers) \& = post_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/foo.cgi\*(Aq, \*(Aq\*(Aq, # 3 \& make_form(OK => \*(Aq1\*(Aq, \& name => \*(AqSampo\*(Aq \& )); \& \& $reply = sslcat($host, $port, $request); # 4 \& \& ($reply, $err, $server_cert) = sslcat($host, $port, $request); # 5 \& \& $Net::SSLeay::trace = 2; # 0=no debugging, 1=ciphers, 2=trace, 3=dump data .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" There is a related module called \f(CW\*(C`Net::SSLeay::Handle\*(C'\fR included in this distribution that you might want to use instead. It has its own pod documentation. .PP This module offers some high level convenience functions for accessing web pages on \s-1SSL\s0 servers (for symmetry, the same \s-1API\s0 is offered for accessing http servers, too), an \f(CW\*(C`sslcat()\*(C'\fR function for writing your own clients, and finally access to the \s-1SSL\s0 api of the SSLeay/OpenSSL package so you can write servers or clients for more complicated applications. .PP For high level functions it is most convenient to import them into your main namespace as indicated in the synopsis. .PP Case 1 demonstrates the typical invocation of \fIget_https()\fR to fetch an \s-1HTML\s0 page from secure server. The first argument provides the hostname or \s-1IP\s0 in dotted decimal notation of the remote server to contact. The second argument is the \s-1TCP\s0 port at the remote end (your own port is picked arbitrarily from high numbered ports as usual for \s-1TCP\s0). The third argument is the \s-1URL\s0 of the page without the host name part. If in doubt consult the \s-1HTTP\s0 specifications at <http://www.w3c.org>. .PP Case 2 demonstrates full fledged use of \f(CW\*(C`get_https()\*(C'\fR. As can be seen, \&\f(CW\*(C`get_https()\*(C'\fR parses the response and response headers and returns them as a list, which can be captured in a hash for later reference. Also a fourth argument to \f(CW\*(C`get_https()\*(C'\fR is used to insert some additional headers in the request. \f(CW\*(C`make_headers()\*(C'\fR is a function that will convert a list or hash to such headers. By default \f(CW\*(C`get_https()\*(C'\fR supplies \f(CW\*(C`Host\*(C'\fR (to make virtual hosting easy) and \f(CW\*(C`Accept\*(C'\fR (reportedly needed by \s-1IIS\s0) headers. .PP Case 2b demonstrates how to get a password protected page. Refer to the \s-1HTTP\s0 protocol specifications for further details (e.g. \s-1RFC\-2617\s0). .PP Case 3 invokes \f(CW\*(C`post_https()\*(C'\fR to submit a \s-1HTML/CGI\s0 form to a secure server. The first four arguments are equal to \f(CW\*(C`get_https()\*(C'\fR (note that the empty string (\f(CW\*(Aq\*(Aq\fR) is passed as header argument). The fifth argument is the contents of the form formatted according to \s-1CGI\s0 specification. In this case the helper function \f(CW\*(C`make_https()\*(C'\fR is used to do the formatting, but you could pass any string. \f(CW\*(C`post_https()\*(C'\fR automatically adds \&\f(CW\*(C`Content\-Type\*(C'\fR and \f(CW\*(C`Content\-Length\*(C'\fR headers to the request. .PP Case 4 shows the fundamental \f(CW\*(C`sslcat()\*(C'\fR function (inspired in spirit by the \f(CW\*(C`netcat\*(C'\fR utility :\-). It's your swiss army knife that allows you to easily contact servers, send some data, and then get the response. You are responsible for formatting the data and parsing the response \- \&\f(CW\*(C`sslcat()\*(C'\fR is just a transport. .PP Case 5 is a full invocation of \f(CW\*(C`sslcat()\*(C'\fR which allows the return of errors as well as the server (peer) certificate. .PP The \f(CW$trace\fR global variable can be used to control the verbosity of the high level functions. Level 0 guarantees silence, level 1 (the default) only emits error messages. .SS "Alternate versions of the \s-1API\s0" .IX Subsection "Alternate versions of the API" The above mentioned functions actually return the response headers as a list, which only gets converted to hash upon assignment (this assignment looses information if the same header occurs twice, as may be the case with cookies). There are also other variants of the functions that return unprocessed headers and that return a reference to a hash. .PP .Vb 4 \& ($page, $response, @headers) = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); \& for ($i = 0; $i < $#headers; $i+=2) { \& print "$headers[$i] = " . $headers[$i+1] . "\en"; \& } \& \& ($page, $response, $headers, $server_cert) \& = get_https3(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); \& print "$headers\en"; \& \& ($page, $response, %headers_ref, $server_cert) \& = get_https4(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); \& for $k (sort keys %{headers_ref}) { \& for $v (@{$headers_ref{$k}}) { \& print "$k = $v\en"; \& } \& } .Ve .PP All of the above code fragments accomplish the same thing: display all values of all headers. The \s-1API\s0 functions ending in \*(L"3\*(R" return the headers simply as a scalar string and it is up to the application to split them up. The functions ending in \*(L"4\*(R" return a reference to a hash of arrays (see perlref and perllol if you are not familiar with complex perl data structures). To access a single value of such a header hash you would do something like .PP .Vb 1 \& print $headers_ref{COOKIE}[0]; .Ve .PP Variants 3 and 4 also allow you to discover the server certificate in case you would like to store or display it, e.g. .PP .Vb 11 \& ($p, $resp, $hdrs, $server_cert) = get_https3(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); \& if (!defined($server_cert) || ($server_cert == 0)) { \& warn "Subject Name: undefined, Issuer Name: undefined"; \& } else { \& warn \*(AqSubject Name: \*(Aq \& . Net::SSLeay::X509_NAME_oneline( \& Net::SSLeay::X509_get_subject_name($server_cert)) \& . \*(AqIssuer Name: \*(Aq \& . Net::SSLeay::X509_NAME_oneline( \& Net::SSLeay::X509_get_issuer_name($server_cert)); \& } .Ve .PP Beware that this method only allows after the fact verification of the certificate: by the time \f(CW\*(C`get_https3()\*(C'\fR has returned the https request has already been sent to the server, whether you decide to trust it or not. To do the verification correctly you must either employ the OpenSSL certificate verification framework or use the lower level \s-1API\s0 to first connect and verify the certificate and only then send the http data. See the implementation of \f(CW\*(C`ds_https3()\*(C'\fR for guidance on how to do this. .SS "Using client certificates" .IX Subsection "Using client certificates" Secure web communications are encrypted using symmetric crypto keys exchanged using encryption based on the certificate of the server. Therefore in all \s-1SSL\s0 connections the server must have a certificate. This serves both to authenticate the server to the clients and to perform the key exchange. .PP Sometimes it is necessary to authenticate the client as well. Two options are available: \s-1HTTP\s0 basic authentication and a client side certificate. The basic authentication over \s-1HTTPS\s0 is actually quite safe because \s-1HTTPS\s0 guarantees that the password will not travel in the clear. Never-the-less, problems like easily guessable passwords remain. The client certificate method involves authentication of the client at the \s-1SSL\s0 level using a certificate. For this to work, both the client and the server have certificates (which typically are different) and private keys. .PP The \s-1API\s0 functions outlined above accept additional arguments that allow one to supply the client side certificate and key files. The format of these files is the same as used for server certificates and the caveat about encrypting private keys applies. .PP .Vb 5 \& ($page, $result, %headers) = # 2c \& = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/protected.html\*(Aq, \& make_headers(Authorization => \& \*(AqBasic \*(Aq . MIME::Base64::encode("$user:$pass",\*(Aq\*(Aq)), \& \*(Aq\*(Aq, $mime_type6, $path_to_crt7, $path_to_key8); \& \& ($page, $response, %reply_headers) \& = post_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/foo.cgi\*(Aq, # 3b \& make_headers(\*(AqAuthorization\*(Aq => \& \*(AqBasic \*(Aq . MIME::Base64::encode("$user:$pass",\*(Aq\*(Aq)), \& make_form(OK => \*(Aq1\*(Aq, name => \*(AqSampo\*(Aq), \& $mime_type6, $path_to_crt7, $path_to_key8); .Ve .PP Case 2c demonstrates getting a password protected page that also requires a client certificate, i.e. it is possible to use both authentication methods simultaneously. .PP Case 3b is a full blown \s-1POST\s0 to a secure server that requires both password authentication and a client certificate, just like in case 2c. .PP Note: The client will not send a certificate unless the server requests one. This is typically achieved by setting the verify mode to \f(CW\*(C`VERIFY_PEER\*(C'\fR on the server: .PP .Vb 1 \& Net::SSLeay::set_verify(ssl, Net::SSLeay::VERIFY_PEER, 0); .Ve .PP See \f(CW\*(C`perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod\*(C'\fR for a full description. .SS "Working through a web proxy" .IX Subsection "Working through a web proxy" \&\f(CW\*(C`Net::SSLeay\*(C'\fR can use a web proxy to make its connections. You need to first set the proxy host and port using \f(CW\*(C`set_proxy()\*(C'\fR and then just use the normal \s-1API\s0 functions, e.g: .PP .Vb 2 \& Net::SSLeay::set_proxy(\*(Aqgateway.myorg.com\*(Aq, 8080); \& ($page) = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/\*(Aq); .Ve .PP If your proxy requires authentication, you can supply a username and password as well .PP .Vb 6 \& Net::SSLeay::set_proxy(\*(Aqgateway.myorg.com\*(Aq, 8080, \*(Aqjoe\*(Aq, \*(Aqsalainen\*(Aq); \& ($page, $result, %headers) = \& = get_https(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/protected.html\*(Aq, \& make_headers(Authorization => \& \*(AqBasic \*(Aq . MIME::Base64::encode("susie:pass",\*(Aq\*(Aq)) \& ); .Ve .PP This example demonstrates the case where we authenticate to the proxy as \&\f(CW"joe"\fR and to the final web server as \f(CW"susie"\fR. Proxy authentication requires the \f(CW\*(C`MIME::Base64\*(C'\fR module to work. .SS "Certificate verification and Certificate Revoocation Lists (CRLs)" .IX Subsection "Certificate verification and Certificate Revoocation Lists (CRLs)" OpenSSL supports the ability to verify peer certificates. It can also optionally check the peer certificate against a Certificate Revocation List (\s-1CRL\s0) from the certificates issuer. A \s-1CRL\s0 is a file, created by the certificate issuer that lists all the certificates that it previously signed, but which it now revokes. CRLs are in \s-1PEM\s0 format. .PP You can enable \f(CW\*(C`Net::SSLeay CRL\*(C'\fR checking like this: .PP .Vb 3 \& &Net::SSLeay::X509_STORE_CTX_set_flags \& (&Net::SSLeay::CTX_get_cert_store($ssl), \& &Net::SSLeay::X509_V_FLAG_CRL_CHECK); .Ve .PP After setting this flag, if OpenSSL checks a peer's certificate, then it will attempt to find a \s-1CRL\s0 for the issuer. It does this by looking for a specially named file in the search directory specified by CTX_load_verify_locations. \s-1CRL\s0 files are named with the hash of the issuer's subject name, followed by \f(CW\*(C`.r0\*(C'\fR, \f(CW\*(C`.r1\*(C'\fR etc. For example \&\f(CW\*(C`ab1331b2.r0\*(C'\fR, \f(CW\*(C`ab1331b2.r1\*(C'\fR. It will read all the .r files for the issuer, and then check for a revocation of the peer cerificate in all of them. (You can also force it to look in a specific named \s-1CRL\s0 file., see below). You can find out the hash of the issuer subject name in a \s-1CRL\s0 with .PP .Vb 1 \& openssl crl \-in crl.pem \-hash \-noout .Ve .PP If the peer certificate does not pass the revocation list, or if no \&\s-1CRL\s0 is found, then the handshaking fails with an error. .PP You can also force OpenSSL to look for CRLs in one or more arbitrarily named files. .PP .Vb 7 \& my $bio = Net::SSLeay::BIO_new_file($crlfilename, \*(Aqr\*(Aq); \& my $crl = Net::SSLeay::PEM_read_bio_X509_CRL($bio); \& if ($crl) { \& Net::SSLeay::X509_STORE_add_crl(Net::SSLeay::CTX_get_cert_store($ssl, $crl); \& } else { \& error reading CRL.... \& } .Ve .SS "Convenience routines" .IX Subsection "Convenience routines" To be used with Low level \s-1API\s0 .PP .Vb 5 \& Net::SSLeay::randomize($rn_seed_file,$additional_seed); \& Net::SSLeay::set_cert_and_key($ctx, $cert_path, $key_path); \& $cert = Net::SSLeay::dump_peer_certificate($ssl); \& Net::SSLeay::ssl_write_all($ssl, $message) or die "ssl write failure"; \& $got = Net::SSLeay::ssl_read_all($ssl) or die "ssl read failure"; \& \& $got = Net::SSLeay::ssl_read_CRLF($ssl [, $max_length]); \& $got = Net::SSLeay::ssl_read_until($ssl [, $delimit [, $max_length]]); \& Net::SSLeay::ssl_write_CRLF($ssl, $message); .Ve .PP \&\f(CW\*(C`randomize()\*(C'\fR seeds the openssl \s-1PRNG\s0 with \f(CW\*(C`/dev/urandom\*(C'\fR (see the top of \f(CW\*(C`SSLeay.pm\*(C'\fR for how to change or configure this) and optionally with user provided data. It is very important to properly seed your random numbers, so do not forget to call this. The high level \s-1API\s0 functions automatically call \f(CW\*(C`randomize()\*(C'\fR so it is not needed with them. See also caveats. .PP \&\f(CW\*(C`set_cert_and_key()\*(C'\fR takes two file names as arguments and sets the certificate and private key to those. This can be used to set either cerver certificates or client certificates. .PP \&\f(CW\*(C`dump_peer_certificate()\*(C'\fR allows you to get a plaintext description of the certificate the peer (usually the server) presented to us. .PP \&\f(CW\*(C`ssl_read_all()\*(C'\fR and \f(CW\*(C`ssl_write_all()\*(C'\fR provide true blocking semantics for these operations (see limitation, below, for explanation). These are much preferred to the low level \s-1API\s0 equivalents (which implement \s-1BSD\s0 blocking semantics). The message argument to \f(CW\*(C`ssl_write_all()\*(C'\fR can be a reference. This is helpful to avoid unnecessary copying when writing something big, e.g: .PP .Vb 2 \& $data = \*(AqA\*(Aq x 1000000000; \& Net::SSLeay::ssl_write_all($ssl, \e$data) or die "ssl write failed"; .Ve .PP \&\f(CW\*(C`ssl_read_CRLF()\*(C'\fR uses \f(CW\*(C`ssl_read_all()\*(C'\fR to read in a line terminated with a carriage return followed by a linefeed (\s-1CRLF\s0). The \s-1CRLF\s0 is included in the returned scalar. .PP \&\f(CW\*(C`ssl_read_until()\*(C'\fR uses \f(CW\*(C`ssl_read_all()\*(C'\fR to read from the \s-1SSL\s0 input stream until it encounters a programmer specified delimiter. If the delimiter is undefined, \f(CW$/\fR is used. If \f(CW$/\fR is undefined, \&\f(CW\*(C`\en\*(C'\fR is used. One can optionally set a maximum length of bytes to read from the \s-1SSL\s0 input stream. .PP \&\f(CW\*(C`ssl_write_CRLF()\*(C'\fR writes \f(CW$message\fR and appends \s-1CRLF\s0 to the \s-1SSL\s0 output stream. .SS "Low level \s-1API\s0" .IX Subsection "Low level API" In addition to the high level functions outlined above, this module contains straight-forward access to \s-1SSL\s0 part of OpenSSL C api. Only the \s-1SSL\s0 subpart of OpenSSL is implemented (if anyone wants to implement other parts, feel free to submit patches). .PP See the \f(CW\*(C`ssl.h\*(C'\fR header from OpenSSL C distribution for a list of low level SSLeay functions to call (check SSLeay.xs to see if some function has been implemented). The module strips the initial \f(CW"SSL_"\fR off of the SSLeay names. Generally you should use \f(CW\*(C`Net::SSLeay::\*(C'\fR in its place. For example: .PP In C: .PP .Vb 1 \& #include <ssl.h> \& \& err = SSL_set_verify (ssl, SSL_VERIFY_CLIENT_ONCE, \& &your_call_back_here); .Ve .PP In Perl: .PP .Vb 1 \& use Net::SSLeay; \& \& $err = Net::SSLeay::set_verify ($ssl, \& Net::SSLeay::VERIFY_CLIENT_ONCE, \& \e&your_call_back_here); .Ve .PP If the function does not start with \f(CW\*(C`SSL_\*(C'\fR you should use the full function name, e.g.: .PP .Vb 1 \& $err = Net::SSLeay::ERR_get_error; .Ve .PP The following new functions behave in perlish way: .PP .Vb 4 \& $got = Net::SSLeay::read($ssl); \& # Performs SSL_read, but returns $got \& # resized according to data received. \& # Returns undef on failure. \& \& Net::SSLeay::write($ssl, $foo) || die; \& # Performs SSL_write, but automatically \& # figures out the size of $foo .Ve .PP In order to use the low level \s-1API\s0 you should start your programs with the following incantation: .PP .Vb 6 \& use Net::SSLeay qw(die_now die_if_ssl_error); \& Net::SSLeay::load_error_strings(); \& Net::SSLeay::SSLeay_add_ssl_algorithms(); # Important! \& Net::SSLeay::ENGINE_load_builtin_engines(); # If you want built\-in engines \& Net::SSLeay::ENGINE_register_all_complete(); # If you want built\-in engines \& Net::SSLeay::randomize(); .Ve .PP \&\f(CW\*(C`die_now()\*(C'\fR and \f(CW\*(C`die_if_ssl_error()\*(C'\fR are used to conveniently print the SSLeay error stack when something goes wrong, thusly: .PP .Vb 2 \& Net::SSLeay::connect($ssl) or die_now("Failed SSL connect ($!)"); \& Net::SSLeay::write($ssl, "foo") or die_if_ssl_error("SSL write ($!)"); .Ve .PP You can also use \f(CW\*(C`Net::SSLeay::print_errs()\*(C'\fR to dump the error stack without exiting the program. As can be seen, your code becomes much more readable if you import the error reporting functions into your main name space. .PP I can not emphasize the need to check for error enough. Use these functions even in the most simple programs, they will reduce debugging time greatly. Do not ask questions on the mailing list without having first sprinkled these in your code. .SS "Sockets" .IX Subsection "Sockets" Perl uses file handles for all I/O. While SSLeay has a quite flexible \s-1BIO\s0 mechanism and perl has an evolved PerlIO mechanism, this module still sticks to using file descriptors. Thus to attach SSLeay to a socket you should use \f(CW\*(C`fileno()\*(C'\fR to extract the underlying file descriptor: .PP .Vb 1 \& Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno .Ve .PP You should also set \f(CW$|\fR to 1 to eliminate \s-1STDIO\s0 buffering so you do not get confused if you use perl I/O functions to manipulate your socket handle. .PP If you need to \f(CWselect(2)\fR on the socket, go right ahead, but be warned that OpenSSL does some internal buffering so SSL_read does not always return data even if the socket selected for reading (just keep on selecting and trying to read). \f(CW\*(C`Net::SSLeay\*(C'\fR is no different from the C language OpenSSL in this respect. .SS "Callbacks" .IX Subsection "Callbacks" You can establish a per-context verify callback function something like this: .PP .Vb 6 \& sub verify { \& my ($ok, $x509_store_ctx) = @_; \& print "Verifying certificate...\en"; \& ... \& return $ok; \& } .Ve .PP It is used like this: .PP .Vb 1 \& Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, \e&verify); .Ve .PP Per-context callbacks for decrypting private keys are implemented. .PP .Vb 5 \& Net::SSLeay::CTX_set_default_passwd_cb($ctx, sub { "top\-secret" }); \& Net::SSLeay::CTX_use_PrivateKey_file($ctx, "key.pem", \& Net::SSLeay::FILETYPE_PEM) \& or die "Error reading private key"; \& Net::SSLeay::CTX_set_default_passwd_cb($ctx, undef); .Ve .PP If Hello Extensions are supported by your OpenSSL, a session secret callback can be set up to be called when a session secret is set by openssl. .PP Establish it like this: Net::SSLeay::set_session_secret_cb($ssl, \e&session_secret_cb, \f(CW$somedata\fR); .PP It will be called like this: .PP .Vb 4 \& sub session_secret_cb \& { \& my ($secret, \e@cipherlist, \e$preferredcipher, $somedata) = @_; \& } .Ve .PP No other callbacks are implemented. You do not need to use any callback for simple (i.e. normal) cases where the SSLeay built-in verify mechanism satisfies your needs. .PP It is required to reset these callbacks to undef immediately after use to prevent memory leaks, thread safety problems and crashes on exit that can occur if different threads set different callbacks. .PP If you want to use callback stuff, see examples/callback.pl! Its the only one I am able to make work reliably. .SS "X509 and \s-1RAND\s0 stuff" .IX Subsection "X509 and RAND stuff" This module largely lacks interface to the X509 and \s-1RAND\s0 routines, but as I was lazy and needed them, the following kludges are implemented: .PP .Vb 4 \& $x509_name = Net::SSLeay::X509_get_subject_name($x509_cert); \& $x509_name = Net::SSLeay::X509_get_issuer_name($x509_cert); \& print Net::SSLeay::X509_NAME_oneline($x509_name); \& $text = Net::SSLeay::X509_NAME_get_text_by_NID($name, $nid); \& \& ($type1, $subject1, $type2, $subject2, ...) = \& Net::SSLeay::X509_get_subjectAltNames($x509_cert) \& \& subjectAltName types as per x509v3.h GEN_*, for example \& GEN_DNS or GEN_IPADD which can be imported. \& \& Net::SSLeay::RAND_seed($buf); # Perlishly figures out buf size \& Net::SSLeay::RAND_bytes($buf, $num); \& Net::SSLeay::RAND_pseudo_bytes($buf, $num); \& Net::SSLeay::RAND_add($buf, $num, $entropy); \& Net::SSLeay::RAND_poll(); \& Net::SSLeay::RAND_status(); \& Net::SSLeay::RAND_cleanup(); \& Net::SSLeay::RAND_file_name($num); \& Net::SSLeay::RAND_load_file($file_name, $how_many_bytes); \& Net::SSLeay::RAND_write_file($file_name); \& Net::SSLeay::RAND_egd($path); \& Net::SSLeay::RAND_egd_bytes($path, $bytes); .Ve .PP Actually you should consider using the following helper functions: .PP .Vb 2 \& print Net::SSLeay::dump_peer_certificate($ssl); \& Net::SSLeay::randomize(); .Ve .SS "\s-1RSA\s0 interface" .IX Subsection "RSA interface" Some \s-1RSA\s0 functions are available: .PP .Vb 3 \& $rsakey = Net::SSLeay::RSA_generate_key(); \& Net::SSLeay::CTX_set_tmp_rsa($ctx, $rsakey); \& Net::SSLeay::RSA_free($rsakey); .Ve .SS "Digests" .IX Subsection "Digests" Some Digest functions are available if supported by the underlying library. These may include \s-1MD2\s0, \s-1MD4\s0, \s-1MD5\s0, and \s-1RIPEMD160:\s0 .PP .Vb 2 \& $hash = Net::SSLeay::MD5($foo); \& print unpack(\*(AqH*\*(Aq, $hash); .Ve .SS "\s-1BIO\s0 interface" .IX Subsection "BIO interface" Some \s-1BIO\s0 functions are available: .PP .Vb 10 \& Net::SSLeay::BIO_s_mem(); \& $bio = Net::SSLeay::BIO_new(BIO_s_mem()) \& $bio = Net::SSLeay::BIO_new_file($filename, $mode); \& Net::SSLeay::BIO_free($bio) \& $count = Net::SSLeay::BIO_write($data); \& $data = Net::SSLeay::BIO_read($bio); \& $data = Net::SSLeay::BIO_read($bio, $maxbytes); \& $is_eof = Net::SSLeay::BIO_eof($bio); \& $count = Net::SSLeay::BIO_pending($bio); \& $count = Net::SSLeay::BIO_wpending ($bio); .Ve .SS "Low level \s-1API\s0" .IX Subsection "Low level API" Some very low level \s-1API\s0 functions are available: .PP .Vb 6 \& $client_random = Net::SSLeay::get_client_random($ssl); \& $server_random = Net::SSLeay::get_server_random($ssl); \& $session = Net::SSLeay::get_session($ssl); \& $master_key = Net::SSLeay::SESSION_get_master_key($session); \& Net::SSLeay::SESSION_set_master_key($session, $master_secret); \& $keyblocksize = Net::SSLeay::get_keyblock_size($session); .Ve .SS "\s-1HTTP\s0 (without S) \s-1API\s0" .IX Subsection "HTTP (without S) API" Over the years it has become clear that it would be convenient to use the light-weight flavour \s-1API\s0 of \f(CW\*(C`Net::SSLeay\*(C'\fR for normal \s-1HTTP\s0 as well (see \&\f(CW\*(C`LWP\*(C'\fR for the heavy-weight object-oriented approach). In fact it would be nice to be able to flip https on and off on the fly. Thus regular \s-1HTTP\s0 support was evolved. .PP .Vb 3 \& use Net::SSLeay qw(get_http post_http tcpcat \& get_httpx post_httpx tcpxcat \& make_headers make_form); \& \& ($page, $result, %headers) = \& = get_http(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/protected.html\*(Aq, \& make_headers(Authorization => \& \*(AqBasic \*(Aq . MIME::Base64::encode("$user:$pass",\*(Aq\*(Aq)) \& ); \& \& ($page, $response, %reply_headers) \& = post_http(\*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/foo.cgi\*(Aq, \*(Aq\*(Aq, \& make_form(OK => \*(Aq1\*(Aq, \& name => \*(AqSampo\*(Aq \& )); \& \& ($reply, $err) = tcpcat($host, $port, $request); \& \& ($page, $result, %headers) = \& = get_httpx($usessl, \*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/protected.html\*(Aq, \& make_headers(Authorization => \& \*(AqBasic \*(Aq . MIME::Base64::encode("$user:$pass",\*(Aq\*(Aq)) \& ); \& \& ($page, $response, %reply_headers) \& = post_httpx($usessl, \*(Aqwww.bacus.pt\*(Aq, 443, \*(Aq/foo.cgi\*(Aq, \*(Aq\*(Aq, \& make_form(OK => \*(Aq1\*(Aq, name => \*(AqSampo\*(Aq )); \& \& ($reply, $err, $server_cert) = tcpxcat($usessl, $host, $port, $request); .Ve .PP As can be seen, the \f(CW"x"\fR family of APIs takes as the first argument a flag which indicates whether \s-1SSL\s0 is used or not. .SH "EXAMPLES" .IX Header "EXAMPLES" One very good example to look at is the implementation of \f(CW\*(C`sslcat()\*(C'\fR in the \&\f(CW\*(C`SSLeay.pm\*(C'\fR file. .PP The following is a simple SSLeay client (with too little error checking :\-( .PP .Vb 6 \& #!/usr/local/bin/perl \& use Socket; \& use Net::SSLeay qw(die_now die_if_ssl_error) ; \& Net::SSLeay::load_error_strings(); \& Net::SSLeay::SSLeay_add_ssl_algorithms(); \& Net::SSLeay::randomize(); \& \& ($dest_serv, $port, $msg) = @ARGV; # Read command line \& $port = getservbyname ($port, \*(Aqtcp\*(Aq) unless $port =~ /^\ed+$/; \& $dest_ip = gethostbyname ($dest_serv); \& $dest_serv_params = sockaddr_in($port, $dest_ip); \& \& socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; \& connect (S, $dest_serv_params) or die "connect: $!"; \& select (S); $| = 1; select (STDOUT); # Eliminate STDIO buffering \& \& # The network connection is now open, lets fire up SSL \& \& $ctx = Net::SSLeay::CTX_new() or die_now("Failed to create SSL_CTX $!"); \& Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) \& and die_if_ssl_error("ssl ctx set options"); \& $ssl = Net::SSLeay::new($ctx) or die_now("Failed to create SSL $!"); \& Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno \& $res = Net::SSLeay::connect($ssl) and die_if_ssl_error("ssl connect"); \& print "Cipher \`" . Net::SSLeay::get_cipher($ssl) . "\*(Aq\en"; \& \& # Exchange data \& \& $res = Net::SSLeay::write($ssl, $msg); # Perl knows how long $msg is \& die_if_ssl_error("ssl write"); \& CORE::shutdown S, 1; # Half close \-\-> No more output, sends EOF to server \& $got = Net::SSLeay::read($ssl); # Perl returns undef on failure \& die_if_ssl_error("ssl read"); \& print $got; \& \& Net::SSLeay::free ($ssl); # Tear down connection \& Net::SSLeay::CTX_free ($ctx); \& close S; .Ve .PP The following is a simple SSLeay echo server (non forking): .PP .Vb 6 \& #!/usr/local/bin/perl \-w \& use Socket; \& use Net::SSLeay qw(die_now die_if_ssl_error); \& Net::SSLeay::load_error_strings(); \& Net::SSLeay::SSLeay_add_ssl_algorithms(); \& Net::SSLeay::randomize(); \& \& $our_ip = "\e0\e0\e0\e0"; # Bind to all interfaces \& $port = 1235; \& $sockaddr_template = \*(AqS n a4 x8\*(Aq; \& $our_serv_params = pack ($sockaddr_template, &AF_INET, $port, $our_ip); \& \& socket (S, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; \& bind (S, $our_serv_params) or die "bind: $!"; \& listen (S, 5) or die "listen: $!"; \& $ctx = Net::SSLeay::CTX_new () or die_now("CTX_new ($ctx): $!"); \& Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) \& and die_if_ssl_error("ssl ctx set options"); \& \& # Following will ask password unless private key is not encrypted \& Net::SSLeay::CTX_use_RSAPrivateKey_file ($ctx, \*(Aqplain\-rsa.pem\*(Aq, \& &Net::SSLeay::FILETYPE_PEM); \& die_if_ssl_error("private key"); \& Net::SSLeay::CTX_use_certificate_file ($ctx, \*(Aqplain\-cert.pem\*(Aq, \& &Net::SSLeay::FILETYPE_PEM); \& die_if_ssl_error("certificate"); \& \& while (1) { \& print "Accepting connections...\en"; \& ($addr = accept (NS, S)) or die "accept: $!"; \& select (NS); $| = 1; select (STDOUT); # Piping hot! \& \& ($af,$client_port,$client_ip) = unpack($sockaddr_template,$addr); \& @inetaddr = unpack(\*(AqC4\*(Aq,$client_ip); \& print "$af connection from " . \& join (\*(Aq.\*(Aq, @inetaddr) . ":$client_port\en"; \& \& # We now have a network connection, lets fire up SSLeay... \& \& $ssl = Net::SSLeay::new($ctx) or die_now("SSL_new ($ssl): $!"); \& Net::SSLeay::set_fd($ssl, fileno(NS)); \& \& $err = Net::SSLeay::accept($ssl) and die_if_ssl_error(\*(Aqssl accept\*(Aq); \& print "Cipher \`" . Net::SSLeay::get_cipher($ssl) . "\*(Aq\en"; \& \& # Connected. Exchange some data. \& \& $got = Net::SSLeay::read($ssl); # Returns undef on fail \& die_if_ssl_error("ssl read"); \& print "Got \`$got\*(Aq (" . length ($got) . " chars)\en"; \& \& Net::SSLeay::write ($ssl, uc ($got)) or die "write: $!"; \& die_if_ssl_error("ssl write"); \& \& Net::SSLeay::free ($ssl); # Tear down connection \& close NS; \& } .Ve .PP Yet another echo server. This one runs from \f(CW\*(C`/etc/inetd.conf\*(C'\fR so it avoids all the socket code overhead. Only caveat is opening an rsa key file \- it had better be without any encryption or else it will not know where to ask for the password. Note how \f(CW\*(C`STDIN\*(C'\fR and \f(CW\*(C`STDOUT\*(C'\fR are wired to \s-1SSL\s0. .PP .Vb 5 \& #!/usr/local/bin/perl \& # /etc/inetd.conf \& # ssltst stream tcp nowait root /path/to/server.pl server.pl \& # /etc/services \& # ssltst 1234/tcp \& \& use Net::SSLeay qw(die_now die_if_ssl_error); \& Net::SSLeay::load_error_strings(); \& Net::SSLeay::SSLeay_add_ssl_algorithms(); \& Net::SSLeay::randomize(); \& \& chdir \*(Aq/key/dir\*(Aq or die "chdir: $!"; \& $| = 1; # Piping hot! \& open LOG, ">>/dev/console" or die "Can\*(Aqt open log file $!"; \& select LOG; print "server.pl started\en"; \& \& $ctx = Net::SSLeay::CTX_new() or die_now "CTX_new ($ctx) ($!)"; \& $ssl = Net::SSLeay::new($ctx) or die_now "new ($ssl) ($!)"; \& Net::SSLeay::set_options($ssl, &Net::SSLeay::OP_ALL) \& and die_if_ssl_error("ssl set options"); \& \& # We get already open network connection from inetd, now we just \& # need to attach SSLeay to STDIN and STDOUT \& Net::SSLeay::set_rfd($ssl, fileno(STDIN)); \& Net::SSLeay::set_wfd($ssl, fileno(STDOUT)); \& \& Net::SSLeay::use_RSAPrivateKey_file ($ssl, \*(Aqplain\-rsa.pem\*(Aq, \& Net::SSLeay::FILETYPE_PEM); \& die_if_ssl_error("private key"); \& Net::SSLeay::use_certificate_file ($ssl, \*(Aqplain\-cert.pem\*(Aq, \& Net::SSLeay::FILETYPE_PEM); \& die_if_ssl_error("certificate"); \& \& Net::SSLeay::accept($ssl) and die_if_ssl_err("ssl accept: $!"); \& print "Cipher \`" . Net::SSLeay::get_cipher($ssl) . "\*(Aq\en"; \& \& $got = Net::SSLeay::read($ssl); \& die_if_ssl_error("ssl read"); \& print "Got \`$got\*(Aq (" . length ($got) . " chars)\en"; \& \& Net::SSLeay::write ($ssl, uc($got)) or die "write: $!"; \& die_if_ssl_error("ssl write"); \& \& Net::SSLeay::free ($ssl); # Tear down the connection \& Net::SSLeay::CTX_free ($ctx); \& close LOG; .Ve .PP There are also a number of example/test programs in the examples directory: .PP .Vb 11 \& sslecho.pl \- A simple server, not unlike the one above \& minicli.pl \- Implements a client using low level SSLeay routines \& sslcat.pl \- Demonstrates using high level sslcat utility function \& get_page.pl \- Is a utility for getting html pages from secure servers \& callback.pl \- Demonstrates certificate verification and callback usage \& stdio_bulk.pl \- Does SSL over Unix pipes \& ssl\-inetd\-serv.pl \- SSL server that can be invoked from inetd.conf \& httpd\-proxy\-snif.pl \- Utility that allows you to see how a browser \& sends https request to given server and what reply \& it gets back (very educative :\-) \& makecert.pl \- Creates a self signed cert (does not use this module) .Ve .SH "LIMITATIONS" .IX Header "LIMITATIONS" \&\f(CW\*(C`Net::SSLeay::read()\*(C'\fR uses an internal buffer of 32KB, thus no single read will return more. In practice one read returns much less, usually as much as fits in one network packet. To work around this, you should use a loop like this: .PP .Vb 5 \& $reply = \*(Aq\*(Aq; \& while ($got = Net::SSLeay::read($ssl)) { \& last if print_errs(\*(AqSSL_read\*(Aq); \& $reply .= $got; \& } .Ve .PP Although there is no built-in limit in \f(CW\*(C`Net::SSLeay::write()\*(C'\fR, the network packet size limitation applies here as well, thus use: .PP .Vb 1 \& $written = 0; \& \& while ($written < length($message)) { \& $written += Net::SSLeay::write($ssl, substr($message, $written)); \& last if print_errs(\*(AqSSL_write\*(Aq); \& } .Ve .PP Or alternatively you can just use the following convenience functions: .PP .Vb 2 \& Net::SSLeay::ssl_write_all($ssl, $message) or die "ssl write failure"; \& $got = Net::SSLeay::ssl_read_all($ssl) or die "ssl read failure"; .Ve .SH "KNOWN BUGS AND CAVEATS" .IX Header "KNOWN BUGS AND CAVEATS" Autoloader emits a .PP .Vb 1 \& Argument "xxx" isn\*(Aqt numeric in entersub at blib/lib/Net/SSLeay.pm\*(Aq .Ve .PP warning if die_if_ssl_error is made autoloadable. If you figure out why, drop me a line. .PP Callback set using \f(CW\*(C`SSL_set_verify()\*(C'\fR does not appear to work. This may well be an openssl problem (e.g. see \f(CW\*(C`ssl/ssl_lib.c\*(C'\fR line 1029). Try using \&\f(CW\*(C`SSL_CTX_set_verify()\*(C'\fR instead and do not be surprised if even this stops working in future versions. .PP Callback and certificate verification stuff is generally too little tested. .PP Random numbers are not initialized randomly enough, especially if you do not have \f(CW\*(C`/dev/random\*(C'\fR and/or \f(CW\*(C`/dev/urandom\*(C'\fR (such as in Solaris platforms \- but I've been suggested that cryptorand daemon from the SUNski package solves this). In this case you should investigate third party software that can emulate these devices, e.g. by way of a named pipe to some program. .PP Another gotcha with random number initialization is randomness depletion. This phenomenon, which has been extensively discussed in OpenSSL, Apache-SSL, and Apache\-mod_ssl forums, can cause your script to block if you use \f(CW\*(C`/dev/random\*(C'\fR or to operate insecurely if you use \f(CW\*(C`/dev/urandom\*(C'\fR. What happens is that when too much randomness is drawn from the operating system's randomness pool then randomness can temporarily be unavailable. \f(CW\*(C`/dev/random\*(C'\fR solves this problem by waiting until enough randomness can be gathered \- and this can take a long time since blocking reduces activity in the machine and less activity provides less random events: a vicious circle. \&\f(CW\*(C`/dev/urandom\*(C'\fR solves this dilemma more pragmatically by simply returning predictable \*(L"random\*(R" numbers. Some\f(CW\*(C` /dev/urandom\*(C'\fR emulation software however actually seems to implement \f(CW\*(C`/dev/random\*(C'\fR semantics. Caveat emptor. .PP I've been pointed to two such daemons by Mik Firestone <mik@@speed.stdio._com> who has used them on Solaris 8: .IP "1." 4 Entropy Gathering Daemon (\s-1EGD\s0) at <http://www.lothar.com/tech/crypto/> .IP "2." 4 Pseudo-random number generating daemon (\s-1PRNGD\s0) at <http://www.aet.tu\-cottbus.de/personen/jaenicke/postfix_tls/prngd.html> .PP If you are using the low level \s-1API\s0 functions to communicate with other \&\s-1SSL\s0 implementations, you would do well to call .PP .Vb 2 \& Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL) \& and die_if_ssl_error("ssl ctx set options"); .Ve .PP to cope with some well know bugs in some other \s-1SSL\s0 implementations. The high level \s-1API\s0 functions always set all known compatibility options. .PP Sometimes \f(CW\*(C`sslcat()\*(C'\fR (and the high level \s-1HTTPS\s0 functions that build on it) is too fast in signaling the \s-1EOF\s0 to legacy \s-1HTTPS\s0 servers. This causes the server to return empty page. To work around this problem you can set the global variable .PP .Vb 1 \& $Net::SSLeay::slowly = 1; # Add sleep so broken servers can keep up .Ve .PP \&\s-1HTTP/1\s0.1 is not supported. Specifically this module does not know to issue or serve multiple http requests per connection. This is a serious shortcoming, but using the \s-1SSL\s0 session cache on your server helps to alleviate the \s-1CPU\s0 load somewhat. .PP As of version 1.09 many newer OpenSSL auxiliary functions were added (from \f(CW\*(C`REM_AUTOMATICALLY_GENERATED_1_09\*(C'\fR onwards in \f(CW\*(C`SSLeay.xs\*(C'\fR). Unfortunately I have not had any opportunity to test these. Some of them are trivial enough that I believe they \*(L"just work\*(R", but others have rather complex interfaces with function pointers and all. In these cases you should proceed wit great caution. .PP This module defaults to using OpenSSL automatic protocol negotiation code for automatically detecting the version of the \s-1SSL\s0 protocol that the other end talks. With most web servers this works just fine, but once in a while I get complaints from people that the module does not work with some web servers. Usually this can be solved by explicitly setting the protocol version, e.g. .PP .Vb 3 \& $Net::SSLeay::ssl_version = 2; # Insist on SSLv2 \& $Net::SSLeay::ssl_version = 3; # Insist on SSLv3 \& $Net::SSLeay::ssl_version = 10; # Insist on TLSv1 .Ve .PP Although the autonegotiation is nice to have, the \s-1SSL\s0 standards do not formally specify any such mechanism. Most of the world has accepted the SSLeay/OpenSSL way of doing it as the de facto standard. But for the few that think differently, you have to explicitly speak the correct version. This is not really a bug, but rather a deficiency in the standards. If a site refuses to respond or sends back some nonsensical error codes (at the \s-1SSL\s0 handshake level), try this option before mailing me. .PP The high level \s-1API\s0 returns the certificate of the peer, thus allowing one to check what certificate was supplied. However, you will only be able to check the certificate after the fact, i.e. you already sent your form data by the time you find out that you did not trust them, oops. .PP So, while being able to know the certificate after the fact is surely useful, the security minded would still choose to do the connection and certificate verification first and only then exchange data with the site. Currently none of the high level \s-1API\s0 functions do this, thus you would have to program it using the low level \s-1API\s0. A good place to start is to see how the \f(CW\*(C`Net::SSLeay::http_cat()\*(C'\fR function is implemented. .PP The high level \s-1API\s0 functions use a global file handle \f(CW\*(C`SSLCAT_S\*(C'\fR internally. This really should not be a problem because there is no way to interleave the high level \s-1API\s0 functions, unless you use threads (but threads are not very well supported in perl anyway (as of version 5.6.1). However, you may run into problems if you call undocumented internal functions in an interleaved fashion. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .IP "Random number generator not seeded!!!" 4 .IX Item "Random number generator not seeded!!!" \&\fB(W)\fR This warning indicates that \f(CW\*(C`randomize()\*(C'\fR was not able to read \&\f(CW\*(C`/dev/random\*(C'\fR or \f(CW\*(C`/dev/urandom\*(C'\fR, possibly because your system does not have them or they are differently named. You can still use \s-1SSL\s0, but the encryption will not be as strong. .IP "open_tcp_connection: destination host not found:`server' (port 123) ($!)" 4 .IX Item "open_tcp_connection: destination host not found:`server' (port 123) ($!)" Name lookup for host named \f(CW\*(C`server\*(C'\fR failed. .IP "open_tcp_connection: failed `server', 123 ($!)" 4 .IX Item "open_tcp_connection: failed `server', 123 ($!)" The name was resolved, but establising the \s-1TCP\s0 connection failed. .IP "msg 123: 1 \- error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto" 4 .IX Item "msg 123: 1 - error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto" SSLeay error string. The first number (123) is the \s-1PID\s0, the second number (1) indicates the position of the error message in SSLeay error stack. You often see a pile of these messages as errors cascade. .IP "msg 123: 1 \- \fIerror:02001002::lib\fR\|(2) :\fIfunc\fR\|(1) :\fIreason\fR\|(2)" 4 .IX Item "msg 123: 1 - error:02001002::lib :func :reason" The same as above, but you didn't call \fIload_error_strings()\fR so SSLeay couldn't verbosely explain the error. You can still find out what it means with this command: .Sp .Vb 1 \& /usr/local/ssl/bin/ssleay errstr 02001002 .Ve .IP "Password is being asked for private key" 4 .IX Item "Password is being asked for private key" This is normal behaviour if your private key is encrypted. Either you have to supply the password or you have to use an unencrypted private key. Scan OpenSSL.org for the \s-1FAQ\s0 that explains how to do this (or just study examples/makecert.pl which is used during \f(CW\*(C`make test\*(C'\fR to do just that). .SH "BUGS AND SUPPORT" .IX Header "BUGS AND SUPPORT" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-Net\-SSLeay at rt.cpan.org\*(C'\fR, or through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=Net\-SSLeay>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .PP Subversion access to the latest source code etc can be obtained at <http://alioth.debian.org/projects/net\-ssleay> .PP The developer mailing list (for people interested in contributing to the source code) can be found at <http://lists.alioth.debian.org/mailman/listinfo/net\-ssleay\-devel> .PP You can find documentation for this module with the \f(CW\*(C`perldoc\*(C'\fR command. .PP .Vb 1 \& perldoc Net::SSLeay .Ve .PP You can also look for information at: .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp <http://annocpan.org/dist/Net\-SSLeay> .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp <http://cpanratings.perl.org/d/Net\-SSLeay> .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp <http://search.cpan.org/dist/Net\-SSLeay> .PP Commercial support for Net::SSLeay may be obtained from .PP .Vb 3 \& Symlabs (netssleay@symlabs.com) \& Tel: +351\-214.222.630 \& Fax: +351\-214.222.637 .Ve .SH "AUTHOR" .IX Header "AUTHOR" Maintained by Mike McCauley and Florian Ragwitz since November 2005 .PP Originally written by Sampo Kelloma\*:ki <sampo@symlabs.com> .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 1996\-2003 Sampo Kelloma\*:ki <sampo@symlabs.com> .PP Copyright (C) 2005\-2006 Florian Ragwitz <rafl@debian.org> .PP Copyright (C) 2005 Mike McCauley <mikem@open.com.au> .PP All Rights Reserved. .PP Distribution and use of this module is under the same terms as the OpenSSL package itself (i.e. free, but mandatory attribution; \s-1NO\s0 \&\s-1WARRANTY\s0). Please consult \s-1LICENSE\s0 file in the root of the OpenSSL distribution. .PP While the source distribution of this perl module does not contain Eric's or OpenSSL's code, if you use this module you will use OpenSSL library. Please give Eric and OpenSSL team credit (as required by their licenses). .PP And remember, you, and nobody else but you, are responsible for auditing this module and OpenSSL library for security problems, backdoors, and general suitability for your application. .SH "SEE ALSO" .IX Header "SEE ALSO" .Vb 10 \& Net::SSLeay::Handle \- File handle interface \& ./examples \- Example servers and a clients \& <http://www.openssl.org/> \- OpenSSL source, documentation, etc \& openssl\-users\-request@openssl.org \- General OpenSSL mailing list \& <http://www.ietf.org/rfc/rfc2246.txt> \- TLS 1.0 specification \& <http://www.w3c.org> \- HTTP specifications \& <http://www.ietf.org/rfc/rfc2617.txt> \- How to send password \& <http://www.lothar.com/tech/crypto/> \- Entropy Gathering Daemon (EGD) \& <http://www.aet.tu\-cottbus.de/personen/jaenicke/postfix_tls/prngd.html> \& \- pseudo\-random number generating daemon (PRNGD) \& perl(1) \& perlref(1) \& perllol(1) \& perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod .Ve .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 1713:" 4 .IX Item "Around line 1713:" Non-ASCII character seen before =encoding in 'Kelloma\*:ki'. Assuming \s-1ISO8859\-1\s0