Creates a new IO::Socket::SSL object. You may use all the friendly options
that came bundled with IO::Socket::INET, plus (optionally) the ones that follow:
There are a number of nasty traps that lie in wait if you are not careful about using
close(). The first of these will bite you if you have been using shutdown() on your
sockets. Since the SSL protocol mandates that a SSL close notify message be
sent before the socket is closed, a shutdown() that closes the sockets write channel
will cause the close() call to hang. For a similar reason, if you try to close a
copy of a socket (as in a forking server) you will affect the original socket as well.
To get around these problems, call close with an object-oriented syntax
(e.g. $socket->close(SSL_no_shutdown => 1))
and one or more of the following parameters:
|peek(...)||This function has exactly the same syntax as sysread(), and performs nearly the same task (reading data from the socket) but will not advance the read position so that successive calls to peek() with the same arguments will return the same results. This function requires OpenSSL 0.9.6a or later to work.|
|pending()||This function will let you know how many bytes of data are immediately ready for reading from the socket. This is especially handy if you are doing reads on a blocking socket or just want to know if new data has been sent over the socket.|
|get_cipher()||Returns the string form of the cipher that the IO::Socket::SSL object is using.|
|dump_peer_certificate()||Returns a parsable string with select fields from the peer SSL certificate. This method directly returns the result of the dump_peer_certificate() method of Net::SSLeay.|
If a peer certificate exists, this function can retrieve values from it.
If no field is given the internal representation of certificate from Net::SSLeay is
The following fields can be queried:
This verifies the given hostname against the peer certificate using the
given scheme. Hostname is usually what you specify within the PeerAddr.
Verification of hostname against a certificate is different between various applications and RFCs. Some scheme allow wildcards for hostnames, some only in subjectAltNames, and even their different wildcard schemes are possible.
To ease the verification the following schemes are predefined:
The scheme can be given either by specifying the name for one of the above predefined schemes, by using a callback (see below) or by using a hash which can have the following keys and values:
If you give a subroutine for verification it will be called with the arguments ($hostname,$commonName,@subjectAltNames), where hostname is the name given for verification, commonName is the result from peer_certificate(cn) and subjectAltNames is the result from peer_certificate(subjectAltNames).
Returns the last error (in string form) that occurred. If you do not have a real
object to perform this method on, call IO::Socket::SSL::errstr() instead.
For read and write errors on non-blocking sockets, this method may include the string SSL wants a read first! or SSL wants a write first! meaning that the other side is expecting to read from or write to the socket and wants to be satisfied before you get to do anything. But with version 0.98 you are better comparing the global exported variable $SSL_ERROR against the exported symbols SSL_WANT_READ and SSL_WANT_WRITE.
|opened()||This returns false if the socket could not be opened, 1 if the socket could be opened and the SSL handshake was successful done and -1 if the underlying IO::Handle is open, but the SSL handshake failed.|
|IO::Socket::SSL->start_SSL($socket, ... )||
This will convert a glob reference or a socket that you provide to an IO::Socket::SSL
object. You may also pass parameters to specify context or connection options as with
a call to new(). If you are using this function on an accept()ed socket, you must
set the parameter SSL_server to 1, i.e. IO::Socket::SSL->start_SSL($socket, SSL_server => 1).
If you have a class that inherits from IO::Socket::SSL and you want the $socket to be blessed
into your own class instead, use MyClass->start_SSL($socket) to achieve the desired effect.
Note that if start_SSL() fails in SSL negotiation, $socket will remain blessed in its original class. For non-blocking sockets you better just upgrade the socket to IO::Socket::SSL and call accept_SSL or connect_SSL and the upgraded object. To just upgrade the socket set SSL_startHandshake explicitly to 0. If you call start_SSL w/o this parameter it will revert to blocking behavior for accept_SSL and connect_SSL.
If given the parameter Timeout it will stop if after the timeout no SSL connection was established. This parameter is only used for blocking sockets, if it is not given the default Timeout from the underlying IO::Socket will be used.
This is the opposite of start_SSL(), e.g. it will shutdown the SSL connection
and return to the class before start_SSL(). It gets the same arguments as close(),
in fact close() calls stop_SSL() (but without downgrading the class).
Will return true if it suceeded and undef if failed. This might be the case for non-blocking sockets. In this case $! is set to EAGAIN and the ssl error to SSL_WANT_READ or SSL_WANT_WRITE. In this case the call should be retried again with the same arguments once the socket is ready is until it succeeds.
|IO::Socket::SSL->new_from_fd($fd, ...)||This will convert a socket identified via a file descriptor into an SSL socket. Note that the argument list does not include a MODE argument; if you supply one, it will be thoughtfully ignored (for compatibility with IO::Socket::INET). Instead, a mode of +< is assumed, and the file descriptor passed must be able to handle such I/O because the initial SSL handshake requires bidirectional communication.|
|IO::Socket::SSL::set_default_context(...)||You may use this to make IO::Socket::SSL automatically re-use a given context (unless specifically overridden in a call to new()). It accepts one argument, which should be either an IO::Socket::SSL object or an IO::Socket::SSL::SSL_Context object. See the SSL_reuse_ctx option of new() for more details. Note that this sets the default context globally, so use with caution (esp. in mod_perl scripts).|
|IO::Socket::SSL::set_default_session_cache(...)||You may use this to make IO::Socket::SSL automatically re-use a given session cache (unless specifically overridden in a call to new()). It accepts one argument, which should be an IO::Socket::SSL::Session_Cache object or similar (e.g something which implements get_session and add_session like IO::Socket::SSL::Session_Cache does). See the SSL_session_cache option of new() for more details. Note that this sets the default cache globally, so use with caution.|
With this function one can set defaults for all SSL_* parameter used for creation of
the context, like the SSL_verify* parameter.
|send/recv||Note that send() and recv() cannot be reliably trapped by a tied filehandle (such as that used by IO::Socket::SSL) and so may send unencrypted data over the socket. Object-oriented calls to these functions will fail, telling you to use the print/printf/syswrite and read/sysread families instead.|
Support for IPv6 with IO::Socket::SSL is expected to work and basic testing is done. If IO::Socket::INET6 is available it will automatically use it instead of IO::Socket::INET4.
Please be aware of the associated problems: If you give a name as a host and the host resolves to both IPv6 and IPv4 it will try IPv6 first and if there is no IPv6 connectivity it will fail.
To avoid these problems you can either force IPv4 by specifying and AF_INET as the Domain (this is per socket) or load IO::Socket::SSL with the option inet4 (This is a global setting, e.g. affects all IO::Socket::SSL objects in the program).
A few changes have gone into IO::Socket::SSL v0.93 and later with respect to return values. The behavior on success remains unchanged, but for all functions, the return value on error is now an empty list. Therefore, the return value will be false in all contexts, but those who have been using the return values as arguments to subroutines (like mysub(IO::Socket::SSL(...)-new, ...)>) may run into problems. The moral of the story: always check the return values of these functions before using them in any way that you consider meaningful.
If you are having problems using IO::Socket::SSL despite the fact that can recite backwards the section of this documentation labelled Using SSL, you should try enabling debugging. To specify the debug level, pass debug# (where # is a number from 0 to 3) to IO::Socket::SSL when calling it. The debug level will also be propagated to Net::SSLeay::trace, see also Net::SSLeay:
use IO::Socket::SSL qw(debug0); No debugging (default). use IO::Socket::SSL qw(debug1); Print out errors from IO::Socket::SSL and ciphers from Net::SSLeay. use IO::Socket::SSL qw(debug2); Print also information about call flow from IO::Socket::SSL and progress information from Net::SSLeay. use IO::Socket::SSL qw(debug3); Print also some data dumps from IO::Socket::SSL and from Net::SSLeay.
See the example directory.
IO::Socket::SSL is not threadsafe. This is because IO::Socket::SSL is based on Net::SSLeay which uses a global object to access some of the API of openssl and is therefore not threadsafe. It might probably work if you dont use SSL_verify_callback and SSL_password_cb.
IO::Socket::SSL does not work together with Storable::fd_retrieve/fd_store. See BUGS file for more information and how to work around the problem.
Non-blocking and timeouts (which are based on non-blocking) are not supported on Win32, because the underlying IO::Socket::INET does not support non-blocking on this platform.
IO::Socket::SSL uses Net::SSLeay as the shiny interface to OpenSSL, which is the shiny interface to the ugliness of SSL. As a result, you will need both Net::SSLeay and OpenSSL on your computer before using this module.
If you have Scalar::Util (standard with Perl 5.8.0 and above) or WeakRef, IO::Socket::SSL sockets will auto-close when they go out of scope, just like IO::Socket::INET sockets. If you do not have one of these modules, then IO::Socket::SSL sockets will stay open until the program ends or you explicitly close them. This is due to the fact that a circular reference is required to make IO::Socket::SSL sockets act simultaneously like objects and glob references.
The following functions are deprecated and are only retained for compatibility:
The following classes have been removed:
context_init() use the SSL_reuse_ctx option if you want to re-use a context socketToSSL() and socket_to_SSL() use IO::Socket::SSL->start_SSL() instead get_peer_certificate() use the peer_certificate() function instead. Used to return X509_Certificate with methods subject_name and issuer_name. Now simply returns $self which has these methods (although depreceated). issuer_name() use peer_certificate( issuer ) instead subject_name() use peer_certificate( subject ) instead
SSL_SSL (not that you should have been directly accessing this anyway): X509_Certificate (but get_peer_certificate() will still Do The Right Thing)
IO::Socket::INET, IO::Socket::INET6, Net::SSLeay.
Steffen Ullrich, <steffen at genua.de> is the current maintainer.
Peter Behroozi, <behrooz at fas.harvard.edu> (Note the lack of an i at the end of behrooz)
Marko Asplund, <marko.asplund at kronodoc.fi>, was the original author of IO::Socket::SSL.
Patches incorporated from various people, see file Changes.
Working support for non-blocking was added by Steffen Ullrich.
The rewrite of this module is Copyright (C) 2002-2005 Peter Behroozi.
The original versions of this module are Copyright (C) 1999-2002 Marko Asplund.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
If you are unfamiliar with the way OpenSSL works, good references may be found in both the book Network Security with OpenSSL (Oreilly & Assoc.) and the web site http://www.tldp.org/HOWTO/SSL-Certificates-HOWTO/ <http://www.tldp.org/HOWTO/SSL-Certificates-HOWTO/>. Read on for a quick overview.
The usual reason for using SSL is to keep your data safe. This means that not only do you have to encrypt the data while it is being transported over a network, but you also have to make sure that the right person gets the data. To accomplish this with SSL, you have to use certificates. A certificate closely resembles a Government-issued ID (at least in places where you can trust them). The ID contains some sort of identifying information such as a name and address, and is usually stamped with a seal of Government Approval. Theoretically, this means that you may trust the information on the card and do business with the owner of the card. The same ideas apply to SSL certificates, which have some identifying information and are stamped [most people refer to this as signing instead] by someone (a Certificate Authority) who you trust will adequately verify the identifying information. In this case, because of some clever number theory, it is extremely difficult to falsify the stamping process. Another useful consequence of number theory is that the certificate is linked to the encryption process, so you may encrypt data (using information on the certificate) that only the certificate owner can decrypt.
What does this mean for you? It means that at least one person in the party has to have an ID to get drinks :-). Seriously, it means that one of the people communicating has to have a certificate to ensure that your data is safe. For client/server interactions, the server must always have a certificate. If the server wants to verify that the client is safe, then the client must also have a personal certificate. To verify that a certificate is safe, one compares the stamped seal [commonly called an encrypted digest/hash/signature] on the certificate with the official seal of the Certificate Authority to make sure that they are the same. To do this, you will need the [unfortunately named] certificate of the Certificate Authority. With all these in hand, you can set up a SSL connection and be reasonably confident that no-one is reading your data.
For servers, you will need to generate a cryptographic private key and a certificate request. You will need to send the certificate request to a Certificate Authority to get a real certificate back, after which you can start serving people. For clients, you will not need anything unless the server wants validation, in which case you will also need a private key and a real certificate. For more information about how to get these, see <http://www.modssl.org/docs/2.8/ssl_faq.html#ToC24>.
|perl v5.12.0||SSL (3)||2010-03-17|