Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #include <botan/tls_extensions.h>
10 #include <botan/internal/tls_reader.h>
11 #include <botan/internal/tls_handshake_io.h>
12 #include <botan/internal/tls_handshake_hash.h>
13 #include <botan/der_enc.h>
14 #include <botan/ber_dec.h>
15
16 namespace Botan {
17
18 namespace TLS {
19
20 Certificate_Status::Certificate_Status(const std::vector<uint8_t>& buf)
21 {
22 if(buf.size() < 5)
23 throw Decoding_Error("Invalid Certificate_Status message: too small");
24
25 if(buf[0] != 1)
26 throw Decoding_Error("Unexpected Certificate_Status message: unexpected message type");
27
28 size_t len = make_uint32(0, buf[1], buf[2], buf[3]);
29
30 // Verify the redundant length field...
31 if(buf.size() != len + 4)
32 throw Decoding_Error("Invalid Certificate_Status: invalid length field");
33
34 m_response = std::make_shared<OCSP::Response>(buf.data() + 4, buf.size() - 4);
35 }
36
37 Certificate_Status::Certificate_Status(Handshake_IO& io,
38 Handshake_Hash& hash,
39 std::shared_ptr<const OCSP::Response> ocsp) :
40 m_response(ocsp)
41 {
42 hash.update(io.send(*this));
43 }
44
45 std::vector<uint8_t> Certificate_Status::serialize() const
46 {
47 BOTAN_ASSERT_NONNULL(m_response);
48 const std::vector<uint8_t>& m_resp_bits = m_response->raw_bits();
49
50 if(m_resp_bits.size() > 0xFFFFFF) // unlikely
51 throw Encoding_Error("OCSP response too long to encode in TLS");
52
53 const uint32_t m_resp_bits_len = static_cast<uint32_t>(m_resp_bits.size());
54
55 std::vector<uint8_t> buf;
56 buf.push_back(1); // type OCSP
57 for(size_t i = 1; i < 4; ++i)
58 buf[i] = get_byte(i, m_resp_bits_len);
59
60 buf += m_resp_bits;
61 return buf;
62 }
63
64 }
65
66 }
Botan::TLS::Handshake_IO::send
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
Botan::TLS::Certificate_Status::Certificate_Status
Certificate_Status(const std::vector< uint8_t > &buf)
Definition: msg_cert_status.cpp:20
Botan::TLS::Handshake_Hash
Definition: tls_handshake_hash.h:22
BOTAN_ASSERT_NONNULL
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
Botan::TLS::Handshake_Hash::update
void update(const uint8_t in[], size_t length)
Definition: tls_handshake_hash.h:25
Botan::Decoding_Error
Definition: exceptn.h:189
Botan::TLS::Handshake_IO
Definition: tls_handshake_io.h:30
Botan
Definition: alg_id.cpp:13
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
Botan::make_uint32
uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:73
Botan::Encoding_Error
Definition: exceptn.h:180
hash
MechanismType hash
Definition: p11_mechanism.cpp:63