OpenCoverage

v3_ocsp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ocsp/v3_ocsp.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2000-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 "internal/cryptlib.h"-
12# include <openssl/conf.h>-
13# include <openssl/asn1.h>-
14# include <openssl/ocsp.h>-
15# include "ocsp_lcl.h"-
16# include <openssl/x509v3.h>-
17# include "../x509v3/ext_dat.h"-
18-
19/*-
20 * OCSP extensions and a couple of CRL entry extensions-
21 */-
22-
23static int i2r_ocsp_crlid(const X509V3_EXT_METHOD *method, void *nonce,-
24 BIO *out, int indent);-
25static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *nonce,-
26 BIO *out, int indent);-
27static int i2r_object(const X509V3_EXT_METHOD *method, void *obj, BIO *out,-
28 int indent);-
29-
30static void *ocsp_nonce_new(void);-
31static int i2d_ocsp_nonce(void *a, unsigned char **pp);-
32static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length);-
33static void ocsp_nonce_free(void *a);-
34static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,-
35 BIO *out, int indent);-
36-
37static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method,-
38 void *nocheck, BIO *out, int indent);-
39static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method,-
40 X509V3_CTX *ctx, const char *str);-
41static int i2r_ocsp_serviceloc(const X509V3_EXT_METHOD *method, void *in,-
42 BIO *bp, int ind);-
43-
44const X509V3_EXT_METHOD v3_ocsp_crlid = {-
45 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),-
46 0, 0, 0, 0,-
47 0, 0,-
48 0, 0,-
49 i2r_ocsp_crlid, 0,-
50 NULL-
51};-
52-
53const X509V3_EXT_METHOD v3_ocsp_acutoff = {-
54 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),-
55 0, 0, 0, 0,-
56 0, 0,-
57 0, 0,-
58 i2r_ocsp_acutoff, 0,-
59 NULL-
60};-
61-
62const X509V3_EXT_METHOD v3_crl_invdate = {-
63 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),-
64 0, 0, 0, 0,-
65 0, 0,-
66 0, 0,-
67 i2r_ocsp_acutoff, 0,-
68 NULL-
69};-
70-
71const X509V3_EXT_METHOD v3_crl_hold = {-
72 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT),-
73 0, 0, 0, 0,-
74 0, 0,-
75 0, 0,-
76 i2r_object, 0,-
77 NULL-
78};-
79-
80const X509V3_EXT_METHOD v3_ocsp_nonce = {-
81 NID_id_pkix_OCSP_Nonce, 0, NULL,-
82 ocsp_nonce_new,-
83 ocsp_nonce_free,-
84 d2i_ocsp_nonce,-
85 i2d_ocsp_nonce,-
86 0, 0,-
87 0, 0,-
88 i2r_ocsp_nonce, 0,-
89 NULL-
90};-
91-
92const X509V3_EXT_METHOD v3_ocsp_nocheck = {-
93 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL),-
94 0, 0, 0, 0,-
95 0, s2i_ocsp_nocheck,-
96 0, 0,-
97 i2r_ocsp_nocheck, 0,-
98 NULL-
99};-
100-
101const X509V3_EXT_METHOD v3_ocsp_serviceloc = {-
102 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC),-
103 0, 0, 0, 0,-
104 0, 0,-
105 0, 0,-
106 i2r_ocsp_serviceloc, 0,-
107 NULL-
108};-
109-
110static int i2r_ocsp_crlid(const X509V3_EXT_METHOD *method, void *in, BIO *bp,-
111 int ind)-
112{-
113 OCSP_CRLID *a = in;-
114 if (a->crlUrl) {
a->crlUrlDescription
TRUEnever evaluated
FALSEevaluated 831 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-831
115 if (BIO_printf(bp, "%*scrlUrl: ", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
116 goto err;
never executed: goto err;
0
117 if (!ASN1_STRING_print(bp, (ASN1_STRING *)a->crlUrl))
!ASN1_STRING_p...G *)a->crlUrl)Description
TRUEnever evaluated
FALSEnever evaluated
0
118 goto err;
never executed: goto err;
0
119 if (BIO_write(bp, "\n", 1) <= 0)
BIO_write(bp, "\n", 1) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
120 goto err;
never executed: goto err;
0
121 }
never executed: end of block
0
122 if (a->crlNum) {
a->crlNumDescription
TRUEnever evaluated
FALSEevaluated 831 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-831
123 if (BIO_printf(bp, "%*scrlNum: ", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
124 goto err;
never executed: goto err;
0
125 if (i2a_ASN1_INTEGER(bp, a->crlNum) <= 0)
i2a_ASN1_INTEG...->crlNum) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
126 goto err;
never executed: goto err;
0
127 if (BIO_write(bp, "\n", 1) <= 0)
BIO_write(bp, "\n", 1) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
128 goto err;
never executed: goto err;
0
129 }
never executed: end of block
0
130 if (a->crlTime) {
a->crlTimeDescription
TRUEnever evaluated
FALSEevaluated 831 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-831
131 if (BIO_printf(bp, "%*scrlTime: ", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
132 goto err;
never executed: goto err;
0
133 if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime))
!ASN1_GENERALI...p, a->crlTime)Description
TRUEnever evaluated
FALSEnever evaluated
0
134 goto err;
never executed: goto err;
0
135 if (BIO_write(bp, "\n", 1) <= 0)
BIO_write(bp, "\n", 1) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
136 goto err;
never executed: goto err;
0
137 }
never executed: end of block
0
138 return 1;
executed 831 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
831
139 err:-
140 return 0;
never executed: return 0;
0
141}-
142-
143static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *cutoff,-
144 BIO *bp, int ind)-
145{-
146 if (BIO_printf(bp, "%*s", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEevaluated 5264 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5264
147 return 0;
never executed: return 0;
0
148 if (!ASN1_GENERALIZEDTIME_print(bp, cutoff))
!ASN1_GENERALI...nt(bp, cutoff)Description
TRUEevaluated 4179 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1085 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1085-4179
149 return 0;
executed 4179 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4179
150 return 1;
executed 1085 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1085
151}-
152-
153static int i2r_object(const X509V3_EXT_METHOD *method, void *oid, BIO *bp,-
154 int ind)-
155{-
156 if (BIO_printf(bp, "%*s", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEevaluated 270 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-270
157 return 0;
never executed: return 0;
0
158 if (i2a_ASN1_OBJECT(bp, oid) <= 0)
i2a_ASN1_OBJECT(bp, oid) <= 0Description
TRUEnever evaluated
FALSEevaluated 270 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-270
159 return 0;
never executed: return 0;
0
160 return 1;
executed 270 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
270
161}-
162-
163/*-
164 * OCSP nonce. This is needs special treatment because it doesn't have an-
165 * ASN1 encoding at all: it just contains arbitrary data.-
166 */-
167-
168static void *ocsp_nonce_new(void)-
169{-
170 return ASN1_OCTET_STRING_new();
never executed: return ASN1_OCTET_STRING_new();
0
171}-
172-
173static int i2d_ocsp_nonce(void *a, unsigned char **pp)-
174{-
175 ASN1_OCTET_STRING *os = a;-
176 if (pp) {
ppDescription
TRUEnever evaluated
FALSEnever evaluated
0
177 memcpy(*pp, os->data, os->length);-
178 *pp += os->length;-
179 }
never executed: end of block
0
180 return os->length;
never executed: return os->length;
0
181}-
182-
183static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length)-
184{-
185 ASN1_OCTET_STRING *os, **pos;-
186 pos = a;-
187 if (pos == NULL || *pos == NULL) {
pos == ((void *)0)Description
TRUEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
*pos == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0-978
188 os = ASN1_OCTET_STRING_new();-
189 if (os == NULL)
os == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-978
190 goto err;
never executed: goto err;
0
191 } else {
executed 978 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
978
192 os = *pos;-
193 }
never executed: end of block
0
194 if (!ASN1_OCTET_STRING_set(os, *pp, length))
!ASN1_OCTET_ST..., *pp, length)Description
TRUEnever evaluated
FALSEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-978
195 goto err;
never executed: goto err;
0
196-
197 *pp += length;-
198-
199 if (pos)
posDescription
TRUEnever evaluated
FALSEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-978
200 *pos = os;
never executed: *pos = os;
0
201 return os;
executed 978 times by 1 test: return os;
Executed by:
  • libcrypto.so.1.1
978
202-
203 err:-
204 if ((pos == NULL) || (*pos != os))
(pos == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
(*pos != os)Description
TRUEnever evaluated
FALSEnever evaluated
0
205 ASN1_OCTET_STRING_free(os);
never executed: ASN1_OCTET_STRING_free(os);
0
206 OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE);-
207 return NULL;
never executed: return ((void *)0) ;
0
208}-
209-
210static void ocsp_nonce_free(void *a)-
211{-
212 ASN1_OCTET_STRING_free(a);-
213}
executed 978 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
978
214-
215static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,-
216 BIO *out, int indent)-
217{-
218 if (BIO_printf(out, "%*s", indent, "") <= 0)
BIO_printf(out...dent, "") <= 0Description
TRUEnever evaluated
FALSEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-978
219 return 0;
never executed: return 0;
0
220 if (i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0)
i2a_ASN1_STRIN...nonce, 4) <= 0Description
TRUEnever evaluated
FALSEevaluated 978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-978
221 return 0;
never executed: return 0;
0
222 return 1;
executed 978 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
978
223}-
224-
225/* Nocheck is just a single NULL. Don't print anything and always set it */-
226-
227static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method, void *nocheck,-
228 BIO *out, int indent)-
229{-
230 return 1;
executed 390 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
390
231}-
232-
233static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method,-
234 X509V3_CTX *ctx, const char *str)-
235{-
236 return ASN1_NULL_new();
never executed: return ASN1_NULL_new();
0
237}-
238-
239static int i2r_ocsp_serviceloc(const X509V3_EXT_METHOD *method, void *in,-
240 BIO *bp, int ind)-
241{-
242 int i;-
243 OCSP_SERVICELOC *a = in;-
244 ACCESS_DESCRIPTION *ad;-
245-
246 if (BIO_printf(bp, "%*sIssuer: ", ind, "") <= 0)
BIO_printf(bp,... ind, "") <= 0Description
TRUEnever evaluated
FALSEevaluated 1972 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1972
247 goto err;
never executed: goto err;
0
248 if (X509_NAME_print_ex(bp, a->issuer, 0, XN_FLAG_ONELINE) <= 0)
X509_NAME_prin...23) | 0)) <= 0Description
TRUEevaluated 1562 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 410 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
410-1562
249 goto err;
executed 1562 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
1562
250 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++) {
i < sk_ACCESS_...um(a->locator)Description
TRUEnever evaluated
FALSEevaluated 410 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-410
251 ad = sk_ACCESS_DESCRIPTION_value(a->locator, i);-
252 if (BIO_printf(bp, "\n%*s", (2 * ind), "") <= 0)
BIO_printf(bp,...ind), "") <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
253 goto err;
never executed: goto err;
0
254 if (i2a_ASN1_OBJECT(bp, ad->method) <= 0)
i2a_ASN1_OBJEC...->method) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
255 goto err;
never executed: goto err;
0
256 if (BIO_puts(bp, " - ") <= 0)
BIO_puts(bp, " - ") <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
257 goto err;
never executed: goto err;
0
258 if (GENERAL_NAME_print(bp, ad->location) <= 0)
GENERAL_NAME_p...location) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
259 goto err;
never executed: goto err;
0
260 }
never executed: end of block
0
261 return 1;
executed 410 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
410
262 err:-
263 return 0;
executed 1562 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1562
264}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2