| 1 |
#include "EXTERN.h" |
| 2 |
#include "perl.h" |
| 3 |
#include "XSUB.h" |
| 4 |
#include "ppport.h" |
| 5 |
|
| 6 |
#include <openssl/ssl.h> |
| 7 |
#include <openssl/bio.h> |
| 8 |
|
| 9 |
#if OPENSSL_VERSION_NUMBER < 0x10100000 |
| 10 |
static const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x) |
| 11 |
{ |
| 12 |
return x->serialNumber; |
| 13 |
} |
| 14 |
#endif |
| 15 |
|
| 16 |
MODULE = POE::Filter::SSL PACKAGE = POE::Filter::SSL |
| 17 |
|
| 18 |
long |
| 19 |
POE_FILTER_SSL_set_tmp_dh(ssl,dh) |
| 20 |
SSL * ssl |
| 21 |
DH * dh |
| 22 |
CODE: |
| 23 |
RETVAL = SSL_set_tmp_dh(ssl,dh); |
| 24 |
OUTPUT: |
| 25 |
RETVAL |
| 26 |
|
| 27 |
long |
| 28 |
POE_FILTER_SSL_CTX_set_tmp_dh(ctx,dh) |
| 29 |
SSL_CTX * ctx |
| 30 |
DH * dh |
| 31 |
CODE: |
| 32 |
RETVAL = SSL_CTX_set_tmp_dh(ctx,dh); |
| 33 |
OUTPUT: |
| 34 |
RETVAL |
| 35 |
|
| 36 |
long |
| 37 |
POE_FILTER_SSL_CTX_set_tmp_rsa(ctx,rsa) |
| 38 |
SSL_CTX * ctx |
| 39 |
RSA * rsa |
| 40 |
CODE: |
| 41 |
RETVAL = SSL_CTX_set_tmp_rsa(ctx,rsa); |
| 42 |
OUTPUT: |
| 43 |
RETVAL |
| 44 |
|
| 45 |
int |
| 46 |
POE_FILTER_SSL_get_ex_data_X509_STORE_CTX_idx() |
| 47 |
CODE: |
| 48 |
RETVAL = SSL_get_ex_data_X509_STORE_CTX_idx(); |
| 49 |
OUTPUT: |
| 50 |
RETVAL |
| 51 |
|
| 52 |
ASN1_INTEGER * |
| 53 |
POE_FILTER_X509_get_serialNumber(cert) |
| 54 |
X509 * cert |
| 55 |
CODE: |
| 56 |
RETVAL = X509_get_serialNumber(cert); |
| 57 |
ST(0) = sv_newmortal(); /* Undefined to start with */ |
| 58 |
sv_setpvn( ST(0), RETVAL->data, RETVAL->length); |
| 59 |
|
| 60 |
ASN1_INTEGER * |
| 61 |
POE_FILTER_verify_serial_against_crl_file(crlfile, serial) |
| 62 |
CODE: |
| 63 |
X509_CRL *crl=NULL; |
| 64 |
X509_REVOKED *revoked; |
| 65 |
STACK_OF(X509_REVOKED) *revokes; |
| 66 |
BIO *in=NULL; |
| 67 |
int n,i,retval = 0; |
| 68 |
STRLEN len, lenser; |
| 69 |
unsigned char* crlfile = SvPV( ST(0), len); |
| 70 |
unsigned char* serial = SvPV( ST(1), lenser); |
| 71 |
ST(0) = sv_newmortal(); /* Undefined to start with */ |
| 72 |
|
| 73 |
/* check peer cert against CRL */ |
| 74 |
if (len <= 0) { |
| 75 |
sv_setpvn(ST(0), "CRL: No file name given!", 24); |
| 76 |
goto end; |
| 77 |
} |
| 78 |
|
| 79 |
in=BIO_new(BIO_s_file()); |
| 80 |
if (in == NULL) { |
| 81 |
sv_setpvn(ST(0), "CRL: BIO err", 12); |
| 82 |
goto end; |
| 83 |
} |
| 84 |
|
| 85 |
if (BIO_read_filename(in, crlfile) <= 0) { |
| 86 |
sv_setpvn(ST(0), "CRL: cannot read CRL File", 25); |
| 87 |
goto end; |
| 88 |
} |
| 89 |
|
| 90 |
crl=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL); |
| 91 |
if (crl == NULL) { |
| 92 |
sv_setpvn(ST(0), "CRL: cannot read from CRL File", 30); |
| 93 |
goto end; |
| 94 |
} |
| 95 |
|
| 96 |
revokes = X509_CRL_get_REVOKED(crl); |
| 97 |
n = sk_X509_REVOKED_num(revokes); |
| 98 |
if (n > 0) { |
| 99 |
for (i = 0; i < n; i++) { |
| 100 |
const ASN1_INTEGER *asn_ser; |
| 101 |
|
| 102 |
revoked = sk_X509_REVOKED_value(revokes, i); |
| 103 |
asn_ser = X509_REVOKED_get0_serialNumber(revoked); |
| 104 |
if ( (asn_ser->length > 0) && |
| 105 |
(asn_ser->length == lenser) && |
| 106 |
(strncmp(asn_ser->data, serial, lenser) == 0)) { |
| 107 |
sv_setpvn( ST(0), asn_ser->data, asn_ser->length); |
| 108 |
goto end; |
| 109 |
} |
| 110 |
} |
| 111 |
sv_setpvn(ST(0), "0", 1); |
| 112 |
} else { |
| 113 |
sv_setpvn(ST(0), "CRL: Empty File", 15); |
| 114 |
} |
| 115 |
end: |
| 116 |
BIO_free(in); |
| 117 |
if (crl) X509_CRL_free (crl); |