This module provides functionality to clone certificates and sign them with a proxy certificate, thus making it easy to intercept SSL connections (man in the middle). It also manages a cache of the generated certificates.

Intercepting SSL connections is useful for analyzing encrypted traffic for security reasons or for testing. It does not break the end-to-end security of SSL, e.g. a properly written client will notice the interception unless you explicitly configure the client to trust your interceptor. Intercepting SSL works the following way:

Create a new CA certificate, which will be used to sign the cloned certificates. This proxy CA certificate should be trusted by the client, or (a properly written client) will throw error messages or deny the connections because it detected a man in the middle attack. Due to the way the interception works there no support for client side certificates is possible.

Using openssl such a proxy CA certificate and private key can be created with:

Configure client to connect to use intercepting proxy or somehow redirect connections from client to the proxy (e.g. packet filter redirects, ARP or DNS spoofing etc).

Accept the TCP connection from the client, e.g. don't do any SSL handshakes with the client yet.

Establish the SSL connection to the server and verify the servers certificate as usually. Then create a new certificate based on the original servers certificate, but signed by your proxy CA. This a the step where IO::Socket::SSL::Intercept helps.

Upgrade the TCP connection to the client to SSL using the cloned certificate from the server. If the client trusts your proxy CA it will accept the upgrade to SSL.

Transfer data between client and server. While the connections to client and server are both encrypted with SSL you will read/write the unencrypted data in your proxy application.

This optional argument specifies the public key used for the cloned certificate. It can be either given by an EVP_PKEY object from Net::SSLeays internal representation, or using a file in PEM format. If not given it will create a new public key on each call of new.

This optional argument gives a way to cache created certificates, so that they don't get recreated on future accesses to the same host. If the argument ist not given an internal HASH ist used.

If the argument is a hash it will store for each generated certificate a hash reference with cert and atime in the hash, where atime is the time of last access (to expire unused entries) and cert is the certificate. Please note, that the certificate is in Net::SSLeays internal X509 format and can thus not be simply dumped and restored. The key for the hash is an ident either given to clone_cert or generated from the original certificate.

If the argument is a subroutine it will be called as $cache->(ident) to get an existing certificate and with $cache->(ident,cert) to cache the newly created certificate.

This clones the given certificate. An ident as the key into the cache can be given (like host:port), if not it will be created from the properties of the original certificate. It returns the cloned certificate and its key (which is the same for alle created certificates).

This creates a serialized version of the object (e.g. a string) which can then be used to persistantly store created certificates over restarts of the application. The cache will only be serialized if it is a HASH. To work together with Storable the STORABLE_freeze function is defined to call serialize.