Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | List of all members
Botan::Roughtime::Chain Class Referencefinal

`#include <roughtime.h>`

## Public Member Functions
void | append (const Link &new_link, size_t max_chain_size)
| Chain ()=default
| Chain (const std::string &str)
const std::vector< Link > & | links () const
Nonce | next_nonce (const Nonce &blind) const
std::vector< Response > | responses () const
std::string | to_string () const

## Detailed Description

Definition at line 109 of file roughtime.h.

## Constructor & Destructor Documentation

## ◆ Chain() [1/2]

Botan::Roughtime::Chain::Chain | ( |  | ) |
| default

## ◆ Chain() [2/2]

Botan::Roughtime::Chain::Chain | ( | const std::string & | str | ) |

Definition at line 253 of file roughtime.cpp.

254 {
255 std::stringstream ss(str);
256 const std::string ERROR_MESSAGE = "Line does not have 4 space separated fields";
257 for(std::string s; std::getline(ss, s);)
258 {
259 size_t start = 0, end = 0;
260 end = s.find(' ', start);
261 if(end == std::string::npos)
262 {
263 throw Decoding_Error(ERROR_MESSAGE);
264 }
265 const auto publicKeyType = s.substr(start, end-start);
266 if(publicKeyType != "ed25519")
267 { throw Not_Implemented("Only ed25519 publicKeyType is implemented"); }
268
269 start = end + 1;
270 end = s.find(' ', start);
271 if(end == std::string::npos)
272 {
273 throw Decoding_Error(ERROR_MESSAGE);
274 }
275 const auto serverPublicKey = Botan::Ed25519_PublicKey(Botan::base64_decode(s.substr(start, end-start)));
276
277 start = end + 1;
278 end = s.find(' ', start);
279 if(end == std::string::npos)
280 {
281 throw Decoding_Error(ERROR_MESSAGE);
282 }
283 if((end - start) != 88)
284 {
285 throw Decoding_Error("Nonce has invalid length");
286 }
287 const auto vec = Botan::base64_decode(s.substr(start, end-start));
288 const auto nonceOrBlind = Nonce(vector_to_array<64>(Botan::base64_decode(s.substr(start, end-start))));
289
290 start = end + 1;
291 end = s.find(' ', start);
292 if(end != std::string::npos)
293 {
294 throw Decoding_Error(ERROR_MESSAGE);
295 }
296 const auto response = Botan::unlock(Botan::base64_decode(s.substr(start)));
297
298 m_links.push_back({response, serverPublicKey, nonceOrBlind});
299 }
300 }
Botan::Ed25519_PublicKey
Definition: ed25519.h:19
Botan::base64_decode
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition: base64.cpp:200
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:72

References Botan::base64_decode(), and Botan::unlock().

## Member Function Documentation

## ◆ append()

void Botan::Roughtime::Chain::append | ( | const Link & | new_link,
|  | size_t | max_chain_size
| ) |  |

Definition at line 321 of file roughtime.cpp.

322 {
323 if(max_chain_size <= 0)
324 { throw Invalid_Argument("Max chain size must be positive"); }
325
326 while(m_links.size() >= max_chain_size)
327 {
328 if(m_links.size() == 1)
329 {
330 auto new_link_updated = new_link;
331 new_link_updated.nonce_or_blind() =
332 nonce_from_blind(m_links[0].response(), new_link.nonce_or_blind()); //we need to convert blind to nonce
333 m_links.clear();
334 m_links.push_back(new_link_updated);
335 return;
336 }
337 if(m_links.size() >= 2)
338 {
339 m_links[1].nonce_or_blind() =
340 nonce_from_blind(m_links[0].response(), m_links[1].nonce_or_blind()); //we need to convert blind to nonce
341 }
342 m_links.erase(m_links.begin());
343 }
344 m_links.push_back(new_link);
345 }
Botan::Roughtime::nonce_from_blind
Nonce nonce_from_blind(const std::vector< uint8_t > &previous_response, const Nonce &blind)
Definition: roughtime.cpp:239

References Botan::Roughtime::nonce_from_blind(), and Botan::Roughtime::Link::nonce_or_blind().

## ◆ links()

const std::vector< Link > & Botan::Roughtime::Chain::links | ( |  | ) | const
| inline

Definition at line 114 of file roughtime.h.

114{ return m_links; }

## ◆ next_nonce()

Nonce Botan::Roughtime::Chain::next_nonce | ( | const Nonce & | blind | ) | const

Definition at line 315 of file roughtime.cpp.

316 {
317 return m_links.empty()
318 ? blind
319 : nonce_from_blind(m_links.back().response(), blind);
320 }

References Botan::Roughtime::nonce_from_blind().

## ◆ responses()

std::vector< Response > Botan::Roughtime::Chain::responses | ( |  | ) | const

Definition at line 301 of file roughtime.cpp.

302 {
303 std::vector<Response> responses;
304 for(unsigned i = 0; i < m_links.size(); ++i)
305 {
306 const auto& l = m_links[i];
307 const auto nonce = i ? nonce_from_blind(m_links[i-1].response(), l.nonce_or_blind()) : l.nonce_or_blind();
308 const auto response = Response::from_bits(l.response(), nonce);
309 if(!response.validate(l.public_key()))
310 { throw Roughtime_Error("Invalid signature or public key"); }
311 responses.push_back(response);
312 }
313 return responses;
314 }
Botan::Roughtime::Chain::responses
std::vector< Response > responses() const
Definition: roughtime.cpp:301
Botan::Roughtime::Response::from_bits
static Response from_bits(const std::vector< uint8_t > &response, const Nonce &nonce)
Definition: roughtime.cpp:179

References Botan::Roughtime::Response::from_bits(), Botan::Roughtime::nonce_from_blind(), and responses().

Referenced by responses().

## ◆ to_string()

std::string Botan::Roughtime::Chain::to_string | ( |  | ) | const

Definition at line 347 of file roughtime.cpp.

348 {
349 std::string s;
350 s.reserve((7+1 + 88+1 + 44+1 + 480)*m_links.size());
351 for(const auto& link : m_links)
352 {
353 s += "ed25519";
354 s += ' ';
355 s += Botan::base64_encode(link.public_key().get_public_key());
356 s += ' ';
357 s += Botan::base64_encode(link.nonce_or_blind().get_nonce().data(), link.nonce_or_blind().get_nonce().size());
358 s += ' ';
359 s += Botan::base64_encode(link.response());
360 s += '\n';
361 }
362 return s;
363 }
Botan::base64_encode
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base64.cpp:185

References Botan::base64_encode().

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

- src/lib/misc/roughtime/roughtime.h
- src/lib/misc/roughtime/roughtime.cpp