Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ocsp/ocsp_prn.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
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 <openssl/bio.h> | - | ||||||
11 | #include <openssl/err.h> | - | ||||||
12 | #include <openssl/ocsp.h> | - | ||||||
13 | #include "ocsp_lcl.h" | - | ||||||
14 | #include "internal/cryptlib.h" | - | ||||||
15 | #include <openssl/pem.h> | - | ||||||
16 | - | |||||||
17 | static int ocsp_certid_print(BIO *bp, OCSP_CERTID *a, int indent) | - | ||||||
18 | { | - | ||||||
19 | BIO_printf(bp, "%*sCertificate ID:\n", indent, ""); | - | ||||||
20 | indent += 2; | - | ||||||
21 | BIO_printf(bp, "%*sHash Algorithm: ", indent, ""); | - | ||||||
22 | i2a_ASN1_OBJECT(bp, a->hashAlgorithm.algorithm); | - | ||||||
23 | BIO_printf(bp, "\n%*sIssuer Name Hash: ", indent, ""); | - | ||||||
24 | i2a_ASN1_STRING(bp, &a->issuerNameHash, 0); | - | ||||||
25 | BIO_printf(bp, "\n%*sIssuer Key Hash: ", indent, ""); | - | ||||||
26 | i2a_ASN1_STRING(bp, &a->issuerKeyHash, 0); | - | ||||||
27 | BIO_printf(bp, "\n%*sSerial Number: ", indent, ""); | - | ||||||
28 | i2a_ASN1_INTEGER(bp, &a->serialNumber); | - | ||||||
29 | BIO_printf(bp, "\n"); | - | ||||||
30 | return 1; executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||
31 | } | - | ||||||
32 | - | |||||||
33 | typedef struct { | - | ||||||
34 | long t; | - | ||||||
35 | const char *m; | - | ||||||
36 | } OCSP_TBLSTR; | - | ||||||
37 | - | |||||||
38 | static const char *do_table2string(long s, const OCSP_TBLSTR *ts, size_t len) | - | ||||||
39 | { | - | ||||||
40 | size_t i; | - | ||||||
41 | for (i = 0; i < len; i++, ts++)
| 0-4 | ||||||
42 | if (ts->t == s)
| 0-4 | ||||||
43 | return ts->m; executed 4 times by 1 test: return ts->m; Executed by:
| 4 | ||||||
44 | return "(UNKNOWN)"; never executed: return "(UNKNOWN)"; | 0 | ||||||
45 | } | - | ||||||
46 | - | |||||||
47 | #define table2string(s, tbl) do_table2string(s, tbl, OSSL_NELEM(tbl)) | - | ||||||
48 | - | |||||||
49 | const char *OCSP_response_status_str(long s) | - | ||||||
50 | { | - | ||||||
51 | static const OCSP_TBLSTR rstat_tbl[] = { | - | ||||||
52 | {OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful"}, | - | ||||||
53 | {OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest"}, | - | ||||||
54 | {OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror"}, | - | ||||||
55 | {OCSP_RESPONSE_STATUS_TRYLATER, "trylater"}, | - | ||||||
56 | {OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired"}, | - | ||||||
57 | {OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized"} | - | ||||||
58 | }; | - | ||||||
59 | return table2string(s, rstat_tbl); executed 2 times by 1 test: return do_table2string(s, rstat_tbl, (sizeof(rstat_tbl)/sizeof((rstat_tbl)[0]))); Executed by:
| 2 | ||||||
60 | } | - | ||||||
61 | - | |||||||
62 | const char *OCSP_cert_status_str(long s) | - | ||||||
63 | { | - | ||||||
64 | static const OCSP_TBLSTR cstat_tbl[] = { | - | ||||||
65 | {V_OCSP_CERTSTATUS_GOOD, "good"}, | - | ||||||
66 | {V_OCSP_CERTSTATUS_REVOKED, "revoked"}, | - | ||||||
67 | {V_OCSP_CERTSTATUS_UNKNOWN, "unknown"} | - | ||||||
68 | }; | - | ||||||
69 | return table2string(s, cstat_tbl); executed 2 times by 1 test: return do_table2string(s, cstat_tbl, (sizeof(cstat_tbl)/sizeof((cstat_tbl)[0]))); Executed by:
| 2 | ||||||
70 | } | - | ||||||
71 | - | |||||||
72 | const char *OCSP_crl_reason_str(long s) | - | ||||||
73 | { | - | ||||||
74 | static const OCSP_TBLSTR reason_tbl[] = { | - | ||||||
75 | {OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified"}, | - | ||||||
76 | {OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise"}, | - | ||||||
77 | {OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise"}, | - | ||||||
78 | {OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged"}, | - | ||||||
79 | {OCSP_REVOKED_STATUS_SUPERSEDED, "superseded"}, | - | ||||||
80 | {OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation"}, | - | ||||||
81 | {OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold"}, | - | ||||||
82 | {OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL"} | - | ||||||
83 | }; | - | ||||||
84 | return table2string(s, reason_tbl); never executed: return do_table2string(s, reason_tbl, (sizeof(reason_tbl)/sizeof((reason_tbl)[0]))); | 0 | ||||||
85 | } | - | ||||||
86 | - | |||||||
87 | int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *o, unsigned long flags) | - | ||||||
88 | { | - | ||||||
89 | int i; | - | ||||||
90 | long l; | - | ||||||
91 | OCSP_CERTID *cid = NULL; | - | ||||||
92 | OCSP_ONEREQ *one = NULL; | - | ||||||
93 | OCSP_REQINFO *inf = &o->tbsRequest; | - | ||||||
94 | OCSP_SIGNATURE *sig = o->optionalSignature; | - | ||||||
95 | - | |||||||
96 | if (BIO_write(bp, "OCSP Request Data:\n", 19) <= 0)
| 0 | ||||||
97 | goto err; never executed: goto err; | 0 | ||||||
98 | l = ASN1_INTEGER_get(inf->version); | - | ||||||
99 | if (BIO_printf(bp, " Version: %lu (0x%lx)", l + 1, l) <= 0)
| 0 | ||||||
100 | goto err; never executed: goto err; | 0 | ||||||
101 | if (inf->requestorName != NULL) {
| 0 | ||||||
102 | if (BIO_write(bp, "\n Requestor Name: ", 21) <= 0)
| 0 | ||||||
103 | goto err; never executed: goto err; | 0 | ||||||
104 | GENERAL_NAME_print(bp, inf->requestorName); | - | ||||||
105 | } never executed: end of block | 0 | ||||||
106 | if (BIO_write(bp, "\n Requestor List:\n", 21) <= 0)
| 0 | ||||||
107 | goto err; never executed: goto err; | 0 | ||||||
108 | for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++) {
| 0 | ||||||
109 | one = sk_OCSP_ONEREQ_value(inf->requestList, i); | - | ||||||
110 | cid = one->reqCert; | - | ||||||
111 | ocsp_certid_print(bp, cid, 8); | - | ||||||
112 | if (!X509V3_extensions_print(bp,
| 0 | ||||||
113 | "Request Single Extensions",
| 0 | ||||||
114 | one->singleRequestExtensions, flags, 8))
| 0 | ||||||
115 | goto err; never executed: goto err; | 0 | ||||||
116 | } never executed: end of block | 0 | ||||||
117 | if (!X509V3_extensions_print(bp, "Request Extensions",
| 0 | ||||||
118 | inf->requestExtensions, flags, 4))
| 0 | ||||||
119 | goto err; never executed: goto err; | 0 | ||||||
120 | if (sig) {
| 0 | ||||||
121 | X509_signature_print(bp, &sig->signatureAlgorithm, sig->signature); | - | ||||||
122 | for (i = 0; i < sk_X509_num(sig->certs); i++) {
| 0 | ||||||
123 | X509_print(bp, sk_X509_value(sig->certs, i)); | - | ||||||
124 | PEM_write_bio_X509(bp, sk_X509_value(sig->certs, i)); | - | ||||||
125 | } never executed: end of block | 0 | ||||||
126 | } never executed: end of block | 0 | ||||||
127 | return 1; never executed: return 1; | 0 | ||||||
128 | err: | - | ||||||
129 | return 0; never executed: return 0; | 0 | ||||||
130 | } | - | ||||||
131 | - | |||||||
132 | int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags) | - | ||||||
133 | { | - | ||||||
134 | int i, ret = 0; | - | ||||||
135 | long l; | - | ||||||
136 | OCSP_CERTID *cid = NULL; | - | ||||||
137 | OCSP_BASICRESP *br = NULL; | - | ||||||
138 | OCSP_RESPID *rid = NULL; | - | ||||||
139 | OCSP_RESPDATA *rd = NULL; | - | ||||||
140 | OCSP_CERTSTATUS *cst = NULL; | - | ||||||
141 | OCSP_REVOKEDINFO *rev = NULL; | - | ||||||
142 | OCSP_SINGLERESP *single = NULL; | - | ||||||
143 | OCSP_RESPBYTES *rb = o->responseBytes; | - | ||||||
144 | - | |||||||
145 | if (BIO_puts(bp, "OCSP Response Data:\n") <= 0)
| 0-2 | ||||||
146 | goto err; never executed: goto err; | 0 | ||||||
147 | l = ASN1_ENUMERATED_get(o->responseStatus); | - | ||||||
148 | if (BIO_printf(bp, " OCSP Response Status: %s (0x%lx)\n",
| 0-2 | ||||||
149 | OCSP_response_status_str(l), l) <= 0)
| 0-2 | ||||||
150 | goto err; never executed: goto err; | 0 | ||||||
151 | if (rb == NULL)
| 0-2 | ||||||
152 | return 1; never executed: return 1; | 0 | ||||||
153 | if (BIO_puts(bp, " Response Type: ") <= 0)
| 0-2 | ||||||
154 | goto err; never executed: goto err; | 0 | ||||||
155 | if (i2a_ASN1_OBJECT(bp, rb->responseType) <= 0)
| 0-2 | ||||||
156 | goto err; never executed: goto err; | 0 | ||||||
157 | if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) {
| 0-2 | ||||||
158 | BIO_puts(bp, " (unknown response type)\n"); | - | ||||||
159 | return 1; never executed: return 1; | 0 | ||||||
160 | } | - | ||||||
161 | - | |||||||
162 | if ((br = OCSP_response_get1_basic(o)) == NULL)
| 0-2 | ||||||
163 | goto err; never executed: goto err; | 0 | ||||||
164 | rd = &br->tbsResponseData; | - | ||||||
165 | l = ASN1_INTEGER_get(rd->version); | - | ||||||
166 | if (BIO_printf(bp, "\n Version: %lu (0x%lx)\n", l + 1, l) <= 0)
| 0-2 | ||||||
167 | goto err; never executed: goto err; | 0 | ||||||
168 | if (BIO_puts(bp, " Responder Id: ") <= 0)
| 0-2 | ||||||
169 | goto err; never executed: goto err; | 0 | ||||||
170 | - | |||||||
171 | rid = &rd->responderId; | - | ||||||
172 | switch (rid->type) { | - | ||||||
173 | case V_OCSP_RESPID_NAME: executed 2 times by 1 test: case 0: Executed by:
| 2 | ||||||
174 | X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE); | - | ||||||
175 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||
176 | case V_OCSP_RESPID_KEY: never executed: case 1: | 0 | ||||||
177 | i2a_ASN1_STRING(bp, rid->value.byKey, 0); | - | ||||||
178 | break; never executed: break; | 0 | ||||||
179 | } | - | ||||||
180 | - | |||||||
181 | if (BIO_printf(bp, "\n Produced At: ") <= 0)
| 0-2 | ||||||
182 | goto err; never executed: goto err; | 0 | ||||||
183 | if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt))
| 0-2 | ||||||
184 | goto err; never executed: goto err; | 0 | ||||||
185 | if (BIO_printf(bp, "\n Responses:\n") <= 0)
| 0-2 | ||||||
186 | goto err; never executed: goto err; | 0 | ||||||
187 | for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++) {
| 2 | ||||||
188 | if (!sk_OCSP_SINGLERESP_value(rd->responses, i))
| 0-2 | ||||||
189 | continue; never executed: continue; | 0 | ||||||
190 | single = sk_OCSP_SINGLERESP_value(rd->responses, i); | - | ||||||
191 | cid = single->certId; | - | ||||||
192 | if (ocsp_certid_print(bp, cid, 4) <= 0)
| 0-2 | ||||||
193 | goto err; never executed: goto err; | 0 | ||||||
194 | cst = single->certStatus; | - | ||||||
195 | if (BIO_printf(bp, " Cert Status: %s",
| 0-2 | ||||||
196 | OCSP_cert_status_str(cst->type)) <= 0)
| 0-2 | ||||||
197 | goto err; never executed: goto err; | 0 | ||||||
198 | if (cst->type == V_OCSP_CERTSTATUS_REVOKED) {
| 0-2 | ||||||
199 | rev = cst->value.revoked; | - | ||||||
200 | if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
| 0 | ||||||
201 | goto err; never executed: goto err; | 0 | ||||||
202 | if (!ASN1_GENERALIZEDTIME_print(bp, rev->revocationTime))
| 0 | ||||||
203 | goto err; never executed: goto err; | 0 | ||||||
204 | if (rev->revocationReason) {
| 0 | ||||||
205 | l = ASN1_ENUMERATED_get(rev->revocationReason); | - | ||||||
206 | if (BIO_printf(bp,
| 0 | ||||||
207 | "\n Revocation Reason: %s (0x%lx)",
| 0 | ||||||
208 | OCSP_crl_reason_str(l), l) <= 0)
| 0 | ||||||
209 | goto err; never executed: goto err; | 0 | ||||||
210 | } never executed: end of block | 0 | ||||||
211 | } never executed: end of block | 0 | ||||||
212 | if (BIO_printf(bp, "\n This Update: ") <= 0)
| 0-2 | ||||||
213 | goto err; never executed: goto err; | 0 | ||||||
214 | if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
| 0-2 | ||||||
215 | goto err; never executed: goto err; | 0 | ||||||
216 | if (single->nextUpdate) {
| 0-2 | ||||||
217 | if (BIO_printf(bp, "\n Next Update: ") <= 0)
| 0 | ||||||
218 | goto err; never executed: goto err; | 0 | ||||||
219 | if (!ASN1_GENERALIZEDTIME_print(bp, single->nextUpdate))
| 0 | ||||||
220 | goto err; never executed: goto err; | 0 | ||||||
221 | } never executed: end of block | 0 | ||||||
222 | if (BIO_write(bp, "\n", 1) <= 0)
| 0-2 | ||||||
223 | goto err; never executed: goto err; | 0 | ||||||
224 | if (!X509V3_extensions_print(bp,
| 0-2 | ||||||
225 | "Response Single Extensions",
| 0-2 | ||||||
226 | single->singleExtensions, flags, 8))
| 0-2 | ||||||
227 | goto err; never executed: goto err; | 0 | ||||||
228 | if (BIO_write(bp, "\n", 1) <= 0)
| 0-2 | ||||||
229 | goto err; never executed: goto err; | 0 | ||||||
230 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
231 | if (!X509V3_extensions_print(bp, "Response Extensions",
| 0-2 | ||||||
232 | rd->responseExtensions, flags, 4))
| 0-2 | ||||||
233 | goto err; never executed: goto err; | 0 | ||||||
234 | if (X509_signature_print(bp, &br->signatureAlgorithm, br->signature) <= 0)
| 0-2 | ||||||
235 | goto err; never executed: goto err; | 0 | ||||||
236 | - | |||||||
237 | for (i = 0; i < sk_X509_num(br->certs); i++) {
| 2 | ||||||
238 | X509_print(bp, sk_X509_value(br->certs, i)); | - | ||||||
239 | PEM_write_bio_X509(bp, sk_X509_value(br->certs, i)); | - | ||||||
240 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
241 | - | |||||||
242 | ret = 1; | - | ||||||
243 | err: code before this statement executed 2 times by 1 test: err: Executed by:
| 2 | ||||||
244 | OCSP_BASICRESP_free(br); | - | ||||||
245 | return ret; executed 2 times by 1 test: return ret; Executed by:
| 2 | ||||||
246 | } | - | ||||||
Source code | Switch to Preprocessed file |