Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/pkcs7/pk7_attr.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||
2 | * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
3 | * | - | ||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||
8 | */ | - | ||||||||||||
9 | - | |||||||||||||
10 | #include <stdio.h> | - | ||||||||||||
11 | #include <stdlib.h> | - | ||||||||||||
12 | #include <openssl/bio.h> | - | ||||||||||||
13 | #include <openssl/asn1.h> | - | ||||||||||||
14 | #include <openssl/asn1t.h> | - | ||||||||||||
15 | #include <openssl/pem.h> | - | ||||||||||||
16 | #include <openssl/pkcs7.h> | - | ||||||||||||
17 | #include <openssl/x509.h> | - | ||||||||||||
18 | #include <openssl/err.h> | - | ||||||||||||
19 | - | |||||||||||||
20 | int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, | - | ||||||||||||
21 | STACK_OF(X509_ALGOR) *cap) | - | ||||||||||||
22 | { | - | ||||||||||||
23 | ASN1_STRING *seq; | - | ||||||||||||
24 | - | |||||||||||||
25 | if ((seq = ASN1_STRING_new()) == NULL) {
| 0-20 | ||||||||||||
26 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
27 | return 0; never executed: return 0; | 0 | ||||||||||||
28 | } | - | ||||||||||||
29 | seq->length = ASN1_item_i2d((ASN1_VALUE *)cap, &seq->data, | - | ||||||||||||
30 | ASN1_ITEM_rptr(X509_ALGORS)); | - | ||||||||||||
31 | return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, executed 20 times by 1 test: return PKCS7_add_signed_attribute(si, 167, 16, seq); Executed by:
| 20 | ||||||||||||
32 | V_ASN1_SEQUENCE, seq); executed 20 times by 1 test: return PKCS7_add_signed_attribute(si, 167, 16, seq); Executed by:
| 20 | ||||||||||||
33 | } | - | ||||||||||||
34 | - | |||||||||||||
35 | STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) | - | ||||||||||||
36 | { | - | ||||||||||||
37 | ASN1_TYPE *cap; | - | ||||||||||||
38 | const unsigned char *p; | - | ||||||||||||
39 | - | |||||||||||||
40 | cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); | - | ||||||||||||
41 | if (cap == NULL || (cap->type != V_ASN1_SEQUENCE))
| 0 | ||||||||||||
42 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
43 | p = cap->value.sequence->data; | - | ||||||||||||
44 | return (STACK_OF(X509_ALGOR) *) never executed: return (struct stack_st_X509_ALGOR *) ASN1_item_d2i( ((void *)0) , &p, cap->value.sequence->length, (&(X509_ALGORS_it))); | 0 | ||||||||||||
45 | ASN1_item_d2i(NULL, &p, cap->value.sequence->length, never executed: return (struct stack_st_X509_ALGOR *) ASN1_item_d2i( ((void *)0) , &p, cap->value.sequence->length, (&(X509_ALGORS_it))); | 0 | ||||||||||||
46 | ASN1_ITEM_rptr(X509_ALGORS)); never executed: return (struct stack_st_X509_ALGOR *) ASN1_item_d2i( ((void *)0) , &p, cap->value.sequence->length, (&(X509_ALGORS_it))); | 0 | ||||||||||||
47 | } | - | ||||||||||||
48 | - | |||||||||||||
49 | /* Basic smime-capabilities OID and optional integer arg */ | - | ||||||||||||
50 | int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) | - | ||||||||||||
51 | { | - | ||||||||||||
52 | ASN1_INTEGER *nbit = NULL; | - | ||||||||||||
53 | X509_ALGOR *alg; | - | ||||||||||||
54 | - | |||||||||||||
55 | if ((alg = X509_ALGOR_new()) == NULL) {
| 0-160 | ||||||||||||
56 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
57 | return 0; never executed: return 0; | 0 | ||||||||||||
58 | } | - | ||||||||||||
59 | ASN1_OBJECT_free(alg->algorithm); | - | ||||||||||||
60 | alg->algorithm = OBJ_nid2obj(nid); | - | ||||||||||||
61 | if (arg > 0) {
| 60-100 | ||||||||||||
62 | if ((alg->parameter = ASN1_TYPE_new()) == NULL) {
| 0-60 | ||||||||||||
63 | goto err; never executed: goto err; | 0 | ||||||||||||
64 | } | - | ||||||||||||
65 | if ((nbit = ASN1_INTEGER_new()) == NULL) {
| 0-60 | ||||||||||||
66 | goto err; never executed: goto err; | 0 | ||||||||||||
67 | } | - | ||||||||||||
68 | if (!ASN1_INTEGER_set(nbit, arg)) {
| 0-60 | ||||||||||||
69 | goto err; never executed: goto err; | 0 | ||||||||||||
70 | } | - | ||||||||||||
71 | alg->parameter->value.integer = nbit; | - | ||||||||||||
72 | alg->parameter->type = V_ASN1_INTEGER; | - | ||||||||||||
73 | nbit = NULL; | - | ||||||||||||
74 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||
75 | if (!sk_X509_ALGOR_push(sk, alg)) {
| 0-160 | ||||||||||||
76 | goto err; never executed: goto err; | 0 | ||||||||||||
77 | } | - | ||||||||||||
78 | return 1; executed 160 times by 1 test: return 1; Executed by:
| 160 | ||||||||||||
79 | err: | - | ||||||||||||
80 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
81 | ASN1_INTEGER_free(nbit); | - | ||||||||||||
82 | X509_ALGOR_free(alg); | - | ||||||||||||
83 | return 0; never executed: return 0; | 0 | ||||||||||||
84 | } | - | ||||||||||||
85 | - | |||||||||||||
86 | int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid) | - | ||||||||||||
87 | { | - | ||||||||||||
88 | if (PKCS7_get_signed_attribute(si, NID_pkcs9_contentType))
| 0-20 | ||||||||||||
89 | return 0; never executed: return 0; | 0 | ||||||||||||
90 | if (!coid)
| 0-20 | ||||||||||||
91 | coid = OBJ_nid2obj(NID_pkcs7_data); executed 20 times by 1 test: coid = OBJ_nid2obj(21); Executed by:
| 20 | ||||||||||||
92 | return PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, executed 20 times by 1 test: return PKCS7_add_signed_attribute(si, 50, 6, coid); Executed by:
| 20 | ||||||||||||
93 | V_ASN1_OBJECT, coid); executed 20 times by 1 test: return PKCS7_add_signed_attribute(si, 50, 6, coid); Executed by:
| 20 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | if (t == NULL && (t = X509_gmtime_adj(NULL, 0)) == NULL) {
| 0-19 | ||||||||||||
99 | PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME, | - | ||||||||||||
100 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
101 | return 0; never executed: return 0; | 0 | ||||||||||||
102 | } | - | ||||||||||||
103 | return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, executed 19 times by 1 test: return PKCS7_add_signed_attribute(si, 52, 23, t); Executed by:
| 19 | ||||||||||||
104 | V_ASN1_UTCTIME, t); executed 19 times by 1 test: return PKCS7_add_signed_attribute(si, 52, 23, t); Executed by:
| 19 | ||||||||||||
105 | } | - | ||||||||||||
106 | - | |||||||||||||
107 | int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, | - | ||||||||||||
108 | const unsigned char *md, int mdlen) | - | ||||||||||||
109 | { | - | ||||||||||||
110 | ASN1_OCTET_STRING *os; | - | ||||||||||||
111 | os = ASN1_OCTET_STRING_new(); | - | ||||||||||||
112 | if (os == NULL)
| 0-20 | ||||||||||||
113 | return 0; never executed: return 0; | 0 | ||||||||||||
114 | if (!ASN1_STRING_set(os, md, mdlen)
| 0-20 | ||||||||||||
115 | || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest,
| 0-20 | ||||||||||||
116 | V_ASN1_OCTET_STRING, os)) {
| 0-20 | ||||||||||||
117 | ASN1_OCTET_STRING_free(os); | - | ||||||||||||
118 | return 0; never executed: return 0; | 0 | ||||||||||||
119 | } | - | ||||||||||||
120 | return 1; executed 20 times by 1 test: return 1; Executed by:
| 20 | ||||||||||||
121 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |