Botan 3.13.0
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 181 of file roughtime.cpp.

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

234 {
235 constexpr std::string_view context("RoughTime v1 delegation signature--\0", 36);
236 PK_Verifier verifier(pk, "Pure");
237 verifier.update(context);
238 verifier.update(m_cert_dele.data(), m_cert_dele.size());
239 return verifier.check_signature(m_cert_sig.data(), m_cert_sig.size());
240}

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


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