Branch Coverage

src/pdfmake_x509.c
Criterion Covered Total %
branch 112 454 24.6


line true false branch
50 0 0 for (i = 0; i < src_len && out < dst_len; i++) {
0 0 for (i = 0; i < src_len && out < dst_len; i++) {
52 0 0 if (val == -1) continue; /* Skip whitespace */
53 0 0 if (val == -2) break; /* Padding '=' */
58 0 0 if (bits >= 8) {
76 0 1 if (!hex) return NULL;
79 20 1 for (i = 0; i < len; i++) {
80 19 1 if (i > 0) *p++ = ':';
92 0 1 if (!oid) return PDFMAKE_SIG_UNKNOWN;
94 0 1 if (strcmp(oid, OID_RSA_MD5) == 0) return PDFMAKE_SIG_RSA_MD5;
95 0 1 if (strcmp(oid, OID_RSA_SHA1) == 0) return PDFMAKE_SIG_RSA_SHA1;
96 1 0 if (strcmp(oid, OID_RSA_SHA256) == 0) return PDFMAKE_SIG_RSA_SHA256;
97 0 0 if (strcmp(oid, OID_RSA_SHA384) == 0) return PDFMAKE_SIG_RSA_SHA384;
98 0 0 if (strcmp(oid, OID_RSA_SHA512) == 0) return PDFMAKE_SIG_RSA_SHA512;
99 0 0 if (strcmp(oid, OID_ECDSA_SHA256) == 0) return PDFMAKE_SIG_ECDSA_SHA256;
100 0 0 if (strcmp(oid, OID_ECDSA_SHA384) == 0) return PDFMAKE_SIG_ECDSA_SHA384;
101 0 0 if (strcmp(oid, OID_ECDSA_SHA512) == 0) return PDFMAKE_SIG_ECDSA_SHA512;
117 0 2 if (!pdfmake_asn1_is_sequence(name_node)) {
130 6 2 while (rdn) {
131 6 0 if (pdfmake_asn1_is_set(rdn)) {
133 6 6 while (atv) {
134 6 0 if (pdfmake_asn1_is_sequence(atv)) {
138 6 0 if (oid_node && val_node) {
6 0 if (oid_node && val_node) {
142 6 0 if (oid && val) {
6 0 if (oid && val) {
146 2 4 if (strcmp(oid, OID_COMMON_NAME) == 0) {
149 2 2 } else if (strcmp(oid, OID_ORGANIZATION) == 0) {
152 0 2 } else if (strcmp(oid, OID_ORGANIZATIONAL_UNIT) == 0) {
155 2 0 } else if (strcmp(oid, OID_COUNTRY) == 0) {
158 0 0 } else if (strcmp(oid, OID_STATE) == 0) {
161 0 0 } else if (strcmp(oid, OID_LOCALITY) == 0) {
164 0 0 } else if (strcmp(oid, OID_EMAIL_ADDRESS) == 0) {
167 0 0 } else if (strcmp(oid, OID_SERIAL_NUMBER) == 0) {
172 6 0 if (target) {
177 6 0 if (attr_name && dn_p < dn_end) {
6 0 if (attr_name && dn_p < dn_end) {
178 4 2 if (dn_p > dn_buf) {
203 0 1 if (!pdfmake_asn1_is_sequence(alg_node)) {
208 0 1 if (!oid_node) return NULL;
229 0 1 if (!pdfmake_asn1_is_sequence(spki)) {
240 1 0 if (!alg_node || !key_node) return;
0 1 if (!alg_node || !key_node) return;
248 0 1 if (!oid_node) return;
251 0 1 if (!oid) return;
253 0 1 if (pdfmake_asn1_get_bit_string(key_node, &bits, &bit_count) != 0) {
257 1 0 if (strcmp(oid, OID_RSA_ENCRYPTION) == 0) {
264 1 0 if (pdfmake_asn1_is_sequence(rsa_key)) {
268 1 0 if (mod && exp) {
1 0 if (mod && exp) {
275 0 0 } else if (strcmp(oid, OID_EC_PUBLIC_KEY) == 0) {
280 0 0 if (param && param->tag == ASN1_TAG_OID) {
0 0 if (param && param->tag == ASN1_TAG_OID) {
284 0 0 if (pdfmake_asn1_oid_equals(param, OID_SECP256R1)) {
286 0 0 } else if (pdfmake_asn1_oid_equals(param, OID_SECP384R1)) {
288 0 0 } else if (pdfmake_asn1_oid_equals(param, OID_SECP521R1)) {
314 0 3 if (!oid_node) return;
318 4 0 while (child) {
319 3 1 if (child->tag == ASN1_TAG_OCTET_STRING) {
325 0 3 if (!value_node) return;
330 0 3 if (!ext_value) return;
333 1 2 if (pdfmake_asn1_oid_equals(oid_node, OID_BASIC_CONSTRAINTS)) {
336 1 0 if (pdfmake_asn1_is_sequence(ext_value)) {
340 1 0 if (ca_node) {
342 1 0 if (pdfmake_asn1_get_bool(ca_node, &is_ca) == 0) {
346 0 1 if (path_node) {
348 0 0 if (pdfmake_asn1_get_int64(path_node, &path_len) == 0) {
355 0 2 else if (pdfmake_asn1_oid_equals(oid_node, OID_KEY_USAGE)) {
357 0 0 if (ext_value->tag == ASN1_TAG_BIT_STRING) {
360 0 0 if (pdfmake_asn1_get_bit_string(ext_value, &bits, &bit_count) == 0 && bit_count > 0) {
0 0 if (pdfmake_asn1_get_bit_string(ext_value, &bits, &bit_count) == 0 && bit_count > 0) {
363 0 0 if (bit_count > 0) ku |= (bits[0] & 0x80) ? PDFMAKE_KU_DIGITAL_SIGNATURE : 0;
364 0 0 if (bit_count > 1) ku |= (bits[0] & 0x40) ? PDFMAKE_KU_NON_REPUDIATION : 0;
365 0 0 if (bit_count > 2) ku |= (bits[0] & 0x20) ? PDFMAKE_KU_KEY_ENCIPHERMENT : 0;
366 0 0 if (bit_count > 3) ku |= (bits[0] & 0x10) ? PDFMAKE_KU_DATA_ENCIPHERMENT : 0;
367 0 0 if (bit_count > 4) ku |= (bits[0] & 0x08) ? PDFMAKE_KU_KEY_AGREEMENT : 0;
368 0 0 if (bit_count > 5) ku |= (bits[0] & 0x04) ? PDFMAKE_KU_KEY_CERT_SIGN : 0;
369 0 0 if (bit_count > 6) ku |= (bits[0] & 0x02) ? PDFMAKE_KU_CRL_SIGN : 0;
370 0 0 if (bit_count > 7) ku |= (bits[0] & 0x01) ? PDFMAKE_KU_ENCIPHER_ONLY : 0;
376 0 2 else if (pdfmake_asn1_oid_equals(oid_node, OID_EXT_KEY_USAGE)) {
378 0 0 if (pdfmake_asn1_is_sequence(ext_value)) {
380 0 0 while (eku) {
381 0 0 if (eku->tag == ASN1_TAG_OID) {
382 0 0 if (pdfmake_asn1_oid_equals(eku, OID_EKU_SERVER_AUTH)) {
384 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_CLIENT_AUTH)) {
386 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_CODE_SIGNING)) {
388 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_EMAIL_PROTECTION)) {
390 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_TIME_STAMPING)) {
392 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_OCSP_SIGNING)) {
394 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_PDF_SIGNING)) {
396 0 0 } else if (pdfmake_asn1_oid_equals(eku, OID_EKU_DOCUMENT_SIGNING)) {
405 1 1 else if (pdfmake_asn1_oid_equals(oid_node, OID_SUBJECT_KEY_ID)) {
407 1 0 if (ext_value->tag == ASN1_TAG_OCTET_STRING) {
413 1 0 else if (pdfmake_asn1_oid_equals(oid_node, OID_AUTHORITY_KEY_ID)) {
415 1 0 if (pdfmake_asn1_is_sequence(ext_value)) {
417 1 0 while (kid) {
418 1 0 if ((kid->tag & 0x1F) == 0 && (kid->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
1 0 if ((kid->tag & 0x1F) == 0 && (kid->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
429 0 0 else if (pdfmake_asn1_oid_equals(oid_node, OID_AUTHORITY_INFO_ACCESS)) {
432 0 0 if (pdfmake_asn1_is_sequence(ext_value)) {
434 0 0 while (ad) {
435 0 0 if (pdfmake_asn1_is_sequence(ad)) {
439 0 0 if (method && location && pdfmake_asn1_oid_equals(method, OID_OCSP)) {
0 0 if (method && location && pdfmake_asn1_oid_equals(method, OID_OCSP)) {
0 0 if (method && location && pdfmake_asn1_oid_equals(method, OID_OCSP)) {
441 0 0 if ((location->tag & 0x1F) == 6 &&
442 0 0 (location->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
444 0 0 if (url) {
457 0 0 else if (pdfmake_asn1_oid_equals(oid_node, OID_CRL_DISTRIBUTION)) {
459 0 0 if (pdfmake_asn1_is_sequence(ext_value)) {
461 0 0 while (dp && !cert->crl_distribution) {
0 0 while (dp && !cert->crl_distribution) {
462 0 0 if (pdfmake_asn1_is_sequence(dp)) {
465 0 0 while (dpname && !cert->crl_distribution) {
0 0 while (dpname && !cert->crl_distribution) {
466 0 0 if ((dpname->tag & 0x1F) == 0 &&
467 0 0 (dpname->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT &&
468 0 0 (dpname->tag & ASN1_CONSTRUCTED)) {
471 0 0 while (gn && !cert->crl_distribution) {
0 0 while (gn && !cert->crl_distribution) {
473 0 0 if ((gn->tag & 0x1F) == 6 &&
474 0 0 (gn->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
476 0 0 if (url) {
502 0 1 if (!extensions) return;
506 3 1 while (ext) {
507 3 0 if (pdfmake_asn1_is_sequence(ext)) {
533 1 0 if (!arena || !der || len == 0) return NULL;
1 0 if (!arena || !der || len == 0) return NULL;
0 1 if (!arena || !der || len == 0) return NULL;
537 0 1 if (!pdfmake_asn1_is_sequence(root)) {
550 1 0 if (!tbs || !sig_alg || !sig_val) {
1 0 if (!tbs || !sig_alg || !sig_val) {
0 1 if (!tbs || !sig_alg || !sig_val) {
556 0 1 if (!cert) return NULL;
567 1 0 cert->tbs_certificate_len = tbs->length + 2 + (tbs->length < 0x80 ? 0 :
568 1 0 tbs->length < 0x100 ? 1 :
569 1 0 tbs->length < 0x10000 ? 2 : 3);
573 1 0 tbs_offset = (tbs->children ? tbs->children->data : tbs->data) - der;
575 6 0 while (tbs_offset > 0 && der[tbs_offset - 1] != (ASN1_TAG_SEQUENCE | ASN1_CONSTRUCTED)) {
5 1 while (tbs_offset > 0 && der[tbs_offset - 1] != (ASN1_TAG_SEQUENCE | ASN1_CONSTRUCTED)) {
578 1 0 if (tbs_offset > 0) tbs_offset--;
588 1 0 if (pdfmake_asn1_get_bit_string(sig_val, &sig_bits, &sig_bit_count) == 0) {
604 0 1 if (!pdfmake_asn1_is_sequence(tbs)) {
611 1 0 if (field && (field->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT &&
1 0 if (field && (field->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT &&
612 1 0 (field->tag & 0x1F) == 0) {
614 1 0 if (ver) {
616 1 0 if (pdfmake_asn1_get_int64(ver, &v) == 0) {
624 1 0 if (field && field->tag == ASN1_TAG_INTEGER) {
1 0 if (field && field->tag == ASN1_TAG_INTEGER) {
632 1 0 if (field) {
637 1 0 if (field) {
643 1 0 if (pdfmake_asn1_is_sequence(field)) {
647 1 0 if (not_before) pdfmake_asn1_get_time(not_before, &cert->not_before);
648 1 0 if (not_after) pdfmake_asn1_get_time(not_after, &cert->not_after);
654 1 0 if (field) {
660 1 0 if (field) {
666 1 1 while (field && (field->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
1 0 while (field && (field->tag & ASN1_CLASS_MASK) == ASN1_CLASS_CONTEXT) {
667 1 0 if ((field->tag & 0x1F) == 3) {
669 1 0 if (field->children) {
677 1 0 if (cert->issuer.dn && cert->subject.dn &&
1 0 if (cert->issuer.dn && cert->subject.dn &&
678 1 0 strcmp(cert->issuer.dn, cert->subject.dn) == 0) {
697 0 0 if (!arena || !pem || len == 0) return NULL;
0 0 if (!arena || !pem || len == 0) return NULL;
0 0 if (!arena || !pem || len == 0) return NULL;
701 0 0 if (!begin) return NULL;
706 0 0 if (!end) return NULL;
712 0 0 if (!der) return NULL;
716 0 0 if (der_len == 0) return NULL;
734 0 0 if (!arena || !pem || len == 0) return NULL;
0 0 if (!arena || !pem || len == 0) return NULL;
0 0 if (!arena || !pem || len == 0) return NULL;
737 0 0 if (!chain) return NULL;
745 0 0 while (p < end) {
747 0 0 if (!begin || begin >= end) break;
0 0 if (!begin || begin >= end) break;
750 0 0 if (!cert_end || cert_end >= end) break;
0 0 if (!cert_end || cert_end >= end) break;
754 0 0 if (cert) {
755 0 0 if (last) {
778 0 0 if (!arena || !path) return NULL;
0 0 if (!arena || !path) return NULL;
781 0 0 if (!f) return NULL;
788 0 0 if (size <= 0 || size > 1024 * 1024) { /* Max 1MB */
0 0 if (size <= 0 || size > 1024 * 1024) { /* Max 1MB */
795 0 0 if (!data) {
800 0 0 if (fread(data, 1, size, f) != (size_t)size) {
807 0 0 if (size > 27 && memcmp(data, "-----BEGIN", 10) == 0) {
0 0 if (size > 27 && memcmp(data, "-----BEGIN", 10) == 0) {
819 0 0 if (!cert) return 0;
821 0 0 if (check_time == 0) {
825 0 0 return (check_time >= cert->not_before && check_time <= cert->not_after);
0 0 return (check_time >= cert->not_before && check_time <= cert->not_after);
830 0 1 if (!cert) return 0;
833 0 1 if (cert->key_usage != 0) {
835 0 0 if (!(cert->key_usage & (PDFMAKE_KU_DIGITAL_SIGNATURE | PDFMAKE_KU_NON_REPUDIATION))) {
841 0 1 if (cert->ext_key_usage != 0) {
845 0 0 if (!(cert->ext_key_usage & signing_ekus)) {
861 0 0 if (!arena || !name) return NULL;
0 0 if (!arena || !name) return NULL;
864 0 0 if (name->dn) {
872 0 0 if (name->common_name) {
875 0 0 if (name->organization && p < end) {
0 0 if (name->organization && p < end) {
876 0 0 if (p > buf) p += snprintf(p, end - p, ", ");
879 0 0 if (name->organizational_unit && p < end) {
0 0 if (name->organizational_unit && p < end) {
880 0 0 if (p > buf) p += snprintf(p, end - p, ", ");
883 0 0 if (name->locality && p < end) {
0 0 if (name->locality && p < end) {
884 0 0 if (p > buf) p += snprintf(p, end - p, ", ");
887 0 0 if (name->state && p < end) {
0 0 if (name->state && p < end) {
888 0 0 if (p > buf) p += snprintf(p, end - p, ", ");
891 0 0 if (name->country && p < end) {
0 0 if (name->country && p < end) {
892 0 0 if (p > buf) p += snprintf(p, end - p, ", ");
937 0 0 if (!cert) return PDFMAKE_EINVAL;
939 0 0 if (!issuer && cert->is_self_signed) {
0 0 if (!issuer && cert->is_self_signed) {
944 0 0 if (issuer) {
965 0 0 if (!chain || chain->count == 0) return PDFMAKE_EINVAL;
0 0 if (!chain || chain->count == 0) return PDFMAKE_EINVAL;
970 0 0 while (cert) {
971 0 0 if (!pdfmake_x509_is_valid(cert, 0)) {