Name

SPVM::Net::SSLeay - OpenSSL Binding and SSL data strcuture.

Description

Net::SSLeay class in SPVM is a binding for OpenSSL. This class itself represents SSL data structure.

Warnings:

The tests haven't been written yet. The features may be changed without notice.

Modules

Usage

use Net::SSLeay;
use Net::SSLeay::Net::SSLeay::SSL_METHOD;
use Net::SSLeay::Net::SSLeay::SSL_CTX;

my $ssl_method = Net::SSLeay::SSL_METHOD->SSLv23_client_method;

my $ssl_ctx = Net::SSLeay::SSL_CTX->new($ssl_method);

my $ssl = Net::SSLeay->new($ssl_ctx);

Examples

See source codes of IO::Socket::SSL about examples of Net::SSLeay.

Fields

ssl_ctx

has ssl_ctx : Net::SSLeay::SSL_CTX;

A Net::SSLeay::SSL_CTX object.

operation_error

has operation_error : ro int;

The place where the return value of SSL_get_error function is stored.

Class Methods

new

static method new : Net::SSLeay ($ssl_ctx : Net::SSLeay::SSL_CTX);

Creates a new Net::SSLeay object, creates a SSL object by calling native SSL_new function given the Net::SSLeay::SSL_CTX object $ssl_ctx, sets the pointer value of the new Net::SSLeay::SSL_CTX object to the return value of SSL_new function, and returns the new Net::SSLeay::SSL_CTX object.

"ssl_ctx" field is set to $ssl_ctx.

Exceptions:

If SSL_new failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

library_init

static method library_init : int ();

Calls native SSL_library_init function, and returns its return value.

load_error_strings

static method load_error_strings : void ();

Calls native SSL_load_error_strings function.

load_client_CA_file

static method load_client_CA_file : Net::SSLeay::X509_NAME[] ($file : string);

Calls native SSL_load_client_CA_file function,.

If its return value is NULL, returns undef.

Ohterwise, converts its return value to the array of Net::SSLeay::X509_NAME, and returns the array.

Exceptions:

The file $file must be defined. Otherwise an exception is thrown.

If load_client_CA_file failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

Instance Methods

set_fd

method set_fd : int ($fd : int);

Calls native SSL_set_fd function given $fd, and returns its return value.

Exceptions:

If SSL_set_fd failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

set_tlsext_host_name

method set_tlsext_host_name : int ($name : string);

Calls native SSL_set_tlsext_host_name function given the host name $name, and returns its return value.

Exceptions:

The host name $name must be defined. Otherwise an exception is thrown.

If SSL_set_tlsext_host_name failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

connect

method connect : int ();

Calls native SSL_connect function, and returns its return value.

Exceptions:

If SSL_connect failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_connect function.

accept

method accept : int ();

Calls native SSL_accept function, and returns its return value.

Exceptions:

If SSL_accept failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_accept function.

shutdown

method shutdown : int ();

Calls native SSL_shutdown function, and returns its return value.

Exceptions:

If SSL_shutdown failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_shutdown function.

read

method read : int ($buf : mutable string, $num : int = -1, $offset : int = 0);

Calls native SSL_read function given $buf at the offest $offset, $num, and returns its return value.

Exceptions:

The buffer $buf must be defined. Otherwise an exception is thrown.

The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.

The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.

If SSL_read failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_read function.

peek

method peek : int ($buf : mutable string, $num : int = -1, $offset : int = 0);

Calls native SSL_peek function given $buf at the offset $offset, $num, and returns its return value.

Exceptions:

The buffer $buf must be defined. Otherwise an exception is thrown.

The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.

The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.

If SSL_peek failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_peek function.

write

method write : int ($buf : string, $num : int = -1, $offset : int = 0);

Calls native SSL_write function, given $buf at the offset $offset, $num, and returns its return value.

Exceptions:

The buffer $buf must be defined. Otherwise an exception is thrown.

The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.

The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.

If SSL_write failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_write function.

get_servername

method get_servername : string ($type : int);

Calls native SSL_get_servername function given $type, and returns its return value.

set_tlsext_status_type

method set_tlsext_status_type : long ($type : int);

Calls native SSL_set_tlsext_status_type function given $type, and returns its return value.

Exceptions:

If SSL_set_tlsext_status_type failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

alert_desc_string_long

method alert_desc_string_long : string ($type : int);

Calls native SSL_alert_desc_string_long function given $type, and returns its return value.

set_mode

method set_mode : long ($mode : long);

Calls native SSL_set_mode function given $mode, and returns its return value.

clear_mode

method clear_mode : long ($mode : long);

Calls native SSL_clear_mode function given $mode, and returns its return value.

get_mode

method get_mode : long ();

Calls native get_mode function, and returns its return value.

version

native method version : int ();

Calls native version function, and returns its return value.

session_reused

native method session_reused : int ();

Calls native SSL_session_reused function, and returns its return value.

get_cipher

method get_cipher : string ();

Calls native SSL_get_cipher function, and returns its return value.

get_peer_certificate

method get_peer_certificate : Net::SSLeay::X509 ();

Calls native SSL_get_peer_certificate function.

If the return value of the native function is NULL, returns undef.

Otherwise, creates a new Net::SSLeay::X509 object, sets the pointer value of the new object to the return value of the native function, and returns the new object.

get_shutdown

method get_shutdown : int ();

Calls native SSL_get_shutdown function, and returns its return value.

pending

method pending : int ();

Calls native SSL_pending function, and returns its return value.

get1_session

method get1_session : Net::SSLeay::SSL_SESSION ();

Calls native SSL_get1_session function.

If the return value of the native function is NULL, returns undef.

Otherwise, creates a new Net::SSLeay::SSL_SESSION object, sets the pointer value of the new object to the return value of the native function, and returns the new object.

set_session

method set_session : int ($session : Net::SSLeay::SSL_SESSION);

Calls native SSL_set_session function given the pointer value of $session, sets "ssl_session" field to $ssl.

If this method succeeds, no_free flag of $session is set to 1.

Exceptions:

If SSL_set_session failed, an exception is thrown with eval_error_id set to the basic type ID of Net::SSLeay::Error class.

get_certificate

method get_certificate : Net::SSLeay::X509 ();

Calls native SSL_get_certificate function.

If the return value of the native function is NULL, returns undef.

Otherwise, creates a new Net::SSLeay::X509 object, sets the pointer value of the new object to the return value of the native function, and returns the new object.

no_free flag of the new object is set to 1.

get0_next_proto_negotiated

method get0_next_proto_negotiated : void ($data_ref : string[], $len_ref : int*);

Calls native SSL_get0_next_proto_negotiated function given $data_ref, $len_ref.

get0_alpn_selected

method get0_alpn_selected : void ($data_ref : string[], $len_ref : int*);

Calls native SSL_get0_alpn_selected function given $data_ref, $len_ref.

get_peer_cert_chain

method get_peer_cert_chain : Net::SSLeay::X509[] ();

Calls native SSL_get_peer_cert_chain function.

If its return value is NULL, returns undef.

Ohterwise, converts its return value to the array of Net::SSLeay::X509, and returns the array.

method get_SSL_CTX : Net::SSLeay::SSL_CTX ();

get_SSL_CTX

method get_SSL_CTX : Net::SSLeay::SSL_CTX ();

Returns the value of "ssl_ctx" field.

DESTROY

method DESTROY : void ();

Frees native SSL object by calling native SSL_free function if no_free flag of the instance is not a true value.

Config Builder

SPVM::Net::SSLeay::ConfigBuilder

Porting

This class is a Perl's Net::SSLeay porting to SPVM.

Repository

SPVM::Net::SSLeay - Github

Author

Yuki Kimoto<kimoto.yuki@gmail.com>

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License