Botan 3.13.0
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 CertIDcertid () const
void decode_from (BER_Decoder &from) override
void encode_into (DER_Encoder &to) const override
bool has_unknown_critical_extension () const
const X509_Timenext_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_Timethis_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 214 of file ocsp.cpp.

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

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

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 136 of file ocsp.cpp.

136 {
137 return SingleResponse(
138 std::move(certid), 0, std::nullopt, std::nullopt, std::move(this_update), std::move(next_update));
139}
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 148 of file ocsp.cpp.

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

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 142 of file ocsp.cpp.

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

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

Referenced by SingleResponse().


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