NAME
Net::SSLeay - Perl extension for using OpenSSL
SYNOPSIS
use Net::SSLeay qw(get_https post_https sslcat make_headers make_form);
($page) = get_https('www.bacus.pt', 443, '/'); # Case 1
($page, $response, %reply_headers)
= get_https('www.bacus.pt', 443, '/', # Case 2
make_headers(User-Agent => 'Cryptozilla/5.0b1',
Referer => 'https://www.bacus.pt'
));
($page, $result, %headers) = # Case 2b
= get_https('www.bacus.pt', 443, '/protected.html',
make_headers(Authorization =>
'Basic ' . MIME::Base64::encode("$user:$pass",''))
);
($page, $response, %reply_headers)
= post_https('www.bacus.pt', 443, '/foo.cgi', '', # Case 3
make_form(OK => '1',
name => 'Sampo'
));
$reply = sslcat($host, $port, $request); # Case 4
($reply, $err, $server_cert) = sslcat($host, $port, $request); # Case 5
$Net::SSLeay::trace = 2; # 0=no debugging, 1=ciphers, 2=trace, 3=dump data
Net::SSLeay::initialize(); # Initialize ssl library once
DESCRIPTION
Net::SSLeay module contains perl bindings to openssl (http://www.openssl.org) library.
COMPATIBILITY NOTE: Net::SSLeay cannot be built with pre-0.9.3 openssl. It is strongly recommended to use at least 0.9.7 (as older versions are not tested during development). Some low level API functions may be available with certain openssl versions.
Net::SSLeay module basically comprise of:
High level functions for accessing web servers (by using HTTP/HTTPS)
Low level API (mostly mapped 1:1 to openssl's C functions)
Convenience functions (related to low level API but with more perl friendly interface)
There is also a related module called Net::SSLeay::Handle included in this distribution that you might want to use instead. It has its own pod documentation.
High level functions for accessing web servers
This module offers some high level convenience functions for accessing web pages on SSL servers (for symmetry, the same API is offered for accessing http servers, too), an sslcat()
function for writing your own clients, and finally access to the SSL api of the SSLeay/OpenSSL package so you can write servers or clients for more complicated applications.
For high level functions it is most convenient to import them into your main namespace as indicated in the synopsis.
Basic set of functions
get_https
post_https
put_https
head_https
do_https
sslcat
https_cat
make_form
make_headers
Case 1 (in SYNOPSIS) demonstrates the typical invocation of get_https() to fetch an HTML page from secure server. The first argument provides the hostname or IP in dotted decimal notation of the remote server to contact. The second argument is the TCP port at the remote end (your own port is picked arbitrarily from high numbered ports as usual for TCP). The third argument is the URL of the page without the host name part. If in doubt consult the HTTP specifications at http://www.w3c.org.
Case 2 (in SYNOPSIS) demonstrates full fledged use of get_https()
. As can be seen, get_https()
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 get_https()
is used to insert some additional headers in the request. make_headers()
is a function that will convert a list or hash to such headers. By default get_https()
supplies Host
(to make virtual hosting easy) and Accept
(reportedly needed by IIS) headers.
Case 2b (in SYNOPSIS) demonstrates how to get a password protected page. Refer to the HTTP protocol specifications for further details (e.g. RFC-2617).
Case 3 (in SYNOPSIS) invokes post_https()
to submit a HTML/CGI form to a secure server. The first four arguments are equal to get_https()
(note that the empty string (''
) is passed as header argument). The fifth argument is the contents of the form formatted according to CGI specification. In this case the helper function make_https()
is used to do the formatting, but you could pass any string. post_https()
automatically adds Content-Type
and Content-Length
headers to the request.
Case 4 (in SYNOPSIS) shows the fundamental sslcat()
function (inspired in spirit by the netcat
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 - sslcat()
is just a transport.
Case 5 (in SYNOPSIS) is a full invocation of sslcat()
which allows the return of errors as well as the server (peer) certificate.
The $trace
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.
Alternate versions of high-level API
get_https3
post_https3
put_https3
get_https4
post_https4
put_https4
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.
($page, $response, @headers) = get_https('www.bacus.pt', 443, '/');
for ($i = 0; $i < $#headers; $i+=2) {
print "$headers[$i] = " . $headers[$i+1] . "\n";
}
($page, $response, $headers, $server_cert)
= get_https3('www.bacus.pt', 443, '/');
print "$headers\n";
($page, $response, %headers_ref, $server_cert)
= get_https4('www.bacus.pt', 443, '/');
for $k (sort keys %{headers_ref}) {
for $v (@{$headers_ref{$k}}) {
print "$k = $v\n";
}
}
All of the above code fragments accomplish the same thing: display all values of all headers. The API functions ending in "3" return the headers simply as a scalar string and it is up to the application to split them up. The functions ending in "4" 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
print $headers_ref{COOKIE}[0];
Variants 3 and 4 also allow you to discover the server certificate in case you would like to store or display it, e.g.
($p, $resp, $hdrs, $server_cert) = get_https3('www.bacus.pt', 443, '/');
if (!defined($server_cert) || ($server_cert == 0)) {
warn "Subject Name: undefined, Issuer Name: undefined";
} else {
warn 'Subject Name: '
. Net::SSLeay::X509_NAME_oneline(
Net::SSLeay::X509_get_subject_name($server_cert))
. 'Issuer Name: '
. Net::SSLeay::X509_NAME_oneline(
Net::SSLeay::X509_get_issuer_name($server_cert));
}
Beware that this method only allows after the fact verification of the certificate: by the time get_https3()
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 API to first connect and verify the certificate and only then send the http data. See the implementation of ds_https3()
for guidance on how to do this.
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 SSL connections the server must have a certificate. This serves both to authenticate the server to the clients and to perform the key exchange.
Sometimes it is necessary to authenticate the client as well. Two options are available: HTTP basic authentication and a client side certificate. The basic authentication over HTTPS is actually quite safe because HTTPS 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 SSL level using a certificate. For this to work, both the client and the server have certificates (which typically are different) and private keys.
The API 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.
($page, $result, %headers) = # 2c
= get_https('www.bacus.pt', 443, '/protected.html',
make_headers(Authorization =>
'Basic ' . MIME::Base64::encode("$user:$pass",'')),
'', $mime_type6, $path_to_crt7, $path_to_key8);
($page, $response, %reply_headers)
= post_https('www.bacus.pt', 443, '/foo.cgi', # 3b
make_headers('Authorization' =>
'Basic ' . MIME::Base64::encode("$user:$pass",'')),
make_form(OK => '1', name => 'Sampo'),
$mime_type6, $path_to_crt7, $path_to_key8);
Case 2c (in SYNOPSIS) demonstrates getting a password protected page that also requires a client certificate, i.e. it is possible to use both authentication methods simultaneously.
Case 3b (in SYNOPSIS) is a full blown POST to a secure server that requires both password authentication and a client certificate, just like in case 2c.
Note: The client will not send a certificate unless the server requests one. This is typically achieved by setting the verify mode to VERIFY_PEER
on the server:
Net::SSLeay::set_verify(ssl, Net::SSLeay::VERIFY_PEER, 0);
See perldoc ~openssl/doc/ssl/SSL_CTX_set_verify.pod
for a full description.
Working through a web proxy
set_proxy
Net::SSLeay
can use a web proxy to make its connections. You need to first set the proxy host and port using set_proxy()
and then just use the normal API functions, e.g:
Net::SSLeay::set_proxy('gateway.myorg.com', 8080);
($page) = get_https('www.bacus.pt', 443, '/');
If your proxy requires authentication, you can supply a username and password as well
Net::SSLeay::set_proxy('gateway.myorg.com', 8080, 'joe', 'salainen');
($page, $result, %headers) =
= get_https('www.bacus.pt', 443, '/protected.html',
make_headers(Authorization =>
'Basic ' . MIME::Base64::encode("susie:pass",''))
);
This example demonstrates the case where we authenticate to the proxy as "joe"
and to the final web server as "susie"
. Proxy authentication requires the MIME::Base64
module to work.
HTTP (without S) API
get_http
post_http
tcpcat
get_httpx
post_httpx
tcpxcat
Over the years it has become clear that it would be convenient to use the light-weight flavour API of Net::SSLeay
for normal HTTP as well (see LWP
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 HTTP support was evolved.
use Net::SSLeay qw(get_http post_http tcpcat
get_httpx post_httpx tcpxcat
make_headers make_form);
($page, $result, %headers)
= get_http('www.bacus.pt', 443, '/protected.html',
make_headers(Authorization =>
'Basic ' . MIME::Base64::encode("$user:$pass",''))
);
($page, $response, %reply_headers)
= post_http('www.bacus.pt', 443, '/foo.cgi', '',
make_form(OK => '1',
name => 'Sampo'
));
($reply, $err) = tcpcat($host, $port, $request);
($page, $result, %headers)
= get_httpx($usessl, 'www.bacus.pt', 443, '/protected.html',
make_headers(Authorization =>
'Basic ' . MIME::Base64::encode("$user:$pass",''))
);
($page, $response, %reply_headers)
= post_httpx($usessl, 'www.bacus.pt', 443, '/foo.cgi', '',
make_form(OK => '1', name => 'Sampo' ));
($reply, $err, $server_cert) = tcpxcat($usessl, $host, $port, $request);
As can be seen, the "x"
family of APIs takes as the first argument a flag which indicates whether SSL is used or not.
Certificate verification and Certificate Revocation Lists (CRLs)
OpenSSL supports the ability to verify peer certificates. It can also optionally check the peer certificate against a Certificate Revocation List (CRL) from the certificates issuer. A CRL 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 PEM format.
You can enable Net::SSLeay CRL
checking like this:
&Net::SSLeay::X509_STORE_set_flags
(&Net::SSLeay::CTX_get_cert_store($ssl),
&Net::SSLeay::X509_V_FLAG_CRL_CHECK);
After setting this flag, if OpenSSL checks a peer's certificate, then it will attempt to find a CRL for the issuer. It does this by looking for a specially named file in the search directory specified by CTX_load_verify_locations. CRL files are named with the hash of the issuer's subject name, followed by .r0
, .r1
etc. For example ab1331b2.r0
, ab1331b2.r1
. It will read all the .r files for the issuer, and then check for a revocation of the peer certificate in all of them. (You can also force it to look in a specific named CRL file., see below). You can find out the hash of the issuer subject name in a CRL with
openssl crl -in crl.pem -hash -noout
If the peer certificate does not pass the revocation list, or if no CRL is found, then the handshaking fails with an error.
You can also force OpenSSL to look for CRLs in one or more arbitrarily named files.
my $bio = Net::SSLeay::BIO_new_file($crlfilename, 'r');
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....
}
Using Net::SSLeay in multi-threaded applications
IMPORTANT: versions 1.42 or earlier are not thread-safe!
Net::SSLeay module implements all necessary stuff to be ready for multi-threaded environment. The implementation fully follows thread safety related requirements of openssl library(see http://www.openssl.org/docs/crypto/threads.html).
If you are about to use Net::SSLeay (or any other module based on Net::SSLeay) in multi-threaded perl application it is recommended to follow this best-practice:
Initialization
Load and initialize Net::SSLeay module in the main thread:
use threads;
use Net::SSLeay;
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
sub do_master_job {
#... call whatever from Net::SSLeay
}
sub do_worker_job {
#... call whatever from Net::SSLeay
}
#start threads
my $master = threads->new(\&do_master_job, 'param1', 'param2');
my @workers = threads->new(\&do_worker_job, 'arg1', 'arg2') for (1..10);
#waiting for all threads to finish
$_->join() for (threads->list);
NOTE: Openssl's int SSL_library_init(void)
function (which is also aliased as SSLeay_add_ssl_algorithms
, OpenSSL_add_ssl_algorithms
and add_ssl_algorithms
) is not re-entrant and multiple calls can cause a crash in threaded application. Net::SSLeay implements flags preventing repeated calls to this function, therefore even multiple initialization via Net::SSLeay::SSLeay_add_ssl_algorithms() should work without trouble.
Using callbacks
Do not use callbacks across threads (the module blocks cross-thread callback operations and throws a warning). Allways do the callback setup, callback use and callback destruction within the same thread.
Using openssl elements
All openssl elements (X509, SSL_CTX, ...) can be directly passed between threads.
use threads;
use Net::SSLeay;
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
sub do_job {
my $context = shift;
Net::SSLeay::CTX_set_default_passwd_cb($context, sub { "secret" });
#...
}
my $c = Net::SSLeay::CTX_new();
threads->create(\&do_job, $c);
Or:
use threads;
use Net::SSLeay;
my $context; #does not need to be 'shared'
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
sub do_job {
Net::SSLeay::CTX_set_default_passwd_cb($context, sub { "secret" });
#...
}
$context = Net::SSLeay::CTX_new();
threads->create(\&do_job);
Using other perl modules based on Net::SSLeay
It should be fine to use any other module based on Net::SSLeay (like IO::Socket::SSL) in multi-threaded applications. It is generally recommended to do any global initialization of such a module in the main thread before calling threads->new(..)
or threads->create(..)
but it might differ module by module.
To be play safe you can load and init Net::SSLeay explicitely in the main thread:
use Net::SSLeay;
use Other::SSLeay::Based::Module;
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();Net::SSLeay::initialize();
Net::SSLeay::initialize();
Or even safer:
use Net::SSLeay;
use Other::SSLeay::Based::Module;
BEGIN {
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();Net::SSLeay::initialize();
}
Combining Net::SSLeay with other modules linked with openssl
BEWARE: This might be a big trouble! This is not guaranteed be thread-safe!
There are many other (XS) modules linked directly to openssl library (like Crypt::SSLeay).
As it is expected that also "another" module will call SSLeay_add_ssl_algorithms
at some point we have again a trouble with multiple openssl initialization by Net::SSLeay and "another" module.
As you can expect Net::SSLeay is not able to avoid multiple initialization of openssl library called by "another" module, thus you have to handle this on your own (in some cases it might not be possible at all to avoid this).
Threading with get_https and friends
The convenience functions get_https, post_https etc all initialize the SSL library by calling Net::SSLeay::initialize which does the conventional library initialization:
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
Net::SSLeay::initialize initializes the SSL library at most once. You can override the Net::SSLeay::initialize function if you desire some other type of initialization behaviour by get_https and friends. You can call Net::SSLeay::initialize from your own code if you desire this conventional library initialization.
Convenience routines
To be used with Low level API
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);
randomize
seeds the openssl PRNG with
/dev/urandom
(see the top ofSSLeay.pm
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 API functions automatically callrandomize()
so it is not needed with them. See also caveats.set_cert_and_key
takes two file names as arguments and sets the certificate and private key to those. This can be used to set either server certificates or client certificates.
dump_peer_certificate
allows you to get a plaintext description of the certificate the peer (usually the server) presented to us.
ssl_read_all
see ssl_write_all (below)
ssl_write_all
ssl_read_all()
andssl_write_all()
provide true blocking semantics for these operations (see limitation, below, for explanation). These are much preferred to the low level API equivalents (which implement BSD blocking semantics). The message argument tossl_write_all()
can be a reference. This is helpful to avoid unnecessary copying when writing something big, e.g:$data = 'A' x 1000000000; Net::SSLeay::ssl_write_all($ssl, \$data) or die "ssl write failed";
ssl_read_CRLF
uses
ssl_read_all()
to read in a line terminated with a carriage return followed by a linefeed (CRLF). The CRLF is included in the returned scalar.ssl_read_until
uses
ssl_read_all()
to read from the SSL input stream until it encounters a programmer specified delimiter. If the delimiter is undefined,$/
is used. If$/
is undefined,\n
is used. One can optionally set a maximum length of bytes to read from the SSL input stream.ssl_write_CRLF
writes
$message
and appends CRLF to the SSL output stream.
Initialization
In order to use the low level API you should start your programs with the following incantation:
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();
Error handling functions
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.
die_now
die_if_ssl_error
die_now()
anddie_if_ssl_error()
are used to conveniently print the SSLeay error stack when something goes wrong:Net::SSLeay::connect($ssl) or die_now("Failed SSL connect ($!)"); Net::SSLeay::write($ssl, "foo") or die_if_ssl_error("SSL write ($!)");
print_errs
You can also use
Net::SSLeay::print_errs()
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.
Sockets
Perl uses file handles for all I/O. While SSLeay has a quite flexible BIO 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 fileno()
to extract the underlying file descriptor:
Net::SSLeay::set_fd($ssl, fileno(S)); # Must use fileno
You should also set $|
to 1 to eliminate STDIO buffering so you do not get confused if you use perl I/O functions to manipulate your socket handle.
If you need to select(2)
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). Net::SSLeay
is no different from the C language OpenSSL in this respect.
Callbacks
You can establish a per-context verify callback function something like this:
sub verify {
my ($ok, $x509_store_ctx) = @_;
print "Verifying certificate...\n";
...
return $ok;
}
It is used like this:
Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, \&verify);
Per-context callbacks for decrypting private keys are implemented.
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);
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.
Establish it like this: Net::SSLeay::set_session_secret_cb($ssl, \&session_secret_cb, $somedata);
It will be called like this:
sub session_secret_cb
{
my ($secret, \@cipherlist, \$preferredcipher, $somedata) = @_;
}
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.
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.
If you want to use callback stuff, see examples/callback.pl! It's the only one I am able to make work reliably.
Low level API
In addition to the high level functions outlined above, this module contains straight-forward access to CRYPTO and SSL parts of OpenSSL C API.
See the *.h
headers 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 "SSL_"
off of the SSLeay names. Generally you should use Net::SSLeay::
in its place.
Note that some functions are prefixed with "P_"
- these are very close to the original API however contain some kind of a wrapper making its interface more perl friendly.
For example:
In C:
#include <ssl.h>
err = SSL_set_verify (ssl, SSL_VERIFY_CLIENT_ONCE,
&your_call_back_here);
In Perl:
use Net::SSLeay;
$err = Net::SSLeay::set_verify ($ssl,
Net::SSLeay::VERIFY_CLIENT_ONCE,
\&your_call_back_here);
If the function does not start with SSL_
you should use the full function name, e.g.:
$err = Net::SSLeay::ERR_get_error;
The following new functions behave in perlish way:
$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
Low level API: Version related functions
SSLeay
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
Gives version number (numeric) of underlaying openssl library.
my $ver_number = Net::SSLeay::SSLeay(); # returns: the number identifying the openssl release # # 0x00903100 => openssl-0.9.3 # 0x00904100 => openssl-0.9.4 # 0x00905100 => openssl-0.9.5 # 0x0090600f => openssl-0.9.6 # 0x0090601f => openssl-0.9.6a # 0x0090602f => openssl-0.9.6b # ... # 0x009060df => openssl-0.9.6m # 0x0090700f => openssl-0.9.7 # 0x0090701f => openssl-0.9.7a # 0x0090702f => openssl-0.9.7b # ... # 0x009070df => openssl-0.9.7m # 0x0090800f => openssl-0.9.8 # 0x0090801f => openssl-0.9.8a # 0x0090802f => openssl-0.9.8b # ... # 0x0090814f => openssl-0.9.8t # 0x1000000f => openssl-1.0.0 # 0x1000004f => openssl-1.0.0d # 0x1000007f => openssl-1.0.0g
You can use it like this:
if (Net::SSLeay::SSLeay() < 0x0090800f) { die "you need openssl-0.9.8 or higher"; }
SSLeay_version
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
Gives version number (string) of underlaying openssl library.
my $ver_string = Net::SSLeay::SSLeay_version($type); # $type # 0 (=SSLEAY_VERSION) - e.g. 'OpenSSL 1.0.0d 8 Feb 2011' # 2 (=SSLEAY_CFLAGS) - e.g. 'compiler: gcc -D_WINDLL -DOPENSSL_USE_APPLINK .....' # 3 (=SSLEAY_BUILT_ON)- e.g. 'built on: Fri May 6 00:00:46 GMT 2011' # 4 (=SSLEAY_PLATFORM)- e.g. 'platform: mingw' # # returns: string Net::SSLeay::SSLeay_version(); #is equivalent to Net::SSLeay::SSLeay_version(0);
Check openssl doc http://www.openssl.org/docs/crypto/SSLeay_version.html
Low level API: Initialization related functions
library_init
Initialize SSL library by registering algorithms.
my $rv = Net::SSLeay::library_init(); # # returns: always 1
Check openssl doc http://www.openssl.org/docs/ssl/SSL_library_init.html
add_ssl_algorithms
The alias for "library_init"
Net::SSLeay::add_ssl_algorithms();
OpenSSL_add_ssl_algorithms
The alias for "library_init"
Net::SSLeay::OpenSSL_add_ssl_algorithms();
SSLeay_add_ssl_algorithms
The alias for "library_init"
Net::SSLeay::SSLeay_add_ssl_algorithms();
load_error_strings
Registers the error strings for all libcrypto + libssl related functions.
Net::SSLeay::load_error_strings(); # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/ERR_load_crypto_strings.html
ERR_load_crypto_strings
Registers the error strings for all libcrypto functions. No need to call this function if you have already called "load_error_strings".
Net::SSLeay::ERR_load_crypto_strings(); # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/ERR_load_crypto_strings.html
ERR_load_RAND_strings
Registers the error strings for RAND related functions. No need to call this function if you have already called "load_error_strings".
Net::SSLeay::ERR_load_RAND_strings(); # # returns: no return value
ERR_load_SSL_strings
Registers the error strings for SSL related functions. No need to call this function if you have already called "load_error_strings".
Net::SSLeay::ERR_load_SSL_strings(); # # returns: no return value
Low level API: ERR_* and SSL_alert_* related functions
NOTE: Please note that SSL_alert_* function have "SSL_" part stripped from their names.
ERR_clear_error
Clear the error queue.
Net::SSLeay::ERR_clear_error(); # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/ERR_clear_error.html
ERR_error_string
Generates a human-readable string representing the error code $error.
my $rv = Net::SSLeay::ERR_error_string($error); # $error - (unsigned integer) error code # # returns: string
Check openssl doc http://www.openssl.org/docs/crypto/ERR_error_string.html
ERR_get_error
Returns the earliest error code from the thread's error queue and removes the entry. This function can be called repeatedly until there are no more error codes to return.
my $rv = Net::SSLeay::ERR_get_error(); # # returns: (unsigned integer) error code
Check openssl doc http://www.openssl.org/docs/crypto/ERR_get_error.html
ERR_peek_error
Returns the earliest error code from the thread's error queue without modifying it.
my $rv = Net::SSLeay::ERR_peek_error(); # # returns: (unsigned integer) error code
Check openssl doc http://www.openssl.org/docs/crypto/ERR_get_error.html
ERR_put_error
Adds an error code to the thread's error queue. It signals that the error of $reason code reason occurred in function $func of library $lib, in line number $line of $file.
Net::SSLeay::ERR_put_error($lib, $func, $reason, $file, $line); # $lib - (integer) library id (check openssl/err.h for constants e.g. ERR_LIB_SSL) # $func - (integer) function id (check openssl/ssl.h for constants e.g. SSL_F_SSL23_READ) # $reason - (integer) reason id (check openssl/ssl.h for constants e.g. SSL_R_SSL_HANDSHAKE_FAILURE) # $file - (string) file name # $line - (integer) line number in $file # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/ERR_put_error.html and http://www.openssl.org/docs/crypto/err.html
alert_desc_string
Returns a two letter string as a short form describing the reason of the alert specified by value.
my $rv = Net::SSLeay::alert_desc_string($value); # $value - (integer) allert id (check openssl/ssl.h for SSL3_AD_* and TLS1_AD_* constants) # # returns: description string (2 letters)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_alert_type_string.html
alert_desc_string_long
Returns a string describing the reason of the alert specified by value.
my $rv = Net::SSLeay::alert_desc_string_long($value); # $value - (integer) allert id (check openssl/ssl.h for SSL3_AD_* and TLS1_AD_* constants) # # returns: description string
Check openssl doc http://www.openssl.org/docs/ssl/SSL_alert_type_string.html
alert_type_string
Returns a one letter string indicating the type of the alert specified by value.
my $rv = Net::SSLeay::alert_type_string($value); # $value - (integer) allert id (check openssl/ssl.h for SSL3_AD_* and TLS1_AD_* constants) # # returns: string (1 letter)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_alert_type_string.html
alert_type_string_long
Returns a string indicating the type of the alert specified by value.
my $rv = Net::SSLeay::alert_type_string_long($value); # $value - (integer) allert id (check openssl/ssl.h for SSL3_AD_* and TLS1_AD_* constants) # # returns: string
Check openssl doc http://www.openssl.org/docs/ssl/SSL_alert_type_string.html
Low level API: SSL_METHOD_* related functions
SSLv2_method
Returns SSL_METHOD structure corresponding to SSLv2 method, the return value can be later used as a param of "CTX_new_with_method".
my $rv = Net::SSLeay::SSLv2_method(); # # returns: value coresponding to openssl's SSL_METHOD structure (0 on failure)
SSLv3_method
Returns SSL_METHOD structure corresponding to SSLv3 method, the return value can be later used as a param of "CTX_new_with_method".
my $rv = Net::SSLeay::SSLv3_method(); # # returns: value coresponding to openssl's SSL_METHOD structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_new.html
TLSv1_method
Returns SSL_METHOD structure corresponding to TLSv1 method, the return value can be later used as a param of "CTX_new_with_method".
my $rv = Net::SSLeay::TLSv1_method(); # # returns: value coresponding to openssl's SSL_METHOD structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_new.html
Low level API: ENGINE_* related functions
ENGINE_load_builtin_engines
Load all bundled ENGINEs into memory and make them visible.
Net::SSLeay::ENGINE_load_builtin_engines(); # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/engine.html
ENGINE_register_all_complete
Register all loaded ENGINEs for every algorithm they collectively implement.
Net::SSLeay::ENGINE_register_all_complete(); # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/engine.html
ENGINE_set_default
Set default engine to $e + set its flags to $flags.
my $rv = Net::SSLeay::ENGINE_set_default($e, $flags); # $e - value coresponding to openssl's ENGINE structure # $flags - (integer) engine flags # flags value can be made by bitwise "OR"ing: # 0x0001 - ENGINE_METHOD_RSA # 0x0002 - ENGINE_METHOD_DSA # 0x0004 - ENGINE_METHOD_DH # 0x0008 - ENGINE_METHOD_RAND # 0x0010 - ENGINE_METHOD_ECDH # 0x0020 - ENGINE_METHOD_ECDSA # 0x0040 - ENGINE_METHOD_CIPHERS # 0x0080 - ENGINE_METHOD_DIGESTS # 0x0100 - ENGINE_METHOD_STORE # 0x0200 - ENGINE_METHOD_PKEY_METHS # 0x0400 - ENGINE_METHOD_PKEY_ASN1_METHS # Obvious all-or-nothing cases: # 0xFFFF - ENGINE_METHOD_ALL # 0x0000 - ENGINE_METHOD_NONE # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/engine.html
ENGINE_by_id
Get ENGINE by its identification $id.
my $rv = Net::SSLeay::ENGINE_by_id($id); # $id - (string) engine identification e.g. "dynamic" # # returns: value coresponding to openssl's ENGINE structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/engine.html
Low level API: EVP_PKEY_* related functions
EVP_PKEY_copy_parameters
Copies the parameters from key $from to key $to.
my $rv = Net::SSLeay::EVP_PKEY_copy_parameters($to, $from); # $to - value coresponding to openssl's EVP_PKEY structure # $from - value coresponding to openssl's EVP_PKEY structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/EVP_PKEY_cmp.html
Low level API: PEM_* related functions
Check openssl doc http://www.openssl.org/docs/crypto/pem.html
PEM_read_bio_DHparams
Reads DH structure from BIO.
my $rv = Net::SSLeay::PEM_read_bio_DHparams($bio); # $bio - value coresponding to openssl's BIO structure # # returns: value coresponding to openssl's DH structure (0 on failure)
PEM_read_bio_X509_CRL
Reads X509_CRL structure from BIO.
my $rv = Net::SSLeay::PEM_read_bio_X509_CRL($bio); # $bio - value coresponding to openssl's BIO structure # # returns: value coresponding to openssl's X509_CRL structure (0 on failure)
PEM_get_string_X509
NOTE: Does not exactly correspond to any low level API function
Converts/exports X509 certificate to string (PEM format).
Net::SSLeay::PEM_get_string_X509($x509); # $x509 - value coresponding to openssl's X509 structure # # returns: string with $x509 in PEM format
Low level API: SESSION_* related functions
d2i_SSL_SESSION
Transforms the external ASN1 representation of an SSL/TLS session, stored as binary data at location pp with length length, into an SSL_SESSION object.
??? (does this function really work?)
my $rv = Net::SSLeay::d2i_SSL_SESSION($a, $pp, $length); # $a - value coresponding to openssl's SSL_SESSION structure # $pp - pointer/buffer ??? # $length - ??? # # returns: ???
Check openssl doc http://www.openssl.org/docs/ssl/d2i_SSL_SESSION.html
i2d_SSL_SESSION
Transforms the SSL_SESSION object in into the ASN1 representation and stores it into the memory location pointed to by pp. The length of the resulting ASN1 representation is returned.
??? (does this function really work?)
my $rv = Net::SSLeay::i2d_SSL_SESSION($in, $pp); # $in - value coresponding to openssl's SSL_SESSION structure # $pp - pointer/data ??? # # returns: 1 on success, 0
Check openssl doc http://www.openssl.org/docs/ssl/d2i_SSL_SESSION.html
SESSION_new
Creates a new SSL_SESSION structure.
my $rv = Net::SSLeay::SESSION_new(); # # returns: value coresponding to openssl's SSL_SESSION structure (0 on failure)
SESSION_free
Free an allocated SSL_SESSION structure.
Net::SSLeay::SESSION_free($ses); # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_free.html
SESSION_cmp
Compare two SSL_SESSION structures.
my $rv = Net::SSLeay::SESSION_cmp($sesa, $sesb); # $sesa - value corresponding to openssl's SSL_SESSION structure # $sesb - value corresponding to openssl's SSL_SESSION structure # # returns: 0 if the two structures are the same
NOTE: Not available in openssl 1.0 or later
SESSION_get_app_data
Can be used to get application defined value/data.
my $rv = Net::SSLeay::SESSION_get_app_data($ses); # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: string/buffer/pointer ???
SESSION_set_app_data
Can be used to set some application defined value/data.
my $rv = Net::SSLeay::SESSION_set_app_data($s, $a); # $s - value coresponding to openssl's SSL_SESSION structure # $a - (string/buffer/pointer ???) data # # returns: ???
SESSION_get_ex_data
Is used to retrieve the information for $idx from session $ses.
my $rv = Net::SSLeay::SESSION_get_ex_data($ses, $idx); # $ses - value coresponding to openssl's SSL_SESSION structure # $idx - (integer) index for application specific data # # returns: pointer to ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_ex_new_index.html
SESSION_set_ex_data
Is used to store application data at arg for idx into the session object.
my $rv = Net::SSLeay::SESSION_set_ex_data($ss, $idx, $data); # $ss - value coresponding to openssl's SSL_SESSION structure # $idx - (integer) ??? # $data - (pointer) ??? # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_ex_new_index.html
SESSION_get_ex_new_index
Is used to register a new index for application specific data.
my $rv = Net::SSLeay::SESSION_get_ex_new_index($argl, $argp, $new_func, $dup_func, $free_func); # $argl - (long) ??? # $argp - (pointer) ??? # $new_func - function pointer ??? (CRYPTO_EX_new *) # $dup_func - function pointer ??? (CRYPTO_EX_dup *) # $free_func - function pointer ??? (CRYPTO_EX_free *) # # returns: (integer) ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_ex_new_index.html
SESSION_get_master_key
NOTE: Does not exactly correspond to any low level API function
Returns 'master_key' value from SSL_SESSION structure $s
Net::SSLeay::SESSION_get_master_key($s); # $s - value coresponding to openssl's SSL_SESSION structure # # returns: master key (binary data)
SESSION_set_master_key
Sets 'master_key' value for SSL_SESSION structure $s
Net::SSLeay::SESSION_set_master_key($s, $key); # $s - value coresponding to openssl's SSL_SESSION structure # $key - master key (binary data) # # returns: no return value
SESSION_get_time
Returns the time at which the session s was established. The time is given in seconds since 1.1.1970.
my $rv = Net::SSLeay::SESSION_get_time($s); # $s - value coresponding to openssl's SSL_SESSION structure # # returns: timestamp (seconds since 1.1.1970)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_time.html
get_time
Technically the same functionality as "SESSION_get_time".
my $rv = Net::SSLeay::get_time($s);
SESSION_get_timeout
Returns the timeout value set for session $s in seconds.
my $rv = Net::SSLeay::SESSION_get_timeout($s); # $s - value coresponding to openssl's SSL_SESSION structure # # returns: timeout (in seconds)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_time.html
get_timeout
Technically the same functionality as "SESSION_get_timeout".
my $rv = Net::SSLeay::get_timeout($s);
SESSION_print
NOTE: Does not exactly correspond to any low level API function
Prints session details (e.g. protocol version, ciprher, session-id ...) to BIO.
my $rv = Net::SSLeay::SESSION_print($fp, $ses); # $fp - value coresponding to openssl's BIO structure # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: 1 on success, 0 on failure
You have to use necessary BIO functions like this:
# let us have $ssl corresponding to openssl's SSL structure my $ses = Net::SSLeay::get_session($ssl); my $bio = Net::SSLeay::BIO_new(&Net::SSLeay::BIO_s_mem); Net::SSLeay::SESSION_print($bio, $ses); print Net::SSLeay::BIO_read($bio);
SESSION_print_fp
Prints session details (e.g. protocol version, ciprher, session-id ...) to file handle.
my $rv = Net::SSLeay::SESSION_print_fp($fp, $ses); # $fp - perl file handle # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: 1 on success, 0 on failure
Example:
# let us have $ssl corresponding to openssl's SSL structure my $ses = Net::SSLeay::get_session($ssl); open my $fh, ">", "output.txt"; Net::SSLeay::SESSION_print_fp($fh,$ses);
SESSION_set_time
Replaces the creation time of the session s with the chosen value $t (seconds since 1.1.1970).
my $rv = Net::SSLeay::SESSION_set_time($ses, $t); # $ses - value coresponding to openssl's SSL_SESSION structure # $t - time value # # returns: 1 on success
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_time.html
set_time
Technically the same functionality as "SESSION_set_time".
my $rv = Net::SSLeay::set_time($ses, $t);
SESSION_set_timeout
Sets the timeout value for session s in seconds to $t.
my $rv = Net::SSLeay::SESSION_set_timeout($s, $t); # $s - value coresponding to openssl's SSL_SESSION structure # $t - timeout (in seconds) # # returns: 1 on success
Check openssl doc http://www.openssl.org/docs/ssl/SSL_SESSION_get_time.html
set_timeout
Technically the same functionality as "SESSION_set_timeout".
my $rv = Net::SSLeay::set_timeout($ses, $t);
Low level API: SSL_CTX_* related functions
NOTE: Please note that the function described in this chapter have "SSL_" part stripped from their original openssl names.
CTX_add_client_CA
Adds the CA name extracted from $cacert to the list of CAs sent to the client when requesting a client certificate for $ctx.
my $rv = Net::SSLeay::CTX_add_client_CA($ctx, $cacert); # $ctx - value coresponding to openssl's SSL_CTX structure # $cacert - value coresponding to openssl's X509 structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_client_CA_list.html
CTX_add_extra_chain_cert
Adds the certificate $x509 to the certificate chain presented together with the certificate. Several certificates can be added one after the other.
my $rv = Net::SSLeay::CTX_add_extra_chain_cert($ctx, $x509); # $ctx - value coresponding to openssl's SSL_CTX structure # $x509 - value coresponding to openssl's X509 structure # # returns: 1 on success, check out the error stack to find out the reason for failure otherwise
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_add_extra_chain_cert.html
CTX_add_session
Adds the session $ses to the context $ctx.
my $rv = Net::SSLeay::CTX_add_session($ctx, $ses); # $ctx - value coresponding to openssl's SSL_CTX structure # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_add_session.html
CTX_callback_ctrl
??? (more info needed)
my $rv = Net::SSLeay::CTX_callback_ctrl($ctx, $cmd, $fp); # $ctx - value coresponding to openssl's SSL_CTX structure # $cmd - (integer) command id # $fp - (function pointer) ??? # # returns: ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_ctrl.html
CTX_check_private_key
Checks the consistency of a private key with the corresponding certificate loaded into $ctx.
my $rv = Net::SSLeay::CTX_check_private_key($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_ctrl
Internal handling function for SSL_CTX objects.
BEWARE: openssl doc says: This function should never be called directly!
my $rv = Net::SSLeay::CTX_ctrl($ctx, $cmd, $larg, $parg); # $ctx - value coresponding to openssl's SSL_CTX structure # $cmd - (integer) command id # $larg - (integer) long ??? # $parg - (string/pointer) ??? # # returns: (long) result of given command ??? #valid $cmd values 1 - SSL_CTRL_NEED_TMP_RSA 2 - SSL_CTRL_SET_TMP_RSA 3 - SSL_CTRL_SET_TMP_DH 4 - SSL_CTRL_SET_TMP_ECDH 5 - SSL_CTRL_SET_TMP_RSA_CB 6 - SSL_CTRL_SET_TMP_DH_CB 7 - SSL_CTRL_SET_TMP_ECDH_CB 8 - SSL_CTRL_GET_SESSION_REUSED 9 - SSL_CTRL_GET_CLIENT_CERT_REQUEST 10 - SSL_CTRL_GET_NUM_RENEGOTIATIONS 11 - SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 12 - SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 13 - SSL_CTRL_GET_FLAGS 14 - SSL_CTRL_EXTRA_CHAIN_CERT 15 - SSL_CTRL_SET_MSG_CALLBACK 16 - SSL_CTRL_SET_MSG_CALLBACK_ARG 17 - SSL_CTRL_SET_MTU 20 - SSL_CTRL_SESS_NUMBER 21 - SSL_CTRL_SESS_CONNECT 22 - SSL_CTRL_SESS_CONNECT_GOOD 23 - SSL_CTRL_SESS_CONNECT_RENEGOTIATE 24 - SSL_CTRL_SESS_ACCEPT 25 - SSL_CTRL_SESS_ACCEPT_GOOD 26 - SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 27 - SSL_CTRL_SESS_HIT 28 - SSL_CTRL_SESS_CB_HIT 29 - SSL_CTRL_SESS_MISSES 30 - SSL_CTRL_SESS_TIMEOUTS 31 - SSL_CTRL_SESS_CACHE_FULL 32 - SSL_CTRL_OPTIONS 33 - SSL_CTRL_MODE 40 - SSL_CTRL_GET_READ_AHEAD 41 - SSL_CTRL_SET_READ_AHEAD 42 - SSL_CTRL_SET_SESS_CACHE_SIZE 43 - SSL_CTRL_GET_SESS_CACHE_SIZE 44 - SSL_CTRL_SET_SESS_CACHE_MODE 45 - SSL_CTRL_GET_SESS_CACHE_MODE 50 - SSL_CTRL_GET_MAX_CERT_LIST 51 - SSL_CTRL_SET_MAX_CERT_LIST 52 - SSL_CTRL_SET_MAX_SEND_FRAGMENT 53 - SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 54 - SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 55 - SSL_CTRL_SET_TLSEXT_HOSTNAME 56 - SSL_CTRL_SET_TLSEXT_DEBUG_CB 57 - SSL_CTRL_SET_TLSEXT_DEBUG_ARG 58 - SSL_CTRL_GET_TLSEXT_TICKET_KEYS 59 - SSL_CTRL_SET_TLSEXT_TICKET_KEYS 60 - SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT 61 - SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 62 - SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 63 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 64 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 65 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 66 - SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 67 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 68 - SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 69 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 70 - SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 71 - SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 72 - SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 73 - DTLS_CTRL_GET_TIMEOUT 74 - DTLS_CTRL_HANDLE_TIMEOUT 75 - DTLS_CTRL_LISTEN 76 - SSL_CTRL_GET_RI_SUPPORT 77 - SSL_CTRL_CLEAR_OPTIONS 78 - SSL_CTRL_CLEAR_MODE
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_ctrl.html
CTX_flush_sessions
Causes a run through the session cache of $ctx to remove sessions expired at time $tm.
Net::SSLeay::CTX_flush_sessions($ctx, $tm); # $ctx - value coresponding to openssl's SSL_CTX structure # $tm - specifies the time which should be used for the expiration test (seconds since 1.1.1970) # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_flush_sessions.html
CTX_free
Free an allocated SSL_CTX object.
Net::SSLeay::CTX_free($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_free.html
CTX_get_app_data
Can be used to get application defined value/data.
my $rv = Net::SSLeay::CTX_get_app_data($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: string/buffer/pointer ???
CTX_set_app_data
Can be used to set some application defined value/data.
my $rv = Net::SSLeay::CTX_set_app_data($ctx, $arg); # $ctx - value coresponding to openssl's SSL_CTX structure # $arg - (string/buffer/pointer ???) data # # returns: ???
CTX_get_cert_store
Returns the current certificate verification storage.
my $rv = Net::SSLeay::CTX_get_cert_store($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's X509_STORE structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cert_store.html
CTX_get_client_CA_list
Returns the list of client CAs explicitly set for $ctx using "CTX_set_client_CA_list".
my $rv = Net::SSLeay::CTX_get_client_CA_list($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's X509_NAME_STACK structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_client_CA_list.html
CTX_get_ex_data
Is used to retrieve the information for index $idx from $ctx.
my $rv = Net::SSLeay::CTX_get_ex_data($ssl, $idx); # $ssl - value coresponding to openssl's SSL_CTX structure # $idx - (integer) index for application specific data # # returns: pointer to ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_ex_new_index.html
CTX_get_ex_new_index
Is used to register a new index for application specific data.
my $rv = Net::SSLeay::CTX_get_ex_new_index($argl, $argp, $new_func, $dup_func, $free_func); # $argl - (long) ??? # $argp - (pointer) ??? # $new_func - function pointer ??? (CRYPTO_EX_new *) # $dup_func - function pointer ??? (CRYPTO_EX_dup *) # $free_func - function pointer ??? (CRYPTO_EX_free *) # # returns: (integer) ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_ex_new_index.html
CTX_get_mode
Returns the mode set for ctx.
my $rv = Net::SSLeay::CTX_get_mode($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: mode (bitmask) #to decode the return value (bitmask) use: 0x00000001 corresponds to SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000002 corresponds to SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000004 corresponds to SSL_MODE_AUTO_RETRY 0x00000008 corresponds to SSL_MODE_NO_AUTO_CHAIN 0x00000010 corresponds to SSL_MODE_RELEASE_BUFFERS (note: some of the bits might not be supported by older openssl versions)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
CTX_set_mode
Adds the mode set via bitmask in $mode to $ctx. Options already set before are not cleared.
my $rv = Net::SSLeay::CTX_set_mode($ctx, $mode); # $ctx - value coresponding to openssl's SSL_CTX structure # $mode - mode bitmask # # returns: the new mode bitmask after adding $mode
For bitmask details see "CTX_get_mode" (above).
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
CTX_get_options
Returns the options (bitmask) set for $ctx.
my $rv = Net::SSLeay::CTX_get_options($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: options (bitmask) #to decode the return value (bitmask) use: 0x00000001 corresponds to SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000002 corresponds to SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000004 corresponds to SSL_OP_LEGACY_SERVER_CONNECT 0x00000008 corresponds to SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000010 corresponds to SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000020 corresponds to SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000040 corresponds to SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000080 corresponds to SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000100 corresponds to SSL_OP_TLS_D5_BUG 0x00000200 corresponds to SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000800 corresponds to SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x80000FFF corresponds to SSL_OP_ALL 0x00001000 corresponds to SSL_OP_NO_QUERY_MTU 0x00002000 corresponds to SSL_OP_COOKIE_EXCHANGE 0x00004000 corresponds to SSL_OP_NO_TICKET 0x00008000 corresponds to SSL_OP_CISCO_ANYCONNECT 0x00010000 corresponds to SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00020000 corresponds to SSL_OP_NO_COMPRESSION 0x00040000 corresponds to SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0x00080000 corresponds to SSL_OP_SINGLE_ECDH_USE 0x00100000 corresponds to SSL_OP_SINGLE_DH_USE 0x00200000 corresponds to SSL_OP_EPHEMERAL_RSA 0x00400000 corresponds to SSL_OP_CIPHER_SERVER_PREFERENCE 0x00800000 corresponds to SSL_OP_TLS_ROLLBACK_BUG 0x01000000 corresponds to SSL_OP_NO_SSLv2 0x02000000 corresponds to SSL_OP_NO_SSLv3 0x04000000 corresponds to SSL_OP_NO_TLSv1 0x08000000 corresponds to SSL_OP_PKCS1_CHECK_1 0x10000000 corresponds to SSL_OP_PKCS1_CHECK_2 0x20000000 corresponds to SSL_OP_NETSCAPE_CA_DN_BUG 0x40000000 corresponds to SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000 corresponds to SSL_OP_CRYPTOPRO_TLSEXT_BUG (note: some of the bits might not be supported by older openssl versions)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
CTX_set_options
Adds the options set via bitmask in $options to ctx. Options already set before are not cleared.
Net::SSLeay::CTX_set_options($ctx, $options); # $ctx - value coresponding to openssl's SSL_CTX structure # $options - options bitmask # # returns: the new options bitmask after adding $options
For bitmask details see "CTX_get_options" (above).
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
CTX_get_quiet_shutdown
Returns the 'quiet shutdown' setting of $ctx.
my $rv = Net::SSLeay::CTX_get_quiet_shutdown($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: (integer) the current setting
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_quiet_shutdown.html
CTX_get_read_ahead
my $rv = Net::SSLeay::CTX_get_read_ahead($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: (integer) read_ahead value
CTX_get_session_cache_mode
Returns the currently used cache mode (bitmask).
my $rv = Net::SSLeay::CTX_get_session_cache_mode($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: mode (bitmask) #to decode the return value (bitmask) use: 0x0000 corresponds to SSL_SESS_CACHE_OFF 0x0001 corresponds to SSL_SESS_CACHE_CLIENT 0x0002 corresponds to SSL_SESS_CACHE_SERVER 0x0080 corresponds to SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0100 corresponds to SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0200 corresponds to SSL_SESS_CACHE_NO_INTERNAL_STORE (note: some of the bits might not be supported by older openssl versions)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_session_cache_mode.html
CTX_set_session_cache_mode
Enables/disables session caching by setting the operational mode for $ctx to $mode.
my $rv = Net::SSLeay::CTX_set_session_cache_mode($ctx, $mode); # $ctx - value coresponding to openssl's SSL_CTX structure # $mode - mode (bitmask) # # returns: previously set cache mode
For bitmask details see "CTX_get_session_cache_mode" (above).
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_session_cache_mode.html
CTX_get_timeout
Returns the currently set timeout value for $ctx.
my $rv = Net::SSLeay::CTX_get_timeout($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: timeout in seconds
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
CTX_get_verify_depth
Returns the verification depth limit currently set in $ctx. If no limit has been explicitly set, -1 is returned and the default value will be used.",
my $rv = Net::SSLeay::CTX_get_verify_depth($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: depth limit currently set in $ctx, -1 if no limit has been explicitly set
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_verify_mode.html
CTX_get_verify_mode
Returns the verification mode (bitmask) currently set in $ctx.
my $rv = Net::SSLeay::CTX_get_verify_mode($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: mode (bitmask) #to decode the return value (bitmask) use: 0x00 corresponds to SSL_VERIFY_NONE 0x01 corresponds to SSL_VERIFY_PEER 0x02 corresponds to SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x04 corresponds to SSL_VERIFY_CLIENT_ONCE (note: some of the bits might not be supported by older openssl versions)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_verify_mode.html
CTX_set_verify
Sets the verification flags for $ctx to be $mode and specifies the verify_callback function to be used.
Net::SSLeay::CTX_set_verify($ctx, $mode, $callback); # $ctx - value coresponding to openssl's SSL_CTX structure # $mode - mode (bitmask) # $callback - [optional] reference to perl callback function # # returns: no return value
For bitmask details see "CTX_get_verify_mode" (above).
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
CTX_load_verify_locations
Specifies the locations for $ctx, at which CA certificates for verification purposes are located. The certificates available via $CAfile and $CApath are trusted.
my $rv = Net::SSLeay::CTX_load_verify_locations($ctx, $CAfile, $CApath); # $ctx - value coresponding to openssl's SSL_CTX structure # $CAfile - (string) file of CA certificates in PEM format, the file can contain several CA certificates (or '') # $CApath - (string) directory containing CA certificates in PEM format (or '') # # returns: 1 on success, 0 on failure (check the error stack to find out the reason)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html
CTX_need_tmp_RSA
Return the result of
SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
my $rv = Net::SSLeay::CTX_need_tmp_RSA($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: result of SSL_CTRL_NEED_TMP_RSA command
CTX_new
The same as "CTX_v23_new"
my $rv = Net::SSLeay::CTX_new(); # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_new.html
CTX_v2_new
Creates a new SSL_CTX object - based on SSLv2_method() - as framework to establish TLS/SSL enabled connections.
my $rv = Net::SSLeay::CTX_v2_new(); # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
CTX_v23_new
Creates a new SSL_CTX object - based on SSLv23_method() - as framework to establish TLS/SSL enabled connections.
my $rv = Net::SSLeay::CTX_v23_new(); # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
CTX_v3_new
Creates a new SSL_CTX object - based on SSLv3_method() - as framework to establish TLS/SSL enabled connections.
my $rv = Net::SSLeay::CTX_v3_new(); # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
CTX_tlsv1_new
Creates a new SSL_CTX object - based on TLSv1_method() - as framework to establish TLS/SSL enabled connections.
my $rv = Net::SSLeay::CTX_tlsv1_new(); # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
CTX_new_with_method
Creates a new SSL_CTX object based on $meth method
my $rv = Net::SSLeay::CTX_new_with_method($meth); # $meth - value coresponding to openssl's SSL_METHOD structure # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure) #example my $ctx = Net::SSLeay::CTX_new_with_method(&Net::SSLeay::TLSv1_method);
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_new.html
CTX_remove_session
Removes the session $ses from the context $ctx.
my $rv = Net::SSLeay::CTX_remove_session($ctx, $ses); # $ctx - value coresponding to openssl's SSL_CTX structure # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_add_session.html
CTX_sess_accept
my $rv = Net::SSLeay::CTX_sess_accept($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of started SSL/TLS handshakes in server mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_accept_good
my $rv = Net::SSLeay::CTX_sess_accept_good($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of successfully established SSL/TLS sessions in server mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_accept_renegotiate
my $rv = Net::SSLeay::CTX_sess_accept_renegotiate($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of start renegotiations in server mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_cache_full
my $rv = Net::SSLeay::CTX_sess_cache_full($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of sessions that were removed because the maximum session cache size was exceeded
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_cb_hits
my $rv = Net::SSLeay::CTX_sess_cb_hits($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of successfully retrieved sessions from the external session cache in server mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_connect
my $rv = Net::SSLeay::CTX_sess_connect($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of started SSL/TLS handshakes in client mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_connect_good
my $rv = Net::SSLeay::CTX_sess_connect_good($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of successfully established SSL/TLS sessions in client mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_connect_renegotiate
my $rv = Net::SSLeay::CTX_sess_connect_renegotiate($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of start renegotiations in client mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_get_cache_size
Returns the currently valid session cache size.
my $rv = Net::SSLeay::CTX_sess_get_cache_size($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: current size
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_set_cache_size.html
CTX_sess_hits
my $rv = Net::SSLeay::CTX_sess_hits($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of successfully reused sessions
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_misses
my $rv = Net::SSLeay::CTX_sess_misses($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of sessions proposed by clients that were not found in the internal session cache in server mode
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_number
my $rv = Net::SSLeay::CTX_sess_number($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: current number of sessions in the internal session cache
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sess_set_cache_size
Sets the size of the internal session cache of context $ctx to $size.
Net::SSLeay::CTX_sess_set_cache_size($ctx, $size); # $ctx - value coresponding to openssl's SSL_CTX structure # $size - cache size (0 = unlimited) # # returns: previously valid size
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_set_cache_size.html
CTX_sess_timeouts
Returns the number of sessions proposed by clients and either found in the internal or external session cache in server mode, but that were invalid due to timeout. These sessions are not included in the SSL_CTX_sess_hits count.
my $rv = Net::SSLeay::CTX_sess_timeouts($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: number of sessions
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html
CTX_sessions
Returns a pointer to the lhash databases containing the internal session cache for ctx.
my $rv = Net::SSLeay::CTX_sessions($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's LHASH structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_sessions.html
CTX_set1_param
Applies X509 verification parameters $vpm on $ctx
my $rv = Net::SSLeay::CTX_set1_param($ctx, $vpm); # $ctx - value coresponding to openssl's SSL_CTX structure # $vpm - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
CTX_set_cert_store
Sets/replaces the certificate verification storage of $ctx to/with $store.
Net::SSLeay::CTX_set_cert_store($ctx, $store); # $ctx - value coresponding to openssl's SSL_CTX structure # $store - value coresponding to openssl's X509_STORE structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cert_store.html
CTX_set_cert_verify_callback
Sets the verification callback function for $ctx. SSL objects that are created from $ctx inherit the setting valid at the time when
Net::SSLeay::new($ctx)
is called.Net::SSLeay::CTX_set_cert_verify_callback($ctx, $func, $data); # $ctx - value coresponding to openssl's SSL_CTX structure # $func - perl reference to callback function # $data - [optional] data that will be passed to callback function when invoked # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cert_verify_callback.html
CTX_set_cipher_list
Sets the list of available ciphers for $ctx using the control string $str. The list of ciphers is inherited by all ssl objects created from $ctx.
my $rv = Net::SSLeay::CTX_set_cipher_list($s, $str); # $s - value coresponding to openssl's SSL_CTX structure # $str - (string) cipher list e.g. '3DES:+RSA' # # returns: 1 if any cipher could be selected and 0 on complete failure
The format of $str is described in www.openssl.org/docs/apps/ciphers.html
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cipher_list.html
CTX_set_client_CA_list
Sets the list of CAs sent to the client when requesting a client certificate for $ctx.
Net::SSLeay::CTX_set_client_CA_list($ctx, $list); # $ctx - value coresponding to openssl's SSL_CTX structure # $list - value coresponding to openssl's X509_NAME_STACK structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_client_CA_list.html
CTX_set_default_passwd_cb
Sets the default password callback called when loading/storing a PEM certificate with encryption.
Net::SSLeay::CTX_set_default_passwd_cb($ctx, $func); # $ctx - value coresponding to openssl's SSL_CTX structure # $func - perl reference to callback function # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_default_passwd_cb.html
CTX_set_default_passwd_cb_userdata
Sets a pointer to userdata which will be provided to the password callback on invocation.
Net::SSLeay::CTX_set_default_passwd_cb_userdata($ctx, $userdata); # $ctx - value coresponding to openssl's SSL_CTX structure # $userdata - data that will be passed to callback function when invoked # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_default_passwd_cb.html
CTX_set_default_verify_paths
??? (more info needed)
my $rv = Net::SSLeay::CTX_set_default_verify_paths($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: 1 on success, 0 on failure
CTX_set_ex_data
Is used to store application data at $data for $idx into the $ctx object.
my $rv = Net::SSLeay::CTX_set_ex_data($ssl, $idx, $data); # $ssl - value coresponding to openssl's SSL_CTX structure # $idx - (integer) ??? # $data - (pointer) ??? # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_ex_new_index.html
CTX_set_purpose
my $rv = Net::SSLeay::CTX_set_purpose($s, $purpose); # $s - value coresponding to openssl's SSL_CTX structure # $purpose - (integer) purpose identifier # # returns: 1 on success, 0 on failure #avainable purpose identifier 1 - X509_PURPOSE_SSL_CLIENT 2 - X509_PURPOSE_SSL_SERVER 3 - X509_PURPOSE_NS_SSL_SERVER 4 - X509_PURPOSE_SMIME_SIGN 5 - X509_PURPOSE_SMIME_ENCRYPT 6 - X509_PURPOSE_CRL_SIGN 7 - X509_PURPOSE_ANY 8 - X509_PURPOSE_OCSP_HELPER 9 - X509_PURPOSE_TIMESTAMP_SIGN #or use corresponding constants $purpose = &Net::SSLeay::X509_PURPOSE_SSL_CLIENT; ... $purpose = &Net::SSLeay::X509_PURPOSE_TIMESTAMP_SIGN;
CTX_set_quiet_shutdown
Sets the 'quiet shutdown' flag for $ctx to be mode. SSL objects created from $ctx inherit the mode valid at the time
Net::SSLeay::new($ctx)
is called.Net::SSLeay::CTX_set_quiet_shutdown($ctx, $mode); # $ctx - value coresponding to openssl's SSL_CTX structure # $mode - 0 or 1 # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_quiet_shutdown.html
CTX_set_read_ahead
my $rv = Net::SSLeay::CTX_set_read_ahead($ctx, $val); # $ctx - value coresponding to openssl's SSL_CTX structure # $val - read_ahead value to be set # # returns: the original read_ahead value
CTX_set_session_id_context
Sets the context $sid_ctx of length $sid_ctx_len within which a session can be reused for the $ctx object.
my $rv = Net::SSLeay::CTX_set_session_id_context($ctx, $sid_ctx, $sid_ctx_len); # $ctx - value coresponding to openssl's SSL_CTX structure # $sid_ctx - data buffer # $sid_ctx_len - lenght of data in $sid_ctx # # returns: 1 on success, 0 on failure (the error is logged to the error stack)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_session_id_context.html
CTX_set_ssl_version
Sets a new default TLS/SSL method for SSL objects newly created from this $ctx. SSL objects already created with
Net::SSLeay::new($ctx)
are not affected, except whenNet::SSLeay:clear($ssl)
is being called.my $rv = Net::SSLeay::CTX_set_ssl_version($ctx, $meth); # $ctx - value coresponding to openssl's SSL_CTX structure # $meth - value coresponding to openssl's SSL_METHOD structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_ssl_version.html
CTX_set_timeout
Sets the timeout for newly created sessions for $ctx to $t. The timeout value $t must be given in seconds.
my $rv = Net::SSLeay::CTX_set_timeout($ctx, $t); # $ctx - value coresponding to openssl's SSL_CTX structure # $t - timeout in seconds # # returns: previously set timeout value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
CTX_set_tmp_dh
Sets DH parameters to be used to be $dh. The key is inherited by all ssl objects created from $ctx.
my $rv = Net::SSLeay::CTX_set_tmp_dh($ctx, $dh); # $ctx - value coresponding to openssl's SSL_CTX structure # $dh - value coresponding to openssl's DH structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_dh_callback.html
CTX_set_tmp_dh_callback
Sets the callback function for $ctx to be used when a DH parameters are required to $tmp_dh_callback.
Net::SSLeay::CTX_set_tmp_dh_callback($ctx, $tmp_dh_callback); # $ctx - value coresponding to openssl's SSL_CTX structure # tmp_dh_callback - (function pointer) ??? # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_dh_callback.html
CTX_set_tmp_rsa
Sets the temporary/ephemeral RSA key to be used to be $rsa.
my $rv = Net::SSLeay::CTX_set_tmp_rsa($ctx, $rsa); # $ctx - value coresponding to openssl's SSL_CTX structure # $rsa - value coresponding to openssl's RSA structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_rsa_callback.html
CTX_set_tmp_rsa_callback
Sets the callback function for ctx to be used when a temporary/ephemeral RSA key is required to $tmp_rsa_callback.
??? (does this function really work?)
Net::SSLeay::CTX_set_tmp_rsa_callback($ctx, $tmp_rsa_callback); # $ctx - value coresponding to openssl's SSL_CTX structure # $tmp_rsa_callback - (function pointer) ??? # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_rsa_callback.html
CTX_set_trust
my $rv = Net::SSLeay::CTX_set_trust($s, $trust); # $s - value coresponding to openssl's SSL_CTX structure # $trust - (integer) trust identifier # # returns: the original value #available trust identifiers 1 - X509_TRUST_COMPAT 2 - X509_TRUST_SSL_CLIENT 3 - X509_TRUST_SSL_SERVER 4 - X509_TRUST_EMAIL 5 - X509_TRUST_OBJECT_SIGN 6 - X509_TRUST_OCSP_SIGN 7 - X509_TRUST_OCSP_REQUEST 8 - X509_TRUST_TSA #or use corresponding constants $trust = &Net::SSLeay::X509_TRUST_COMPAT; ... $trust = &Net::SSLeay::X509_TRUST_TSA;
CTX_set_verify_depth
Sets the maximum depth for the certificate chain verification that shall be allowed for ctx.
Net::SSLeay::CTX_set_verify_depth($ctx, $depth); # $ctx - value coresponding to openssl's SSL_CTX structure # $depth - max. depth # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
CTX_use_PKCS12_file
Adds the certificate and private key from PKCS12 file $p12filename to $ctx.
my $rv = Net::SSLeay::CTX_use_PKCS12_file($ctx, $p12filename, $password); # $ctx - value coresponding to openssl's SSL_CTX structure # $p12filename - (string) filename # $password - (string) password to decrypt private key # # returns: 1 on success, 0 on failure
CTX_use_PrivateKey
Adds the private key $pkey to $ctx.
my $rv = Net::SSLeay::CTX_use_PrivateKey($ctx, $pkey); # $ctx - value coresponding to openssl's SSL_CTX structure # $pkey - value coresponding to openssl's EVP_PKEY structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_use_PrivateKey_file
Adds the first private key found in $file to $ctx.
my $rv = Net::SSLeay::CTX_use_PrivateKey_file($ctx, $file, $type); # $ctx - value coresponding to openssl's SSL_CTX structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_use_RSAPrivateKey
Adds the RSA private key $rsa to $ctx.
my $rv = Net::SSLeay::CTX_use_RSAPrivateKey($ctx, $rsa); # $ctx - value coresponding to openssl's SSL_CTX structure # $rsa - value coresponding to openssl's RSA structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_use_RSAPrivateKey_file
Adds the first RSA private key found in $file to $ctx.
my $rv = Net::SSLeay::CTX_use_RSAPrivateKey_file($ctx, $file, $type); # $ctx - value coresponding to openssl's SSL_CTX structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
CTX_use_certificate
Loads the certificate $x into $ctx
my $rv = Net::SSLeay::CTX_use_certificate($ctx, $x); # $ctx - value coresponding to openssl's SSL_CTX structure # $x - value coresponding to openssl's X509 structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_use_certificate_chain_file
Loads a certificate chain from $file into $ctx. The certificates must be in PEM format and must be sorted starting with the subject's certificate (actual client or server certificate), followed by intermediate CA certificates if applicable, and ending at the highest level (root) CA.
my $rv = Net::SSLeay::CTX_use_certificate_chain_file($ctx, $file); # $ctx - value coresponding to openssl's SSL_CTX structure # $file - (string) file name # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
CTX_use_certificate_file
Loads the first certificate stored in $file into $ctx.
my $rv = Net::SSLeay::CTX_use_certificate_file($ctx, $file, $type); # $ctx - value coresponding to openssl's SSL_CTX structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
Low level API: SSL_* related functions
NOTE: Please note that the function described in this chapter have "SSL_" part stripped from their original openssl names.
new
Creates a new SSL structure which is needed to hold the data for a TLS/SSL connection. The new structure inherits the settings of the underlying context $ctx: connection method (SSLv2/v3/TLSv1), options, verification settings, timeout settings.
my $rv = Net::SSLeay::new($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's SSL structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_new.html
accept
Waits for a TLS/SSL client to initiate the TLS/SSL handshake. The communication channel must already have been set and assigned to the ssl by setting an underlying BIO.
my $rv = Net::SSLeay::accept($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 = success, 0 = handshake not successfull, <0 = fatal error during handshake
Check openssl doc http://www.openssl.org/docs/ssl/SSL_accept.html
add_client_CA
Adds the CA name extracted from cacert to the list of CAs sent to the client when requesting a client certificate for the chosen ssl, overriding the setting valid for ssl's SSL_CTX object.
my $rv = Net::SSLeay::add_client_CA($ssl, $x); # $ssl - value coresponding to openssl's SSL structure # $x - value coresponding to openssl's X509 structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_client_CA_list.html
callback_ctrl
??? (more info needed)
my $rv = Net::SSLeay::callback_ctrl($ssl, $cmd, $fp); # $ssl - value coresponding to openssl's SSL structure # $cmd - (integer) command id # $fp - (function pointer) ??? # # returns: ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_ctrl.html
check_private_key
Checks the consistency of a private key with the corresponding certificate loaded into $ssl
my $rv = Net::SSLeay::check_private_key($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
clear
Reset SSL object to allow another connection.
Net::SSLeay::clear($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_clear.html
connect
Initiate the TLS/SSL handshake with an TLS/SSL server.
my $rv = Net::SSLeay::connect($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 = success, 0 = handshake not successfull, <0 = fatal error during handshake
Check openssl doc http://www.openssl.org/docs/ssl/SSL_connect.html
copy_session_id
Copies the session structure fro $from to $to (+ also the private key and certificate associated with $from).
Net::SSLeay::copy_session_id($to, $from); # $to - value coresponding to openssl's SSL structure # $from - value coresponding to openssl's SSL structure # # returns: no return value
ctrl
Internal handling function for SSL objects.
BEWARE: openssl doc says: This function should never be called directly!
my $rv = Net::SSLeay::ctrl($ssl, $cmd, $larg, $parg); # $ssl - value coresponding to openssl's SSL structure # $cmd - (integer) command id # $larg - (integer) long ??? # $parg - (string/pointer) ??? # # returns: (long) result of given command ???
For more details about valid $cmd values check "CTX_ctrl".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_ctrl.html
do_handshake
Will wait for a SSL/TLS handshake to take place. If the connection is in client mode, the handshake will be started. The handshake routines may have to be explicitly set in advance using either SSL_set_connect_state or SSL_set_accept_state(3).
my $rv = Net::SSLeay::do_handshake($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 = success, 0 = handshake not successfull, <0 = fatal error during handshake
Check openssl doc http://www.openssl.org/docs/ssl/SSL_do_handshake.html
dup
Returns a duplicate of $ssl.
my $rv = Net::SSLeay::dup($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL structure (0 on failure)
free
Free an allocated SSL structure.
Net::SSLeay::free($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_free.html
get_SSL_CTX
Returns a pointer to the SSL_CTX object, from which $ssl was created with Net::SSLeay::new.
my $rv = Net::SSLeay::get_SSL_CTX($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL_CTX structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_SSL_CTX.html
get_app_data
Can be used to get application defined value/data.
my $rv = Net::SSLeay::get_app_data($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: string/buffer/pointer ???
set_app_data
Can be used to set some application defined value/data.
my $rv = Net::SSLeay::set_app_data($ssl, $arg); # $ssl - value coresponding to openssl's SSL structure # $arg - (string/buffer/pointer ???) data # # returns: ???
get_certificate
Gets X509 certificate from an established SSL connection.
my $rv = Net::SSLeay::get_certificate($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's X509 structure (0 on failure)
get_cipher
Obtains the name of the currently used cipher.
my $rv = Net::SSLeay::get_cipher($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (string) cipher name e.g. 'DHE-RSA-AES256-SHA' or '', when no session has been established.
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_current_cipher.html
get_cipher_bits
Obtain the number of secret/algorithm bits used.
my $rv = Net::SSLeay::get_cipher_bits($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: number of secret bits used by current cipher
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_current_cipher.html and www.openssl.org/docs/ssl/SSL_CIPHER_get_name.html
get_cipher_list
Returns the name (string) of the SSL_CIPHER listed for $ssl with priority $n.
my $rv = Net::SSLeay::get_cipher_list($ssl, $n); # $ssl - value coresponding to openssl's SSL structure # $n - (integer) priority # # returns: (string) cipher name e.g. 'EDH-DSS-DES-CBC3-SHA' or '' in case of error
Call Net::SSLeay::get_cipher_list with priority starting from 0 to obtain the sorted list of available ciphers, until '' is returned:
my $priority = 0; while (my $c = Net::SSLeay::get_cipher_list($ssl, $priority)) { print "cipher[$priority] = $c\n"; $priority++; }
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_ciphers.html
get_client_CA_list
Returns the list of client CAs explicitly set for $ssl using
Net::SSleay::set_client_CA_list
or $ssl's SSL_CTX object withNet::SSLeay::CTX_set_client_CA_list
, when in server mode.In client mode, returns the list of client CAs sent from the server, if any.
my $rv = Net::SSLeay::get_client_CA_list($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's STACK_OF(X509_NAME) structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_client_CA_list.html
get_current_cipher
Returns the cipher actually used.
my $rv = Net::SSLeay::get_current_cipher($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL_CIPHER structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_current_cipher.html
get_default_timeout
Returns the default timeout value assigned to SSL_SESSION objects negotiated for the protocol valid for $ssl.
my $rv = Net::SSLeay::get_default_timeout($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (long) timeout in seconds
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_default_timeout.html
get_error
Returns a result code for a preceding call to
connect
,accept
,do_handshake
,read
,peek
orwrite
on $ssl.my $rv = Net::SSLeay::get_error($ssl, $ret); # $ssl - value coresponding to openssl's SSL structure # $ret - return value of preceeding TLS/SSL I/O operation # # returns: result code, which is one of the following values: # 0 - SSL_ERROR_NONE # 1 - SSL_ERROR_SSL # 2 - SSL_ERROR_WANT_READ # 3 - SSL_ERROR_WANT_WRITE # 4 - SSL_ERROR_WANT_X509_LOOKUP # 5 - SSL_ERROR_SYSCALL # 6 - SSL_ERROR_ZERO_RETURN # 7 - SSL_ERROR_WANT_CONNECT # 8 - SSL_ERROR_WANT_ACCEPT
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_error.html
get_ex_data
Is used to retrieve the information for $idx from $ssl.
my $rv = Net::SSLeay::get_ex_data($ssl, $idx); # $ssl - value coresponding to openssl's SSL structure # $idx - (integer) index for application specific data # # returns: pointer to ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_ex_new_index.html
set_ex_data
Is used to store application data at $data for $idx into the $ssl object.
my $rv = Net::SSLeay::set_ex_data($ssl, $idx, $data); # $ssl - value coresponding to openssl's SSL structure # $idx - (integer) ??? # $data - (pointer) ??? # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_ex_new_index.html
get_ex_new_index
Is used to register a new index for application specific data.
my $rv = Net::SSLeay::get_ex_new_index($argl, $argp, $new_func, $dup_func, $free_func); # $argl - (long) ??? # $argp - (pointer) ??? # $new_func - function pointer ??? (CRYPTO_EX_new *) # $dup_func - function pointer ??? (CRYPTO_EX_dup *) # $free_func - function pointer ??? (CRYPTO_EX_free *) # # returns: (integer) ???
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_ex_new_index.html
get_fd
Returns the file descriptor which is linked to $ssl.
my $rv = Net::SSLeay::get_fd($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: file descriptor (>=0) or -1 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_fd.html
get_finished
Obtains the latest 'Finished' message sent to the peer.
??? (does this function really work?)
my $rv = Net::SSLeay::get_finished($ssl, $buf, $count); # $ssl - value coresponding to openssl's SSL structure # $buf - buffer where the returned data will be stored (pointer ???, pre-allocated ???) # $count - max. size of return data # # returns: actual size of the returned data in $buf
get_peer_finished
Obtains the latest 'Finished' message expected from the peer.
??? (does this function really work?)
my $rv = Net::SSLeay::get_peer_finished($ssl, $buf, $count); # $ssl - value coresponding to openssl's SSL structure # $buf - buffer where the returned data will be stored (pointer ???, pre-allocated ???) # $count - max. size of the return data # # returns: actual size of the returned data in $buf
get_keyblock_size
NOTE: Does not exactly correspond to any low level API function.
??? (more info needed)
my $rv = Net::SSLeay::get_keyblock_size($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: keyblock size, -1 on error
get_mode
Returns the mode (bitmask) set for $ssl.
my $rv = Net::SSLeay::get_mode($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: mode (bitmask)
To decode the return value (bitmask) see documentation for "CTX_get_mode".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
set_mode
Adds the mode set via bitmask in $mode to $ssl. Options already set before are not cleared.
my $rv = Net::SSLeay::set_mode($ssl, $mode); # $ssl - value coresponding to openssl's SSL structure # $mode - mode (bitmask) # # returns: the new mode bitmask after adding $mode
For $mode bitmask details see "CTX_get_mode".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
get_options
Returns the options (bitmask) set for $ssl.
my $rv = Net::SSLeay::get_options($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: options (bitmask)
To decode the return value (bitmask) see documentation for "CTX_get_options".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
set_options
Adds the options set via bitmask in $options to $ssl. Options already set before are not cleared!
Net::SSLeay::set_options($ssl, $options); # $ssl - value coresponding to openssl's SSL structure # $options - options (bitmask) # # returns: the new options bitmask after adding $options
For $options bitmask details see "CTX_get_options".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
get_peer_certificate
Get the X509 certificate of the peer.
my $rv = Net::SSLeay::get_peer_certificate($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's X509 structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_peer_certificate.html
get_quiet_shutdown
Returns the 'quiet shutdown' setting of ssl.
my $rv = Net::SSLeay::get_quiet_shutdown($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (integer) current 'quiet shutdown' value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_quiet_shutdown.html
get_rbio
Get 'read' BIO linked to an SSL object $ssl.
my $rv = Net::SSLeay::get_rbio($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_rbio.html
get_read_ahead
my $rv = Net::SSLeay::get_read_ahead($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (integer) read_ahead value
set_read_ahead
Net::SSLeay::set_read_ahead($ssl, $val); # $ssl - value coresponding to openssl's SSL structure # $val - read_ahead value to be set # # returns: the original read_ahead value
get_server_random
Returns internal SSLv3 server_random value.
Net::SSLeay::get_server_random($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: server_random value (binary data)
get_client_random
NOTE: Does not exactly correspond to any low level API function
Returns internal SSLv3 client_random value.
Net::SSLeay::get_client_random($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: client_random value (binary data)
get_session
Retrieve TLS/SSL session data used in $ssl. The reference count of the SSL_SESSION is NOT incremented.
my $rv = Net::SSLeay::get_session($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL_SESSION structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_session.html
SSL_get0_session
The alias for "get_session" (note that the name is
SSL_get0_session
NOTget0_session
).my $rv = Net::SSLeay::SSL_get0_session();
get1_session
Returns a pointer to the SSL_SESSION actually used in $ssl. The reference count of the SSL_SESSION is incremented by 1.
my $rv = Net::SSLeay::get1_session($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL_SESSION structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_session.html
get_shared_ciphers
??? (does this function really work?)
my $rv = Net::SSLeay::get_shared_ciphers($ssl, $buf, $len); # $ssl - value coresponding to openssl's SSL structure # $buf - (string/buffer/pointer) ??? # $len - (integer) buffer length ??? # # returns: ???
get_shutdown
Returns the shutdown mode of $ssl.
my $rv = Net::SSLeay::get_shutdown($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: shutdown mode (bitmask) of ssl #to decode the return value (bitmask) use: 0 - No shutdown setting, yet 1 - SSL_SENT_SHUTDOWN 2 - SSL_RECEIVED_SHUTDOWN
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_shutdown.html
get_ssl_method
Returns a function pointer to the TLS/SSL method set in $ssl.
my $rv = Net::SSLeay::get_ssl_method($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's SSL_METHOD structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_ssl_version.html
get_state
Returns the SSL connection state.
my $rv = Net::SSLeay::get_state($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (integer) state value # to decode the returned state check: # SSL_ST_* constants in openssl/ssl.h # SSL2_ST_* constants in openssl/ssl2.h # SSL23_ST_* constants in openssl/ssl23.h # SSL3_ST_* + DTLS1_ST_* constants in openssl/ssl3.h
state
Exactly the same as "get_state".
my $rv = Net::SSLeay::state($ssl);
get_verify_depth
Returns the verification depth limit currently set in $ssl.
my $rv = Net::SSLeay::get_verify_depth($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: current depth or -1 if no limit has been explicitly set
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_verify_mode.html
set_verify_depth
Sets the maximum depth for the certificate chain verification that shall be allowed for $ssl.
Net::SSLeay::set_verify_depth($ssl, $depth); # $ssl - value coresponding to openssl's SSL structure # $depth - (integer) depth # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
get_verify_mode
Returns the verification mode (bitmask) currently set in $ssl.
my $rv = Net::SSLeay::get_verify_mode($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: mode (bitmask)
To decode the return value (bitmask) see documentation for "CTX_get_verify_mode".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_get_verify_mode.html
set_verify
Sets the verification flags for $ssl to be $mode and specifies the $verify_callback function to be used.
Net::SSLeay::set_verify($ssl, $mode, $callback); # $ssl - value coresponding to openssl's SSL structure # $mode - mode (bitmask) # $callback - [optional] reference to perl callback function # # returns: no return value
For $mode bitmask details see "CTX_get_verify_mode".
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
get_verify_result
Returns the result of the verification of the X509 certificate presented by the peer, if any.
my $rv = Net::SSLeay::get_verify_result($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (integer) # 0 - X509_V_OK: ok # 2 - X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate # 3 - X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL # 4 - X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature # 5 - X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature # 6 - X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key # 7 - X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure # 8 - X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure # 9 - X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid # 10 - X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired # 11 - X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid # 12 - X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired # 13 - X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field # 14 - X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field # 15 - X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field # 16 - X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field # 17 - X509_V_ERR_OUT_OF_MEM: out of memory # 18 - X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate # 19 - X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain # 20 - X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate # 21 - X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate # 22 - X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long # 23 - X509_V_ERR_CERT_REVOKED: certificate revoked # 24 - X509_V_ERR_INVALID_CA: invalid CA certificate # 25 - X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded # 26 - X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose # 27 - X509_V_ERR_CERT_UNTRUSTED: certificate not trusted # 28 - X509_V_ERR_CERT_REJECTED: certificate rejected # 29 - X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch # 30 - X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch # 31 - X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch # 32 - X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing # 50 - X509_V_ERR_APPLICATION_VERIFICATION: application verification failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_verify_result.html
set_verify_result
Override result of peer certificate verification.
Net::SSLeay::set_verify_result($ssl, $v); # $ssl - value coresponding to openssl's SSL structure # $v - (integer) result value # # returns: no return value
For more info about valid return values see "get_verify_result"
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_verify_result.html
get_wbio
Get 'write' BIO linked to an SSL object $ssl.
my $rv = Net::SSLeay::get_wbio($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_get_rbio.html
load_client_CA_file
Load X509 certificates from file (PEM formated).
my $rv = Net::SSLeay::load_client_CA_file($file); # $file - (string) file name # # returns: value coresponding to openssl's STACK_OF(X509_NAME) structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_load_client_CA_file.html
clear_num_renegotiations
Executes SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS command on $ssl.
my $rv = Net::SSLeay::clear_num_renegotiations($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: command result
need_tmp_RSA
Executes SSL_CTRL_NEED_TMP_RSA command on $ssl.
my $rv = Net::SSLeay::need_tmp_RSA($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: command result
num_renegotiations
Executes SSL_CTRL_GET_NUM_RENEGOTIATIONS command on $ssl.
my $rv = Net::SSLeay::num_renegotiations($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: command result
total_renegotiations
Executes SSL_CTRL_GET_TOTAL_RENEGOTIATIONS command on $ssl.
my $rv = Net::SSLeay::total_renegotiations($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: command result
peek
Copies $max bytes from the specified $ssl into the returned value. In constrast to the
Net::SSLeay::read()
function, the data in the SSL buffer is unmodified after the SSL_peek() operation.Net::SSLeay::peek($ssl, $max); # $ssl - value coresponding to openssl's SSL structure # $max - [optional] max bytes to peek (integer) - default is 32768 # # returns: read data, undef on error
pending
Obtain number of readable bytes buffered in $ssl object.
my $rv = Net::SSLeay::pending($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: the number of bytes pending
Check openssl doc http://www.openssl.org/docs/ssl/SSL_pending.html
read
Tries to read $max bytes from the specified $ssl.
my $rv = Net::SSLeay::read($ssl, $max); # $ssl - value coresponding to openssl's SSL structure # $max - [optional] max bytes to read (integer) - default is 32768 # # returns: data read from a TLS/SSL connection, undef on error
Check openssl doc http://www.openssl.org/docs/ssl/SSL_read.html
renegotiate
Turn on flags for renegotiation so that renegotiation will happen
my $rv = Net::SSLeay::renegotiate($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 on success, 0 on failure
rstate_string
Returns a 2 letter string indicating the current read state of the SSL object $ssl.
my $rv = Net::SSLeay::rstate_string($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 2-letter string
Check openssl doc http://www.openssl.org/docs/ssl/SSL_rstate_string.html
rstate_string_long
Returns a string indicating the current read state of the SSL object ssl.
my $rv = Net::SSLeay::rstate_string_long($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: string with current state
Check openssl doc http://www.openssl.org/docs/ssl/SSL_rstate_string.html
session_reused
Query whether a reused session was negotiated during handshake.
my $rv = Net::SSLeay::session_reused($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 0 - new session was negotiated; 1 - session was reused.
Check openssl doc http://www.openssl.org/docs/ssl/SSL_session_reused.html
set1_param
Applies X509 verification parameters $vpm on $ssl
my $rv = Net::SSLeay::set1_param($ssl, $vpm); # $ssl - value coresponding to openssl's SSL structure # $vpm - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
set_accept_state
Sets $ssl to work in server mode.
Net::SSLeay::set_accept_state($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_connect_state.html
set_bio
Connects the BIOs $rbio and $wbio for the read and write operations of the TLS/SSL (encrypted) side of $ssl.
Net::SSLeay::set_bio($ssl, $rbio, $wbio); # $ssl - value coresponding to openssl's SSL structure # $rbio - value coresponding to openssl's BIO structure # $wbio - value coresponding to openssl's BIO structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_bio.html
set_cipher_list
Sets the list of ciphers only for ssl.
my $rv = Net::SSLeay::set_cipher_list($ssl, $str); # $ssl - value coresponding to openssl's SSL structure # $str - (string) cipher list e.g. '3DES:+RSA' # # returns: 1 if any cipher could be selected and 0 on complete failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cipher_list.html
set_client_CA_list
Sets the list of CAs sent to the client when requesting a client certificate for the chosen $ssl, overriding the setting valid for $ssl's SSL_CTX object.
my $rv = Net::SSLeay::set_client_CA_list($ssl, $list); # $ssl - value coresponding to openssl's SSL structure # $list - value coresponding to openssl's STACK_OF(X509_NAME) structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_client_CA_list.html
set_connect_state
Sets $ssl to work in client mode.
Net::SSLeay::set_connect_state($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_connect_state.html
set_fd
Sets the file descriptor $fd as the input/output facility for the TLS/SSL (encrypted) side of $ssl, $fd will typically be the socket file descriptor of a network connection.
my $rv = Net::SSLeay::set_fd($ssl, $fd); # $ssl - value coresponding to openssl's SSL structure # $fd - (integer) file handle (got via perl's fileno) # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_fd.html
set_rfd
Sets the file descriptor $fd as the input (read) facility for the TLS/SSL (encrypted) side of $ssl.
my $rv = Net::SSLeay::set_rfd($ssl, $fd); # $ssl - value coresponding to openssl's SSL structure # $fd - (integer) file handle (got via perl's fileno) # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_fd.html
set_wfd
my $rv = Net::SSLeay::set_wfd($ssl, $fd); # $ssl - value coresponding to openssl's SSL structure # $fd - (integer) file handle (got via perl's fileno) # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_fd.html
set_info_callback
Sets the callback function, that can be used to obtain state information for $ssl during connection setup and use. When callback is 0 (NULL), the callback setting currently valid for ctx is used.
??? (does this function really work?)
Net::SSLeay::set_info_callback($ssl, $cb); # $ssl - value coresponding to openssl's SSL structure # $cb - pointer to function ??? # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_info_callback.html
set_pref_cipher
Sets the list of available ciphers for $ssl using the control string $str.
my $rv = Net::SSLeay::set_pref_cipher($ssl, $str); # $ssl - value coresponding to openssl's SSL structure # $str - (string) cipher list e.g. '3DES:+RSA' # # returns: 1 if any cipher could be selected and 0 on complete failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_cipher_list.html
set_purpose
my $rv = Net::SSLeay::set_purpose($ssl, $purpose); # $ssl - value coresponding to openssl's SSL structure # $purpose - (integer) purpose identifier # # returns: 1 on success, 0 on failure
For more info about available $purpose identifiers see "CTX_set_purpose".
set_quiet_shutdown
Sets the 'quiet shutdown' flag for $ssl to be $mode.
Net::SSLeay::set_quiet_shutdown($ssl, $mode); # $ssl - value coresponding to openssl's SSL structure # $mode - 0 or 1 # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_quiet_shutdown.html
set_session
Set a TLS/SSL session to be used during TLS/SSL connect.
my $rv = Net::SSLeay::set_session($to, $ses); # $to - value coresponding to openssl's SSL structure # $ses - value coresponding to openssl's SSL_SESSION structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_session.html
set_session_id_context
Sets the context $sid_ctx of length $sid_ctx_len within which a session can be reused for the $ssl object.
my $rv = Net::SSLeay::set_session_id_context($ssl, $sid_ctx, $sid_ctx_len); # $ssl - value coresponding to openssl's SSL structure # $sid_ctx - data buffer # $sid_ctx_len - lenght of data in $sid_ctx # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_session_id_context.html
set_session_secret_cb
Setup pre-shared secret session resumption function.
Net::SSLeay::set_session_secret_cb($ssl, $func, $data); # $ssl - value coresponding to openssl's SSL structure # $func - perl reference to callback function # $data - [optional] data that will be passed to callback function when invoked # # returns: no return value
set_shutdown
Sets the shutdown state of $ssl to $mode.
Net::SSLeay::set_shutdown($ssl, $mode); # $ssl - value coresponding to openssl's SSL structure # $mode - (integer) shutdown mode: # 0 - No shutdown # 1 - SSL_SENT_SHUTDOWN # 2 - SSL_RECEIVED_SHUTDOWN # 3 - SSL_RECEIVED_SHUTDOWN+SSL_SENT_SHUTDOWN # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_set_shutdown.html
set_ssl_method
Sets a new TLS/SSL method for a particular $ssl object.
my $rv = Net::SSLeay::set_ssl_method($ssl, $method); # $ssl - value coresponding to openssl's SSL structure # $method - value coresponding to openssl's SSL_METHOD structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_ssl_version.html
set_tmp_dh
Sets DH parameters to be used to be $dh.
my $rv = Net::SSLeay::set_tmp_dh($ssl, $dh); # $ssl - value coresponding to openssl's SSL structure # $dh - value coresponding to openssl's DH structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_dh_callback.html
set_tmp_dh_callback
Sets the callback function for $ssl to be used when a DH parameters are required to $dh_cb.
??? (does this function really work?)
Net::SSLeay::set_tmp_dh_callback($ssl, $dh); # $ssl - value coresponding to openssl's SSL structure # $dh_cb - pointer to function ??? # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_dh_callback.html
set_tmp_rsa
Sets the temporary/ephemeral RSA key to be used in $ssl to be $rsa.
my $rv = Net::SSLeay::set_tmp_rsa($ssl, $rsa); # $ssl - value coresponding to openssl's SSL structure # $rsa - value coresponding to openssl's RSA structure # # returns: 1 on success, 0 on failure
Example:
$rsakey = Net::SSLeay::RSA_generate_key(); Net::SSLeay::set_tmp_rsa($ssl, $rsakey); Net::SSLeay::RSA_free($rsakey);
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_rsa_callback.html
set_tmp_rsa_callback
Sets the callback function for $ssl to be used when a temporary/ephemeral RSA key is required to $tmp_rsa_callback.
??? (does this function really work?)
Net::SSLeay::set_tmp_rsa_callback($ssl, $tmp_rsa_callback); # $ssl - value coresponding to openssl's SSL structure # $tmp_rsa_callback - (function pointer) ??? # # returns: no return value
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_set_tmp_rsa_callback.html
set_trust
my $rv = Net::SSLeay::set_trust($ssl, $trust); # $ssl - value coresponding to openssl's SSL structure # $trust - (integer) trust identifier # # returns: the original value
For more details about $trust values see "CTX_set_trust".
shutdown
Shuts down an active TLS/SSL connection. It sends the 'close notify' shutdown alert to the peer.
my $rv = Net::SSLeay::shutdown($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 1 - shutdown was successfully completed # 0 - shutdown is not yet finished, # -1 - shutdown was not successful
Check openssl doc http://www.openssl.org/docs/ssl/SSL_shutdown.html
state_string
Returns a 6 letter string indicating the current state of the SSL object $ssl.
my $rv = Net::SSLeay::state_string($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: 6-letter string
Check openssl doc http://www.openssl.org/docs/ssl/SSL_state_string.html
state_string_long
Returns a string indicating the current state of the SSL object $ssl.
my $rv = Net::SSLeay::state_string_long($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: state strings
Check openssl doc http://www.openssl.org/docs/ssl/SSL_state_string.html
use_PrivateKey
Adds $pkey as private key to $ssl.
my $rv = Net::SSLeay::use_PrivateKey($ssl, $pkey); # $ssl - value coresponding to openssl's SSL structure # $pkey - value coresponding to openssl's EVP_PKEY structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_PrivateKey_ASN1
Adds the private key of type $pk stored in $data to $ssl.
my $rv = Net::SSLeay::use_PrivateKey_ASN1($pk, $ssl, $d, $len); # $pk - (integer) key type, NID of corresponding algorithm # $ssl - value coresponding to openssl's SSL structure # $data - key data (binary) # $len - length of $data # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_PrivateKey_file
Adds the first private key found in $file to $ssl.
my $rv = Net::SSLeay::use_PrivateKey_file($ssl, $file, $type); # $ssl - value coresponding to openssl's SSL structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_RSAPrivateKey
Adds $rsa as RSA private key to $ssl.
my $rv = Net::SSLeay::use_RSAPrivateKey($ssl, $rsa); # $ssl - value coresponding to openssl's SSL structure # $rsa - value coresponding to openssl's RSA structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_RSAPrivateKey_ASN1
Adds RSA private key stored in $data to $ssl.
my $rv = Net::SSLeay::use_RSAPrivateKey_ASN1($ssl, $data, $len); # $ssl - value coresponding to openssl's SSL structure # $data - key data (binary) # $len - length of $data # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_RSAPrivateKey_file
Adds the first RSA private key found in $file to $ssl.
my $rv = Net::SSLeay::use_RSAPrivateKey_file($ssl, $file, $type); # $ssl - value coresponding to openssl's SSL structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_certificate
Loads the certificate $x into $ssl.
my $rv = Net::SSLeay::use_certificate($ssl, $x); # $ssl - value coresponding to openssl's SSL structure # $x - value coresponding to openssl's X509 structure # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_certificate_ASN1
Loads the ASN1 encoded certificate from $data to $ssl.
my $rv = Net::SSLeay::use_certificate_ASN1($ssl, $data, $len); # $ssl - value coresponding to openssl's SSL structure # $data - certificate data (binary) # $len - length of $data # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
use_certificate_file
Loads the first certificate stored in $file into $ssl.
my $rv = Net::SSLeay::use_certificate_file($ssl, $file, $type); # $ssl - value coresponding to openssl's SSL structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, otherwise check out the error stack to find out the reason
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html
version
Returns SSL/TLS protocol version
my $rv = Net::SSLeay::version($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: (integer) protocol version # 0x0002 - SSL2_VERSION (SSLv2) # 0x0300 - SSL3_VERSION (SSLv3) # 0x0301 - TLS1_VERSION (TLSv1) # 0xFEFF - DTLS1_VERSION (DTLSv1)
want
Returns state information for the SSL object $ssl.
my $rv = Net::SSLeay::want($ssl); # $ssl - value coresponding to openssl's SSL structure # # returns: state # 1 - SSL_NOTHING # 2 - SSL_WRITING # 3 - SSL_READING # 4 - SSL_X509_LOOKUP
Check openssl doc http://www.openssl.org/docs/ssl/SSL_want.html
write
Writes data from the buffer $data into the specified $ssl connection.
my $rv = Net::SSLeay::write($ssl, $data); # $ssl - value coresponding to openssl's SSL structure # $data - data to be written # # returns: >0 - (success) number of bytes actually written to the TLS/SSL connection # 0 - write not successful, probably the underlying connection was closed # <0 - error
Check openssl doc http://www.openssl.org/docs/ssl/SSL_write.html
write_partial
NOTE: Does not exactly correspond to any low level API function
Writes a fragment of data data from the buffer $data into the specified $ssl connection.
my $rv = Net::SSLeay::write_partial($ssl, $from, $count, $data); # $ssl - value coresponding to openssl's SSL structure # $from - (integer) offset from the beginning of $data # $count - (integer) length of data to be written # $data - data buffer # # returns: >0 - (success) number of bytes actually written to the TLS/SSL connection # 0 - write not successful, probably the underlying connection was closed # <0 - error
Low level API: RAND_* related functions
Check openssl doc related to RAND stuff http://www.openssl.org/docs/crypto/rand.html
RAND_add
Mixes the $num bytes at $buf into the PRNG state.
Net::SSLeay::RAND_add($buf, $num, $entropy); # $buf - buffer with data to be mixed into the PRNG state # $num - number of bytes in $buf # $entropy - estimate of how much randomness is contained in $buf (in bytes) # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/RAND_add.html
RAND_seed
Equivalent to "RAND_add" when $num == $entropy.
Net::SSLeay::RAND_seed($buf); # Perlishly figures out buf size # $buf - buffer with data to be mixed into the PRNG state # $num - number of bytes in $buf # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/RAND_add.html
RAND_status
Gives PRNG status (seeded enough or not).
my $rv = Net::SSLeay::RAND_status(); #returns: 1 if the PRNG has been seeded with enough data, 0 otherwise
Check openssl doc http://www.openssl.org/docs/crypto/RAND_add.html
RAND_bytes
Puts $num cryptographically strong pseudo-random bytes into $buf.
my $rv = Net::SSLeay::RAND_bytes($buf, $num); # $buf - buffer where the random data will be stored # $num - the size (in bytes) of requested random data # # returns: 1 on success, 0 otherwise
Check openssl doc http://www.openssl.org/docs/crypto/RAND_bytes.html
RAND_pseudo_bytes
Puts $num pseudo-random (not necessarily unpredictable) bytes into $buf.
my $rv = Net::SSLeay::RAND_pseudo_bytes($buf, $num); # $buf - buffer where the random data will be stored # $num - the size (in bytes) of requested random data # # returns: 1 if the bytes generated are cryptographically strong, 0 otherwise
Check openssl doc http://www.openssl.org/docs/crypto/RAND_bytes.html
RAND_cleanup
Erase the PRNG state.
Net::SSLeay::RAND_cleanup(); # no args, no return value
Check openssl doc http://www.openssl.org/docs/crypto/RAND_cleanup.html
RAND_egd
Queries the entropy gathering daemon EGD on socket $path for 255 bytes.
my $rv = Net::SSLeay::RAND_egd($path); # $path - path to a socket of entropy gathering daemon EGD # # returns: the number of bytes read from the daemon on success, and -1 on failure
Check openssl doc http://www.openssl.org/docs/crypto/RAND_egd.html
RAND_egd_bytes
Queries the entropy gathering daemon EGD on socket $path for $bytes bytes.
my $rv = Net::SSLeay::RAND_egd_bytes($path, $bytes); # $path - path to a socket of entropy gathering daemon EGD # $bytes - number of bytes we want from EGD # # returns: the number of bytes read from the daemon on success, and -1 on failure
Check openssl doc http://www.openssl.org/docs/crypto/RAND_egd.html
RAND_file_name
Generates a default path for the random seed file.
my $file = Net::SSLeay::RAND_file_name($num); # $num - maximum size of returned file name # # returns: string with file name on success, '' (empty string) on failure
Check openssl doc http://www.openssl.org/docs/crypto/RAND_load_file.html
RAND_load_file
Reads $max_bytes of bytes from $file_name and adds them to the PRNG.
my $rv = Net::SSLeay::RAND_load_file($file_name, $max_bytes); # $file_name - the name of file # $max_bytes - bytes to read from $file_name; -1 => the complete file is read # # returns: the number of bytes read
Check openssl doc http://www.openssl.org/docs/crypto/RAND_load_file.html
RAND_write_file
Writes 1024 random bytes to $file_name which can be used to initialize the PRNG by calling "RAND_load_file" in a later session.
my $rv = Net::SSLeay::RAND_write_file($file_name); # $file_name - the name of file # # returns: the number of bytes written, and -1 if the bytes written were generated without appropriate seed
Check openssl doc http://www.openssl.org/docs/crypto/RAND_load_file.html
RAND_poll
Collects some entropy from operating system and adds it to the PRNG.
my $rv = Net::SSLeay::RAND_poll(); # returns: 1 on success, 0 on failure (unable to gather reasonable entropy)
Low level API: OBJ_* related functions
OBJ_cmp
Compares ASN1_OBJECT $a to ASN1_OBJECT $b.
my $rv = Net::SSLeay::OBJ_cmp($a, $b); # $a - value coresponding to openssl's ASN1_OBJECT structure # $b - value coresponding to openssl's ASN1_OBJECT structure # # returns: if the two are identical 0 is returned
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_dup
Returns a copy/duplicate of $o.
my $rv = Net::SSLeay::OBJ_dup($o); # $o - value coresponding to openssl's ASN1_OBJECT structure # # returns: value coresponding to openssl's ASN1_OBJECT structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_nid2ln
Returns long name for given NID $n.
my $rv = Net::SSLeay::OBJ_nid2ln($n); # $n - (integer) NID # # returns: (string) long name e.g. 'commonName'
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_ln2nid
Returns NID corresponding to given long name $n.
my $rv = Net::SSLeay::OBJ_ln2nid($s); # $s - (string) long name e.g. 'commonName' # # returns: (integer) NID
OBJ_nid2sn
Returns short name for given NID $n.
my $rv = Net::SSLeay::OBJ_nid2sn($n); # $n - (integer) NID # # returns: (string) short name e.g. 'CN'
Example:
print Net::SSLeay::OBJ_nid2sn(&Net::SSLeay::NID_commonName);
OBJ_sn2nid
Returns NID corresponding to given short name $s.
my $rv = Net::SSLeay::OBJ_sn2nid($s); # $s - (string) short name e.g. 'CN' # # returns: (integer) NID
Example:
print "NID_commonName constant=", &Net::SSLeay::NID_commonName; print "OBJ_sn2nid('CN')=", Net::SSLeay::OBJ_sn2nid('CN');
OBJ_nid2obj
Returns ASN1_OBJECT for given NID $n.
my $rv = Net::SSLeay::OBJ_nid2obj($n); # $n - (integer) NID # # returns: value coresponding to openssl's ASN1_OBJECT structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_obj2nid
Returns NID corresponding to given ASN1_OBJECT $o.
my $rv = Net::SSLeay::OBJ_obj2nid($o); # $o - value coresponding to openssl's ASN1_OBJECT structure # # returns: (integer) NID
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_txt2obj
Converts the text string s into an ASN1_OBJECT structure. If $no_name is 0 then long names (e.g. 'commonName') and short names (e.g. 'CN') will be interpreted as well as numerical forms (e.g. '2.5.4.3'). If $no_name is 1 only the numerical form is acceptable.
my $rv = Net::SSLeay::OBJ_txt2obj($s, $no_name); # $s - text string to be converted # $no_name - (integer) 0 or 1 # # returns: value coresponding to openssl's ASN1_OBJECT structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_obj2txt
Converts the ASN1_OBJECT a into a textual representation.
Net::SSLeay::OBJ_obj2txt($a, $no_name); # $a - value coresponding to openssl's ASN1_OBJECT structure # $no_name - (integer) 0 or 1 # # returns: textual representation e.g. 'commonName' ($no_name=0), '2.5.4.3' ($no_name=1)
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
OBJ_txt2nid
Returns NID corresponding to text string $s which can be a long name, a short name or the numerical respresentation of an object.
my $rv = Net::SSLeay::OBJ_txt2nid($s); # $s - (string) e.g. 'commonName' or 'CN' or '2.5.4.3' # # returns: (integer) NID
Example:
my $nid = Net::SSLeay::OBJ_txt2nid('2.5.4.3'); Net::SSLeay::OBJ_nid2sn($n);
Check openssl doc http://www.openssl.org/docs/crypto/OBJ_nid2obj.html
Low level API: ASN1_TIME_* related functions
ASN1_TIME_new
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
my $time = ASN1_TIME_new(); # returns: value coresponding to openssl's ASN1_TIME structure
ASN1_TIME_free
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
ASN1_TIME_free($time); # $time - value coresponding to openssl's ASN1_TIME structure
ASN1_TIME_set
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
ASN1_TIME_set($time, $t); # $time - value coresponding to openssl's ASN1_TIME structure # $t - time value in seconds since 1.1.1970
BEWARE: It is platform dependent how this function will handle dates after 2038. Although perl's integer is large enough the internal implementation of this function is dependant on the size of time_t structure (32bit time_t has problem with 2038).
If you want to safely set date and time after 2038 use function "P_ASN1_TIME_set_isotime".
P_ASN1_TIME_get_isotime
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7e
NOTE: Does not exactly correspond to any low level API function
Gives ISO-8601 string representation of ASN1_TIME structure.
my $datetime_string = P_ASN1_TIME_get_isotime($time); # $time - value coresponding to openssl's ASN1_TIME structure # # returns: datetime string like '2033-05-16T20:39:37Z' or '' on failure
The output format is compatible with module DateTime::Format::RFC3339
P_ASN1_TIME_set_isotime
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7e
NOTE: Does not exactly correspond to any low level API function
Sets time and date value of ANS1_time structure.
my $rv = P_ASN1_TIME_set_isotime($time, $string); # $time - value coresponding to openssl's ASN1_TIME structure # $string - ISO-8601 timedate string like '2033-05-16T20:39:37Z' # # returns: 1 on success, 0 on failure
The
$string
parameter has to be in full form like"2012-03-22T23:55:33"
or"2012-03-22T23:55:33Z"
or"2012-03-22T23:55:33CET"
. Short forms like"2012-03-22T23:55"
or"2012-03-22"
are not supported.P_ASN1_TIME_put2string
COMPATIBILITY: not available in Net-SSLeay-1.42 and before, has bugs with openssl-0.9.8i
NOTE: Does not exactly correspond to any low level API function
Gives string representation of ASN1_TIME structure.
my $str = P_ASN1_TIME_put2string($time); # $time - value coresponding to openssl's ASN1_TIME structure # # returns: datetime string like 'May 16 20:39:37 2033 GMT'
P_ASN1_UTCTIME_put2string
NOTE: deprecated function, only for backward compatibility, just an alias for "P_ASN1_TIME_put2string"
Low level API: X509_* related functions
X509V3_EXT_d2i
Parses an extension and returns its internal structure.
my $rv = Net::SSLeay::X509V3_EXT_d2i($ext); # $ext - value coresponding to openssl's X509_EXTENSION structure # # returns: pointer ???
X509_NAME_get_text_by_NID
Retrieves the text from the first entry in name which matches $nid, if no such entry exists -1 is returned.
openssl note: this is a legacy function which has various limitations which makes it of minimal use in practice. It can only find the first matching entry and will copy the contents of the field verbatim: this can be highly confusing if the target is a muticharacter string type like a BMPString or a UTF8String.
Net::SSLeay::X509_NAME_get_text_by_NID($name, $nid); # $name - value coresponding to openssl's X509_NAME structure # $nid - NID value (integer) # # returns: text value
Check openssl doc http://www.openssl.org/docs/crypto/X509_NAME_get_index_by_NID.html
X509_NAME_oneline
Return an ASCII version of $name.
Net::SSLeay::X509_NAME_oneline($name); # $name - value coresponding to openssl's X509_NAME structure # # returns: (string) ASCII version of $name
Check openssl doc http://www.openssl.org/docs/crypto/X509_NAME_print_ex.html
X509_STORE_CTX_get_current_cert
Returns the certificate in ctx which caused the error or 0 if no certificate is relevant.
my $rv = Net::SSLeay::X509_STORE_CTX_get_current_cert($x509_store_ctx); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # # returns: value coresponding to openssl's X509 structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_get_error.html
X509_STORE_CTX_get_error
Returns the error code of $ctx.
my $rv = Net::SSLeay::X509_STORE_CTX_get_error($x509_store_ctx); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # # returns: (integer) error code
For more info about erro code values check function "get_verify_result".
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_get_error.html
X509_STORE_CTX_get_error_depth
Returns the depth of the error. This is a non-negative integer representing where in the certificate chain the error occurred. If it is zero it occured in the end entity certificate, one if it is the certificate which signed the end entity certificate and so on.
my $rv = Net::SSLeay::X509_STORE_CTX_get_error_depth($x509_store_ctx); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # # returns: (integer) depth
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_get_error.html
X509_STORE_CTX_get_ex_data
Is used to retrieve the information for $idx from $x509_store_ctx.
my $rv = Net::SSLeay::X509_STORE_CTX_get_ex_data($x509_store_ctx, $idx); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # $idx - (integer) index for application specific data # # returns: pointer to ???
X509_STORE_CTX_set_ex_data
Is used to store application data at arg for idx into $x509_store_ctx.
my $rv = Net::SSLeay::X509_STORE_CTX_set_ex_data($x509_store_ctx, $idx, $data); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # $idx - (integer) ??? # $data - (pointer) ??? # # returns: 1 on success, 0 on failure
X509_STORE_CTX_set_cert
Sets the certificate to be vertified in $x509_store_ctx to $x.
Net::SSLeay::X509_STORE_CTX_set_cert($x509_store_ctx, $x); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # $x - value coresponding to openssl's X509 structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_new.html
X509_STORE_CTX_set_error
Sets the error code of $ctx to $s. For example it might be used in a verification callback to set an error based on additional checks.
Net::SSLeay::X509_STORE_CTX_set_error($x509_store_ctx, $s); # $x509_store_ctx - value coresponding to openssl's X509_STORE_CTX structure # $s - (integer) error id # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_get_error.html
X509_STORE_add_cert
Adds X509 certificate $x into the X509_STORE $store.
my $rv = Net::SSLeay::X509_STORE_add_cert($store, $x); # $store - value coresponding to openssl's X509_STORE structure # $x - value coresponding to openssl's X509 structure # # returns: 1 on success, 0 on failure
X509_STORE_add_crl
Adds X509 CRL $x into the X509_STORE $store.
my $rv = Net::SSLeay::X509_STORE_add_crl($store, $x); # $store - value coresponding to openssl's X509_STORE structure # $x - value coresponding to openssl's X509_CRL structure # # returns: 1 on success, 0 on failure
X509_STORE_set1_param
??? (more info needed)
my $rv = Net::SSLeay::X509_STORE_set1_param($store, $pm); # $store - value coresponding to openssl's X509_STORE structure # $pm - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
X509_STORE_set_flags
Net::SSLeay::X509_STORE_set_flags($ctx, $flags); # $ctx - value coresponding to openssl's X509_STORE structure # $flags - (unsigned long) flags to be set (bitmask) # # returns: no return value #to create $flags value use: 0x0001 - X509_V_FLAG_CB_ISSUER_CHECK - Send issuer+subject checks to verify_cb 0x0002 - X509_V_FLAG_USE_CHECK_TIME - Use check time instead of current time 0x0004 - X509_V_FLAG_CRL_CHECK - Lookup CRLs 0x0008 - X509_V_FLAG_CRL_CHECK_ALL - Lookup CRLs for whole chain 0x0010 - X509_V_FLAG_IGNORE_CRITICAL - Ignore unhandled critical extensions 0x0020 - X509_V_FLAG_X509_STRICT - Disable workarounds for broken certificates 0x0040 - X509_V_FLAG_ALLOW_PROXY_CERTS - Enable proxy certificate validation 0x0080 - X509_V_FLAG_POLICY_CHECK - Enable policy checking 0x0100 - X509_V_FLAG_EXPLICIT_POLICY - Policy variable require-explicit-policy 0x0200 - X509_V_FLAG_INHIBIT_ANY - Policy variable inhibit-any-policy 0x0400 - X509_V_FLAG_INHIBIT_MAP - Policy variable inhibit-policy-mapping 0x0800 - X509_V_FLAG_NOTIFY_POLICY - Notify callback that policy is OK 0x1000 - X509_V_FLAG_EXTENDED_CRL_SUPPORT - Extended CRL features such as indirect CRLs, alternate CRL signing keys 0x2000 - X509_V_FLAG_USE_DELTAS - Delta CRL support 0x4000 - X509_V_FLAG_CHECK_SS_SIGNATURE - Check selfsigned CA signature #or use corresponding constants like $flags = &Net::SSLeay::X509_V_FLAG_CB_ISSUER_CHECK; ... $flags = &Net::SSLeay::X509_V_FLAG_CHECK_SS_SIGNATURE;
X509_STORE_set_purpose
Net::SSLeay::X509_STORE_set_purpose($ctx, $purpose); # $ctx - value coresponding to openssl's X509_STORE structure # $purpose - (integer) purpose identifier # # returns: no return value
For more details about $purpose identifier check "CTX_set_purpose".
X509_STORE_set_trust
Net::SSLeay::X509_STORE_set_trust($ctx, $trust); # $ctx - value coresponding to openssl's X509_STORE structure # $trust - (integer) trust identifier # # returns: no return value
For more details about $trust identifier check "CTX_set_trust".
X509_VERIFY_PARAM_add0_policy
Enables policy checking (it is disabled by default) and adds $policy to the acceptable policy set.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_add0_policy($param, $policy); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $policy - value coresponding to openssl's ASN1_OBJECT structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_add0_table
??? (more info needed)
my $rv = Net::SSLeay::X509_VERIFY_PARAM_add0_table($param); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
X509_VERIFY_PARAM_clear_flags
Clears the flags $flags in param.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_clear_flags($param, $flags); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $flags - (unsigned long) flags to be set (bitmask) # # returns: 1 on success, 0 on failure
For more details about $flags bitmask see "X509_STORE_set_flags".
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_free
Frees up the X509_VERIFY_PARAM structure.
Net::SSLeay::X509_VERIFY_PARAM_free($param); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: no return value
X509_VERIFY_PARAM_get_depth
Returns the current verification depth.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_get_depth($param); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: (ineger) depth
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_get_flags
Returns the current verification flags.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_get_flags($param); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: (unsigned long) flags to be set (bitmask)
For more details about returned flags bitmask see "X509_STORE_set_flags".
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_set_flags
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set_flags($param, $flags); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $flags - (unsigned long) flags to be set (bitmask) # # returns: 1 on success, 0 on failure
For more details about $flags bitmask see "X509_STORE_set_flags".
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_inherit
??? (more info needed)
my $rv = Net::SSLeay::X509_VERIFY_PARAM_inherit($to, $from); # $to - value coresponding to openssl's X509_VERIFY_PARAM structure # $from - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
X509_VERIFY_PARAM_lookup
Finds X509_VERIFY_PARAM by name.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_lookup($name); # $name - (string) name we want to find # # returns: value coresponding to openssl's X509_VERIFY_PARAM structure (0 on failure)
X509_VERIFY_PARAM_new
Creates a new X509_VERIFY_PARAM structure.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_new(); # # returns: value coresponding to openssl's X509_VERIFY_PARAM structure (0 on failure)
X509_VERIFY_PARAM_set1
Sets the name of X509_VERIFY_PARAM structure $to to the same value as the name of X509_VERIFY_PARAM structure $from.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set1($to, $from); # $to - value coresponding to openssl's X509_VERIFY_PARAM structure # $from - value coresponding to openssl's X509_VERIFY_PARAM structure # # returns: 1 on success, 0 on failure
X509_VERIFY_PARAM_set1_name
Sets the name of X509_VERIFY_PARAM structure $param to $name.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set1_name($param, $name); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $name - (string) name to be set # # returns: 1 on success, 0 on failure
X509_VERIFY_PARAM_set1_policies
Enables policy checking (it is disabled by default) and sets the acceptable policy set to policies. Any existing policy set is cleared. The policies parameter can be 0 to clear an existing policy set.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set1_policies($param, $policies); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $policies - value coresponding to openssl's STACK_OF(ASN1_OBJECT) structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_set_depth
Sets the maximum verification depth to depth. That is the maximum number of untrusted CA certificates that can appear in a chain.
Net::SSLeay::X509_VERIFY_PARAM_set_depth($param, $depth); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $depth - (integer) depth to be set # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_set_purpose
Sets the verification purpose in $param to $purpose. This determines the acceptable purpose of the certificate chain, for example SSL client or SSL server.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set_purpose($param, $purpose); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $purpose - (integer) purpose identifier # # returns: 1 on success, 0 on failure
For more details about $purpose identifier check "CTX_set_purpose".
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_set_time
Sets the verification time in $param to $t. Normally the current time is used.
Net::SSLeay::X509_VERIFY_PARAM_set_time($param, $t); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $t - (time_t) time in seconds since 1.1.1970 # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_set_trust
Sets the trust setting in $param to $trust.
my $rv = Net::SSLeay::X509_VERIFY_PARAM_set_trust($param, $trust); # $param - value coresponding to openssl's X509_VERIFY_PARAM structure # $trust - (integer) trust identifier # # returns: 1 on success, 0 on failure
For more details about $trust identifier check "CTX_set_trust".
Check openssl doc http://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html
X509_VERIFY_PARAM_table_cleanup
??? (more info needed)
Net::SSLeay::X509_VERIFY_PARAM_table_cleanup(); # # returns: no return value
X509_free
Frees up the X509 structure.
Net::SSLeay::X509_free($a); # $a - value coresponding to openssl's X509 structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/X509_new.html
X509_get_ext
Returns X509_EXTENSION from $x509 based on given position/index.
my $rv = Net::SSLeay::X509_get_ext($x509, $index); # $x509 - value coresponding to openssl's X509 structure # $index - (integer) position/index of extension within $x509 # # returns: value coresponding to openssl's X509_EXTENSION structure (0 on failure)
X509_get_ext_by_NID
Returns X509_EXTENSION from $x509 based on given NID.
my $rv = Net::SSLeay::X509_get_ext_by_NID($x509, $nid, $loc); # $x509 - value coresponding to openssl's X509 structure # $nid - (integer) NID value # $loc - (integer) position to start lookup at # # returns: position/index of extension, negative value on error # call Net::SSLeay::X509_get_ext($x509, $rv) to get the actual extension
X509_get_fingerprint
Returns fingerprint of certificate $cert.
NOTE: Does not exactly correspond to any low level API function. The implementation is basen on openssl's
X509_digest()
.Net::SSLeay::X509_get_fingerprint($x509, $type); # $x509 - value coresponding to openssl's X509 structure # $type - (string) digest type, currently supported values: # "md5" # "sha1" # "sha256" # "ripemd160" # # returns: certificate digest - hexadecimal string (NOT binary data!)
X509_get_issuer_name
Return an X509_NAME object representing the issuer of the certificate $cert.
my $rv = Net::SSLeay::X509_get_issuer_name($cert); # $cert - value coresponding to openssl's X509 structure # # returns: value coresponding to openssl's X509_NAME structure (0 on failure)
X509_get_notAfter
Return an object giving the time after which the certificate $cert is not valid.
my $rv = Net::SSLeay::X509_get_notAfter($cert); # $cert - value coresponding to openssl's X509 structure # # returns: value coresponding to openssl's ASN1_TIME structure (0 on failure)
To get human readable/printable form the return value you can use:
my $time = Net::SSLeay::X509_get_notAfter($cert); print "notAfter=", Net::SSLeay::P_ASN1_TIME_get_isotime($time), "\n";
X509_get_notBefore
Return an object giving the time before which the certificate $cert is not valid
my $rv = Net::SSLeay::X509_get_notBefore($cert); # $cert - value coresponding to openssl's X509 structure # # returns: value coresponding to openssl's ASN1_TIME structure (0 on failure)
To get human readable/printable form the return value you can use:
my $time = Net::SSLeay::X509_get_notBefore($cert); print "notBefore=", Net::SSLeay::P_ASN1_TIME_get_isotime($time), "\n";
X509_get_subjectAltNames
NOTE: Does not exactly correspond to any low level API function.
Returns the list of alternative subject names from X509 certificate $cert.
my @rv = Net::SSLeay::X509_get_subjectAltNames($cert); # $cert - value coresponding to openssl's X509 structure # # returns: list containing pairs - name_type (integer), name_value (string) # where name_type can be: # 0 - GEN_OTHERNAME # 1 - GEN_EMAIL # 2 - GEN_DNS # 3 - GEN_X400 # 4 - GEN_DIRNAME # 5 - GEN_EDIPARTY # 6 - GEN_URI # 7 - GEN_IPADD # 8 - GEN_RID
X509_get_subject_name
Returns the subject of the certificate $cert.
my $rv = Net::SSLeay::X509_get_subject_name($cert); # $cert - value coresponding to openssl's X509 structure # # returns: value coresponding to openssl's X509_NAME structure (0 on failure)
X509_gmtime_adj
Adjust th ASN1_TIME object to the timestamp (in GMT).
my $rv = Net::SSLeay::X509_gmtime_adj($s, $adj); # $s - value coresponding to openssl's ASN1_TIME structure # $adj - timestamp (seconds since 1.1.1970) # # returns: value coresponding to openssl's ASN1_TIME structure (0 on failure)
BEWARE: this function may fail for dates after 2038 as it is dependant on time_t size on your system (32bit time_t does not work after 2038). Consider using "P_ASN1_TIME_set_isotime" instead).
X509_load_cert_crl_file
Takes PEM file and loads all X509 certificates and X509 CRLs from that file into X509_LOOKUP structure.
my $rv = Net::SSLeay::X509_load_cert_crl_file($ctx, $file, $type); # $ctx - value coresponding to openssl's X509_LOOKUP structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # if not FILETYPE_PEM then behaves as Net::SSLeay::X509_load_cert_file() # # returns: 1 on success, 0 on failure
X509_load_cert_file
Loads/adds X509 certificate from $file to X509_LOOKUP structure
my $rv = Net::SSLeay::X509_load_cert_file($ctx, $file, $type); # $ctx - value coresponding to openssl's X509_LOOKUP structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, 0 on failure
X509_load_crl_file
Loads/adds X509 CRL from $file to X509_LOOKUP structure
my $rv = Net::SSLeay::X509_load_crl_file($ctx, $file, $type); # $ctx - value coresponding to openssl's X509_LOOKUP structure # $file - (string) file name # $type - (integer) type - use constants &Net::SSLeay::FILETYPE_PEM or &Net::SSLeay::FILETYPE_ASN1 # # returns: 1 on success, 0 on failure
X509_policy_level_get0_node
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_level_get0_node($level, $i); # $level - value coresponding to openssl's X509_POLICY_LEVEL structure # $i - (integer) index/position # # returns: value coresponding to openssl's X509_POLICY_NODE structure (0 on failure)
X509_policy_level_node_count
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_level_node_count($level); # $level - value coresponding to openssl's X509_POLICY_LEVEL structure # # returns: (integer) node count
X509_policy_node_get0_parent
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_node_get0_parent($node); # $node - value coresponding to openssl's X509_POLICY_NODE structure # # returns: value coresponding to openssl's X509_POLICY_NODE structure (0 on failure)
X509_policy_node_get0_policy
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_node_get0_policy($node); # $node - value coresponding to openssl's X509_POLICY_NODE structure # # returns: value coresponding to openssl's ASN1_OBJECT structure (0 on failure)
X509_policy_node_get0_qualifiers
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_node_get0_qualifiers($node); # $node - value coresponding to openssl's X509_POLICY_NODE structure # # returns: value coresponding to openssl's STACK_OF(POLICYQUALINFO) structure (0 on failure)
X509_policy_tree_free
??? (more info needed)
Net::SSLeay::X509_policy_tree_free($tree); # $tree - value coresponding to openssl's X509_POLICY_TREE structure # # returns: no return value
X509_policy_tree_get0_level
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_tree_get0_level($tree, $i); # $tree - value coresponding to openssl's X509_POLICY_TREE structure # $i - (integer) level index # # returns: value coresponding to openssl's X509_POLICY_LEVEL structure (0 on failure)
X509_policy_tree_get0_policies
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_tree_get0_policies($tree); # $tree - value coresponding to openssl's X509_POLICY_TREE structure # # returns: value coresponding to openssl's X509_POLICY_NODE structure (0 on failure)
X509_policy_tree_get0_user_policies
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_tree_get0_user_policies($tree); # $tree - value coresponding to openssl's X509_POLICY_TREE structure # # returns: value coresponding to openssl's X509_POLICY_NODE structure (0 on failure)
X509_policy_tree_level_count
??? (more info needed)
my $rv = Net::SSLeay::X509_policy_tree_level_count($tree); # $tree - value coresponding to openssl's X509_POLICY_TREE structure # # returns: (integer) count
X509_verify_cert_error_string
Returns a human readable error string for verification error $n.
my $rv = Net::SSLeay::X509_verify_cert_error_string($n); # $n - (long) numeric error code # # returns: error string
Check openssl doc http://www.openssl.org/docs/crypto/X509_STORE_CTX_get_error.html
sk_X509_NAME_free
Free an allocated STACK_OF(X509_NAME) structure.
Net::SSLeay::sk_X509_NAME_free($sk); # $sk - value coresponding to openssl's STACK_OF(X509_NAME) structure # # returns: no return value
sk_X509_NAME_num
Return number of items in STACK_OF(X509_NAME)
my $rv = Net::SSLeay::sk_X509_NAME_num($sk); # $sk - value coresponding to openssl's STACK_OF(X509_NAME) structure # # returns: number of items
sk_X509_NAME_value
Returns X509_NAME from position $index in STACK_OF(X509_NAME)
my $rv = Net::SSLeay::sk_X509_NAME_value($sk, $i); # $sk - value coresponding to openssl's STACK_OF(X509_NAME) structure # $i - (integer) index/position # # returns: value coresponding to openssl's X509_NAME structure (0 on failure)
add_file_cert_subjects_to_stack
Add a file of certs to a stack. All certs in $file that are not already in the $stackCAs will be added.
my $rv = Net::SSLeay::add_file_cert_subjects_to_stack($stackCAs, $file); # $stackCAs - value coresponding to openssl's STACK_OF(X509_NAME) structure # $file - (string) filename # # returns: 1 on success, 0 on failure
add_dir_cert_subjects_to_stack
Add a directory of certs to a stack. All certs in $dir that are not already in the $stackCAs will be added.
my $rv = Net::SSLeay::add_dir_cert_subjects_to_stack($stackCAs, $dir); # $stackCAs - value coresponding to openssl's STACK_OF(X509_NAME) structure # $dir - (string) the directory to append from. All files in this directory will be examined as potential certs. Any that are acceptable to SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be included. # # returns: 1 on success, 0 on failure
Low level API: Digest related functions
OpenSSL_add_all_digests
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
Net::SSLeay::OpenSSL_add_all_digests(); # no args, no return value
http://www.openssl.org/docs/crypto/OpenSSL_add_all_algorithms.html
P_EVP_MD_list_all
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-1.0.0
NOTE: Does not exactly correspond to any low level API function
my $rv = Net::SSLeay::P_EVP_MD_list_all(); # # returns: arrayref - list of available digest names
The returned digest names correspond to values expected by "EVP_get_digestbyname".
Note that some of the digets are available by default and some only after calling "OpenSSL_add_all_digests".
EVP_get_digestbyname
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
my $rv = Net::SSLeay::EVP_get_digestbyname($name); # $name - string with digest name # # returns: value coresponding to openssl's EVP_MD structure
The $name param can be:
md2 md4 md5 mdc2 ripemd160 sha sha1 sha224 sha256 sha512 whirlpool
Or better check the supported digests by calling "P_EVP_MD_list_all".
EVP_MD_type
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
my $rv = Net::SSLeay::EVP_MD_type($md); # $md - value coresponding to openssl's EVP_MD structure # # returns: the NID (integer) of the OBJECT IDENTIFIER representing the given message digest
EVP_MD_size
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
my $rv = Net::SSLeay::EVP_MD_size($md); # $md - value coresponding to openssl's EVP_MD structure # # returns: the size of the message digest in bytes (e.g. 20 for SHA1)
EVP_MD_CTX_md
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Net::SSLeay::EVP_MD_CTX_md($ctx); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # # returns: value coresponding to openssl's EVP_MD structure
EVP_MD_CTX_create
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Allocates, initializes and returns a digest context.
my $rv = Net::SSLeay::EVP_MD_CTX_create(); # # returns: value coresponding to openssl's EVP_MD_CTX structure
The complete idea behind EVP_MD_CTX looks like this example:
Net::SSLeay::OpenSSL_add_all_digests(); my $md = Net::SSLeay::EVP_get_digestbyname("sha1"); my $ctx = Net::SSLeay::EVP_MD_CTX_create(); Net::SSLeay::EVP_DigestInit($ctx, $md); while(my $chunk = get_piece_of_data()) { Net::SSLeay::EVP_DigestUpdate($ctx,$chunk); } my $result = Net::SSLeay::EVP_DigestFinal($ctx); Net::SSLeay::EVP_MD_CTX_destroy($ctx); print "digest=", unpack('H*', $result), "\n"; #print hex value
EVP_DigestInit_ex
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Sets up digest context $ctx to use a digest $type from ENGINE $impl, $ctx must be initialized before calling this function, type will typically be supplied by a function such as "EVP_get_digestbyname". If $impl is 0 then the default implementation of digest $type is used.
my $rv = Net::SSLeay::EVP_DigestInit_ex($ctx, $type, $impl); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # $type - value coresponding to openssl's EVP_MD structure # $impl - value coresponding to openssl's ENGINE structure # # returns: 1 for success and 0 for failure
EVP_DigestInit
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Behaves in the same way as "EVP_DigestInit_ex" except the passed context $ctx does not have to be initialized, and it always uses the default digest implementation.
my $rv = Net::SSLeay::EVP_DigestInit($ctx, $type); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # $type - value coresponding to openssl's EVP_MD structure # # returns: 1 for success and 0 for failure
EVP_MD_CTX_destroy
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Cleans up digest context $ctx and frees up the space allocated to it, it should be called only on a context created using "EVP_MD_CTX_create".
Net::SSLeay::EVP_MD_CTX_destroy($ctx); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # # returns: no return value
EVP_DigestUpdate
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
my $rv = Net::SSLeay::EVP_DigestUpdate($ctx, $data); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # $data - data to be hashed # # returns: 1 for success and 0 for failure
EVP_DigestFinal_ex
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Retrieves the digest value from $ctx. After calling "EVP_DigestFinal_ex" no additional calls to "EVP_DigestUpdate" can be made, but "EVP_DigestInit_ex" can be called to initialize a new digest operation.
my $digest_value = Net::SSLeay::EVP_DigestFinal_ex($ctx); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # # returns: hash value (binary) #to get printable (hex) value of digest use: print unpack('H*', $digest_value);
EVP_DigestFinal
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Similar to "EVP_DigestFinal_ex" except the digest context ctx is automatically cleaned up.
my $rv = Net::SSLeay::EVP_DigestFinal($ctx); # $ctx - value coresponding to openssl's EVP_MD_CTX structure # # returns: hash value (binary) #to get printable (hex) value of digest use: print unpack('H*', $digest_value);
MD2
COMPATIBILITY: no supported by default in openssl-1.0.0
Computes MD2 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::MD2($data); print "digest(hexadecimal)=", unpack('H*', $digest);
MD4
Computes MD4 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::MD4($data); print "digest(hexadecimal)=", unpack('H*', $digest);
MD5
Computes MD5 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::MD5($data); print "digest(hexadecimal)=", unpack('H*', $digest);
RIPEMD160
Computes RIPEMD160 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::RIPEMD160($data); print "digest(hexadecimal)=", unpack('H*', $digest);
SHA1
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
Computes SHA1 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::SHA1($data); print "digest(hexadecimal)=", unpack('H*', $digest);
SHA256
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.8
Computes SHA256 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::SHA256($data); print "digest(hexadecimal)=", unpack('H*', $digest);
SHA512
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.8
Computes SHA512 from given $data (all data needs to be loaded into memory)
my $digest = Net::SSLeay::SHA512($data); print "digest(hexadecimal)=", unpack('H*', $digest);
EVP_Digest
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.7
Computes "any" digest from given $data (all data needs to be loaded into memory)
my $md = Net::SSLeay::EVP_get_digestbyname("sha1"); #or any other algorithm my $digest = Net::SSLeay::EVP_Digest($data, $md); print "digest(hexadecimal)=", unpack('H*', $digest);
EVP_sha1
COMPATIBILITY: not available in Net-SSLeay-1.42 and before
my $md = Net::SSLeay::EVP_sha1(); # # returns: value coresponding to openssl's EVP_MD structure
EVP_sha256
COMPATIBILITY: requires at least openssl-0.9.8
my $md = Net::SSLeay::EVP_sha256(); # # returns: value coresponding to openssl's EVP_MD structure
EVP_sha512
COMPATIBILITY: not available in Net-SSLeay-1.42 and before; requires at least openssl-0.9.8
my $md = Net::SSLeay::EVP_sha512(); # # returns: value coresponding to openssl's EVP_MD structure
EVP_add_digest
my $rv = Net::SSLeay::EVP_add_digest($digest); # $digest - value coresponding to openssl's EVP_MD structure # # returns: 1 on success, 0 otherwise
Low level API: CIPHER_* related functions
CIPHER_get_name
Returns name of the cipher used.
my $rv = Net::SSLeay::CIPHER_description($cipher); # $cipher - value coresponding to openssl's SSL_CIPHER structure # # returns: (string) cipher name e.g. 'DHE-RSA-AES256-SHA'
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CIPHER_get_name.html
Example:
my $ssl_cipher = Net::SSLeay::get_current_cipher($ssl); my $cipher_name = Net::SSLeay::CIPHER_get_name($ssl_cipher);
CIPHER_description
Returns a textual description of the cipher used.
??? (does this function really work?)
my $rv = Net::SSLeay::CIPHER_description($cipher, $buf, $size); # $cipher - value coresponding to openssl's SSL_CIPHER structure # $bufer - (string/buffer) ??? # $size - (integer) ??? # # returns: (string) cipher description e.g. 'DHE-RSA-AES256-SHA SSLv3 Kx=DH Au=RSA Enc=AES(256) Mac=SHA1'
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CIPHER_get_name.html
CIPHER_get_bits
Returns the number of secret bits used for cipher.
my $rv = Net::SSLeay::CIPHER_get_bits($c); # $c - value coresponding to openssl's SSL_CIPHER structure # # returns: (integert) number of secret bits, 0 on error
Check openssl doc http://www.openssl.org/docs/ssl/SSL_CIPHER_get_name.html
Low level API: RSA_* related functions
RSA_generate_key
Generates a key pair and returns it in a newly allocated RSA structure. The pseudo-random number generator must be seeded prior to calling RSA_generate_key.
my $rv = Net::SSLeay::RSA_generate_key($bits, $e, $perl_cb, $perl_cb_arg); # $bits - (integer) modulus size in bits e.g. 512, 1024, 2048 # $e - (integer) public exponent, an odd number, typically 3, 17 or 65537 # $perl_cb - [optional] reference to perl callback function # $perl_cb_arg - [optional] data that will be passed to callback function when invoked # # returns: value coresponding to openssl's RSA structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/RSA_generate_key.html
RSA_free
Frees the RSA structure and its components. The key is erased before the memory is returned to the system.
Net::SSLeay::RSA_free($r); # $r - value coresponding to openssl's RSA structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/RSA_new.html
Low level API: BIO_* related functions
BIO_eof
Returns 1 if the BIO has read EOF, the precise meaning of 'EOF' varies according to the BIO type.
my $rv = Net::SSLeay::BIO_eof($s); # $s - value coresponding to openssl's BIO structure # # returns: 1 if EOF has been reached 0 otherwise
Check openssl doc http://www.openssl.org/docs/crypto/BIO_ctrl.html
BIO_f_ssl
Returns the SSL BIO method. This is a filter BIO which is a wrapper round the OpenSSL SSL routines adding a BIO 'flavour' to SSL I/O.
my $rv = Net::SSLeay::BIO_f_ssl(); # # returns: value coresponding to openssl's BIO_METHOD structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
BIO_free
Frees up a single BIO.
my $rv = Net::SSLeay::BIO_free($bio;); # $bio; - value coresponding to openssl's BIO structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/BIO_new.html
BIO_new
Returns a new BIO using method $type
my $rv = Net::SSLeay::BIO_new($type); # $type - value coresponding to openssl's BIO_METHOD structure # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_new.html
BIO_new_buffer_ssl_connect
Creates a new BIO chain consisting of a buffering BIO, an SSL BIO (using ctx) and a connect BIO.
my $rv = Net::SSLeay::BIO_new_buffer_ssl_connect($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
BIO_new_file
Creates a new file BIO with mode mode the meaning of mode is the same as the stdio function fopen(). The BIO_CLOSE flag is set on the returned BIO.
my $rv = Net::SSLeay::BIO_new_file($filename, $mode); # $filename - (string) filename # $mode - (string) opening mode (as mode by stdio function fopen) # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_s_file.html
BIO_new_ssl
Allocates an SSL BIO using SSL_CTX ctx and using client mode if client is non zero.
my $rv = Net::SSLeay::BIO_new_ssl($ctx, $client); # $ctx - value coresponding to openssl's SSL_CTX structure # $client - (integer) 0 or 1 - indicates ssl client mode # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
BIO_new_ssl_connect
Creates a new BIO chain consisting of an SSL BIO (using ctx) followed by a connect BIO.
my $rv = Net::SSLeay::BIO_new_ssl_connect($ctx); # $ctx - value coresponding to openssl's SSL_CTX structure # # returns: value coresponding to openssl's BIO structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
BIO_pending
Return the number of pending characters in the BIOs read buffers.
my $rv = Net::SSLeay::BIO_pending($s); # $s - value coresponding to openssl's BIO structure # # returns: the amount of pending data
Check openssl doc http://www.openssl.org/docs/crypto/BIO_ctrl.html
BIO_wpending
Return the number of pending characters in the BIOs write buffers.
my $rv = Net::SSLeay::BIO_wpending($s); # $s - value coresponding to openssl's BIO structure # # returns: the amount of pending data
Check openssl doc http://www.openssl.org/docs/crypto/BIO_ctrl.html
BIO_read
Read the underlying descriptor.
Net::SSLeay::BIO_read($s, $max); # $s - value coresponding to openssl's BIO structure # $max - [optional] max. bytes to read (if not specified, the value 32768 is used) # # returns: data
Check openssl doc http://www.openssl.org/docs/crypto/BIO_read.html
BIO_write
Attempts to write data from $buffer to BIO $b.
my $rv = Net::SSLeay::BIO_write($b, $buffer); # $b - value coresponding to openssl's BIO structure # $buffer - data # # returns: amount of data successfully written # or that no data was successfully read or written if the result is 0 or -1 # or -2 when the operation is not implemented in the specific BIO type
Check openssl doc http://www.openssl.org/docs/crypto/BIO_read.html
BIO_s_mem
Return the memory BIO method function.
my $rv = Net::SSLeay::BIO_s_mem(); # # returns: value coresponding to openssl's BIO_METHOD structure (0 on failure)
Check openssl doc http://www.openssl.org/docs/crypto/BIO_s_mem.html
BIO_ssl_copy_session_id
Copies an SSL session id between BIO chains from and to. It does this by locating the SSL BIOs in each chain and calling SSL_copy_session_id() on the internal SSL pointer.
my $rv = Net::SSLeay::BIO_ssl_copy_session_id($to, $from); # $to - value coresponding to openssl's BIO structure # $from - value coresponding to openssl's BIO structure # # returns: 1 on success, 0 on failure
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
BIO_ssl_shutdown
Closes down an SSL connection on BIO chain bio. It does this by locating the SSL BIO in the chain and calling SSL_shutdown() on its internal SSL pointer.
Net::SSLeay::BIO_ssl_shutdown($ssl_bio); # $ssl_bio - value coresponding to openssl's BIO structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/BIO_f_ssl.html
Low level API: Other functions
COMP_add_compression_method
Adds the compression method cm with the identifier id to the list of available compression methods. This list is globally maintained for all SSL operations within this application. It cannot be set for specific SSL_CTX or SSL objects.
my $rv = Net::SSLeay::COMP_add_compression_method($id, $cm); # $id - (integer) compression method id # 0 to 63: methods defined by the IETF # 64 to 192: external party methods assigned by IANA # 193 to 255: reserved for private use # # $cm - value coresponding to openssl's COMP_METHOD structure # # returns: 0 on success, 1 on failure (check the error queue to find out the reason)
Check openssl doc http://www.openssl.org/docs/ssl/SSL_COMP_add_compression_method.html
DH_free
Frees the DH structure and its components. The values are erased before the memory is returned to the system.
Net::SSLeay::DH_free($dh); # $dh - value coresponding to openssl's DH structure # # returns: no return value
Check openssl doc http://www.openssl.org/docs/crypto/DH_new.html
Constants
There are many openssl constants available in Net::SSLeay. You can use them like this:
use Net::SSLeay;
print &Net::SSLeay::NID_commonName;
#or
print Net::SSLeay::NID_commonName();
Or you can import them and use:
use Net::SSLeay qw/NID_commonName/;
print &NID_commonName;
#or
print NID_commonName();
#or
print NID_commonName;
The list of all available constant names:
AT_MD5_WITH_RSA_ENCRYPTION NID_id_ad OP_SSLREF2_REUSE_CERT_TYPE_BUG
CB_ACCEPT_EXIT NID_id_ce OP_TLS_D5_BUG
CB_ACCEPT_LOOP NID_id_kp OP_TLS_ROLLBACK_BUG
CB_CONNECT_EXIT NID_id_pbkdf2 PE_BAD_CERTIFICATE
CB_CONNECT_LOOP NID_id_pe PE_NO_CERTIFICATE
CK_DES_192_EDE3_CBC_WITH_MD5 NID_id_pkix PE_NO_CIPHER
CK_DES_192_EDE3_CBC_WITH_SHA NID_id_qt_cps PE_UNSUPPORTED_CERTIFICATE_TYPE
CK_DES_64_CBC_WITH_MD5 NID_id_qt_unotice READING
CK_DES_64_CBC_WITH_SHA NID_idea_cbc RECEIVED_SHUTDOWN
CK_DES_64_CFB64_WITH_MD5_1 NID_idea_cfb64 RSA_3
CK_IDEA_128_CBC_WITH_MD5 NID_idea_ecb RSA_F4
CK_NULL NID_idea_ofb64 RWERR_BAD_MAC_DECODE
CK_NULL_WITH_MD5 NID_info_access RWERR_BAD_WRITE_RETRY
CK_RC2_128_CBC_EXPORT40_WITH_MD5 NID_initials RWERR_INTERNAL_ERROR
CK_RC2_128_CBC_WITH_MD5 NID_invalidity_date R_BAD_AUTHENTICATION_TYPE
CK_RC4_128_EXPORT40_WITH_MD5 NID_issuer_alt_name R_BAD_CHECKSUM
CK_RC4_128_WITH_MD5 NID_keyBag R_BAD_MAC_DECODE
CLIENT_VERSION NID_key_usage R_BAD_RESPONSE_ARGUMENT
CT_X509_CERTIFICATE NID_localKeyID R_BAD_SSL_FILETYPE
ERROR_NONE NID_localityName R_BAD_SSL_SESSION_ID_LENGTH
ERROR_SSL NID_md2 R_BAD_STATE
ERROR_SYSCALL NID_md2WithRSAEncryption R_BAD_WRITE_RETRY
ERROR_WANT_CONNECT NID_md5 R_CHALLENGE_IS_DIFFERENT
ERROR_WANT_READ NID_md5WithRSA R_CIPHER_CODE_TOO_LONG
ERROR_WANT_WRITE NID_md5WithRSAEncryption R_CIPHER_TABLE_SRC_ERROR
ERROR_WANT_X509_LOOKUP NID_md5_sha1 R_CONECTION_ID_IS_DIFFERENT
ERROR_ZERO_RETURN NID_mdc2 R_INVALID_CHALLENGE_LENGTH
FILETYPE_ASN1 NID_mdc2WithRSA R_NO_CERTIFICATE_SET
FILETYPE_PEM NID_ms_code_com R_NO_CERTIFICATE_SPECIFIED
F_CLIENT_CERTIFICATE NID_ms_code_ind R_NO_CIPHER_LIST
F_CLIENT_HELLO NID_ms_ctl_sign R_NO_CIPHER_MATCH
F_CLIENT_MASTER_KEY NID_ms_efs R_NO_CIPHER_WE_TRUST
F_D2I_SSL_SESSION NID_ms_ext_req R_NO_PRIVATEKEY
F_GET_CLIENT_FINISHED NID_ms_sgc R_NO_PUBLICKEY
F_GET_CLIENT_HELLO NID_name R_NO_READ_METHOD_SET
F_GET_CLIENT_MASTER_KEY NID_netscape R_NO_WRITE_METHOD_SET
F_GET_SERVER_FINISHED NID_netscape_base_url R_NULL_SSL_CTX
F_GET_SERVER_HELLO NID_netscape_ca_policy_url R_PEER_DID_NOT_RETURN_A_CERTIFICATE
F_GET_SERVER_VERIFY NID_netscape_ca_revocation_url R_PEER_ERROR
F_I2D_SSL_SESSION NID_netscape_cert_extension R_PEER_ERROR_CERTIFICATE
F_READ_N NID_netscape_cert_sequence R_PEER_ERROR_NO_CIPHER
F_REQUEST_CERTIFICATE NID_netscape_cert_type R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE
F_SERVER_HELLO NID_netscape_comment R_PERR_ERROR_NO_CERTIFICATE
F_SSL_ACCEPT NID_netscape_data_type R_PUBLIC_KEY_ENCRYPT_ERROR
F_SSL_CERT_NEW NID_netscape_renewal_url R_PUBLIC_KEY_IS_NOT_RSA
F_SSL_CONNECT NID_netscape_revocation_url R_PUBLIC_KEY_NO_RSA
F_SSL_ENC_DES_CBC_INIT NID_netscape_ssl_server_name R_READ_WRONG_PACKET_TYPE
F_SSL_ENC_DES_CFB_INIT NID_ns_sgc R_REVERSE_KEY_ARG_LENGTH_IS_WRONG
F_SSL_ENC_DES_EDE3_CBC_INIT NID_organizationName R_REVERSE_MASTER_KEY_LENGTH_IS_WRONG
F_SSL_ENC_IDEA_CBC_INIT NID_organizationalUnitName R_REVERSE_SSL_SESSION_ID_LENGTH_IS_WRONG
F_SSL_ENC_NULL_INIT NID_pbeWithMD2AndDES_CBC R_SHORT_READ
F_SSL_ENC_RC2_CBC_INIT NID_pbeWithMD2AndRC2_CBC R_SSL_SESSION_ID_IS_DIFFERENT
F_SSL_ENC_RC4_INIT NID_pbeWithMD5AndCast5_CBC R_UNABLE_TO_EXTRACT_PUBLIC_KEY
F_SSL_GET_NEW_SESSION NID_pbeWithMD5AndDES_CBC R_UNDEFINED_INIT_STATE
F_SSL_MAKE_CIPHER_LIST NID_pbeWithMD5AndRC2_CBC R_UNKNOWN_REMOTE_ERROR_TYPE
F_SSL_NEW NID_pbeWithSHA1AndDES_CBC R_UNKNOWN_STATE
F_SSL_READ NID_pbeWithSHA1AndRC2_CBC R_UNSUPORTED_CIPHER
F_SSL_RSA_PRIVATE_DECRYPT NID_pbe_WithSHA1And128BitRC2_CBC R_WRONG_PUBLIC_KEY_TYPE
F_SSL_RSA_PUBLIC_ENCRYPT NID_pbe_WithSHA1And128BitRC4 R_X509_LIB
F_SSL_SESSION_NEW NID_pbe_WithSHA1And2_Key_TripleDES_CBC SENT_SHUTDOWN
F_SSL_SESSION_PRINT_FP NID_pbe_WithSHA1And3_Key_TripleDES_CBC SERVER_VERSION
F_SSL_SET_CERTIFICATE NID_pbe_WithSHA1And40BitRC2_CBC SESSION_ASN1_VERSION
F_SSL_SET_FD NID_pbe_WithSHA1And40BitRC4 ST_ACCEPT
F_SSL_SET_RFD NID_pbes2 ST_BEFORE
F_SSL_SET_WFD NID_pbmac1 ST_CLIENT_START_ENCRYPTION
F_SSL_STARTUP NID_pkcs ST_CONNECT
F_SSL_USE_CERTIFICATE NID_pkcs3 ST_GET_CLIENT_FINISHED_A
F_SSL_USE_CERTIFICATE_ASN1 NID_pkcs7 ST_GET_CLIENT_FINISHED_B
F_SSL_USE_CERTIFICATE_FILE NID_pkcs7_data ST_GET_CLIENT_HELLO_A
F_SSL_USE_PRIVATEKEY NID_pkcs7_digest ST_GET_CLIENT_HELLO_B
F_SSL_USE_PRIVATEKEY_ASN1 NID_pkcs7_encrypted ST_GET_CLIENT_MASTER_KEY_A
F_SSL_USE_PRIVATEKEY_FILE NID_pkcs7_enveloped ST_GET_CLIENT_MASTER_KEY_B
F_SSL_USE_RSAPRIVATEKEY NID_pkcs7_signed ST_GET_SERVER_FINISHED_A
F_SSL_USE_RSAPRIVATEKEY_ASN1 NID_pkcs7_signedAndEnveloped ST_GET_SERVER_FINISHED_B
F_SSL_USE_RSAPRIVATEKEY_FILE NID_pkcs8ShroudedKeyBag ST_GET_SERVER_HELLO_A
F_WRITE_PENDING NID_pkcs9 ST_GET_SERVER_HELLO_B
GEN_DIRNAME NID_pkcs9_challengePassword ST_GET_SERVER_VERIFY_A
GEN_DNS NID_pkcs9_contentType ST_GET_SERVER_VERIFY_B
GEN_EDIPARTY NID_pkcs9_countersignature ST_INIT
GEN_EMAIL NID_pkcs9_emailAddress ST_OK
GEN_IPADD NID_pkcs9_extCertAttributes ST_READ_BODY
GEN_OTHERNAME NID_pkcs9_messageDigest ST_READ_HEADER
GEN_RID NID_pkcs9_signingTime ST_SEND_CLIENT_CERTIFICATE_A
GEN_URI NID_pkcs9_unstructuredAddress ST_SEND_CLIENT_CERTIFICATE_B
GEN_X400 NID_pkcs9_unstructuredName ST_SEND_CLIENT_CERTIFICATE_C
MAX_MASTER_KEY_LENGTH_IN_BITS NID_private_key_usage_period ST_SEND_CLIENT_CERTIFICATE_D
MAX_RECORD_LENGTH_2_BYTE_HEADER NID_rc2_40_cbc ST_SEND_CLIENT_FINISHED_A
MAX_RECORD_LENGTH_3_BYTE_HEADER NID_rc2_64_cbc ST_SEND_CLIENT_FINISHED_B
MAX_SSL_SESSION_ID_LENGTH_IN_BYTES NID_rc2_cbc ST_SEND_CLIENT_HELLO_A
MIN_RSA_MODULUS_LENGTH_IN_BYTES NID_rc2_cfb64 ST_SEND_CLIENT_HELLO_B
MT_CLIENT_CERTIFICATE NID_rc2_ecb ST_SEND_CLIENT_MASTER_KEY_A
MT_CLIENT_FINISHED NID_rc2_ofb64 ST_SEND_CLIENT_MASTER_KEY_B
MT_CLIENT_HELLO NID_rc4 ST_SEND_REQUEST_CERTIFICATE_A
MT_CLIENT_MASTER_KEY NID_rc4_40 ST_SEND_REQUEST_CERTIFICATE_B
MT_ERROR NID_rc5_cbc ST_SEND_REQUEST_CERTIFICATE_C
MT_REQUEST_CERTIFICATE NID_rc5_cfb64 ST_SEND_REQUEST_CERTIFICATE_D
MT_SERVER_FINISHED NID_rc5_ecb ST_SEND_SERVER_FINISHED_A
MT_SERVER_HELLO NID_rc5_ofb64 ST_SEND_SERVER_FINISHED_B
MT_SERVER_VERIFY NID_ripemd160 ST_SEND_SERVER_HELLO_A
NID_OCSP_sign NID_ripemd160WithRSA ST_SEND_SERVER_HELLO_B
NID_SMIMECapabilities NID_rle_compression ST_SEND_SERVER_VERIFY_A
NID_X500 NID_rsa ST_SEND_SERVER_VERIFY_B
NID_X509 NID_rsaEncryption ST_SERVER_START_ENCRYPTION
NID_ad_OCSP NID_rsadsi ST_X509_GET_CLIENT_CERTIFICATE
NID_ad_ca_issuers NID_safeContentsBag ST_X509_GET_SERVER_CERTIFICATE
NID_algorithm NID_sdsiCertificate TXT_DES_192_EDE3_CBC_WITH_MD5
NID_authority_key_identifier NID_secretBag TXT_DES_192_EDE3_CBC_WITH_SHA
NID_basic_constraints NID_serialNumber TXT_DES_64_CBC_WITH_MD5
NID_bf_cbc NID_server_auth TXT_DES_64_CBC_WITH_SHA
NID_bf_cfb64 NID_sha TXT_DES_64_CFB64_WITH_MD5_1
NID_bf_ecb NID_sha1 TXT_IDEA_128_CBC_WITH_MD5
NID_bf_ofb64 NID_sha1WithRSA TXT_NULL
NID_cast5_cbc NID_sha1WithRSAEncryption TXT_NULL_WITH_MD5
NID_cast5_cfb64 NID_shaWithRSAEncryption TXT_RC2_128_CBC_EXPORT40_WITH_MD5
NID_cast5_ecb NID_stateOrProvinceName TXT_RC2_128_CBC_WITH_MD5
NID_cast5_ofb64 NID_subject_alt_name TXT_RC4_128_EXPORT40_WITH_MD5
NID_certBag NID_subject_key_identifier TXT_RC4_128_WITH_MD5
NID_certificate_policies NID_surname VERIFY_CLIENT_ONCE
NID_client_auth NID_sxnet VERIFY_FAIL_IF_NO_PEER_CERT
NID_code_sign NID_time_stamp VERIFY_NONE
NID_commonName NID_title VERIFY_PEER
NID_countryName NID_undef WRITING
NID_crlBag NID_uniqueIdentifier X509_LOOKUP
NID_crl_distribution_points NID_x509Certificate X509_PURPOSE_ANY
NID_crl_number NID_x509Crl X509_PURPOSE_CRL_SIGN
NID_crl_reason NID_zlib_compression X509_PURPOSE_NS_SSL_SERVER
NID_delta_crl NOTHING X509_PURPOSE_OCSP_HELPER
NID_des_cbc OPENSSL_VERSION_NUMBER X509_PURPOSE_SMIME_ENCRYPT
NID_des_cfb64 OP_ALL X509_PURPOSE_SMIME_SIGN
NID_des_ecb OP_CIPHER_SERVER_PREFERENCE X509_PURPOSE_SSL_CLIENT
NID_des_ede OP_COOKIE_EXCHANGE X509_PURPOSE_SSL_SERVER
NID_des_ede3 OP_DONT_INSERT_EMPTY_FRAGMENTS X509_PURPOSE_TIMESTAMP_SIGN
NID_des_ede3_cbc OP_EPHEMERAL_RSA X509_TRUST_COMPAT
NID_des_ede3_cfb64 OP_MICROSOFT_BIG_SSLV3_BUFFER X509_TRUST_EMAIL
NID_des_ede3_ofb64 OP_MICROSOFT_SESS_ID_BUG X509_TRUST_OBJECT_SIGN
NID_des_ede_cbc OP_MSIE_SSLV2_RSA_PADDING X509_TRUST_OCSP_REQUEST
NID_des_ede_cfb64 OP_NETSCAPE_CA_DN_BUG X509_TRUST_OCSP_SIGN
NID_des_ede_ofb64 OP_NETSCAPE_CA_DN_BUG X509_TRUST_SSL_CLIENT
NID_des_ofb64 OP_NETSCAPE_CHALLENGE_BUG X509_TRUST_SSL_SERVER
NID_description OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG X509_TRUST_TSA
NID_desx_cbc OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG X509_V_FLAG_ALLOW_PROXY_CERTS
NID_dhKeyAgreement OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG X509_V_FLAG_CB_ISSUER_CHECK
NID_dnQualifier OP_NON_EXPORT_FIRST X509_V_FLAG_CRL_CHECK
NID_dsa OP_NO_COMPRESSION X509_V_FLAG_CRL_CHECK_ALL
NID_dsaWithSHA OP_NO_QUERY_MTU X509_V_FLAG_EXPLICIT_POLICY
NID_dsaWithSHA1 OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION X509_V_FLAG_IGNORE_CRITICAL
NID_dsaWithSHA1_2 OP_NO_SSLv2 X509_V_FLAG_INHIBIT_ANY
NID_dsa_2 OP_NO_SSLv3 X509_V_FLAG_INHIBIT_MAP
NID_email_protect OP_NO_TICKET X509_V_FLAG_NOTIFY_POLICY
NID_ext_key_usage OP_NO_TLSv1 X509_V_FLAG_POLICY_CHECK
NID_ext_req OP_PKCS1_CHECK_1 X509_V_FLAG_USE_CHECK_TIME
NID_friendlyName OP_PKCS1_CHECK_2 X509_V_FLAG_X509_STRICT
NID_givenName OP_SINGLE_DH_USE
NID_hmacWithSHA1 OP_SSLEAY_080_CLIENT_DH_BUG
INTERNAL ONLY functions (do not use these)
The following functions are not intended for use from outside of Net::SSLeay module. They might be removed, renamed or changed without prior notice in future version.
Simply DO NOT USE THEM!
hello
blength
constant
EXAMPLES
One very good example to look at is the implementation of sslcat()
in the SSLeay.pm
file.
The following is a simple SSLeay client (with too little error checking :-(
#!/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, 'tcp') unless $port =~ /^\d+$/;
$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) . "'\n";
# 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;
The following is a simple SSLeay echo server (non forking):
#!/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 = "\0\0\0\0"; # Bind to all interfaces
$port = 1235;
$sockaddr_template = 'S n a4 x8';
$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, 'plain-rsa.pem',
&Net::SSLeay::FILETYPE_PEM);
die_if_ssl_error("private key");
Net::SSLeay::CTX_use_certificate_file ($ctx, 'plain-cert.pem',
&Net::SSLeay::FILETYPE_PEM);
die_if_ssl_error("certificate");
while (1) {
print "Accepting connections...\n";
($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('C4',$client_ip);
print "$af connection from " .
join ('.', @inetaddr) . ":$client_port\n";
# 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('ssl accept');
print "Cipher `" . Net::SSLeay::get_cipher($ssl) . "'\n";
# Connected. Exchange some data.
$got = Net::SSLeay::read($ssl); # Returns undef on fail
die_if_ssl_error("ssl read");
print "Got `$got' (" . length ($got) . " chars)\n";
Net::SSLeay::write ($ssl, uc ($got)) or die "write: $!";
die_if_ssl_error("ssl write");
Net::SSLeay::free ($ssl); # Tear down connection
close NS;
}
Yet another echo server. This one runs from /etc/inetd.conf
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 STDIN
and STDOUT
are wired to SSL.
#!/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 '/key/dir' or die "chdir: $!";
$| = 1; # Piping hot!
open LOG, ">>/dev/console" or die "Can't open log file $!";
select LOG; print "server.pl started\n";
$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, 'plain-rsa.pem',
Net::SSLeay::FILETYPE_PEM);
die_if_ssl_error("private key");
Net::SSLeay::use_certificate_file ($ssl, 'plain-cert.pem',
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) . "'\n";
$got = Net::SSLeay::read($ssl);
die_if_ssl_error("ssl read");
print "Got `$got' (" . length ($got) . " chars)\n";
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;
There are also a number of example/test programs in the examples directory:
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)
LIMITATIONS
Net::SSLeay::read()
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:
$reply = '';
while ($got = Net::SSLeay::read($ssl)) {
last if print_errs('SSL_read');
$reply .= $got;
}
Although there is no built-in limit in Net::SSLeay::write()
, the network packet size limitation applies here as well, thus use:
$written = 0;
while ($written < length($message)) {
$written += Net::SSLeay::write($ssl, substr($message, $written));
last if print_errs('SSL_write');
}
Or alternatively you can just use the following convenience functions:
Net::SSLeay::ssl_write_all($ssl, $message) or die "ssl write failure";
$got = Net::SSLeay::ssl_read_all($ssl) or die "ssl read failure";
KNOWN BUGS AND CAVEATS
Autoloader emits a
Argument "xxx" isn't numeric in entersub at blib/lib/Net/SSLeay.pm'
warning if die_if_ssl_error is made autoloadable. If you figure out why, drop me a line.
Callback set using SSL_set_verify()
does not appear to work. This may well be an openssl problem (e.g. see ssl/ssl_lib.c
line 1029). Try using SSL_CTX_set_verify()
instead and do not be surprised if even this stops working in future versions.
Callback and certificate verification stuff is generally too little tested.
Random numbers are not initialized randomly enough, especially if you do not have /dev/random
and/or /dev/urandom
(such as in Solaris platforms - but it's 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.
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 /dev/random
or to operate insecurely if you use /dev/urandom
. What happens is that when too much randomness is drawn from the operating system's randomness pool then randomness can temporarily be unavailable. /dev/random
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. /dev/urandom
solves this dilemma more pragmatically by simply returning predictable "random" numbers. Some /dev/urandom
emulation software however actually seems to implement /dev/random
semantics. Caveat emptor.
I've been pointed to two such daemons by Mik Firestone <mik@@speed.stdio._com> who has used them on Solaris 8:
Entropy Gathering Daemon (EGD) at http://www.lothar.com/tech/crypto/
Pseudo-random number generating daemon (PRNGD) at http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html
If you are using the low level API functions to communicate with other SSL implementations, you would do well to call
Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL)
and die_if_ssl_error("ssl ctx set options");
to cope with some well know bugs in some other SSL implementations. The high level API functions always set all known compatibility options.
Sometimes sslcat()
(and the high level HTTPS functions that build on it) is too fast in signaling the EOF to legacy HTTPS servers. This causes the server to return empty page. To work around this problem you can set the global variable
$Net::SSLeay::slowly = 1; # Add sleep so broken servers can keep up
HTTP/1.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 SSL session cache on your server helps to alleviate the CPU load somewhat.
As of version 1.09 many newer OpenSSL auxiliary functions were added (from REM_AUTOMATICALLY_GENERATED_1_09
onwards in SSLeay.xs
). Unfortunately I have not had any opportunity to test these. Some of them are trivial enough that I believe they "just work", but others have rather complex interfaces with function pointers and all. In these cases you should proceed wit great caution.
This module defaults to using OpenSSL automatic protocol negotiation code for automatically detecting the version of the SSL 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.
$Net::SSLeay::ssl_version = 2; # Insist on SSLv2
$Net::SSLeay::ssl_version = 3; # Insist on SSLv3
$Net::SSLeay::ssl_version = 10; # Insist on TLSv1
Although the autonegotiation is nice to have, the SSL 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 SSL handshake level), try this option before mailing me.
On some systems, OpenSSL may be compiled without support for SSLv2. If this is the case, Net::SSLeay will warn if ssl_version has been set to 2.
The high level API 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.
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 API functions do this, thus you would have to program it using the low level API. A good place to start is to see how the Net::SSLeay::http_cat()
function is implemented.
The high level API functions use a global file handle SSLCAT_S
internally. This really should not be a problem because there is no way to interleave the high level API 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. The best solution is to "require Net::SSLeay" in one thread after all the threads have been created.
DIAGNOSTICS
- Random number generator not seeded!!!
-
(W) This warning indicates that
randomize()
was not able to read/dev/random
or/dev/urandom
, possibly because your system does not have them or they are differently named. You can still use SSL, but the encryption will not be as strong. - open_tcp_connection: destination host not found:`server' (port 123) ($!)
-
Name lookup for host named
server
failed. - open_tcp_connection: failed `server', 123 ($!)
-
The name was resolved, but establishing the TCP connection failed.
- msg 123: 1 - error:140770F8:SSL routines:SSL23_GET_SERVER_HELLO:unknown proto
-
SSLeay error string. The first number (123) is the PID, 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.
- msg 123: 1 - error:02001002::lib(2) :func(1) :reason(2)
-
The same as above, but you didn't call load_error_strings() so SSLeay couldn't verbosely explain the error. You can still find out what it means with this command:
/usr/local/ssl/bin/ssleay errstr 02001002
- 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 FAQ that explains how to do this (or just study examples/makecert.pl which is used during
make test
to do just that).
BUGS AND SUPPORT
Please report any bugs or feature requests to bug-Net-SSLeay at rt.cpan.org
, 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.
Subversion access to the latest source code etc can be obtained at http://alioth.debian.org/projects/net-ssleay
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
You can find documentation for this module with the perldoc
command.
perldoc Net::SSLeay
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
Commercial support for Net::SSLeay may be obtained from
Symlabs (netssleay@symlabs.com)
Tel: +351-214.222.630
Fax: +351-214.222.637
AUTHOR
Maintained by Mike McCauley and Florian Ragwitz since November 2005
Originally written by Sampo Kellomäki <sampo@symlabs.com>
COPYRIGHT
Copyright (c) 1996-2003 Sampo Kellomäki <sampo@symlabs.com>
Copyright (C) 2005-2006 Florian Ragwitz <rafl@debian.org>
Copyright (C) 2005 Mike McCauley <mikem@open.com.au>
All Rights Reserved.
Distribution and use of this module is under the same terms as the OpenSSL package itself (i.e. free, but mandatory attribution; NO WARRANTY). Please consult LICENSE file in the root of the OpenSSL distribution.
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).
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.
SEE ALSO
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
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 2142:
alternative text 'www.openssl.org/docs/apps/ciphers.html' contains non-escaped | or /
- Around line 2683:
alternative text 'www.openssl.org/docs/ssl/SSL_CIPHER_get_name.html' contains non-escaped | or /
- Around line 6081:
Non-ASCII character seen before =encoding in 'Kellomäki'. Assuming UTF-8