Botan 3.10.0
Crypto and TLS for C&
msg_cert_status.cpp
Go to the documentation of this file.
1/*
2* Certificate Status
3* (C) 2016 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/tls_messages.h>
9
10#include <botan/ocsp.h>
11#include <botan/internal/loadstor.h>
12#include <botan/internal/tls_handshake_hash.h>
13#include <botan/internal/tls_handshake_io.h>
14
15namespace Botan::TLS {
16
17Certificate_Status::Certificate_Status(const std::vector<uint8_t>& buf, const Connection_Side /*side*/) {
18 if(buf.size() < 5) {
19 throw Decoding_Error("Invalid Certificate_Status message: too small");
20 }
21
22 if(buf[0] != 1) { // not OCSP
23 throw Decoding_Error("Unexpected Certificate_Status message: unexpected response type");
24 }
25
26 size_t len = make_uint32(0, buf[1], buf[2], buf[3]);
27
28 // Verify the redundant length field...
29 if(buf.size() != len + 4) {
30 throw Decoding_Error("Invalid Certificate_Status: invalid length field");
31 }
32
33 m_response.assign(buf.begin() + 4, buf.end());
34}
35
37 m_response(ocsp.raw_bits()) {
38 hash.update(io.send(*this));
39}
40
42 Handshake_Hash& hash,
43 std::vector<uint8_t> raw_response_bytes) :
44 Certificate_Status(std::move(raw_response_bytes)) {
45 hash.update(io.send(*this));
46}
47
48Certificate_Status::Certificate_Status(std::vector<uint8_t> raw_response_bytes) :
49 m_response(std::move(raw_response_bytes)) {}
50
51std::vector<uint8_t> Certificate_Status::serialize() const {
52 if(m_response.size() > 0xFFFFFF) { // unlikely
53 throw Encoding_Error("OCSP response too long to encode in TLS");
54 }
55
56 const uint32_t response_len = static_cast<uint32_t>(m_response.size());
57
58 std::vector<uint8_t> buf;
59 buf.reserve(1 + 3 + m_response.size());
60 buf.push_back(1); // type OCSP
61 for(size_t i = 1; i < 4; ++i) {
62 buf.push_back(get_byte_var(i, response_len));
63 }
64
65 buf += m_response;
66 return buf;
67}
68
69} // namespace Botan::TLS
Certificate_Status(const std::vector< uint8_t > &buf, Connection_Side from)
std::vector< uint8_t > serialize() const override
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition loadstor.h:104
constexpr uint8_t get_byte_var(size_t byte_num, T input)
Definition loadstor.h:69