NAME

Net::mbedTLS - mbedTLS in Perl

SYNOPSIS

my $fh = IO::Socket::INET->new("example.com:12345");

my $mbedtls = Net::mbedTLS->new();

my $client = $mbedtls->create_client($fh);

# Optional, but useful to do separately if, e.g., you want
# to report a successful handshake.
$client->shake_hands();

# Throws if the error is an “unexpected” one:
my $input = "\0" x 23;
my $got = $client->read($input) // do {

    # We get here if, e.g., the socket is non-blocking and we
    # weren’t ready to read.
};

# Similar to read(); throws on “unexpected” errors:
my $wrote = $tls->write($byte_string) // do {
    # ...
};

DESCRIPTION

OpenSSL is great, and so is Net::SSLeay, its Perl binding. Both are rather large, though.

This distribution allows use of mbedTLS, a smaller, simpler TLS library, from Perl.

AVAILABLE FUNCTIONALITY

For now this module largely just exposes the ability to do TLS. mbedTLS itself exposes a good deal more functionality (e.g., raw crypto, configurable ciphers); if you want that stuff, file a feature request. (Ideally send a patch.)

BUILDING/LINKING

This library can link to mbedTLS in several ways:

Dynamic linking allows Net::mbedTLS to use the most recent (compatible) mbedTLS but requires you to have a shared mbedTLS available, whereas static linking alleviates that dependency at the cost of always using the same library version.

mbedTLS, alas, as of this writing does not support pkg-config. (GitHub issue) If that changes then dynamic linking will become more reliable.

METHODS

$obj = CLASS->new( %OPTS )

Instantiates this class. %OPTS are:

$client = OBJ->create_client( $SOCKET, %OPTS )

Initializes a client session on $SOCKET. Returns a Net::mbedTLS::Client instance.

%OPTS are:

$client = OBJ->create_server( $SOCKET, %OPTS )

Initializes a server session on $SOCKET. Returns a Net::mbedTLS::Server instance.

%OPTS are:

CONSTANTS

These come from mbedTLS:

AUTHOR & COPYRIGHT

Copyright 2021 Gasper Software Consulting.

POD ERRORS

Hey! The above document had some coding errors, which are explained below: