Second round of fixing the OpenSSL perl/ stuff. It now at least compiled fine
under Unix and passes some trivial tests I've now added. But the whole stuff is horribly incomplete, so a README.1ST with a disclaimer was added to make sure no one expects that this stuff really works in the OpenSSL 0.9.2 release. Additionally I've started to clean the XS sources up and fixed a few little bugs and inconsistencies in OpenSSL.{pm,xs} and openssl_bio.xs. PS: I'm still not convinces whether we should try to make this finally running or kick it out and replace it with some other module....
This commit is contained in:
parent
9ea0e64de7
commit
84107e6ca8
9
CHANGES
9
CHANGES
@ -5,6 +5,15 @@
|
|||||||
|
|
||||||
Changes between 0.9.1c and 0.9.2
|
Changes between 0.9.1c and 0.9.2
|
||||||
|
|
||||||
|
*) Second round of fixing the OpenSSL perl/ stuff. It now at least compiled
|
||||||
|
fine under Unix and passes some trivial tests I've now added. But the
|
||||||
|
whole stuff is horribly incomplete, so a README.1ST with a disclaimer was
|
||||||
|
added to make sure no one expects that this stuff really works in the
|
||||||
|
OpenSSL 0.9.2 release. Additionally I've started to clean the XS sources
|
||||||
|
up and fixed a few little bugs and inconsistencies in OpenSSL.{pm,xs} and
|
||||||
|
openssl_bio.xs.
|
||||||
|
[Ralf S. Engelschall]
|
||||||
|
|
||||||
*) Fix the generation of two part addresses in perl.
|
*) Fix the generation of two part addresses in perl.
|
||||||
[Kenji Miyake <kenji@miyake.org>, integrated by Ben Laurie]
|
[Kenji Miyake <kenji@miyake.org>, integrated by Ben Laurie]
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
README.1ST
|
||||||
MANIFEST
|
MANIFEST
|
||||||
Makefile.PL
|
Makefile.PL
|
||||||
typemap
|
typemap
|
||||||
@ -12,3 +13,6 @@ openssl_err.xs
|
|||||||
openssl_ssl.xs
|
openssl_ssl.xs
|
||||||
openssl_x509.xs
|
openssl_x509.xs
|
||||||
openssl_cb.c
|
openssl_cb.c
|
||||||
|
t/01-use.t
|
||||||
|
t/02-version.t
|
||||||
|
t/03-bio.t
|
||||||
|
@ -2,14 +2,19 @@
|
|||||||
## Makefile.PL -- Perl MakeMaker specification
|
## Makefile.PL -- Perl MakeMaker specification
|
||||||
##
|
##
|
||||||
|
|
||||||
|
$V = '0.9.2';
|
||||||
|
print "Configuring companion Perl module for OpenSSL $V\n";
|
||||||
|
|
||||||
use ExtUtils::MakeMaker;
|
use ExtUtils::MakeMaker;
|
||||||
|
|
||||||
WriteMakefile(
|
WriteMakefile(
|
||||||
'OPTIMIZE' => '',
|
'OPTIMIZE' => '',
|
||||||
'DISTNAME' => 'OpenSSL-0.9.2',
|
'DISTNAME' => "openssl-$V",
|
||||||
'NAME' => 'OpenSSL',
|
'NAME' => 'OpenSSL',
|
||||||
'VERSION_FROM' => 'OpenSSL.pm',
|
'VERSION_FROM' => 'OpenSSL.pm',
|
||||||
'LIBS' => ['-L.. -lssl -lcrypto'],
|
'LIBS' => ( $^O eq 'MSWin32'
|
||||||
|
? [ '-L../out32dll -lssleay32 -llibeay32' ]
|
||||||
|
: [ '-L.. -lssl -lcrypto' ] ),
|
||||||
'DEFINE' => '',
|
'DEFINE' => '',
|
||||||
'INC' => '-I../include',
|
'INC' => '-I../include',
|
||||||
'H' => ['openssl.h'],
|
'H' => ['openssl.h'],
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package OpenSSL;
|
package OpenSSL;
|
||||||
|
|
||||||
|
require 5.000;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
use DynaLoader;
|
use DynaLoader;
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ use DynaLoader;
|
|||||||
@EXPORT = qw();
|
@EXPORT = qw();
|
||||||
|
|
||||||
$VERSION = '0.92';
|
$VERSION = '0.92';
|
||||||
bootstrap penSSL;
|
bootstrap OpenSSL;
|
||||||
|
|
||||||
@OpenSSL::BN::ISA = qw(OpenSSL::ERR);
|
@OpenSSL::BN::ISA = qw(OpenSSL::ERR);
|
||||||
@OpenSSL::MD::ISA = qw(OpenSSL::ERR);
|
@OpenSSL::MD::ISA = qw(OpenSSL::ERR);
|
||||||
@ -27,7 +28,9 @@ bootstrap penSSL;
|
|||||||
@SSL::CTX::ISA = qw(OpenSSL::SSL::CTX);
|
@SSL::CTX::ISA = qw(OpenSSL::SSL::CTX);
|
||||||
@BIO::ISA = qw(OpenSSL::BIO);
|
@BIO::ISA = qw(OpenSSL::BIO);
|
||||||
|
|
||||||
@OpenSSL::MD::names=qw(md2 md5 sha sha1 ripemd160 mdc2);
|
@OpenSSL::MD::names = qw(
|
||||||
|
md2 md5 sha sha1 ripemd160 mdc2
|
||||||
|
);
|
||||||
|
|
||||||
@OpenSSL::Cipher::names = qw(
|
@OpenSSL::Cipher::names = qw(
|
||||||
des-ecb des-cfb des-ofb des-cbc
|
des-ecb des-cfb des-ofb des-cbc
|
||||||
@ -41,34 +44,38 @@ bootstrap penSSL;
|
|||||||
rc5-ecb rc5-cfb rc5-ofb rc5-cbc
|
rc5-ecb rc5-cfb rc5-ofb rc5-cbc
|
||||||
);
|
);
|
||||||
|
|
||||||
sub OpenSSL::SSL::CTX::new_ssl { OpenSSL::SSL::new($_[0]); }
|
sub OpenSSL::SSL::CTX::new_ssl {
|
||||||
|
OpenSSL::SSL::new($_[0]);
|
||||||
|
}
|
||||||
|
|
||||||
sub OpenSSL::ERR::error
|
sub OpenSSL::ERR::error {
|
||||||
{
|
|
||||||
my($o) = @_;
|
my($o) = @_;
|
||||||
my($s, $ret);
|
my($s, $ret);
|
||||||
|
|
||||||
while (($s=$o->get_error()) != 0)
|
while (($s = $o->get_error()) != 0) {
|
||||||
{
|
|
||||||
$ret.=$s."\n";
|
$ret.=$s."\n";
|
||||||
}
|
}
|
||||||
return($ret);
|
return($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OpenSSL::Cipher::aliases=qw(des desx des3 idea rc2 bf cast);
|
@OpenSSL::Cipher::aliases = qw(
|
||||||
|
des desx des3 idea rc2 bf cast
|
||||||
|
);
|
||||||
|
|
||||||
package OpenSSL::BN;
|
package OpenSSL::BN;
|
||||||
|
|
||||||
sub bnfix { (ref($_[0]) ne "OpenSSL::BN")?OpenSSL::BN::dec2bn($_[0]):$_[0]; }
|
sub bnfix {
|
||||||
|
(ref($_[0]) ne "OpenSSL::BN") ? OpenSSL::BN::dec2bn($_[0]) : $_[0];
|
||||||
|
}
|
||||||
|
|
||||||
use overload
|
use overload
|
||||||
"=" => sub { dup($_[0]); },
|
"=" => sub { dup($_[0]); },
|
||||||
"+" => sub { add($_[0],$_[1]); },
|
"+" => sub { add($_[0],$_[1]); },
|
||||||
"-" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2];
|
"-" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; OpenSSL::BN::sub($_[0],$_[1]); },
|
||||||
OpenSSL::BN::sub($_[0],$_[1]); },
|
|
||||||
"*" => sub { mul($_[0],$_[1]); },
|
"*" => sub { mul($_[0],$_[1]); },
|
||||||
|
"**" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; OpenSSL::BN::exp($_[0],$_[1]); },
|
||||||
"/" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; (div($_[0],$_[1]))[0]; },
|
"/" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; (div($_[0],$_[1]))[0]; },
|
||||||
"%" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; mod($_[0],$_[1]); },
|
"%" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; mod($_[0],$_[1]); },
|
||||||
"**" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; exp($_[0],$_[1]); },
|
|
||||||
"<<" => sub { lshift($_[0],$_[1]); },
|
"<<" => sub { lshift($_[0],$_[1]); },
|
||||||
">>" => sub { rshift($_[0],$_[1]); },
|
">>" => sub { rshift($_[0],$_[1]); },
|
||||||
"<=>" => sub { OpenSSL::BN::cmp($_[0],$_[1]); },
|
"<=>" => sub { OpenSSL::BN::cmp($_[0],$_[1]); },
|
||||||
@ -76,5 +83,8 @@ use overload
|
|||||||
'0+' => sub { dec2bn($_[0]); },
|
'0+' => sub { dec2bn($_[0]); },
|
||||||
"bool" => sub { ref($_[0]) eq "OpenSSL::BN"; };
|
"bool" => sub { ref($_[0]) eq "OpenSSL::BN"; };
|
||||||
|
|
||||||
sub OpenSSL::BIO::do_accept { OpenSSL::BIO::do_handshake(@_); }
|
sub OpenSSL::BIO::do_accept {
|
||||||
|
OpenSSL::BIO::do_handshake(@_);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include "openssl.h"
|
#include "openssl.h"
|
||||||
|
|
||||||
SV *new_ref(type,obj,mort)
|
SV *
|
||||||
|
new_ref(type, obj, mort)
|
||||||
char *type;
|
char *type;
|
||||||
char *obj;
|
char *obj;
|
||||||
{
|
{
|
||||||
@ -14,12 +15,15 @@ char *obj;
|
|||||||
ret = sv_newmortal();
|
ret = sv_newmortal();
|
||||||
else
|
else
|
||||||
ret = newSViv(0);
|
ret = newSViv(0);
|
||||||
|
#ifdef DEBUG
|
||||||
printf(">new_ref %d\n",type);
|
printf(">new_ref %d\n",type);
|
||||||
|
#endif
|
||||||
sv_setref_pv(ret, type, (void *)obj);
|
sv_setref_pv(ret, type, (void *)obj);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ex_new(obj,data,ad,idx,argl,argp)
|
int
|
||||||
|
ex_new(obj, data, ad, idx, argl, argp)
|
||||||
char *obj;
|
char *obj;
|
||||||
SV *data;
|
SV *data;
|
||||||
CRYPTO_EX_DATA *ad;
|
CRYPTO_EX_DATA *ad;
|
||||||
@ -29,15 +33,20 @@ char *argp;
|
|||||||
{
|
{
|
||||||
SV *sv;
|
SV *sv;
|
||||||
|
|
||||||
fprintf(stderr,"ex_new %08X %s\n",obj,argp);
|
#ifdef DEBUG
|
||||||
|
printf("ex_new %08X %s\n",obj,argp);
|
||||||
|
#endif
|
||||||
sv = sv_newmortal();
|
sv = sv_newmortal();
|
||||||
sv_setref_pv(sv, argp, (void *)obj);
|
sv_setref_pv(sv, argp, (void *)obj);
|
||||||
|
#ifdef DEBUG
|
||||||
printf("%d>new_ref '%s'\n", sv, argp);
|
printf("%d>new_ref '%s'\n", sv, argp);
|
||||||
|
#endif
|
||||||
CRYPTO_set_ex_data(ad, idx, (char *)sv);
|
CRYPTO_set_ex_data(ad, idx, (char *)sv);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ex_cleanup(obj,data,ad,idx,argl,argp)
|
void
|
||||||
|
ex_cleanup(obj, data, ad, idx, argl, argp)
|
||||||
char *obj;
|
char *obj;
|
||||||
SV *data;
|
SV *data;
|
||||||
CRYPTO_EX_DATA *ad;
|
CRYPTO_EX_DATA *ad;
|
||||||
@ -46,7 +55,9 @@ long argl;
|
|||||||
char *argp;
|
char *argp;
|
||||||
{
|
{
|
||||||
pr_name("ex_cleanup");
|
pr_name("ex_cleanup");
|
||||||
fprintf(stderr,"ex_cleanup %08X %s\n",obj,argp);
|
#ifdef DEBUG
|
||||||
|
printf("ex_cleanup %08X %s\n", obj, argp);
|
||||||
|
#endif
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
SvREFCNT_dec((SV *)data);
|
SvREFCNT_dec((SV *)data);
|
||||||
}
|
}
|
||||||
|
4
perl/README.1ST
Normal file
4
perl/README.1ST
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
WARNING, this Perl interface to OpenSSL is horrible incomplete.
|
||||||
|
Don't expect it to be really useable!!
|
||||||
|
|
@ -58,15 +58,16 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "EXTERN.h"
|
#include "EXTERN.h"
|
||||||
#include "perl.h"
|
#include "perl.h"
|
||||||
#include "XSUB.h"
|
#include "XSUB.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct datum_st
|
typedef struct datum_st {
|
||||||
{
|
|
||||||
char *dptr;
|
char *dptr;
|
||||||
int dsize;
|
int dsize;
|
||||||
} datum;
|
} datum;
|
||||||
@ -79,7 +80,7 @@ typedef struct datum_st
|
|||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
|
|
||||||
#if 0
|
#ifdef DEBUG
|
||||||
#define pr_name(name) printf("%s\n",name)
|
#define pr_name(name) printf("%s\n",name)
|
||||||
#define pr_name_d(name,p2) printf("%s %d\n",name,p2)
|
#define pr_name_d(name,p2) printf("%s %d\n",name,p2)
|
||||||
#define pr_name_dd(name,p2,p3) printf("%s %d %d\n",name,p2,p3)
|
#define pr_name_dd(name,p2,p3) printf("%s %d %d\n",name,p2,p3)
|
||||||
@ -91,6 +92,5 @@ typedef struct datum_st
|
|||||||
|
|
||||||
SV *new_ref(char *type, char *obj, int mort);
|
SV *new_ref(char *type, char *obj, int mort);
|
||||||
int ex_new(char *obj, SV *data, CRYPTO_EX_DATA *ad, int idx, long argl, char *argp);
|
int ex_new(char *obj, SV *data, CRYPTO_EX_DATA *ad, int idx, long argl, char *argp);
|
||||||
void ex_cleanup(char *obj,SV *data,CRYPTO_EX_DATA *ad,int idx,
|
void ex_cleanup(char *obj, SV *data, CRYPTO_EX_DATA *ad, int idx, long argl, char *argp);
|
||||||
long argl,char *argp);
|
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@ static int p5_bio_ex_bio_ptr=0;
|
|||||||
static int p5_bio_ex_bio_callback = 0;
|
static int p5_bio_ex_bio_callback = 0;
|
||||||
static int p5_bio_ex_bio_callback_data = 0;
|
static int p5_bio_ex_bio_callback_data = 0;
|
||||||
|
|
||||||
static long p5_bio_callback(bio,state,parg,cmd,larg,ret)
|
static long
|
||||||
|
p5_bio_callback(bio,state,parg,cmd,larg,ret)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
int state;
|
int state;
|
||||||
char *parg;
|
char *parg;
|
||||||
@ -18,21 +19,18 @@ int ret;
|
|||||||
|
|
||||||
me = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
me = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
||||||
cb = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_callback);
|
cb = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_callback);
|
||||||
if (cb != NULL)
|
if (cb != NULL) {
|
||||||
{
|
|
||||||
dSP;
|
dSP;
|
||||||
|
|
||||||
ENTER;
|
ENTER;
|
||||||
SAVETMPS;
|
SAVETMPS;
|
||||||
|
|
||||||
PUSHMARK(sp);
|
PUSHMARK(sp);
|
||||||
XPUSHs(sv_2mortal(newSViv(me)));
|
XPUSHs(sv_2mortal(newSVsv(me)));
|
||||||
XPUSHs(sv_2mortal(newSViv(state)));
|
XPUSHs(sv_2mortal(newSViv(state)));
|
||||||
XPUSHs(sv_2mortal(newSViv(cmd)));
|
XPUSHs(sv_2mortal(newSViv(cmd)));
|
||||||
if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
|
if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
|
||||||
{
|
|
||||||
XPUSHs(sv_2mortal(newSVpv(parg,larg)));
|
XPUSHs(sv_2mortal(newSVpv(parg,larg)));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
XPUSHs(&sv_undef);
|
XPUSHs(&sv_undef);
|
||||||
/* ptr one */
|
/* ptr one */
|
||||||
@ -51,24 +49,18 @@ int ret;
|
|||||||
FREETMPS;
|
FREETMPS;
|
||||||
LEAVE;
|
LEAVE;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
croak("Internal error in p5_bio_callback");
|
||||||
croak("Internal error in SSL p5_ssl_info_callback");
|
|
||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int boot_bio()
|
int
|
||||||
|
boot_bio(void)
|
||||||
{
|
{
|
||||||
p5_bio_ex_bio_ptr=
|
p5_bio_ex_bio_ptr = BIO_get_ex_new_index(0, "OpenSSL::BIO", ex_new, NULL, ex_cleanup);
|
||||||
BIO_get_ex_new_index(0,"OpenSSL::BIO",ex_new,NULL,
|
p5_bio_ex_bio_callback = BIO_get_ex_new_index(0, "bio_callback", NULL, NULL, ex_cleanup);
|
||||||
ex_cleanup);
|
p5_bio_ex_bio_callback_data = BIO_get_ex_new_index(0, "bio_callback_data", NULL, NULL, ex_cleanup);
|
||||||
p5_bio_ex_bio_callback=
|
|
||||||
BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
|
|
||||||
ex_cleanup);
|
|
||||||
p5_bio_ex_bio_callback_data=
|
|
||||||
BIO_get_ex_new_index(0,"bio_callback_data",NULL,NULL,
|
|
||||||
ex_cleanup);
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +70,7 @@ VERSIONCHECK: DISABLE
|
|||||||
|
|
||||||
void
|
void
|
||||||
p5_BIO_new_buffer_ssl_connect(...)
|
p5_BIO_new_buffer_ssl_connect(...)
|
||||||
|
PROTOTYPE: ;$
|
||||||
PREINIT:
|
PREINIT:
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
@ -89,11 +82,9 @@ p5_BIO_new_buffer_ssl_connect(...)
|
|||||||
arg = ST(1);
|
arg = ST(1);
|
||||||
else
|
else
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
|
|
||||||
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
|
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
|
||||||
croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
|
croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
IV tmp = SvIV((SV *)SvRV(arg));
|
IV tmp = SvIV((SV *)SvRV(arg));
|
||||||
ctx = (SSL_CTX *)tmp;
|
ctx = (SSL_CTX *)tmp;
|
||||||
}
|
}
|
||||||
@ -104,6 +95,7 @@ p5_BIO_new_buffer_ssl_connect(...)
|
|||||||
|
|
||||||
void
|
void
|
||||||
p5_BIO_new_ssl_connect(...)
|
p5_BIO_new_ssl_connect(...)
|
||||||
|
PROTOTYPE: ;$
|
||||||
PREINIT:
|
PREINIT:
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
@ -115,11 +107,9 @@ p5_BIO_new_ssl_connect(...)
|
|||||||
arg = ST(1);
|
arg = ST(1);
|
||||||
else
|
else
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
|
|
||||||
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
|
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
|
||||||
croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
|
croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
IV tmp = SvIV((SV *)SvRV(arg));
|
IV tmp = SvIV((SV *)SvRV(arg));
|
||||||
ctx = (SSL_CTX *)tmp;
|
ctx = (SSL_CTX *)tmp;
|
||||||
}
|
}
|
||||||
@ -130,6 +120,7 @@ p5_BIO_new_ssl_connect(...)
|
|||||||
|
|
||||||
void
|
void
|
||||||
p5_BIO_new(...)
|
p5_BIO_new(...)
|
||||||
|
PROTOTYPE: ;$
|
||||||
PREINIT:
|
PREINIT:
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
char *type;
|
char *type;
|
||||||
@ -142,12 +133,21 @@ p5_BIO_new(...)
|
|||||||
type = SvPV(ST(1),na);
|
type = SvPV(ST(1),na);
|
||||||
else
|
else
|
||||||
croak("Usage: OpenSSL::BIO::new(type)");
|
croak("Usage: OpenSSL::BIO::new(type)");
|
||||||
|
|
||||||
EXTEND(sp,1);
|
EXTEND(sp,1);
|
||||||
if (strcmp(type,"connect") == 0)
|
if (strcmp(type, "mem") == 0)
|
||||||
|
bio=BIO_new(BIO_s_mem());
|
||||||
|
else if (strcmp(type, "socket") == 0)
|
||||||
|
bio=BIO_new(BIO_s_socket());
|
||||||
|
else if (strcmp(type, "connect") == 0)
|
||||||
bio=BIO_new(BIO_s_connect());
|
bio=BIO_new(BIO_s_connect());
|
||||||
else if (strcmp(type, "accept") == 0)
|
else if (strcmp(type, "accept") == 0)
|
||||||
bio=BIO_new(BIO_s_accept());
|
bio=BIO_new(BIO_s_accept());
|
||||||
|
else if (strcmp(type, "fd") == 0)
|
||||||
|
bio=BIO_new(BIO_s_fd());
|
||||||
|
else if (strcmp(type, "file") == 0)
|
||||||
|
bio=BIO_new(BIO_s_file());
|
||||||
|
else if (strcmp(type, "null") == 0)
|
||||||
|
bio=BIO_new(BIO_s_null());
|
||||||
else if (strcmp(type, "ssl") == 0)
|
else if (strcmp(type, "ssl") == 0)
|
||||||
bio=BIO_new(BIO_f_ssl());
|
bio=BIO_new(BIO_f_ssl());
|
||||||
else if (strcmp(type, "buffer") == 0)
|
else if (strcmp(type, "buffer") == 0)
|
||||||
@ -161,6 +161,7 @@ int
|
|||||||
p5_BIO_hostname(bio, name)
|
p5_BIO_hostname(bio, name)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
char *name;
|
char *name;
|
||||||
|
PROTOTYPE: $$
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_set_conn_hostname(bio, name);
|
RETVAL = BIO_set_conn_hostname(bio, name);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -170,6 +171,7 @@ int
|
|||||||
p5_BIO_set_accept_port(bio, str)
|
p5_BIO_set_accept_port(bio, str)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
char *str;
|
char *str;
|
||||||
|
PROTOTYPE: $$
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_set_accept_port(bio, str);
|
RETVAL = BIO_set_accept_port(bio, str);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -178,6 +180,7 @@ p5_BIO_set_accept_port(bio,str)
|
|||||||
int
|
int
|
||||||
p5_BIO_do_handshake(bio)
|
p5_BIO_do_handshake(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_do_handshake(bio);
|
RETVAL = BIO_do_handshake(bio);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -187,6 +190,7 @@ BIO *
|
|||||||
p5_BIO_push(b, bio)
|
p5_BIO_push(b, bio)
|
||||||
BIO *b;
|
BIO *b;
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $$
|
||||||
CODE:
|
CODE:
|
||||||
/* This reference will be reduced when the reference is
|
/* This reference will be reduced when the reference is
|
||||||
* let go, and then when the BIO_free_all() is called
|
* let go, and then when the BIO_free_all() is called
|
||||||
@ -200,37 +204,29 @@ p5_BIO_push(b,bio)
|
|||||||
void
|
void
|
||||||
p5_BIO_pop(b)
|
p5_BIO_pop(b)
|
||||||
BIO *b
|
BIO *b
|
||||||
|
PROTOTYPE: $
|
||||||
PREINIT:
|
PREINIT:
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
char *type;
|
char *type;
|
||||||
SV *arg;
|
SV *arg;
|
||||||
PPCODE:
|
PPCODE:
|
||||||
bio = BIO_pop(b);
|
bio = BIO_pop(b);
|
||||||
if (bio != NULL)
|
if (bio != NULL) {
|
||||||
{
|
|
||||||
/* This BIO will either be one created in the
|
/* This BIO will either be one created in the
|
||||||
* perl library, in which case it will have a perl
|
* perl library, in which case it will have a perl
|
||||||
* SV, otherwise it will have been created internally,
|
* SV, otherwise it will have been created internally,
|
||||||
* inside OpenSSL. For the 'pushed in', it needs
|
* inside OpenSSL. For the 'pushed in', it needs
|
||||||
* the reference count decememted. */
|
* the reference count decememted. */
|
||||||
arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
||||||
if (arg == NULL)
|
if (arg == NULL) {
|
||||||
{
|
|
||||||
arg = new_ref("OpenSSL::BIO",(char *)bio,0);
|
arg = new_ref("OpenSSL::BIO",(char *)bio,0);
|
||||||
BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
|
BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
|
||||||
PUSHs(arg);
|
PUSHs(arg);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* it was pushed in */
|
/* it was pushed in */
|
||||||
SvREFCNT_inc(arg);
|
SvREFCNT_inc(arg);
|
||||||
PUSHs(arg);
|
PUSHs(arg);
|
||||||
#if 0 /* This does not need to be done. */
|
|
||||||
if (bio->references < 1)
|
|
||||||
abort();
|
|
||||||
/* decrement the reference count */
|
|
||||||
BIO_free(bio);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +235,7 @@ p5_BIO_sysread(bio,in,num, ...)
|
|||||||
BIO *bio;
|
BIO *bio;
|
||||||
SV *in;
|
SV *in;
|
||||||
int num;
|
int num;
|
||||||
|
PROTOTYPE: $$$;
|
||||||
PREINIT:
|
PREINIT:
|
||||||
int i,n,olen;
|
int i,n,olen;
|
||||||
int offset;
|
int offset;
|
||||||
@ -248,27 +245,24 @@ p5_BIO_sysread(bio,in,num, ...)
|
|||||||
if (!SvPOK(in))
|
if (!SvPOK(in))
|
||||||
sv_setpvn(in, "", 0);
|
sv_setpvn(in, "", 0);
|
||||||
SvPV(in, olen);
|
SvPV(in, olen);
|
||||||
if (items > 3)
|
if (items > 3) {
|
||||||
{
|
|
||||||
offset = SvIV(ST(3));
|
offset = SvIV(ST(3));
|
||||||
if (offset < 0)
|
if (offset < 0) {
|
||||||
{
|
|
||||||
if (-offset > olen)
|
if (-offset > olen)
|
||||||
croak("Offset outside string");
|
croak("Offset outside string");
|
||||||
offset+=olen;
|
offset+=olen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((num+offset) > olen)
|
if ((num+offset) > olen) {
|
||||||
{
|
|
||||||
SvGROW(in, num+offset+1);
|
SvGROW(in, num+offset+1);
|
||||||
p=SvPV(in, i);
|
p=SvPV(in, i);
|
||||||
memset(&(p[olen]), 0, (num+offset)-olen+1);
|
memset(&(p[olen]), 0, (num+offset)-olen+1);
|
||||||
}
|
}
|
||||||
p = SvPV(in,n);
|
p = SvPV(in,n);
|
||||||
|
|
||||||
i = BIO_read(bio, p+offset, num);
|
i = BIO_read(bio, p+offset, num);
|
||||||
RETVAL = i;
|
RETVAL = i;
|
||||||
if (i <= 0) i=0;
|
if (i <= 0)
|
||||||
|
i = 0;
|
||||||
SvCUR_set(in, offset+i);
|
SvCUR_set(in, offset+i);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
@ -277,6 +271,7 @@ int
|
|||||||
p5_BIO_syswrite(bio, in, ...)
|
p5_BIO_syswrite(bio, in, ...)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
SV *in;
|
SV *in;
|
||||||
|
PROTOTYPE: $$;
|
||||||
PREINIT:
|
PREINIT:
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int len,in_len;
|
int len,in_len;
|
||||||
@ -284,14 +279,11 @@ p5_BIO_syswrite(bio,in, ...)
|
|||||||
int n;
|
int n;
|
||||||
CODE:
|
CODE:
|
||||||
ptr = SvPV(in, in_len);
|
ptr = SvPV(in, in_len);
|
||||||
if (items > 2)
|
if (items > 2) {
|
||||||
{
|
|
||||||
len = SvOK(ST(2)) ? SvIV(ST(2)) : in_len;
|
len = SvOK(ST(2)) ? SvIV(ST(2)) : in_len;
|
||||||
if (items > 3)
|
if (items > 3) {
|
||||||
{
|
|
||||||
offset = SvIV(ST(3));
|
offset = SvIV(ST(3));
|
||||||
if (offset < 0)
|
if (offset < 0) {
|
||||||
{
|
|
||||||
if (-offset > in_len)
|
if (-offset > in_len)
|
||||||
croak("Offset outside string");
|
croak("Offset outside string");
|
||||||
offset+=in_len;
|
offset+=in_len;
|
||||||
@ -304,7 +296,6 @@ p5_BIO_syswrite(bio,in, ...)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
len = in_len;
|
len = in_len;
|
||||||
|
|
||||||
RETVAL = BIO_write(bio, ptr+offset, len);
|
RETVAL = BIO_write(bio, ptr+offset, len);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
@ -312,6 +303,7 @@ p5_BIO_syswrite(bio,in, ...)
|
|||||||
void
|
void
|
||||||
p5_BIO_getline(bio)
|
p5_BIO_getline(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
PREINIT:
|
PREINIT:
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
@ -323,12 +315,14 @@ p5_BIO_getline(bio)
|
|||||||
SvGROW(ST(0), 1024);
|
SvGROW(ST(0), 1024);
|
||||||
p=SvPV(ST(0), na);
|
p=SvPV(ST(0), na);
|
||||||
i = BIO_gets(bio, p, 1024);
|
i = BIO_gets(bio, p, 1024);
|
||||||
if (i < 0) i=0;
|
if (i < 0)
|
||||||
|
i = 0;
|
||||||
SvCUR_set(ST(0), i);
|
SvCUR_set(ST(0), i);
|
||||||
|
|
||||||
int
|
int
|
||||||
p5_BIO_flush(bio)
|
p5_BIO_flush(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_flush(bio);
|
RETVAL = BIO_flush(bio);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -337,6 +331,7 @@ p5_BIO_flush(bio)
|
|||||||
char *
|
char *
|
||||||
p5_BIO_type(bio)
|
p5_BIO_type(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = bio->method->name;
|
RETVAL = bio->method->name;
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -345,24 +340,22 @@ p5_BIO_type(bio)
|
|||||||
void
|
void
|
||||||
p5_BIO_next_bio(b)
|
p5_BIO_next_bio(b)
|
||||||
BIO *b
|
BIO *b
|
||||||
|
PROTOTYPE: $
|
||||||
PREINIT:
|
PREINIT:
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
char *type;
|
char *type;
|
||||||
SV *arg;
|
SV *arg;
|
||||||
PPCODE:
|
PPCODE:
|
||||||
bio = b->next_bio;
|
bio = b->next_bio;
|
||||||
if (bio != NULL)
|
if (bio != NULL) {
|
||||||
{
|
|
||||||
arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
|
||||||
if (arg == NULL)
|
if (arg == NULL) {
|
||||||
{
|
|
||||||
arg = new_ref("OpenSSL::BIO", (char *)bio, 0);
|
arg = new_ref("OpenSSL::BIO", (char *)bio, 0);
|
||||||
BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
|
BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
|
||||||
bio->references++;
|
bio->references++;
|
||||||
PUSHs(arg);
|
PUSHs(arg);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
SvREFCNT_inc(arg);
|
SvREFCNT_inc(arg);
|
||||||
PUSHs(arg);
|
PUSHs(arg);
|
||||||
}
|
}
|
||||||
@ -372,6 +365,7 @@ int
|
|||||||
p5_BIO_puts(bio, in)
|
p5_BIO_puts(bio, in)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
SV *in;
|
SV *in;
|
||||||
|
PROTOTYPE: $$
|
||||||
PREINIT:
|
PREINIT:
|
||||||
char *ptr;
|
char *ptr;
|
||||||
CODE:
|
CODE:
|
||||||
@ -384,33 +378,33 @@ void
|
|||||||
p5_BIO_set_callback(bio, cb,...)
|
p5_BIO_set_callback(bio, cb,...)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
SV *cb;
|
SV *cb;
|
||||||
|
PROTOTYPE: $$;
|
||||||
PREINIT:
|
PREINIT:
|
||||||
SV *arg = NULL;
|
SV *arg = NULL;
|
||||||
SV *arg2 = NULL;
|
SV *arg2 = NULL;
|
||||||
CODE:
|
CODE:
|
||||||
if (items > 3)
|
if (items > 3)
|
||||||
croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
|
croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
|
||||||
if (items == 3)
|
if (items == 3) {
|
||||||
{
|
|
||||||
arg2 = sv_mortalcopy(ST(2));
|
arg2 = sv_mortalcopy(ST(2));
|
||||||
SvREFCNT_inc(arg2);
|
SvREFCNT_inc(arg2);
|
||||||
BIO_set_ex_data(bio,p5_bio_ex_bio_callback_data,
|
BIO_set_ex_data(bio, p5_bio_ex_bio_callback_data, (char *)arg2);
|
||||||
(char *)arg2);
|
|
||||||
}
|
}
|
||||||
arg = sv_mortalcopy(ST(1));
|
arg = sv_mortalcopy(ST(1));
|
||||||
SvREFCNT_inc(arg);
|
SvREFCNT_inc(arg);
|
||||||
BIO_set_ex_data(bio, p5_bio_ex_bio_callback, (char *)arg);
|
BIO_set_ex_data(bio, p5_bio_ex_bio_callback, (char *)arg);
|
||||||
printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr));
|
/* printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr)); */
|
||||||
BIO_set_callback(bio, p5_bio_callback);
|
BIO_set_callback(bio, p5_bio_callback);
|
||||||
|
|
||||||
void
|
void
|
||||||
p5_BIO_DESTROY(bio)
|
p5_BIO_DESTROY(bio)
|
||||||
BIO *bio
|
BIO *bio
|
||||||
|
PROTOTYPE: $
|
||||||
PREINIT:
|
PREINIT:
|
||||||
SV *sv;
|
SV *sv;
|
||||||
PPCODE:
|
PPCODE:
|
||||||
pr_name_d("p5_BIO_DESTROY",bio->references);
|
pr_name_d("p5_BIO_DESTROY",bio->references);
|
||||||
printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references);
|
/* printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references); */
|
||||||
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
|
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
|
||||||
BIO_free_all(bio);
|
BIO_free_all(bio);
|
||||||
|
|
||||||
@ -418,6 +412,7 @@ int
|
|||||||
p5_BIO_set_ssl(bio, ssl)
|
p5_BIO_set_ssl(bio, ssl)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
|
PROTOTYPE: $$
|
||||||
CODE:
|
CODE:
|
||||||
pr_name("p5_BIO_set_ssl");
|
pr_name("p5_BIO_set_ssl");
|
||||||
ssl->references++;
|
ssl->references++;
|
||||||
@ -428,6 +423,7 @@ p5_BIO_set_ssl(bio,ssl)
|
|||||||
int
|
int
|
||||||
p5_BIO_number_read(bio)
|
p5_BIO_number_read(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_number_read(bio);
|
RETVAL = BIO_number_read(bio);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -436,6 +432,7 @@ p5_BIO_number_read(bio)
|
|||||||
int
|
int
|
||||||
p5_BIO_number_written(bio)
|
p5_BIO_number_written(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = BIO_number_written(bio);
|
RETVAL = BIO_number_written(bio);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@ -444,6 +441,7 @@ p5_BIO_number_written(bio)
|
|||||||
int
|
int
|
||||||
p5_BIO_references(bio)
|
p5_BIO_references(bio)
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
|
PROTOTYPE: $
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = bio->references;
|
RETVAL = bio->references;
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
13
perl/t/01-use.t
Normal file
13
perl/t/01-use.t
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
BEGIN {
|
||||||
|
$| = 1;
|
||||||
|
print "1..1\n";
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
print "not ok 1\n" unless $loaded;
|
||||||
|
}
|
||||||
|
use OpenSSL;
|
||||||
|
$loaded = 1;
|
||||||
|
print "ok 1\n";
|
||||||
|
|
||||||
|
|
10
perl/t/02-version.t
Normal file
10
perl/t/02-version.t
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
print "1..1\n";
|
||||||
|
use OpenSSL;
|
||||||
|
if ($OpenSSL::VERSION ne '') {
|
||||||
|
print "ok 1\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "not ok 1\n";
|
||||||
|
}
|
||||||
|
|
16
perl/t/03-bio.t
Normal file
16
perl/t/03-bio.t
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
BEGIN {
|
||||||
|
$| = 1;
|
||||||
|
print "1..1\n";
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
print "not ok 1\n" unless $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
use OpenSSL;
|
||||||
|
my $bio = OpenSSL::BIO::new("mem") || die;
|
||||||
|
undef $bio;
|
||||||
|
|
||||||
|
$ok = 1;
|
||||||
|
print "ok 1\n";
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user