Alt-Crypt-OpenSSL-PKCS12-Broadbean
view release on metacpan or search on metacpan
BIO *bio;
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
print_name(bio, "", X509_get_subject_name(x));
SV *sv = extractBioString(aTHX_ bio);
return sv;
}
SV * get_cert_issuer_name(pTHX_ X509 *x)
{
BIO *bio;
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
print_name(bio, "", X509_get_issuer_name(x));
SV *sv = extractBioString(aTHX_ bio);
return sv;
}
void get_hex(char *out, unsigned char *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
if (i == (len-1))
out += sprintf(out, "%02X", buf[i]);
else
out += sprintf(out, "%02X ", buf[i]);
}
}
void hex_prin(BIO *out, unsigned char *buf, int len)
{
int i;
for (i = 0; i < len; i++)
BIO_printf(out, "%02X ", buf[i]);
}
/* Generalised x509 attribute value print */
void print_attribute(pTHX_ BIO *out, CONST_ASN1_TYPE *av, char **attribute)
{
char *value;
/*
const char *ln;
char objbuf[80];
*/
switch (av->type) {
case V_ASN1_BMPSTRING:
value = OPENSSL_uni2asc(av->value.bmpstring->data,
av->value.bmpstring->length);
if(*attribute != NULL) {
Renew(*attribute, av->value.bmpstring->length, char);
strncpy(*attribute, value, av->value.bmpstring->length);
} else {
BIO_printf(out, "%s\n", value);
OPENSSL_free(value);
}
break;
case V_ASN1_UTF8STRING:
if(*attribute != NULL) {
Renew(*attribute, av->value.utf8string->length, char);
strncpy(*attribute, (const char * ) av->value.utf8string->data, av->value.utf8string->length);
} else {
BIO_printf(out, "%.*s\n", av->value.utf8string->length,
av->value.utf8string->data);
}
break;
case V_ASN1_OCTET_STRING:
if(*attribute != NULL) {
Renew(*attribute, av->value.octet_string->length * 4, char);
get_hex(*attribute, av->value.octet_string->data, av->value.octet_string->length);
} else {
hex_prin(out, av->value.octet_string->data,
av->value.octet_string->length);
BIO_printf(out, "\n");
}
break;
case V_ASN1_BIT_STRING:
if(*attribute != NULL) {
Renew(*attribute, av->value.bit_string->length *4, char);
get_hex(*attribute, av->value.bit_string->data, av->value.bit_string->length);
} else {
hex_prin(out, av->value.bit_string->data,
av->value.bit_string->length);
BIO_printf(out, "\n");
}
break;
/* case V_ASN1_OBJECT:
ln = OBJ_nid2ln(OBJ_obj2nid(av->value.object));
if (!ln)
ln = "";
OBJ_obj2txt(objbuf, sizeof(objbuf), av->value.object, 1);
if(*attribute != NULL) {
Renew(*attribute, strlen(ln), char);
strncpy(*attribute, ln, strlen(*attribute));
} else {
BIO_printf(out, "%s (%s)", ln, objbuf);
BIO_printf(out, "\n");
}
break;
*/
default:
if(*attribute != NULL) {
Renew(*attribute, (strlen("<Unsupported tag >") + sizeof(av->type)), char);
sprintf(*attribute, "<Unsupported tag %i>\n", av->type);
}
else {
BIO_printf(out, "<Unsupported tag %d>\n", av->type);
}
break;
}
}
/* Generalised attribute print: handle PKCS#8 and bag attributes */
int print_attribs(pTHX_ BIO *out, CONST_STACK_OF(X509_ATTRIBUTE) *attrlst,
const char *name, HV * hash)
{
X509_ATTRIBUTE *attr;
ASN1_TYPE *av;
int i, j, attr_nid;
AV * bags_av = newAV();
if (!attrlst) {
( run in 1.978 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )