Crypt-OpenSSL-PKCS12
view release on metacpan or search on metacpan
if (SvOK(pwd)) {
pwd_str = SvPV(pwd, pwd_len);
if (pwd_len > (STRLEN)INT_MAX)
croak("password length exceeds INT_MAX");
}
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
RETVAL = newSVpvn("",0);
dump_certs_keys_p12(aTHX_ bio, pkcs12, pwd_str, (int)pwd_len, CACERTS|NOKEYS, NULL, NULL);
RETVAL = extractBioString(aTHX_ bio);
OUTPUT:
RETVAL
SV*
private_key(pkcs12, pwd = &PL_sv_undef)
Crypt::OpenSSL::PKCS12 pkcs12
SV *pwd
PREINIT:
BIO *bio;
STRLEN pwd_len = 0;
const char *pwd_str = "";
CODE:
if (SvOK(pwd)) {
pwd_str = SvPV(pwd, pwd_len);
if (pwd_len > (STRLEN)INT_MAX)
croak("password length exceeds INT_MAX");
}
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
PKCS12_unpack_authsafes(pkcs12);
dump_certs_keys_p12(aTHX_ bio, pkcs12, pwd_str, (int)pwd_len, NOCERTS, NULL, NULL);
RETVAL = extractBioString(aTHX_ bio);
OUTPUT:
RETVAL
HV* info_as_hash(pkcs12, pwd = &PL_sv_undef)
Crypt::OpenSSL::PKCS12 pkcs12
SV *pwd
PREINIT:
BIO *bio;
STACK_OF(PKCS7) *asafes = NULL;
STRLEN pwd_len = 0;
const char *pwd_str = "";
CONST_ASN1_INTEGER *tmaciter;
#if OPENSSL_VERSION_NUMBER > 0x10100000L
SV *value;
CONST_X509_ALGOR *macalgid;
CONST_ASN1_OBJECT *macobj;
CONST_ASN1_OCTET_STRING *tmac;
CONST_ASN1_OCTET_STRING *tsalt;
#endif
CODE:
if (SvOK(pwd)) {
pwd_str = SvPV(pwd, pwd_len);
if (pwd_len > (STRLEN)INT_MAX)
croak("password length exceeds INT_MAX");
}
RETVAL = newHV();
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
RETVAL = newHV();
HV * mac = newHV();
#if OPENSSL_VERSION_NUMBER > 0x10100000L
PKCS12_get0_mac(&tmac, &macalgid, &tsalt, &tmaciter, pkcs12);
/* current hash algorithms do not use parameters so extract just name,
in future alg_print() may be needed */
X509_ALGOR_get0(&macobj, NULL, NULL, macalgid);
i2a_ASN1_OBJECT(bio, macobj);
value = extractBioString(aTHX_ bio);
if((hv_store(mac, "digest", strlen("digest"), value, 0)) == NULL)
croak("unable to add digest to the hash");
#else
tmaciter = pkcs12->mac->iter;
#endif
SV * mac_iteration = newSViv (tmaciter != NULL ? ASN1_INTEGER_get(tmaciter) : 1L);
if((hv_store(mac, "iteration", strlen("iteration"), mac_iteration, 0)) == NULL)
croak("unable to add iteration to the hash");
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
/* BIO_printf(bio, "MAC length: %ld, salt length: %ld", */
#if OPENSSL_VERSION_NUMBER > 0x10100000L
SV * mac_len = newSViv(tmac != NULL ? ASN1_STRING_length(tmac) : 0L);
SV * salt_len = newSViv(tsalt != NULL ? ASN1_STRING_length(tsalt) : 0L);
if((hv_store(mac, "length", 6, mac_len, 0)) == NULL)
croak("unable to add length to the hash");
#else
SV * salt_len = newSViv((pkcs12)->mac ? pkcs12->mac->salt->length : 0L);
#endif
if((hv_store(mac, "salt_length", strlen("salt_length"), INT2PTR(SV*, salt_len), 0)) == NULL)
croak("unable to add salt_length to the hash");
if((hv_store(RETVAL, "mac", strlen("mac"), newRV_inc((SV *) mac), 0)) == NULL)
croak("unable to add MAC to the hash");
dump_certs_keys_p12(aTHX_ bio, pkcs12, pwd_str, (int)pwd_len, INFO, NULL, RETVAL);
SV * end = extractBioString(aTHX_ bio);
if (SvPOK(end)) {
if (SvCUR(end) != 0)
printf("BIO %s\n", SvPVbyte_nolen(end));
warn("bio from info_as_hash should be zero length - report issue");
}
sv_2mortal((SV*)RETVAL);
OUTPUT:
RETVAL
SV*
info(pkcs12, pwd = &PL_sv_undef)
Crypt::OpenSSL::PKCS12 pkcs12
SV *pwd
PREINIT:
BIO *bio;
STACK_OF(PKCS7) *asafes = NULL;
STRLEN pwd_len = 0;
const char *pwd_str = "";
CONST_ASN1_INTEGER *tmaciter;
#if OPENSSL_VERSION_NUMBER > 0x10100000L
CONST_X509_ALGOR *macalgid;
CONST_ASN1_OBJECT *macobj;
CONST_ASN1_OCTET_STRING *tmac;
CONST_ASN1_OCTET_STRING *tsalt;
#endif
CODE:
if (SvOK(pwd)) {
pwd_str = SvPV(pwd, pwd_len);
if (pwd_len > (STRLEN)INT_MAX)
croak("password length exceeds INT_MAX");
}
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
RETVAL = newSVpvn("",0);
#if OPENSSL_VERSION_NUMBER > 0x10100000L
PKCS12_get0_mac(&tmac, &macalgid, &tsalt, &tmaciter, pkcs12);
/* current hash algorithms do not use parameters so extract just name,
in future alg_print() may be needed */
X509_ALGOR_get0(&macobj, NULL, NULL, macalgid);
BIO_puts(bio, "MAC: ");
i2a_ASN1_OBJECT(bio, macobj);
/* current hash algorithms do not use parameters so extract just name,
in future alg_print() may be needed */
BIO_printf(bio, ", Iteration %ld\n",
tmaciter != NULL ? ASN1_INTEGER_get(tmaciter) : 1L);
BIO_printf(bio, "MAC length: %ld, salt length: %ld\n",
tmac != NULL ? ASN1_STRING_length(tmac) : 0L,
tsalt != NULL ? ASN1_STRING_length(tsalt) : 0L);
#else
tmaciter = pkcs12->mac->iter;
BIO_printf(bio, "MAC Iteration %ld\n",
tmaciter != NULL ? ASN1_INTEGER_get(tmaciter) : 1L);
/* If we enter empty password try no password first */
if (!PKCS12_verify_mac(pkcs12, pwd_str, (int)pwd_len)) {
BIO_printf(bio, "Mac verify error: invalid password?\n");
ERR_print_errors(bio);
goto end;
}
BIO_printf(bio, "MAC verified OK\n");
end:
#endif
dump_certs_keys_p12(aTHX_ bio, pkcs12, pwd_str, (int)pwd_len, INFO, NULL, NULL);
RETVAL = extractBioString(aTHX_ bio);
OUTPUT:
RETVAL
( run in 2.393 seconds using v1.01-cache-2.11-cpan-acf6aa7dc9e )