summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ocsp/ocsp_prn.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_prn.c278
1 files changed, 147 insertions, 131 deletions
diff --git a/src/lib/libcrypto/ocsp/ocsp_prn.c b/src/lib/libcrypto/ocsp/ocsp_prn.c
index 87608ff399..9e4b81f061 100644
--- a/src/lib/libcrypto/ocsp/ocsp_prn.c
+++ b/src/lib/libcrypto/ocsp/ocsp_prn.c
@@ -66,8 +66,9 @@
66#include <openssl/ocsp.h> 66#include <openssl/ocsp.h>
67#include <openssl/pem.h> 67#include <openssl/pem.h>
68 68
69static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent) 69static int
70 { 70ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
71{
71 BIO_printf(bp, "%*sCertificate ID:\n", indent, ""); 72 BIO_printf(bp, "%*sCertificate ID:\n", indent, "");
72 indent += 2; 73 indent += 2;
73 BIO_printf(bp, "%*sHash Algorithm: ", indent, ""); 74 BIO_printf(bp, "%*sHash Algorithm: ", indent, "");
@@ -80,60 +81,68 @@ static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
80 i2a_ASN1_INTEGER(bp, a->serialNumber); 81 i2a_ASN1_INTEGER(bp, a->serialNumber);
81 BIO_printf(bp, "\n"); 82 BIO_printf(bp, "\n");
82 return 1; 83 return 1;
83 } 84}
84 85
85typedef struct 86typedef struct {
86 {
87 long t; 87 long t;
88 const char *m; 88 const char *m;
89 } OCSP_TBLSTR; 89} OCSP_TBLSTR;
90 90
91static const char *table2string(long s, const OCSP_TBLSTR *ts, int len) 91static const char *
92table2string(long s, const OCSP_TBLSTR *ts, int len)
92{ 93{
93 const OCSP_TBLSTR *p; 94 const OCSP_TBLSTR *p;
95
94 for (p=ts; p < ts + len; p++) 96 for (p=ts; p < ts + len; p++)
95 if (p->t == s) 97 if (p->t == s)
96 return p->m; 98 return p->m;
97 return "(UNKNOWN)"; 99 return "(UNKNOWN)";
98} 100}
99 101
100const char *OCSP_response_status_str(long s) 102const char *
101 { 103OCSP_response_status_str(long s)
104{
102 static const OCSP_TBLSTR rstat_tbl[] = { 105 static const OCSP_TBLSTR rstat_tbl[] = {
103 { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" }, 106 { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" },
104 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" }, 107 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
105 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" }, 108 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
106 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" }, 109 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" },
107 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" }, 110 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" },
108 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } }; 111 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" }
112 };
109 return table2string(s, rstat_tbl, 6); 113 return table2string(s, rstat_tbl, 6);
110 } 114}
111 115
112const char *OCSP_cert_status_str(long s) 116const char *
113 { 117OCSP_cert_status_str(long s)
118{
114 static const OCSP_TBLSTR cstat_tbl[] = { 119 static const OCSP_TBLSTR cstat_tbl[] = {
115 { V_OCSP_CERTSTATUS_GOOD, "good" }, 120 { V_OCSP_CERTSTATUS_GOOD, "good" },
116 { V_OCSP_CERTSTATUS_REVOKED, "revoked" }, 121 { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
117 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } }; 122 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" }
123 };
118 return table2string(s, cstat_tbl, 3); 124 return table2string(s, cstat_tbl, 3);
119 } 125}
120 126
121const char *OCSP_crl_reason_str(long s) 127const char *
122 { 128OCSP_crl_reason_str(long s)
129{
123 static const OCSP_TBLSTR reason_tbl[] = { 130 static const OCSP_TBLSTR reason_tbl[] = {
124 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" }, 131 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
125 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" }, 132 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
126 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" }, 133 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
127 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" }, 134 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
128 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" }, 135 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
129 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" }, 136 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },
130 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" }, 137 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
131 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } }; 138 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" }
139 };
132 return table2string(s, reason_tbl, 8); 140 return table2string(s, reason_tbl, 8);
133 } 141}
134 142
135int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags) 143int
136 { 144OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
145{
137 int i; 146 int i;
138 long l; 147 long l;
139 OCSP_CERTID* cid = NULL; 148 OCSP_CERTID* cid = NULL;
@@ -141,45 +150,45 @@ int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
141 OCSP_REQINFO *inf = o->tbsRequest; 150 OCSP_REQINFO *inf = o->tbsRequest;
142 OCSP_SIGNATURE *sig = o->optionalSignature; 151 OCSP_SIGNATURE *sig = o->optionalSignature;
143 152
144 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err; 153 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0)
145 l=ASN1_INTEGER_get(inf->version); 154 goto err;
146 if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0) goto err; 155 l = ASN1_INTEGER_get(inf->version);
147 if (inf->requestorName != NULL) 156 if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0)
148 { 157 goto err;
158 if (inf->requestorName != NULL) {
149 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0) 159 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
150 goto err; 160 goto err;
151 GENERAL_NAME_print(bp, inf->requestorName); 161 GENERAL_NAME_print(bp, inf->requestorName);
152 } 162 }
153 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err; 163 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0)
154 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++) 164 goto err;
155 { 165 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++) {
156 one = sk_OCSP_ONEREQ_value(inf->requestList, i); 166 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
157 cid = one->reqCert; 167 cid = one->reqCert;
158 ocsp_certid_print(bp, cid, 8); 168 ocsp_certid_print(bp, cid, 8);
159 if (!X509V3_extensions_print(bp, 169 if (!X509V3_extensions_print(bp, "Request Single Extensions",
160 "Request Single Extensions", 170 one->singleRequestExtensions, flags, 8))
161 one->singleRequestExtensions, flags, 8)) 171 goto err;
162 goto err; 172 }
163 }
164 if (!X509V3_extensions_print(bp, "Request Extensions", 173 if (!X509V3_extensions_print(bp, "Request Extensions",
165 inf->requestExtensions, flags, 4)) 174 inf->requestExtensions, flags, 4))
166 goto err; 175 goto err;
167 if (sig) 176 if (sig) {
168 { 177 X509_signature_print(bp, sig->signatureAlgorithm,
169 X509_signature_print(bp, sig->signatureAlgorithm, sig->signature); 178 sig->signature);
170 for (i=0; i<sk_X509_num(sig->certs); i++) 179 for (i=0; i<sk_X509_num(sig->certs); i++) {
171 {
172 X509_print(bp, sk_X509_value(sig->certs,i)); 180 X509_print(bp, sk_X509_value(sig->certs,i));
173 PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i)); 181 PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i));
174 }
175 } 182 }
183 }
176 return 1; 184 return 1;
177err: 185err:
178 return 0; 186 return 0;
179 } 187}
180 188
181int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags) 189int
182 { 190OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
191{
183 int i, ret = 0; 192 int i, ret = 0;
184 long l; 193 long l;
185 OCSP_CERTID *cid = NULL; 194 OCSP_CERTID *cid = NULL;
@@ -191,100 +200,107 @@ int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
191 OCSP_SINGLERESP *single = NULL; 200 OCSP_SINGLERESP *single = NULL;
192 OCSP_RESPBYTES *rb = o->responseBytes; 201 OCSP_RESPBYTES *rb = o->responseBytes;
193 202
194 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err; 203 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0)
195 l=ASN1_ENUMERATED_get(o->responseStatus); 204 goto err;
205 l = ASN1_ENUMERATED_get(o->responseStatus);
196 if (BIO_printf(bp," OCSP Response Status: %s (0x%lx)\n", 206 if (BIO_printf(bp," OCSP Response Status: %s (0x%lx)\n",
197 OCSP_response_status_str(l), l) <= 0) goto err; 207 OCSP_response_status_str(l), l) <= 0)
198 if (rb == NULL) return 1; 208 goto err;
199 if (BIO_puts(bp," Response Type: ") <= 0) 209 if (rb == NULL)
200 goto err; 210 return 1;
211 if (BIO_puts(bp," Response Type: ") <= 0)
212 goto err;
201 if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0) 213 if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0)
202 goto err; 214 goto err;
203 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) 215 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) {
204 {
205 BIO_puts(bp," (unknown response type)\n"); 216 BIO_puts(bp," (unknown response type)\n");
206 return 1; 217 return 1;
207 } 218 }
208 219
209 i = ASN1_STRING_length(rb->response); 220 i = ASN1_STRING_length(rb->response);
210 if (!(br = OCSP_response_get1_basic(o))) goto err; 221 if (!(br = OCSP_response_get1_basic(o)))
222 goto err;
211 rd = br->tbsResponseData; 223 rd = br->tbsResponseData;
212 l=ASN1_INTEGER_get(rd->version); 224 l = ASN1_INTEGER_get(rd->version);
213 if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n", 225 if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n", l+1,l) <= 0)
214 l+1,l) <= 0) goto err; 226 goto err;
215 if (BIO_puts(bp," Responder Id: ") <= 0) goto err; 227 if (BIO_puts(bp," Responder Id: ") <= 0)
228 goto err;
216 229
217 rid = rd->responderId; 230 rid = rd->responderId;
218 switch (rid->type) 231 switch (rid->type) {
219 { 232 case V_OCSP_RESPID_NAME:
220 case V_OCSP_RESPID_NAME: 233 X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE);
221 X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE); 234 break;
222 break; 235 case V_OCSP_RESPID_KEY:
223 case V_OCSP_RESPID_KEY: 236 i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING);
224 i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING); 237 break;
225 break; 238 }
226 }
227 239
228 if (BIO_printf(bp,"\n Produced At: ")<=0) goto err; 240 if (BIO_printf(bp,"\n Produced At: ")<=0)
229 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err; 241 goto err;
230 if (BIO_printf(bp,"\n Responses:\n") <= 0) goto err; 242 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt))
231 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++) 243 goto err;
232 { 244 if (BIO_printf(bp,"\n Responses:\n") <= 0)
233 if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue; 245 goto err;
246 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++) {
247 if (! sk_OCSP_SINGLERESP_value(rd->responses, i))
248 continue;
234 single = sk_OCSP_SINGLERESP_value(rd->responses, i); 249 single = sk_OCSP_SINGLERESP_value(rd->responses, i);
235 cid = single->certId; 250 cid = single->certId;
236 if(ocsp_certid_print(bp, cid, 4) <= 0) goto err; 251 if (ocsp_certid_print(bp, cid, 4) <= 0)
252 goto err;
237 cst = single->certStatus; 253 cst = single->certStatus;
238 if (BIO_printf(bp," Cert Status: %s", 254 if (BIO_printf(bp," Cert Status: %s",
239 OCSP_cert_status_str(cst->type)) <= 0) 255 OCSP_cert_status_str(cst->type)) <= 0)
240 goto err; 256 goto err;
241 if (cst->type == V_OCSP_CERTSTATUS_REVOKED) 257 if (cst->type == V_OCSP_CERTSTATUS_REVOKED) {
242 { 258 rev = cst->value.revoked;
243 rev = cst->value.revoked;
244 if (BIO_printf(bp, "\n Revocation Time: ") <= 0) 259 if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
245 goto err;
246 if (!ASN1_GENERALIZEDTIME_print(bp,
247 rev->revocationTime))
248 goto err; 260 goto err;
249 if (rev->revocationReason) 261 if (!ASN1_GENERALIZEDTIME_print(bp,
250 { 262 rev->revocationTime))
251 l=ASN1_ENUMERATED_get(rev->revocationReason); 263 goto err;
252 if (BIO_printf(bp, 264 if (rev->revocationReason) {
253 "\n Revocation Reason: %s (0x%lx)", 265 l = ASN1_ENUMERATED_get(rev->revocationReason);
254 OCSP_crl_reason_str(l), l) <= 0) 266 if (BIO_printf(bp,
255 goto err; 267 "\n Revocation Reason: %s (0x%lx)",
256 } 268 OCSP_crl_reason_str(l), l) <= 0)
269 goto err;
257 } 270 }
258 if (BIO_printf(bp,"\n This Update: ") <= 0) goto err; 271 }
272 if (BIO_printf(bp,"\n This Update: ") <= 0)
273 goto err;
259 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate)) 274 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
260 goto err; 275 goto err;
261 if (single->nextUpdate) 276 if (single->nextUpdate) {
262 { 277 if (BIO_printf(bp,"\n Next Update: ") <= 0)
263 if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err; 278 goto err;
264 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate)) 279 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate))
265 goto err; 280 goto err;
266 }
267 if (BIO_write(bp,"\n",1) <= 0) goto err;
268 if (!X509V3_extensions_print(bp,
269 "Response Single Extensions",
270 single->singleExtensions, flags, 8))
271 goto err;
272 if (BIO_write(bp,"\n",1) <= 0) goto err;
273 } 281 }
282 if (BIO_write(bp,"\n",1) <= 0)
283 goto err;
284 if (!X509V3_extensions_print(bp, "Response Single Extensions",
285 single->singleExtensions, flags, 8))
286 goto err;
287 if (BIO_write(bp,"\n",1) <= 0)
288 goto err;
289 }
274 if (!X509V3_extensions_print(bp, "Response Extensions", 290 if (!X509V3_extensions_print(bp, "Response Extensions",
275 rd->responseExtensions, flags, 4)) 291 rd->responseExtensions, flags, 4))
276 goto err; 292 goto err;
277 if(X509_signature_print(bp, br->signatureAlgorithm, br->signature) <= 0) 293 if (X509_signature_print(bp, br->signatureAlgorithm, br->signature) <=
278 goto err; 294 0)
295 goto err;
279 296
280 for (i=0; i<sk_X509_num(br->certs); i++) 297 for (i = 0; i < sk_X509_num(br->certs); i++) {
281 { 298 X509_print(bp, sk_X509_value(br->certs, i));
282 X509_print(bp, sk_X509_value(br->certs,i)); 299 PEM_write_bio_X509(bp,sk_X509_value(br->certs, i));
283 PEM_write_bio_X509(bp,sk_X509_value(br->certs,i)); 300 }
284 }
285 301
286 ret = 1; 302 ret = 1;
287err: 303err:
288 OCSP_BASICRESP_free(br); 304 OCSP_BASICRESP_free(br);
289 return ret; 305 return ret;
290 } 306}