Crypt-OpenSSL-X509
view release on metacpan or search on metacpan
croak("X509_new");
}
if (!X509_set_version(RETVAL, 2)) {
X509_free(RETVAL);
croak ("%s - can't X509_set_version()", SvPV_nolen(class));
}
ASN1_INTEGER_set(X509_get_serialNumber(RETVAL), 0L);
OUTPUT:
RETVAL
Crypt::OpenSSL::X509
new_from_string(class, string, format = FORMAT_PEM)
SV *class
SV *string
int format
ALIAS:
new_from_file = 1
PREINIT:
BIO *bio;
STRLEN len;
char *cert;
CODE:
cert = SvPV(string, len);
if (ix == 1) {
bio = BIO_new_file(cert, "r");
} else {
bio = BIO_new_mem_buf(cert, len);
}
if (!bio) croak("%s: Failed to create BIO", SvPV_nolen(class));
/* this can come in any number of ways */
if (format == FORMAT_ASN1) {
RETVAL = (X509*)d2i_X509_bio(bio, NULL);
} else {
RETVAL = (X509*)PEM_read_bio_X509(bio, NULL, NULL, NULL);
}
BIO_free_all(bio);
if (!RETVAL) croak("%s: failed to read X509 certificate.", SvPV_nolen(class));
OUTPUT:
RETVAL
void
DESTROY(x509)
Crypt::OpenSSL::X509 x509;
PPCODE:
if (x509) X509_free(x509); x509 = 0;
# This is called via an END block in the Perl module to clean up initialization that happened in BOOT.
void
__X509_cleanup(void)
PPCODE:
#if OPENSSL_VERSION_NUMBER < 0x10100000
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
ERR_remove_state(0);
EVP_cleanup();
#endif
SV*
accessor(x509)
Crypt::OpenSSL::X509 x509;
ALIAS:
subject = 1
issuer = 2
serial = 3
hash = 4
subject_hash = 4
notBefore = 5
notAfter = 6
email = 7
version = 8
sig_alg_name = 9
key_alg_name = 10
issuer_hash = 11
PREINIT:
BIO *bio;
X509_NAME *name;
CODE:
bio = sv_bio_create();
/* this includes both subject and issuer since they are so much alike */
if (ix == 1 || ix == 2) {
if (ix == 1) {
name = (X509_NAME *)X509_get_subject_name(x509);
} else {
name = (X509_NAME *)X509_get_issuer_name(x509);
}
/* this is prefered over X509_NAME_oneline() */
X509_NAME_print_ex(bio, name, 0, (XN_FLAG_SEP_CPLUS_SPC | ASN1_STRFLGS_UTF8_CONVERT) & ~ASN1_STRFLGS_ESC_MSB);
/* this need not be pure ascii, try to get a native perl character string with * utf8 */
sv_bio_utf8_on(bio);
} else if (ix == 3) {
i2a_ASN1_INTEGER(bio, X509_get0_serialNumber(x509));
} else if (ix == 4) {
BIO_printf(bio, "%08lx", X509_subject_name_hash(x509));
} else if (ix == 5) {
#if OPENSSL_VERSION_NUMBER < 0x10100000
ASN1_TIME_print(bio, X509_get_notBefore(x509));
#else
( run in 1.355 second using v1.01-cache-2.11-cpan-71847e10f99 )