Socket-Class
view release on metacpan or search on metacpan
xs/sc_ssl/SSL.xs view on Meta::CPAN
#include "sc_ssl_mod_def.h"
mod_sc_t *mod_sc;
mod_sc_ssl_t mod_sc_ssl;
MODULE = Socket::Class::SSL PACKAGE = Socket::Class::SSL PREFIX = SSL_
BOOT:
{
SV **psv;
#ifdef SC_DEBUG
_debug( "INIT called\n" );
#endif
#if SC_DEBUG > 1
debug_init();
#endif
psv = hv_fetch( PL_modglobal, "Socket::Class", 13, 0 );
if( psv == NULL )
Perl_croak(aTHX_ "Socket::Class 2.0 or higher is required");
mod_sc = INT2PTR( mod_sc_t *, SvIV( *psv ) );
/*
if( strcmp( mod_sc->sc_version, SC_VERSION ) != 0 )
Perl_croak(aTHX_ "Socket::Class has been changed, "
"please recompile Socket::Class::SSL");
*/
Copy( mod_sc, &mod_sc_ssl, 1, mod_sc_t );
/* replace existing functions */
mod_sc_ssl.sc_create = mod_sc_ssl_create;
mod_sc_ssl.sc_connect = mod_sc_ssl_connect;
mod_sc_ssl.sc_listen = mod_sc_ssl_listen;
mod_sc_ssl.sc_accept = mod_sc_ssl_accept;
mod_sc_ssl.sc_recv = mod_sc_ssl_recv;
mod_sc_ssl.sc_send = mod_sc_ssl_send;
mod_sc_ssl.sc_recvfrom = mod_sc_ssl_recvfrom;
mod_sc_ssl.sc_sendto = mod_sc_ssl_sendto;
mod_sc_ssl.sc_read = mod_sc_ssl_read;
mod_sc_ssl.sc_write = mod_sc_ssl_write;
mod_sc_ssl.sc_readline = mod_sc_ssl_readline;
mod_sc_ssl.sc_writeln = mod_sc_ssl_writeln;
mod_sc_ssl.sc_printf = mod_sc_ssl_printf;
mod_sc_ssl.sc_vprintf = mod_sc_ssl_vprintf;
mod_sc_ssl.sc_available = mod_sc_ssl_available;
mod_sc_ssl.sc_set_userdata = mod_sc_ssl_set_userdata;
mod_sc_ssl.sc_get_userdata = mod_sc_ssl_get_userdata;
/* set additional functions */
mod_sc_ssl.sc_ssl_version = XS_VERSION;
mod_sc_ssl.sc_ssl_create_server_context = mod_sc_ssl_create_server_context;
mod_sc_ssl.sc_ssl_create_client_context = mod_sc_ssl_create_client_context;
mod_sc_ssl.sc_ssl_set_certificate = mod_sc_ssl_set_certificate;
mod_sc_ssl.sc_ssl_set_private_key = mod_sc_ssl_set_private_key;
mod_sc_ssl.sc_ssl_set_client_ca = mod_sc_ssl_set_client_ca;
mod_sc_ssl.sc_ssl_set_verify_locations = mod_sc_ssl_set_verify_locations;
mod_sc_ssl.sc_ssl_check_private_key = mod_sc_ssl_check_private_key;
mod_sc_ssl.sc_ssl_enable_compatibility = mod_sc_ssl_enable_compatibility;
mod_sc_ssl.sc_ssl_get_cipher_name = mod_sc_ssl_get_cipher_name;
mod_sc_ssl.sc_ssl_get_cipher_version = mod_sc_ssl_get_cipher_version;
mod_sc_ssl.sc_ssl_get_version = mod_sc_ssl_get_version;
mod_sc_ssl.sc_ssl_starttls = mod_sc_ssl_starttls;
mod_sc_ssl.sc_ssl_set_ssl_method = mod_sc_ssl_set_ssl_method;
mod_sc_ssl.sc_ssl_set_cipher_list = mod_sc_ssl_set_cipher_list;
mod_sc_ssl.sc_ssl_read_packet = mod_sc_ssl_read_packet;
mod_sc_ssl.sc_ssl_ctx_create = mod_sc_ssl_ctx_create;
mod_sc_ssl.sc_ssl_ctx_destroy = mod_sc_ssl_ctx_destroy;
mod_sc_ssl.sc_ssl_ctx_create_class = mod_sc_ssl_ctx_create_class;
mod_sc_ssl.sc_ssl_ctx_from_class = mod_sc_ssl_ctx_from_class;
mod_sc_ssl.sc_ssl_ctx_set_ssl_method = mod_sc_ssl_ctx_set_ssl_method;
mod_sc_ssl.sc_ssl_ctx_set_private_key = mod_sc_ssl_ctx_set_private_key;
mod_sc_ssl.sc_ssl_ctx_set_certificate = mod_sc_ssl_ctx_set_certificate;
mod_sc_ssl.sc_ssl_ctx_set_client_ca = mod_sc_ssl_ctx_set_client_ca;
mod_sc_ssl.sc_ssl_ctx_set_verify_locations = mod_sc_ssl_ctx_set_verify_locations;
mod_sc_ssl.sc_ssl_ctx_set_cipher_list = mod_sc_ssl_ctx_set_cipher_list;
mod_sc_ssl.sc_ssl_ctx_check_private_key = mod_sc_ssl_ctx_check_private_key;
mod_sc_ssl.sc_ssl_ctx_enable_compatibility = mod_sc_ssl_ctx_enable_compatibility;
/* store the c module interface in the modglobal hash */
(void) hv_store( PL_modglobal,
"Socket::Class::SSL", 18, newSViv( PTR2IV( &mod_sc_ssl ) ), 0 );
/* openssl initialization */
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
Zero( &sc_ssl_global, 1, sc_ssl_global_t );
sc_ssl_global.process_id = PROCESS_ID();
#ifdef USE_ITHREADS
MUTEX_INIT( &sc_ssl_global.thread_lock );
#endif
}
#/*****************************************************************************
# * SSL_c_module()
# *****************************************************************************/
void
SSL_c_module( ... )
PPCODE:
/* returns the c module interface */
XSRETURN_IV( PTR2IV( &mod_sc_ssl ) );
#/*****************************************************************************
# * SSL_END()
# *****************************************************************************/
void
SSL_END( ... )
PREINIT:
/*
sc_ssl_ctx_t *ctx1, *ctx2;
int i;
*/
CODE:
(void) items; /* avoid compiler warning */
if( sc_ssl_global.destroyed || sc_ssl_global.process_id != PROCESS_ID() )
return;
sc_ssl_global.destroyed = TRUE;
#ifdef SC_DEBUG
_debug( "END called\n" );
#endif
/*
#ifdef USE_ITHREADS
MUTEX_LOCK( &sc_ssl_global.thread_lock );
#endif
for( i = 0; i <= SC_SSL_CTX_CASCADE; i++ ) {
ctx1 = sc_ssl_global.ctx[i];
while( ctx1 != NULL ) {
ctx2 = ctx1->next;
free_context( ctx1 );
ctx1 = ctx2;
}
sc_ssl_global.ctx[i] = NULL;
}
#ifdef USE_ITHREADS
MUTEX_UNLOCK( &sc_ssl_global.thread_lock );
#endif
xs/sc_ssl/SSL.xs view on Meta::CPAN
if( rlen == 0 )
XSRETURN_NO;
XSRETURN_IV( rlen );
}
#/*****************************************************************************
# * SSL_read_packet( this, separator [, maxsize] )
# *****************************************************************************/
void
SSL_read_packet( this, separator, maxsize = 0 )
SV *this;
char *separator;
int maxsize;
PREINIT:
sc_t *socket;
int rlen, r;
char *rbuf;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_ssl_read_packet(
socket, separator, (size_t) maxsize, &rbuf, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( rbuf, rlen ) );
XSRETURN(1);
#/*****************************************************************************
# * SSL_to_string( this )
# *****************************************************************************/
void
SSL_to_string( this )
SV *this;
PREINIT:
sc_t *socket;
char tmp[1024], *s;
size_t len = sizeof(tmp);
userdata_t *ud;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc->sc_to_string( socket, tmp, &len ) != SC_OK )
XSRETURN_EMPTY;
ud = (userdata_t *) mod_sc->sc_get_userdata( socket );
s = tmp + len - 1;
if( ud->ssl != NULL ) {
s = my_strcpy( s, ";SSL=" );
s = my_strcpy( s, SSL_get_version( ud->ssl ) );
}
*s ++ = ')';
*s = '\0';
ST(0) = sv_2mortal( newSVpvn( tmp, (s - tmp) ) );
XSRETURN(1);
#/*****************************************************************************
# * SSL_set_private_key( this, private_key )
# *****************************************************************************/
void
SSL_set_private_key( this, private_key )
SV *this;
char *private_key;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_private_key( socket, private_key ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_certificate( this, certificate )
# *****************************************************************************/
void
SSL_set_certificate( this, certificate )
SV *this;
char *certificate;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_certificate( socket, certificate ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_client_ca( this, client_ca )
# *****************************************************************************/
void
SSL_set_client_ca( this, client_ca )
SV *this;
char *client_ca;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_client_ca( socket, client_ca ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_verify_locations( this, ca_file [, ca_path] )
# *****************************************************************************/
void
SSL_set_verify_locations( this, ca_file, ca_path = NULL )
SV *this;
SV *ca_file;
SV *ca_path;
PREINIT:
sc_t *socket;
char *caf, *cap;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
caf = SvPOK( ca_file ) ? SvPV_nolen( ca_file ) : NULL;
cap = ca_path != NULL && SvPOK( ca_path ) ? SvPV_nolen( ca_path ) : NULL;
if( mod_sc_ssl_set_verify_locations( socket, caf, cap ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_create_client_context( this )
# *****************************************************************************/
void
SSL_create_client_context( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_create_client_context( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_create_server_context( this )
# *****************************************************************************/
void
SSL_create_server_context( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_create_server_context( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_check_private_key( this )
# *****************************************************************************/
void
SSL_check_private_key( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_check_private_key( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_enable_compatibility( this )
# *****************************************************************************/
void
SSL_enable_compatibility( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_enable_compatibility( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_get_cipher_name( this )
# *****************************************************************************/
void
SSL_get_cipher_name( this )
SV *this;
PREINIT:
sc_t *socket;
const char *s;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s = mod_sc_ssl_get_cipher_name( socket );
if( s == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( s, strlen( s ) ) );
XSRETURN_EMPTY;
#/*****************************************************************************
# * SSL_get_cipher_version( this )
# *****************************************************************************/
void
SSL_get_cipher_version( this )
SV *this;
PREINIT:
sc_t *socket;
const char *s;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s = mod_sc_ssl_get_cipher_version( socket );
if( s == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( s, strlen( s ) ) );
XSRETURN_EMPTY;
xs/sc_ssl/SSL.xs view on Meta::CPAN
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
}
r = mod_sc_ssl_ctx_create( args, argc, &ctx );
Safefree( args );
if( r != SC_OK )
XSRETURN_EMPTY;
r = mod_sc_ssl_ctx_create_class( ctx, &sv );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( sv );
XSRETURN(1);
#/*****************************************************************************
# * CTX_DESTROY( this, ... )
# *****************************************************************************/
void
CTX_DESTROY( this, ... )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
/*
#ifdef USE_ITHREADS
if( !ctx->dont_clone && ctx->thread_id == THREAD_ID() ) {
ctx->dont_clone = TRUE;
#ifdef SC_DEBUG
_debug( "disable futher CLONE for ctx %d\n", ctx->id );
#endif
}
#endif
*/
mod_sc_ssl_ctx_destroy( ctx );
#/*****************************************************************************
# * CTX_set_ssl_method( this, name )
# *****************************************************************************/
void
CTX_set_ssl_method( this, name )
SV *this;
char *name;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_ssl_method( ctx, name ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_private_key( this, pk )
# *****************************************************************************/
void
CTX_set_private_key( this, pk )
SV *this;
char *pk;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_private_key( ctx, pk ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_certificate( this, crt )
# *****************************************************************************/
void
CTX_set_certificate( this, crt )
SV *this;
char *crt;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_certificate( ctx, crt ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_client_ca( this, client_ca )
# *****************************************************************************/
void
CTX_set_client_ca( this, client_ca )
SV *this;
char *client_ca;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_client_ca( ctx, client_ca ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_verify_locations( this, ca_file )
# *****************************************************************************/
void
CTX_set_verify_locations( this, ca_file, ca_path = NULL )
SV *this;
char *ca_file;
char *ca_path;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_verify_locations( ctx, ca_file, ca_path ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_cipher_list( this, str )
# *****************************************************************************/
void
CTX_set_cipher_list( this, str )
SV *this;
char *str;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_cipher_list( ctx, str ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_check_private_key( this )
# *****************************************************************************/
void
CTX_check_private_key( this )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_check_private_key( ctx ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_enable_compatibility( this )
# *****************************************************************************/
void
CTX_enable_compatibility( this )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_enable_compatibility( ctx ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
( run in 2.735 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )