Branch Coverage

PKCS12.xs
Criterion Covered Total %
branch 277 476 58.1


line true false branch
96 0 4 if (!strncmp(keyString, "----", 4)) {
98 0 0 CHECK_OPEN_SSL(stringBIO = BIO_new_mem_buf(keyString, strlen(keyString)));
102 0 4 CHECK_OPEN_SSL(stringBIO = BIO_new_file(keyString, "r"));
110 0 4 CHECK_OPEN_SSL(pkey);
121 0 4 if (!strncmp(keyString, "----", 4)) {
122 0 0 CHECK_OPEN_SSL(stringBIO = BIO_new_mem_buf(keyString, strlen(keyString)));
124 0 4 CHECK_OPEN_SSL(stringBIO = BIO_new_file(keyString, "r"));
128 4 4 for (i = 0; i < sk_X509_INFO_num(xis); i++) {
130 4 0 if (xi->x509 != NULL && stack != NULL) {
4 0 if (xi->x509 != NULL && stack != NULL) {
131 0 4 CHECK_OPEN_SSL(xi->x509);
132 0 4 if (!sk_X509_push(stack, xi->x509))
149 0 0 if (sv) sv_free(sv);
160 0 202 CHECK_OPEN_SSL(BIO_flush(p_stringBio) == 1);
165 0 202 CHECK_OPEN_SSL(BIO_set_close(p_stringBio, BIO_CLOSE) == 1);
175 0 7 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
206 0 2 if (options & NOKEYS) return 1;
210 0 2 if (!(pkey = EVP_PKCS82PKEY (p8))) return 0;
212 2 0 if (options & INFO) {
214 1 1 if (bag_hv) {
216 0 1 if((hv_store(bag_hv, "type", strlen("type"), value, 0)) == NULL)
221 0 1 CHECK_OPEN_SSL(keybio = BIO_new(BIO_s_mem()));
225 0 1 if((hv_store(bag_hv, "key", strlen("key"), key_sv, 0)) == NULL)
245 5 13 if (options & NOKEYS) return 1;
247 0 13 if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL)
249 0 13 if ((pkey = EVP_PKCS82PKEY (p8)) == NULL) {
253 10 3 if (options & INFO) {
264 5 5 if (bag_hv) {
267 0 5 if((hv_store(bag_hv, "type", strlen("type"), str_bag, 0)) == NULL)
273 0 5 if((hv_store(bag_hv, "parameters", strlen("parameters"), newRV_inc((SV *) parameters_hv), 0)) == NULL)
277 0 5 if((hv_store(bag_hv, "type", strlen("type"), str_key_bag, 0)) == NULL)
284 0 5 CHECK_OPEN_SSL(keybio = BIO_new(BIO_s_mem()));
288 0 5 if((hv_store(bag_hv, "key", strlen("key"), key_sv, 0)) == NULL)
310 6 41 if (options & NOCERTS) return 1;
312 21 20 if (PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID)) {
314 1 20 if (options & CACERTS) return 1;
316 3 17 } else if (options & CLCERTS) {
321 0 37 if (PKCS12_SAFEBAG_get_bag_nid(bag) != NID_x509Certificate) return 1;
323 0 37 if ((x509 = PKCS12_SAFEBAG_get1_cert(bag)) == NULL) return 0;
324 32 5 if (options & INFO) {
325 16 16 if (bag_hv) {
327 0 16 CHECK_OPEN_SSL(keybio = BIO_new(BIO_s_mem()));
330 0 16 if((hv_store(bag_hv, "type", strlen("type"), value, 0)) == NULL)
332 0 16 if((hv_store(bag_hv, "subject", strlen("subject"), get_cert_subject_name(aTHX_ x509), 0)) == NULL)
334 0 16 if((hv_store(bag_hv, "issuer", strlen("issuer"), get_cert_issuer_name(aTHX_ x509), 0)) == NULL)
338 0 16 if((hv_store(bag_hv, "cert", strlen("cert"), key_sv, 0)) == NULL)
358 53 0 if (options & INFO) {
360 52 1 if (bag_hv){
362 0 52 if((hv_store(bag_hv, "type", strlen("type"), value, 0)) == NULL)
367 0 52 if(hv_store(bag_hv, "bag_value", strlen("bag_value"), newSVpvn(attribute_value, strlen(attribute_value)), 0) == NULL)
380 0 0 if (!bag_hv)
386 2 0 if (options & INFO) {
387 1 1 if(bag_hv) {
389 0 1 if((hv_store(bag_hv, "type", strlen("type"), value, 0)) == NULL)
405 0 0 if(bag_hv)
421 68 33 if(hash) {
424 122 101 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
425 75 47 if(hash)
427 0 122 if (!dump_certs_pkeys_bag (aTHX_ bio, sk_PKCS12_SAFEBAG_value (bags, i), pass, passlen, options, pempass, enc, bag_hv)) {
430 75 47 if(hash)
434 68 33 if (hash) {
437 68 0 if (hv_exists(bag_hv, "type", strlen("type"))) {
439 68 0 if (svp != NULL)
442 68 0 if (svp != NULL) {
443 1 67 if (strcmp(type, "safe_contents_bag") == 0 ) {
444 0 1 if((hv_store(hash, "safe_contents_bag", strlen("safe_contents_bag"), newRV_inc((SV *) bags_av), 0)) == NULL)
447 0 67 if((hv_store(hash, "bags", strlen("bags"), newRV_inc((SV *) bags_av), 0)) == NULL)
467 0 77 if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL) {
472 99 77 for (i = 0; i < sk_PKCS7_num(asafes); i++) {
474 67 32 if (orig_hash) {
483 26 73 if (bagnid == NID_pkcs7_data) {
485 18 8 if (options & INFO) {
486 9 9 if (orig_hash) {
495 73 0 } else if (bagnid == NID_pkcs7_encrypted) {
496 65 8 if (options & INFO) {
497 58 7 if (orig_hash) {
500 58 0 if (p7->d.encrypted != NULL)
502 0 58 if((hv_store(bag_hv, "parameters", strlen("parameters"), newRV_inc((SV *) parameters_hv), 0)) == NULL)
504 0 58 if((hv_store(orig_hash, "pkcs7_encrypted_data", strlen("pkcs7_encrypted_data"), newRV_inc((SV *) bag_hv), 0)) == NULL)
509 0 7 if (p7->d.encrypted == NULL) {
522 0 99 if (bags == NULL) return 0;
524 0 99 if (!dump_certs_pkeys_bags(aTHX_ bio, bags, pass, passlen, options, pempass, enc, bag_hv)) {
529 67 32 if (orig_hash) {
530 0 67 if((hv_store(orig_hash, "pkcs7_data", strlen("pkcs7_data"), newRV_inc((SV *) pkcs7_bags_av), 0)) == NULL)
532 0 67 if((hv_store(orig_hash, "pkcs7_encrypted_data", strlen("pkcs7_encrypted_data"), newRV_inc((SV *) pkcs7_enc_bags_av), 0)) == NULL)
572 0 64 nmflag_set ? nmflag : ESC_FLAGS | XN_FLAG_SEP_CPLUS_SPC | ASN1_STRFLGS_UTF8_CONVERT | XN_FLAG_SPC_EQ;
582 0 64 if (out == NULL)
584 64 0 if (title != NULL)
586 0 64 if ((lflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
590 0 64 if (lflags == XN_FLAG_COMPAT) {
596 0 64 if (mline)
613 0 16 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
623 0 16 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
633 1607 119 for (i = 0; i < len; i++) {
634 119 1488 if (i == (len-1))
644 230 17 for (i = 0; i < len; i++)
661 73 0 if (length < 0 || length > (INT_MAX - 1))
0 73 if (length < 0 || length > (INT_MAX - 1))
664 62 11 if(*attribute != NULL) {
675 52 1 if(*attribute != NULL) {
676 52 0 if (length < 0 || length > (INT_MAX - 1))
0 52 if (length < 0 || length > (INT_MAX - 1))
679 52 0 if (length)
689 118 16 if(*attribute != NULL) {
690 118 0 if (length < 0 || length > INT_MAX / 4)
0 118 if (length < 0 || length > INT_MAX / 4)
702 1 1 if(*attribute != NULL) {
703 1 0 if (length < 0 || length > INT_MAX / 4)
0 1 if (length < 0 || length > INT_MAX / 4)
728 2 2 if(*attribute != NULL) {
748 24 87 if (!attrlst) {
749 12 12 if(hash) {
758 0 87 if (!sk_X509_ATTRIBUTE_num(attrlst)) {
759 0 0 if(hash) {
767 18 69 if(!hash)
771 213 87 for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
776 30 183 if (!hash) {
777 3 27 if (attr_nid == NID_undef) {
783 27 0 if (!hash) {
791 213 0 if (X509_ATTRIBUTE_count(attr)) {
792 213 213 for (j = 0; j < X509_ATTRIBUTE_count(attr); j++)
796 183 30 if(hash) {
800 129 54 if (attr_nid != NID_undef) {
803 129 0 if (attribute_id) {
804 0 129 if((hv_store(bag_hv, attribute_id, strlen(attribute_id), newSVpvn(attribute_value, strlen(attribute_value)), 0)) == NULL)
811 0 54 CHECK_OPEN_SSL(attr_bio = BIO_new(BIO_s_mem()));
814 0 54 CHECK_OPEN_SSL(BIO_flush(attr_bio) == 1);
817 54 0 if (bptr->length > 0) {
818 0 54 if((hv_store(bag_hv, bptr->data, bptr->length, newSVpvn(attribute_value, strlen(attribute_value)), 0)) == NULL)
822 0 54 CHECK_OPEN_SSL(BIO_set_close(attr_bio, BIO_CLOSE) == 1);
835 69 18 if (hash) {
836 0 69 if((hv_store(hash, name, strlen(name), newRV_inc((SV *) bag_hv), 0)) == NULL)
851 63 12 if (parameters_hash) {
853 0 63 if((hv_store(parameters_hash, "nid_long_name", strlen("nid_long_name"), nid_long_name, 0)) == NULL)
856 0 63 if((hv_store(parameters_hash, "nid_short_name", strlen("nid_short_name"), nid_short_name, 0)) == NULL)
865 14 61 if (pbenid == NID_pbes2) {
868 14 0 if (aparamtype == V_ASN1_SEQUENCE)
870 0 14 if (pbe2 == NULL) {
879 7 7 if (parameters_hash) {
881 0 7 if((hv_store(parameters_hash, "nid_long_name", strlen("nid_long_name"), nid_long_name, 0)) == NULL)
884 0 7 if((hv_store(parameters_hash, "nid_short_name", strlen("nid_short_name"), nid_short_name, 0)) == NULL)
890 14 0 if (pbenid == NID_id_pbkdf2) {
893 14 0 if (aparamtype == V_ASN1_SEQUENCE)
895 0 14 if (kdf == NULL) {
900 0 14 if (kdf->prf == NULL) {
906 7 7 if (parameters_hash) {
908 0 7 if((hv_store(parameters_hash, "iteration", strlen("iteration"), iteration, 0)) == NULL)
917 0 0 } else if (pbenid == NID_id_scrypt) {
920 0 0 if (aparamtype == V_ASN1_SEQUENCE)
922 0 0 if (kdf == NULL) {
926 0 0 if (parameters_hash) {
927 0 0 if((hv_store(parameters_hash, "salt_length", strlen("salt_length"), newSViv(ASN1_STRING_length(kdf->salt)), 0)) == NULL)
929 0 0 if((hv_store(parameters_hash, "cost", strlen("cost"), newSViv(ASN1_INTEGER_get(kdf->costParameter)), 0)) == NULL)
931 0 0 if((hv_store(parameters_hash, "block_size", strlen("block_size"), newSViv(ASN1_INTEGER_get(kdf->blockSize)), 0)) == NULL)
933 0 0 if((hv_store(parameters_hash, "parallelism", strlen("parallelism"), newSViv(ASN1_INTEGER_get(kdf->parallelizationParameter)), 0)) == NULL)
949 61 0 if (aparamtype == V_ASN1_SEQUENCE)
951 0 61 if (pbe == NULL) {
955 56 5 if (parameters_hash) {
958 0 56 if((hv_store(parameters_hash, "iteration", strlen("iteration"), iteration, 0)) == NULL)
965 12 63 if(!parameters_hash)
993 80 16 for (i = 0; (name = Crypt__OpenSSL__PKCS12__const[i].n); i++) {
1004 0 0 if ((RETVAL = PKCS12_new()) == NULL) {
1017 1 0 if (legacy)
1039 0 36 SvGETMAGIC(string);
0 0 SvGETMAGIC(string);
1043 0 36 if (legacy == NULL) {
1047 0 36 if (deflt == NULL) {
1053 12 24 if (SvPOKp(string) || SvNOKp(string) || SvIOKp(string)) {
10 2 if (SvPOKp(string) || SvNOKp(string) || SvIOKp(string)) {
2 8 if (SvPOKp(string) || SvNOKp(string) || SvIOKp(string)) {
1054 15 13 if (ix == 1) {
1063 4 9 if (SvUTF8(string)) {
1072 24 0 if (!str_ptr || !str_len) croak("PKCS12_new_from: No string or file was passed.");
0 24 if (!str_ptr || !str_len) croak("PKCS12_new_from: No string or file was passed.");
1074 15 9 if (ix == 1) {
1080 0 24 if (!bio) croak("Failed to create BIO");
1083 6 18 if ((RETVAL = d2i_PKCS12_bio(bio, 0)) == NULL) {
1099 18 0 if (pkcs12) {
1124 0 3 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1126 0 3 if (!(i2d_PKCS12_bio(bio, pkcs12))) {
1143 9 0 const char *pwd_str = "";
1147 9 0 if (SvOK(pwd)) {
1149 0 9 if (pwd_len > (STRLEN)INT_MAX)
1153 1 8 if (!(PKCS12_verify_mac(pkcs12, pwd_str, (int)pwd_len)))
1170 0 0 const char *newpwd_str = "";
1174 0 0 if (SvOK(oldpwd)) {
1176 0 0 if (memchr(oldpwd_str, '\0', oldpwd_len) != NULL)
1180 0 0 if (SvOK(newpwd)) {
1182 0 0 if (memchr(newpwd_str, '\0', newpwd_len) != NULL)
1187 0 0 if (!(PKCS12_newpass(pkcs12, oldpwd_str, newpwd_str))) {
1211 0 4 const char *pass_str = NULL;
1215 4 0 if (SvOK(pass)) {
1217 1 3 if (memchr(pass_str, '\0', pass_len) != NULL)
1226 0 3 if (!p12) {
1231 0 3 if (!(fp = fopen(file, "wb"))) {
1259 0 2 const char *pass_str = NULL;
1263 2 0 if (SvOK(pass)) {
1265 1 1 if (memchr(pass_str, '\0', pass_len) != NULL)
1274 0 1 if (!p12) {
1279 0 1 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1297 4 0 const char *pwd_str = "";
1301 4 0 if (SvOK(pwd)) {
1303 0 4 if (pwd_len > (STRLEN)INT_MAX)
1307 0 4 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1309 0 4 if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
1328 1 0 const char *pwd_str = "";
1332 1 0 if (SvOK(pwd)) {
1334 0 1 if (pwd_len > (STRLEN)INT_MAX)
1338 0 1 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1340 0 1 if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
1358 3 0 const char *pwd_str = "";
1362 3 0 if (SvOK(pwd)) {
1364 0 3 if (pwd_len > (STRLEN)INT_MAX)
1368 0 3 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1387 60 0 const char *pwd_str = "";
1399 60 0 if (SvOK(pwd)) {
1401 0 60 if (pwd_len > (STRLEN)INT_MAX)
1406 0 60 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1408 0 60 if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
1418 0 60 if((hv_store(mac, "digest", strlen("digest"), value, 0)) == NULL)
1423 60 0 SV * mac_iteration = newSViv (tmaciter != NULL ? ASN1_INTEGER_get(tmaciter) : 1L);
1425 0 60 if((hv_store(mac, "iteration", strlen("iteration"), mac_iteration, 0)) == NULL)
1427 0 60 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1430 60 0 SV * mac_len = newSViv(tmac != NULL ? ASN1_STRING_length(tmac) : 0L);
1431 60 0 SV * salt_len = newSViv(tsalt != NULL ? ASN1_STRING_length(tsalt) : 0L);
1433 0 60 if((hv_store(mac, "length", 6, mac_len, 0)) == NULL)
1439 0 60 if((hv_store(mac, "salt_length", strlen("salt_length"), INT2PTR(SV*, salt_len), 0)) == NULL)
1442 0 60 if((hv_store(RETVAL, "mac", strlen("mac"), newRV_inc((SV *) mac), 0)) == NULL)
1448 0 60 if (SvPOK(end)) {
1449 0 0 if (SvCUR(end) != 0)
1468 9 0 const char *pwd_str = "";
1479 9 0 if (SvOK(pwd)) {
1481 0 9 if (pwd_len > (STRLEN)INT_MAX)
1485 0 9 CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
1487 0 9 if ((asafes = PKCS12_unpack_authsafes(pkcs12)) == NULL)
1499 9 0 tmaciter != NULL ? ASN1_INTEGER_get(tmaciter) : 1L);
1501 9 0 tmac != NULL ? ASN1_STRING_length(tmac) : 0L,
1502 9 0 tsalt != NULL ? ASN1_STRING_length(tsalt) : 0L);