OpenCoverage

x509_set.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/x509_set.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2017 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 "internal/cryptlib.h"-
12#include "internal/refcount.h"-
13#include <openssl/asn1.h>-
14#include <openssl/objects.h>-
15#include <openssl/evp.h>-
16#include <openssl/x509.h>-
17#include <openssl/x509v3.h>-
18#include "internal/asn1_int.h"-
19#include "internal/x509_int.h"-
20#include "x509_lcl.h"-
21-
22int X509_set_version(X509 *x, long version)-
23{-
24 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 518 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-518
25 return 0;
never executed: return 0;
0
26 if (version == 0) {
version == 0Description
TRUEnever evaluated
FALSEevaluated 518 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-518
27 ASN1_INTEGER_free(x->cert_info.version);-
28 x->cert_info.version = NULL;-
29 return 1;
never executed: return 1;
0
30 }-
31 if (x->cert_info.version == NULL) {
x->cert_info.v...== ((void *)0)Description
TRUEevaluated 518 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-518
32 if ((x->cert_info.version = ASN1_INTEGER_new()) == NULL)
(x->cert_info....== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 518 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-518
33 return 0;
never executed: return 0;
0
34 }
executed 518 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
518
35 return ASN1_INTEGER_set(x->cert_info.version, version);
executed 518 times by 1 test: return ASN1_INTEGER_set(x->cert_info.version, version);
Executed by:
  • libcrypto.so.1.1
518
36}-
37-
38int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)-
39{-
40 ASN1_INTEGER *in;-
41-
42 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11
43 return 0;
never executed: return 0;
0
44 in = &x->cert_info.serialNumber;-
45 if (in != serial)
in != serialDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-11
46 return ASN1_STRING_copy(in, serial);
executed 11 times by 1 test: return ASN1_STRING_copy(in, serial);
Executed by:
  • libcrypto.so.1.1
11
47 return 1;
never executed: return 1;
0
48}-
49-
50int X509_set_issuer_name(X509 *x, X509_NAME *name)-
51{-
52 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-15
53 return 0;
never executed: return 0;
0
54 return X509_NAME_set(&x->cert_info.issuer, name);
executed 15 times by 1 test: return X509_NAME_set(&x->cert_info.issuer, name);
Executed by:
  • libcrypto.so.1.1
15
55}-
56-
57int X509_set_subject_name(X509 *x, X509_NAME *name)-
58{-
59 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 417 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-417
60 return 0;
never executed: return 0;
0
61 return X509_NAME_set(&x->cert_info.subject, name);
executed 417 times by 1 test: return X509_NAME_set(&x->cert_info.subject, name);
Executed by:
  • libcrypto.so.1.1
417
62}-
63-
64int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm)-
65{-
66 ASN1_TIME *in;-
67 in = *ptm;-
68 if (in != tm) {
in != tmDescription
TRUEnever evaluated
FALSEnever evaluated
0
69 in = ASN1_STRING_dup(tm);-
70 if (in != NULL) {
in != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
71 ASN1_TIME_free(*ptm);-
72 *ptm = in;-
73 }
never executed: end of block
0
74 }
never executed: end of block
0
75 return (in != NULL);
never executed: return (in != ((void *)0) );
0
76}-
77-
78int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm)-
79{-
80 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
81 return 0;
never executed: return 0;
0
82 return x509_set1_time(&x->cert_info.validity.notBefore, tm);
never executed: return x509_set1_time(&x->cert_info.validity.notBefore, tm);
0
83}-
84-
85int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm)-
86{-
87 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
88 return 0;
never executed: return 0;
0
89 return x509_set1_time(&x->cert_info.validity.notAfter, tm);
never executed: return x509_set1_time(&x->cert_info.validity.notAfter, tm);
0
90}-
91-
92int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)-
93{-
94 if (x == NULL)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
95 return 0;
never executed: return 0;
0
96 return X509_PUBKEY_set(&(x->cert_info.key), pkey);
executed 10 times by 1 test: return X509_PUBKEY_set(&(x->cert_info.key), pkey);
Executed by:
  • libcrypto.so.1.1
10
97}-
98-
99int X509_up_ref(X509 *x)-
100{-
101 int i;-
102-
103 if (CRYPTO_UP_REF(&x->references, &i, x->lock) <= 0)
CRYPTO_UP_REF(... x->lock) <= 0Description
TRUEnever evaluated
FALSEevaluated 35269 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35269
104 return 0;
never executed: return 0;
0
105-
106 REF_PRINT_COUNT("X509", x);-
107 REF_ASSERT_ISNT(i < 2);-
108 return ((i > 1) ? 1 : 0);
executed 35269 times by 1 test: return ((i > 1) ? 1 : 0);
Executed by:
  • libcrypto.so.1.1
(i > 1)Description
TRUEevaluated 35269 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-35269
109}-
110-
111long X509_get_version(const X509 *x)-
112{-
113 return ASN1_INTEGER_get(x->cert_info.version);
executed 13990 times by 1 test: return ASN1_INTEGER_get(x->cert_info.version);
Executed by:
  • libcrypto.so.1.1
13990
114}-
115-
116const ASN1_TIME *X509_get0_notBefore(const X509 *x)-
117{-
118 return x->cert_info.validity.notBefore;
executed 5637 times by 1 test: return x->cert_info.validity.notBefore;
Executed by:
  • libcrypto.so.1.1
5637
119}-
120-
121const ASN1_TIME *X509_get0_notAfter(const X509 *x)-
122{-
123 return x->cert_info.validity.notAfter;
executed 5399 times by 1 test: return x->cert_info.validity.notAfter;
Executed by:
  • libcrypto.so.1.1
5399
124}-
125-
126ASN1_TIME *X509_getm_notBefore(const X509 *x)-
127{-
128 return x->cert_info.validity.notBefore;
executed 15 times by 1 test: return x->cert_info.validity.notBefore;
Executed by:
  • libcrypto.so.1.1
15
129}-
130-
131ASN1_TIME *X509_getm_notAfter(const X509 *x)-
132{-
133 return x->cert_info.validity.notAfter;
executed 15 times by 1 test: return x->cert_info.validity.notAfter;
Executed by:
  • libcrypto.so.1.1
15
134}-
135-
136int X509_get_signature_type(const X509 *x)-
137{-
138 return EVP_PKEY_type(OBJ_obj2nid(x->sig_alg.algorithm));
never executed: return EVP_PKEY_type(OBJ_obj2nid(x->sig_alg.algorithm));
0
139}-
140-
141X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x)-
142{-
143 return x->cert_info.key;
executed 1373 times by 1 test: return x->cert_info.key;
Executed by:
  • libcrypto.so.1.1
1373
144}-
145-
146const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x)-
147{-
148 return x->cert_info.extensions;
executed 1348 times by 1 test: return x->cert_info.extensions;
Executed by:
  • libcrypto.so.1.1
1348
149}-
150-
151void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid,-
152 const ASN1_BIT_STRING **psuid)-
153{-
154 if (piuid != NULL)
piuid != ((void *)0)Description
TRUEevaluated 1346 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1346
155 *piuid = x->cert_info.issuerUID;
executed 1346 times by 1 test: *piuid = x->cert_info.issuerUID;
Executed by:
  • libcrypto.so.1.1
1346
156 if (psuid != NULL)
psuid != ((void *)0)Description
TRUEevaluated 1346 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1346
157 *psuid = x->cert_info.subjectUID;
executed 1346 times by 1 test: *psuid = x->cert_info.subjectUID;
Executed by:
  • libcrypto.so.1.1
1346
158}
executed 1346 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1346
159-
160const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x)-
161{-
162 return &x->cert_info.signature;
executed 1489 times by 1 test: return &x->cert_info.signature;
Executed by:
  • libcrypto.so.1.1
1489
163}-
164-
165int X509_SIG_INFO_get(const X509_SIG_INFO *siginf, int *mdnid, int *pknid,-
166 int *secbits, uint32_t *flags)-
167{-
168 if (mdnid != NULL)
mdnid != ((void *)0)Description
TRUEevaluated 12007 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1138 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1138-12007
169 *mdnid = siginf->mdnid;
executed 12007 times by 1 test: *mdnid = siginf->mdnid;
Executed by:
  • libcrypto.so.1.1
12007
170 if (pknid != NULL)
pknid != ((void *)0)Description
TRUEevaluated 12007 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1138 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1138-12007
171 *pknid = siginf->pknid;
executed 12007 times by 1 test: *pknid = siginf->pknid;
Executed by:
  • libcrypto.so.1.1
12007
172 if (secbits != NULL)
secbits != ((void *)0)Description
TRUEevaluated 11502 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1643 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1643-11502
173 *secbits = siginf->secbits;
executed 11502 times by 1 test: *secbits = siginf->secbits;
Executed by:
  • libcrypto.so.1.1
11502
174 if (flags != NULL)
flags != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13145 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13145
175 *flags = siginf->flags;
never executed: *flags = siginf->flags;
0
176 return (siginf->flags & X509_SIG_INFO_VALID) != 0;
executed 13145 times by 1 test: return (siginf->flags & 0x1) != 0;
Executed by:
  • libcrypto.so.1.1
13145
177}-
178-
179void X509_SIG_INFO_set(X509_SIG_INFO *siginf, int mdnid, int pknid,-
180 int secbits, uint32_t flags)-
181{-
182 siginf->mdnid = mdnid;-
183 siginf->pknid = pknid;-
184 siginf->secbits = secbits;-
185 siginf->flags = flags;-
186}
executed 15 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
15
187-
188int X509_get_signature_info(X509 *x, int *mdnid, int *pknid, int *secbits,-
189 uint32_t *flags)-
190{-
191 X509_check_purpose(x, -1, -1);-
192 return X509_SIG_INFO_get(&x->siginf, mdnid, pknid, secbits, flags);
executed 13145 times by 1 test: return X509_SIG_INFO_get(&x->siginf, mdnid, pknid, secbits, flags);
Executed by:
  • libcrypto.so.1.1
13145
193}-
194-
195static void x509_sig_info_init(X509_SIG_INFO *siginf, const X509_ALGOR *alg,-
196 const ASN1_STRING *sig)-
197{-
198 int pknid, mdnid;-
199 const EVP_MD *md;-
200-
201 siginf->mdnid = NID_undef;-
202 siginf->pknid = NID_undef;-
203 siginf->secbits = -1;-
204 siginf->flags = 0;-
205 if (!OBJ_find_sigid_algs(OBJ_obj2nid(alg->algorithm), &mdnid, &pknid)
!OBJ_find_sigi...mdnid, &pknid)Description
TRUEevaluated 204 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12297 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
204-12297
206 || pknid == NID_undef)
pknid == 0Description
TRUEnever evaluated
FALSEevaluated 12297 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-12297
207 return;
executed 204 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
204
208 siginf->pknid = pknid;-
209 if (mdnid == NID_undef) {
mdnid == 0Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12242 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
55-12242
210 /* If we have one, use a custom handler for this algorithm */-
211 const EVP_PKEY_ASN1_METHOD *ameth = EVP_PKEY_asn1_find(NULL, pknid);-
212 if (ameth == NULL || ameth->siginf_set == NULL
ameth == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 55 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ameth->siginf_...== ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-55
213 || ameth->siginf_set(siginf, alg, sig) == 0)
ameth->siginf_...alg, sig) == 0Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 15 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
15-39
214 return;
executed 40 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
40
215 siginf->flags |= X509_SIG_INFO_VALID;-
216 return;
executed 15 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
15
217 }-
218 siginf->flags |= X509_SIG_INFO_VALID;-
219 siginf->mdnid = mdnid;-
220 md = EVP_get_digestbynid(mdnid);-
221 if (md == NULL)
md == ((void *)0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8-12234
222 return;
executed 8 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
8
223 /* Security bits: half number of bits in digest */-
224 siginf->secbits = EVP_MD_size(md) * 4;-
225 switch (mdnid) {-
226 case NID_sha1:
executed 2265 times by 1 test: case 64:
Executed by:
  • libcrypto.so.1.1
2265
227 case NID_sha256:
executed 9920 times by 1 test: case 672:
Executed by:
  • libcrypto.so.1.1
9920
228 case NID_sha384:
executed 5 times by 1 test: case 673:
Executed by:
  • libcrypto.so.1.1
5
229 case NID_sha512:
executed 8 times by 1 test: case 674:
Executed by:
  • libcrypto.so.1.1
8
230 siginf->flags |= X509_SIG_INFO_TLS;-
231 }
executed 12198 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12198
232}
executed 12234 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12234
233-
234void x509_init_sig_info(X509 *x)-
235{-
236 x509_sig_info_init(&x->siginf, &x->sig_alg, &x->signature);-
237}
executed 12501 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12501
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2