Botan 3.14.1
Crypto and TLS for C&
Botan::OCSP::SingleResponse Class Referencefinal

#include <ocsp.h>

Inheritance diagram for Botan::OCSP::SingleResponse:
Botan::ASN1_Object

Public Member Functions

std::vector< uint8_t > BER_encode () const
size_t cert_status () const
const CertID & certid () const
void decode_from (BER_Decoder &from) override
void encode_into (DER_Encoder &to) const override
bool has_unknown_critical_extension () const
const X509_Time & next_update () const
const std::optional< CRL_Code > & revocation_reason () const
 The revocationReason, when cert_status() is 1 and one was provided.
const std::optional< X509_Time > & revocation_time () const
 The revocationTime; set only when cert_status() is 1 (revoked).
 SingleResponse ()=default
const X509_Time & this_update () const

Static Public Member Functions

static SingleResponse good (CertID certid, X509_Time this_update, X509_Time next_update)
static SingleResponse revoked (CertID certid, X509_Time revocation_time, std::optional< CRL_Code > reason, X509_Time this_update, X509_Time next_update)
 As good(), but asserting a revoked status with the given RevokedInfo.
static SingleResponse unknown (CertID certid, X509_Time this_update, X509_Time next_update)
 As good(), but asserting an unknown status.

Detailed Description

Definition at line 51 of file ocsp.h.

Constructor & Destructor Documentation

◆ SingleResponse()

Botan::OCSP::SingleResponse::SingleResponse ( )
default

Member Function Documentation

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 21 of file asn1_obj.cpp.

21 {
22 std::vector<uint8_t> output;
23 DER_Encoder der(output);
24 this->encode_into(der);
25 return output;
26}
virtual void encode_into(DER_Encoder &to) const =0

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::PSS_Params::PSS_Params().

◆ cert_status()

size_t Botan::OCSP::SingleResponse::cert_status ( ) const
inline

Definition at line 74 of file ocsp.h.

74{ return m_cert_status; }

Referenced by decode_from().

◆ certid()

const CertID & Botan::OCSP::SingleResponse::certid ( ) const
inline

Definition at line 72 of file ocsp.h.

72{ return m_certid; }

Referenced by good(), revoked(), SingleResponse(), and unknown().

◆ decode_from()

void Botan::OCSP::SingleResponse::decode_from ( BER_Decoder & from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 213 of file ocsp.cpp.

213 {
214 /*
215 * RFC 6960 Section 4.2.1
216 *
217 * SingleResponse ::= SEQUENCE {
218 * certID CertID,
219 * certStatus CertStatus,
220 * thisUpdate GeneralizedTime,
221 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
222 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
223 *
224 * CertStatus ::= CHOICE {
225 * good [0] IMPLICIT NULL,
226 * revoked [1] IMPLICIT RevokedInfo,
227 * unknown [2] IMPLICIT UnknownInfo }
228 *
229 * RevokedInfo ::= SEQUENCE {
230 * revocationTime GeneralizedTime,
231 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
232 */
233 BER_Object cert_status;
234 Extensions extensions;
235
236 auto seq = from.start_sequence();
237 seq.decode(m_certid)
238 .get_next(cert_status)
239 .decode(m_thisupdate)
240 .decode_optional(m_nextupdate, ASN1_Type(0), ASN1_Class::ContextSpecific | ASN1_Class::Constructed);
241
242 check_generalized_time(m_thisupdate, "thisUpdate");
243 if(m_nextupdate.time_is_set()) {
244 check_generalized_time(m_nextupdate, "nextUpdate");
245 }
246
247 if(seq.more_items()) {
248 const BER_Object next = seq.get_next_object();
250 BER_Decoder ext_decoder(next, BER_Decoder::Limits::DER());
251 extensions.decode_from(ext_decoder, Extension_Context::OCSP_Response);
252 ext_decoder.verify_end();
253 } else {
254 throw Decoding_Error("Unexpected tag in OCSP SingleResponse");
255 }
256 }
257 seq.end_cons();
258
259 const auto cert_status_class = cert_status.get_class();
260 if(cert_status_class != ASN1_Class::ContextSpecific &&
261 cert_status_class != (ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
262 throw Decoding_Error("OCSP::SingleResponse: certStatus has unexpected class tag");
263 }
264
265 m_cert_status = static_cast<uint32_t>(cert_status.type());
266 if(m_cert_status > 2) {
267 throw Decoding_Error("Unknown OCSP CertStatus tag");
268 }
269
270 m_revocation_time.reset();
271 m_revocation_reason.reset();
272
273 if(m_cert_status == 1) {
274 BER_Decoder revoked_info(cert_status, BER_Decoder::Limits::DER());
276 revoked_info.decode(revocation_time);
277 check_generalized_time(revocation_time, "revocationTime");
278 m_revocation_time = std::move(revocation_time);
279
280 if(revoked_info.peek_next_object().is_a(0, ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
281 size_t reason = 0;
282 revoked_info.start_context_specific(0).decode(reason, ASN1_Type::Enumerated, ASN1_Class::Universal).end_cons();
283 if(reason == 7 || reason > 10) {
284 throw Decoding_Error(fmt("CRLReason has unknown enumeration value {}", reason));
285 }
286 m_revocation_reason = static_cast<CRL_Code>(reason);
287 }
288 revoked_info.verify_end();
289 } else if(cert_status.length() != 0) {
290 // good [0] / unknown [2] are both IMPLICIT NULL
291 throw Decoding_Error("OCSP CertStatus has unexpected content");
292 }
293
294 // We don't currently recognize any extensions here so if any are critical we should reject
295 m_has_unknown_critical_ext = !extensions.critical_extensions().empty();
296}
static Limits DER()
Definition ber_dec.h:44
const std::optional< X509_Time > & revocation_time() const
The revocationTime; set only when cert_status() is 1 (revoked).
Definition ocsp.h:81
size_t cert_status() const
Definition ocsp.h:74
ASN1_Time X509_Time
Definition asn1_obj.h:27
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
ASN1_Type
Definition asn1_obj.h:47

References cert_status(), Botan::Constructed, Botan::ContextSpecific, Botan::Extensions::critical_extensions(), Botan::BER_Decoder::decode(), Botan::Extensions::decode_from(), Botan::BER_Decoder::decode_optional(), Botan::BER_Decoder::Limits::DER(), Botan::BER_Decoder::end_cons(), Botan::Enumerated, Botan::fmt(), Botan::BER_Decoder::get_next(), Botan::BER_Object::is_a(), Botan::OCSP_Response, Botan::BER_Decoder::peek_next_object(), revocation_time(), Botan::BER_Decoder::start_context_specific(), Botan::BER_Decoder::start_sequence(), Botan::Universal, and Botan::BER_Decoder::verify_end().

◆ encode_into()

void Botan::OCSP::SingleResponse::encode_into ( DER_Encoder & to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 186 of file ocsp.cpp.

186 {
187 // The SingleResponse / CertStatus / RevokedInfo ASN.1 is quoted in
188 // decode_from below
189 to.start_sequence();
190 to.encode(m_certid);
191 if(m_cert_status == 1) {
192 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
193 to.start_cons(ASN1_Type(1), ASN1_Class::ContextSpecific).encode(m_revocation_time.value());
194 if(m_revocation_reason.has_value() && *m_revocation_reason != CRL_Code::Unspecified) {
195 to.start_explicit(0)
196 .encode(static_cast<size_t>(*m_revocation_reason), ASN1_Type::Enumerated, ASN1_Class::Universal)
197 .end_explicit();
198 }
199 to.end_cons();
200 } else {
201 // good [0] / unknown [2], both IMPLICIT NULL
202 const std::span<const uint8_t> empty;
203 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
204 to.add_object(ASN1_Type(m_cert_status), ASN1_Class::ContextSpecific, empty);
205 }
206 to.encode(m_thisupdate);
207 if(m_nextupdate.time_is_set()) {
208 to.start_explicit(0).encode(m_nextupdate).end_explicit();
209 }
210 to.end_cons();
211}

References Botan::DER_Encoder::add_object(), Botan::ContextSpecific, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::end_explicit(), Botan::Enumerated, Botan::DER_Encoder::start_cons(), Botan::DER_Encoder::start_explicit(), Botan::DER_Encoder::start_sequence(), Botan::Universal, and Botan::Unspecified.

◆ good()

SingleResponse Botan::OCSP::SingleResponse::good ( CertID certid,
X509_Time this_update,
X509_Time next_update )
static

Create a SingleResponse asserting a good status, as emitted by an OCSP responder. All times must be tagged as GeneralizedTime; an unset next_update omits the optional nextUpdate field.

Definition at line 135 of file ocsp.cpp.

135 {
136 return SingleResponse(
137 std::move(certid), 0, std::nullopt, std::nullopt, std::move(this_update), std::move(next_update));
138}
const CertID & certid() const
Definition ocsp.h:72
const X509_Time & next_update() const
Definition ocsp.h:78
const X509_Time & this_update() const
Definition ocsp.h:76

References certid(), next_update(), SingleResponse(), and this_update().

Referenced by SingleResponse().

◆ has_unknown_critical_extension()

bool Botan::OCSP::SingleResponse::has_unknown_critical_extension ( ) const
inline

Definition at line 90 of file ocsp.h.

90{ return m_has_unknown_critical_ext; }

◆ next_update()

const X509_Time & Botan::OCSP::SingleResponse::next_update ( ) const
inline

Definition at line 78 of file ocsp.h.

78{ return m_nextupdate; }

Referenced by good(), revoked(), SingleResponse(), and unknown().

◆ revocation_reason()

const std::optional< CRL_Code > & Botan::OCSP::SingleResponse::revocation_reason ( ) const
inline

The revocationReason, when cert_status() is 1 and one was provided.

Definition at line 84 of file ocsp.h.

84{ return m_revocation_reason; }

◆ revocation_time()

const std::optional< X509_Time > & Botan::OCSP::SingleResponse::revocation_time ( ) const
inline

The revocationTime; set only when cert_status() is 1 (revoked).

Definition at line 81 of file ocsp.h.

81{ return m_revocation_time; }

Referenced by decode_from(), revoked(), and SingleResponse().

◆ revoked()

SingleResponse Botan::OCSP::SingleResponse::revoked ( CertID certid,
X509_Time revocation_time,
std::optional< CRL_Code > reason,
X509_Time this_update,
X509_Time next_update )
static

As good(), but asserting a revoked status with the given RevokedInfo.

Definition at line 147 of file ocsp.cpp.

151 {
152 return SingleResponse(
153 std::move(certid), 1, std::move(revocation_time), reason, std::move(this_update), std::move(next_update));
154}

References certid(), next_update(), revocation_time(), SingleResponse(), and this_update().

Referenced by SingleResponse().

◆ this_update()

const X509_Time & Botan::OCSP::SingleResponse::this_update ( ) const
inline

Definition at line 76 of file ocsp.h.

76{ return m_thisupdate; }

Referenced by good(), revoked(), SingleResponse(), and unknown().

◆ unknown()

SingleResponse Botan::OCSP::SingleResponse::unknown ( CertID certid,
X509_Time this_update,
X509_Time next_update )
static

As good(), but asserting an unknown status.

Definition at line 141 of file ocsp.cpp.

141 {
142 return SingleResponse(
143 std::move(certid), 2, std::nullopt, std::nullopt, std::move(this_update), std::move(next_update));
144}

References certid(), next_update(), SingleResponse(), and this_update().

Referenced by SingleResponse().


The documentation for this class was generated from the following files: