Botan 3.14.1
Crypto and TLS for C&
Botan::Roughtime::Response Class Referencefinal

#include <roughtime.h>

Public Types

using microseconds32 = std::chrono::duration<uint32_t, std::micro>
using microseconds64 = std::chrono::duration<uint64_t, std::micro>
using sys_microseconds64 = std::chrono::time_point<std::chrono::system_clock, microseconds64>

Public Member Functions

sys_microseconds64 utc_midpoint () const
microseconds32 utc_radius () const
bool validate (const Ed25519_PublicKey &pk) const

Static Public Member Functions

static Response from_bits (const std::vector< uint8_t > &response, const Nonce &nonce)

Detailed Description

An Roughtime response.

Definition at line 103 of file roughtime.h.

Member Typedef Documentation

◆ microseconds32

using Botan::Roughtime::Response::microseconds32 = std::chrono::duration<uint32_t, std::micro>

A 32 bit microsecond duration

Definition at line 108 of file roughtime.h.

◆ microseconds64

using Botan::Roughtime::Response::microseconds64 = std::chrono::duration<uint64_t, std::micro>

A 64 bit microsecond duration

Definition at line 113 of file roughtime.h.

◆ sys_microseconds64

using Botan::Roughtime::Response::sys_microseconds64 = std::chrono::time_point<std::chrono::system_clock, microseconds64>

A system clock time point with microsecond resolution

Definition at line 118 of file roughtime.h.

Member Function Documentation

◆ from_bits()

Response Botan::Roughtime::Response::from_bits ( const std::vector< uint8_t > & response,
const Nonce & nonce )
static

Parse a Roughtime response

Parameters
responsethe raw response bytes
noncethe nonce which was sent in the request
Returns
the parsed response

Definition at line 186 of file roughtime.cpp.

186 {
187 const auto response_v = unpack_roughtime_packet(response);
188 const auto cert = unpack_roughtime_packet(get_v(response_v, "CERT"));
189 const auto cert_dele = get<std::array<uint8_t, 72>>(cert, "DELE");
190 const auto cert_sig = get<std::array<uint8_t, 64>>(cert, "SIG");
191 const auto cert_dele_v = unpack_roughtime_packet(cert_dele);
192 const auto srep = get_v(response_v, "SREP");
193 const auto srep_v = unpack_roughtime_packet(srep);
194
195 const auto cert_dele_pubk = get<std::array<uint8_t, 32>>(cert_dele_v, "PUBK");
196 const auto sig = get<std::array<uint8_t, 64>>(response_v, "SIG");
197 if(!verify_signature(cert_dele_pubk, srep, sig)) {
198 throw Roughtime_Error("Response signature invalid");
199 }
200
201 const auto indx = get<uint32_t>(response_v, "INDX");
202 const auto path = get_v(response_v, "PATH");
203 const auto srep_root = get<std::array<uint8_t, 64>>(srep_v, "ROOT");
204 const size_t size = path.size();
205 const size_t levels = size / 64;
206
207 if(size % 64 != 0) {
208 throw Roughtime_Error("Merkle tree path size must be multiple of 64 bytes");
209 }
210 if(levels >= 32 || indx >= (uint32_t(1) << levels)) {
211 throw Roughtime_Error("Merkle tree path is too short");
212 }
213
214 BufferSlicer slicer(path);
215 auto hash = hashLeaf(nonce.get_nonce());
216 auto index = indx;
217 for(std::size_t level = 0; level < levels; ++level) {
218 hashNode(hash, slicer.take<64>(), index % 2 == 1);
219 index >>= 1;
220 }
221
222 if(srep_root != hash) {
223 throw Roughtime_Error("Nonce verification failed");
224 }
225
226 const auto cert_dele_maxt = sys_microseconds64(get<microseconds64>(cert_dele_v, "MAXT"));
227 const auto cert_dele_mint = sys_microseconds64(get<microseconds64>(cert_dele_v, "MINT"));
228 const auto srep_midp = sys_microseconds64(get<microseconds64>(srep_v, "MIDP"));
229 const auto srep_radi = get<microseconds32>(srep_v, "RADI");
230 if(srep_midp < cert_dele_mint) {
231 throw Roughtime_Error("Midpoint earlier than delegation start");
232 }
233 if(srep_midp > cert_dele_maxt) {
234 throw Roughtime_Error("Midpoint later than delegation end");
235 }
236 return {cert_dele, cert_sig, srep_midp, srep_radi};
237}
std::chrono::time_point< std::chrono::system_clock, microseconds64 > sys_microseconds64
Definition roughtime.h:118
const char * path
Definition ffi_tls.h:139
bool verify_signature(std::span< const uint8_t, ED448_LEN > pk, bool phflag, std::span< const uint8_t > context, std::span< const uint8_t > sig, std::span< const uint8_t > msg)
Verify a signature(RFC 8032 5.2.7).

References Botan::Roughtime::Nonce::get_nonce(), path, Botan::BufferSlicer::take(), and Botan::verify_signature().

Referenced by Botan::Roughtime::Chain::responses().

◆ utc_midpoint()

sys_microseconds64 Botan::Roughtime::Response::utc_midpoint ( ) const
inline

Return the midpoint of the time interval reported by the server

Returns
the UTC midpoint

Definition at line 139 of file roughtime.h.

139{ return m_utc_midpoint; }

◆ utc_radius()

microseconds32 Botan::Roughtime::Response::utc_radius ( ) const
inline

Return the radius of the time interval reported by the server

Returns
the UTC radius

Definition at line 145 of file roughtime.h.

145{ return m_utc_radius; }

◆ validate()

bool Botan::Roughtime::Response::validate ( const Ed25519_PublicKey & pk) const

Check the signatures on this response

Parameters
pkthe long term public key of the server
Returns
true if the response is valid

Definition at line 239 of file roughtime.cpp.

239 {
240 constexpr std::string_view context("RoughTime v1 delegation signature--\0", 36);
241 PK_Verifier verifier(pk, "Pure");
242 verifier.update(context);
243 verifier.update(m_cert_dele.data(), m_cert_dele.size());
244 return verifier.check_signature(m_cert_sig.data(), m_cert_sig.size());
245}

References Botan::PK_Verifier::check_signature(), and Botan::PK_Verifier::update().


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