1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
.\" $OpenBSD: OCSP_resp_find_status.3,v 1.10 2019/08/27 10:00:41 schwarze Exp $
.\" full merge up to: OpenSSL c952780c Jun 21 07:03:34 2016 -0400
.\" selective merge up to: OpenSSL 1212818e Sep 11 13:22:14 2018 +0100
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\"
.\" Copyright (c) 2016, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>
.\" and David von Oheimb <David.von.Oheimb@siemens.com>.
.\" Copyright (c) 2014, 2018 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: August 27 2019 $
.Dt OCSP_RESP_FIND_STATUS 3
.Os
.Sh NAME
.Nm OCSP_SINGLERESP_new ,
.Nm OCSP_SINGLERESP_free ,
.Nm OCSP_CERTSTATUS_new ,
.Nm OCSP_CERTSTATUS_free ,
.Nm OCSP_REVOKEDINFO_new ,
.Nm OCSP_REVOKEDINFO_free ,
.Nm OCSP_resp_find_status ,
.Nm OCSP_cert_status_str ,
.Nm OCSP_resp_count ,
.Nm OCSP_resp_get0 ,
.Nm OCSP_resp_find ,
.Nm OCSP_SINGLERESP_get0_id ,
.Nm OCSP_single_get0_status ,
.Nm OCSP_check_validity ,
.Nm OCSP_basic_verify
.Nd OCSP response utility functions
.Sh SYNOPSIS
.In openssl/ocsp.h
.Ft OCSP_SINGLERESP *
.Fn OCSP_SINGLERESP_new void
.Ft void
.Fn OCSP_SINGLERESP_free "OCSP_SINGLERESP *single"
.Ft OCSP_CERTSTATUS *
.Fn OCSP_CERTSTATUS_new void
.Ft void
.Fn OCSP_CERTSTATUS_free "OCSP_CERTSTATUS *certstatus"
.Ft OCSP_REVOKEDINFO *
.Fn OCSP_REVOKEDINFO_new void
.Ft void
.Fn OCSP_REVOKEDINFO_free "OCSP_REVOKEDINFO *revokedinfo"
.Ft int
.Fo OCSP_resp_find_status
.Fa "OCSP_BASICRESP *bs"
.Fa "OCSP_CERTID *id"
.Fa "int *status"
.Fa "int *reason"
.Fa "ASN1_GENERALIZEDTIME **revtime"
.Fa "ASN1_GENERALIZEDTIME **thisupd"
.Fa "ASN1_GENERALIZEDTIME **nextupd"
.Fc
.Ft const char *
.Fo OCSP_cert_status_str
.Fa "long status"
.Fc
.Ft int
.Fo OCSP_resp_count
.Fa "OCSP_BASICRESP *bs"
.Fc
.Ft OCSP_SINGLERESP *
.Fo OCSP_resp_get0
.Fa "OCSP_BASICRESP *bs"
.Fa "int idx"
.Fc
.Ft int
.Fo OCSP_resp_find
.Fa "OCSP_BASICRESP *bs"
.Fa "OCSP_CERTID *id"
.Fa "int last"
.Fc
.Ft const OCSP_CERTID *
.Fo OCSP_SINGLERESP_get0_id
.Fa "const OCSP_SINGLERESP *single"
.Fc
.Ft int
.Fo OCSP_single_get0_status
.Fa "OCSP_SINGLERESP *single"
.Fa "int *reason"
.Fa "ASN1_GENERALIZEDTIME **revtime"
.Fa "ASN1_GENERALIZEDTIME **thisupd"
.Fa "ASN1_GENERALIZEDTIME **nextupd"
.Fc
.Ft int
.Fo OCSP_check_validity
.Fa "ASN1_GENERALIZEDTIME *thisupd"
.Fa "ASN1_GENERALIZEDTIME *nextupd"
.Fa "long sec"
.Fa "long maxsec"
.Fc
.Ft int
.Fo OCSP_basic_verify
.Fa "OCSP_BASICRESP *bs"
.Fa "STACK_OF(X509) *certs"
.Fa "X509_STORE *st"
.Fa "unsigned long flags"
.Fc
.Sh DESCRIPTION
.Fn OCSP_SINGLERESP_new
allocates and initializes an empty
.Vt OCSP_SINGLERESP
object, representing an ASN.1
.Vt SingleResponse
structure defined in RFC 6960.
Each such object can store the server's answer regarding the validity
of one individual certificate.
Such objects are used inside the
.Vt OCSP_RESPDATA
of
.Vt OCSP_BASICRESP
objects, which are described in
.Xr OCSP_BASICRESP_new 3 .
.Fn OCSP_SINGLERESP_free
frees
.Fa single .
.Pp
.Fn OCSP_CERTSTATUS_new
allocates and initializes an empty
.Vt OCSP_CERTSTATUS
object, representing an ASN.1
.Vt CertStatus
structure defined in RFC 6960.
Such an object is used inside
.Vt OCSP_SINGLERESP .
.Fn OCSP_CERTSTATUS_free
frees
.Fa certstatus .
.Pp
.Fn OCSP_REVOKEDINFO_new
allocates and initializes an empty
.Vt OCSP_REVOKEDINFO
object, representing an ASN.1
.Vt RevokedInfo
structure defined in RFC 6960.
Such an object is used inside
.Vt OCSP_CERTSTATUS .
.Fn OCSP_REVOKEDINFO_free
frees
.Fa revokedinfo .
.Pp
.Fn OCSP_resp_find_status
searches
.Fa bs
for an OCSP response for
.Fa id .
If it is successful, the fields of the response are returned in
.Pf * Fa status ,
.Pf * Fa reason ,
.Pf * Fa revtime ,
.Pf * Fa thisupd
and
.Pf * Fa nextupd .
The
.Pf * Fa status
value will be one of
.Dv V_OCSP_CERTSTATUS_GOOD ,
.Dv V_OCSP_CERTSTATUS_REVOKED ,
or
.Dv V_OCSP_CERTSTATUS_UNKNOWN .
The
.Pf * Fa reason
and
.Pf * Fa revtime
fields are only set if the status is
.Dv V_OCSP_CERTSTATUS_REVOKED .
If set, the
.Pf * Fa reason
field will be set to the revocation reason which will be one of
.Dv OCSP_REVOKED_STATUS_NOSTATUS ,
.Dv OCSP_REVOKED_STATUS_UNSPECIFIED ,
.Dv OCSP_REVOKED_STATUS_KEYCOMPROMISE ,
.Dv OCSP_REVOKED_STATUS_CACOMPROMISE ,
.Dv OCSP_REVOKED_STATUS_AFFILIATIONCHANGED ,
.Dv OCSP_REVOKED_STATUS_SUPERSEDED ,
.Dv OCSP_REVOKED_STATUS_CESSATIONOFOPERATION ,
.Dv OCSP_REVOKED_STATUS_CERTIFICATEHOLD
or
.Dv OCSP_REVOKED_STATUS_REMOVEFROMCRL .
.Pp
.Fn OCSP_cert_status_str
converts one of the
.Fa status
codes retrieved by
.Fn OCSP_resp_find_status
to a string consisting of one word.
.Pp
.Fn OCSP_resp_count
returns the number of
.Vt OCSP_SINGLERESP
structures in
.Fa bs .
.Pp
.Fn OCSP_resp_get0
returns the
.Vt OCSP_SINGLERESP
structure in
.Fa bs
corresponding to index
.Fa idx ,
where
.Fa idx
runs from 0 to
.Fn OCSP_resp_count bs No - 1 .
.Pp
.Fn OCSP_resp_find
searches
.Fa bs
for
.Fa id
and returns the index of the first matching entry after
.Fa last
or starting from the beginning if
.Fa last
is -1.
.Pp
.Fn OCSP_single_get0_status
extracts the fields of
.Fa single
in
.Pf * Fa reason ,
.Pf * Fa revtime ,
.Pf * Fa thisupd ,
and
.Pf * Fa nextupd .
.Pp
.Fn OCSP_check_validity
checks the validity of
.Fa thisupd
and
.Fa nextupd
values which will be typically obtained from
.Fn OCSP_resp_find_status
or
.Fn OCSP_single_get0_status .
If
.Fa sec
is non-zero it indicates how many seconds leeway should be allowed in
the check.
If
.Fa maxsec
is positive it indicates the maximum age of
.Fa thisupd
in seconds.
.Pp
Applications will typically call
.Fn OCSP_resp_find_status
using the certificate ID of interest and then check its validity using
.Fn OCSP_check_validity .
They can then take appropriate action based on the status of the
certificate.
.Pp
An OCSP response for a certificate contains
.Sy thisUpdate
and
.Sy nextUpdate
fields.
Normally the current time should be between these two values.
To account for clock skew, the
.Fa maxsec
field can be set to non-zero in
.Fn OCSP_check_validity .
Some responders do not set the
.Sy nextUpdate
field.
This would otherwise mean an ancient response would be considered
valid: the
.Fa maxsec
parameter to
.Fn OCSP_check_validity
can be used to limit the permitted age of responses.
.Pp
The values written to
.Pf * Fa revtime ,
.Pf * Fa thisupd ,
and
.Pf * Fa nextupd
by
.Fn OCSP_resp_find_status
and
.Fn OCSP_single_get0_status
are internal pointers which must not be freed up by the calling
application.
Any or all of these parameters can be set to
.Dv NULL
if their value is not required.
.Pp
.Fn OCSP_basic_verify
checks that the basic response message
.Fa bs
is correctly signed and that the signer certificate can be validated.
It takes
.Fa st
as the trusted store and
.Fa certs
as a set of untrusted intermediate certificates.
The function first tries to find the signer certificate of the response in
.Fa certs .
It also searches the certificates the responder may have included in
.Fa bs
unless the
.Fa flags
contain
.Dv OCSP_NOINTERN .
It fails if the signer certificate cannot be found.
Next, the function checks the signature of
.Fa bs
and fails on error unless the
.Fa flags
contain
.Dv OCSP_NOSIGS .
Then the function already returns
success if the
.Fa flags
contain
.Dv OCSP_NOVERIFY
or if the signer certificate was found in
.Fa certs
and the
.Fa flags
contain
.Dv OCSP_TRUSTOTHER .
Otherwise the function continues by validating the signer certificate.
To this end, all certificates in
.Fa certs
and in
.Fa bs
are considered as untrusted certificates for the construction of
the validation path for the signer certificate unless the
.Dv OCSP_NOCHAIN
flag is set.
After successful path
validation, the function returns success if the
.Dv OCSP_NOCHECKS
flag is set.
Otherwise it verifies that the signer certificate meets the OCSP issuer
criteria including potential delegation.
If this does not succeed and the
.Fa flags
do not contain
.Dv OCSP_NOEXPLICIT ,
the function checks for explicit trust for OCSP signing
in the root CA certificate.
.Sh RETURN VALUES
.Fn OCSP_SINGLERESP_new ,
.Fn OCSP_CERTSTATUS_new ,
and
.Fn OCSP_REVOKEDINFO_new
return a pointer to an empty
.Vt OCSP_SINGLERESP ,
.Vt OCSP_CERTSTATUS ,
or
.Vt OCSP_REVOKEDINFO
object, respectively, or
.Dv NULL
if an error occurred.
.Pp
.Fn OCSP_resp_find_status
returns 1 if
.Fa id
is found in
.Fa bs
or 0 otherwise.
.Pp
.Fn OCSP_cert_status_str
returns a pointer to a static string.
.Pp
.Fn OCSP_resp_count
returns the total number of
.Vt OCSP_SINGLERESP
fields in
.Fa bs .
.Pp
.Fn OCSP_resp_get0
returns a pointer to an
.Vt OCSP_SINGLERESP
structure or
.Dv NULL
if
.Fa idx
is out of range.
.Pp
.Fn OCSP_resp_find
returns the index of
.Fa id
in
.Fa bs
(which may be 0) or -1 if
.Fa id
was not found.
.Pp
.Fn OCSP_SINGLERESP_get0_id
returns an internal pointer to the certificate ID object used by
.Fa single ;
the returned pointer should not be freed by the caller.
.Pp
.Fn OCSP_single_get0_status
returns the status of
.Fa single
or -1 if an error occurred.
.Pp
.Fn OCSP_basic_verify
returns 1 on success, 0 on error, or -1 on fatal error such as malloc failure.
.Sh SEE ALSO
.Xr OCSP_cert_to_id 3 ,
.Xr OCSP_CRLID_new 3 ,
.Xr OCSP_request_add1_nonce 3 ,
.Xr OCSP_REQUEST_new 3 ,
.Xr OCSP_response_status 3 ,
.Xr OCSP_sendreq_new 3
.Sh STANDARDS
RFC 6960: X.509 Internet Public Key Infrastructure Online Certificate
Status Protocol, section 4.2: Response Syntax
.Sh HISTORY
.Fn OCSP_SINGLERESP_new ,
.Fn OCSP_SINGLERESP_free ,
.Fn OCSP_CERTSTATUS_new ,
.Fn OCSP_CERTSTATUS_free ,
.Fn OCSP_REVOKEDINFO_new ,
.Fn OCSP_REVOKEDINFO_free ,
.Fn OCSP_resp_find_status ,
.Fn OCSP_cert_status_str ,
.Fn OCSP_resp_count ,
.Fn OCSP_resp_get0 ,
.Fn OCSP_resp_find ,
.Fn OCSP_single_get0_status ,
and
.Fn OCSP_check_validity
first appeared in OpenSSL 0.9.7 and have been available since
.Ox 3.2 .
.Pp
.Fn OCSP_SINGLERESP_get0_id
first appeared in OpenSSL 1.1.0 and has been available since
.Ox 6.3 .
|