Botan 2.19.5 Crypto and TLS for C&

Classes | Functions | Variables
Botan::Roughtime Namespace Reference

## Classes
class | Chain
class | Link
class | Nonce
class | Response
class | Roughtime_Error
struct | Server_Information

## Functions
std::array< uint8_t, request_min_size > | encode_request (const Nonce &nonce)
Nonce | nonce_from_blind (const std::vector< uint8_t > &previous_response, const Nonce &blind)
std::vector< uint8_t > | online_request (const std::string &uri, const Nonce &nonce, std::chrono::milliseconds timeout)
std::vector< Server_Information > | servers_from_str (const std::string &str)

## Variables
const unsigned | request_min_size = 1024

## Function Documentation

## ◆ encode_request()

std::array< uint8_t, request_min_size > Botan::Roughtime::encode_request | ( | const Nonce & | nonce | ) |

An Roughtime request.

Definition at line 171 of file roughtime.cpp.

172 {
173 std::array<uint8_t, request_min_size> buf = {{2, 0, 0, 0, 64, 0, 0, 0, 'N', 'O', 'N', 'C', 'P', 'A', 'D', 0xff}};
174 std::memcpy(buf.data() + 16, nonce.get_nonce().data(), nonce.get_nonce().size());
175 std::memset(buf.data() + 16 + nonce.get_nonce().size(), 0, buf.size() - 16 - nonce.get_nonce().size());
176 return buf;
177 }
Botan::Roughtime::Nonce::get_nonce
const std::array< uint8_t, 64 > & get_nonce() const
Definition: roughtime.h:43

References Botan::Roughtime::Nonce::get_nonce().

Referenced by online_request().

## ◆ nonce_from_blind()

Nonce Botan::Roughtime::nonce_from_blind | ( | const std::vector< uint8_t > & | previous_response,
|  | const Nonce & | blind
| ) |  |

Definition at line 239 of file roughtime.cpp.

241 {
242 std::array<uint8_t, 64> ret;
243 const auto blind_arr = blind.get_nonce();
244 std::unique_ptr<Botan::HashFunction> hash(Botan::HashFunction::create_or_throw("SHA-512"));
245 hash->update(previous_response);
246 hash->update(hash->final());
247 hash->update(blind_arr.data(), blind_arr.size());
248 hash->final(ret.data());
249
250 return ret;
251 }
Botan::HashFunction::create_or_throw
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:329
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

References Botan::HashFunction::create_or_throw(), Botan::Roughtime::Nonce::get_nonce(), and hash.

Referenced by Botan::Roughtime::Chain::append(), Botan::Roughtime::Chain::next_nonce(), and Botan::Roughtime::Chain::responses().

## ◆ online_request()

std::vector< uint8_t > Botan::Roughtime::online_request | ( | const std::string & | url,
|  | const Nonce & | nonce,
|  | std::chrono::milliseconds | timeout = `std::chrono::seconds(3)`
| ) |  |

Makes an online Roughtime request via UDP and returns the Roughtime response.

Parameters

  url | Roughtime server UDP endpoint (host:port)
  nonce | the nonce to send to the server
  timeout | a timeout on the UDP request

Returns
  Roughtime response

Definition at line 365 of file roughtime.cpp.

368 {
369 const std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now();
370 auto socket = OS::open_socket_udp(uri, timeout);
371 if(!socket)
372 { throw Not_Implemented("No socket support enabled in build"); }
373
374 const auto encoded = encode_request(nonce);
375 socket->write(encoded.data(), encoded.size());
376
377 if(std::chrono::system_clock::now() - start_time > timeout)
378 { throw System_Error("Timeout during socket write"); }
379
380 std::vector<uint8_t> buffer;
381 buffer.resize(360+64*10+1); //response basic size is 360 bytes + 64 bytes for each level of merkle tree
382 //add one additional byte to be able to differentiate if datagram got truncated
383 const auto n = socket->read(buffer.data(), buffer.size());
384
385 if(!n || std::chrono::system_clock::now() - start_time > timeout)
386 { throw System_Error("Timeout waiting for response"); }
387
388 if(n == buffer.size())
389 { throw System_Error("Buffer too small"); }
390
391 buffer.resize(n);
392 return buffer;
393 }
Botan::Not_Implemented
Definition: exceptn.h:356
Botan::System_Error
Definition: exceptn.h:324
Botan::OS::open_socket_udp
std::unique_ptr< SocketUDP > BOTAN_TEST_API open_socket_udp(const std::string &hostname, const std::string &service, std::chrono::microseconds timeout)
Definition: socket_udp.cpp:318
Botan::Roughtime::encode_request
std::array< uint8_t, request_min_size > encode_request(const Nonce &nonce)
Definition: roughtime.cpp:171

References encode_request(), and Botan::OS::open_socket_udp().

## ◆ servers_from_str()

std::vector< Server_Information > Botan::Roughtime::servers_from_str | ( | const std::string & | str | ) |

Definition at line 395 of file roughtime.cpp.

396 {
397 std::vector<Server_Information> servers;
398 std::stringstream ss(str);
399 const std::string ERROR_MESSAGE = "Line does not have at least 5 space separated fields";
400 for(std::string s; std::getline(ss, s);)
401 {
402 size_t start = 0, end = 0;
403 end = s.find(' ', start);
404 if(end == std::string::npos)
405 {
406 throw Decoding_Error(ERROR_MESSAGE);
407 }
408 const auto name = s.substr(start, end-start);
409
410 start = end + 1;
411 end = s.find(' ', start);
412 if(end == std::string::npos)
413 {
414 throw Decoding_Error(ERROR_MESSAGE);
415 }
416 const auto publicKeyType = s.substr(start, end-start);
417 if(publicKeyType != "ed25519")
418 { throw Not_Implemented("Only ed25519 publicKeyType is implemented"); }
419
420 start = end + 1;
421 end = s.find(' ', start);
422
423 if(end == std::string::npos)
424 {
425 throw Decoding_Error(ERROR_MESSAGE);
426 }
427 const auto publicKeyBase64 = s.substr(start, end-start);
428 const auto publicKey = Botan::Ed25519_PublicKey(Botan::base64_decode(publicKeyBase64));
429
430 start = end + 1;
431 end = s.find(' ', start);
432 if(end == std::string::npos)
433 {
434 throw Decoding_Error(ERROR_MESSAGE);
435 }
436 const auto protocol = s.substr(start, end-start);
437 if(protocol != "udp")
438 { throw Not_Implemented("Only UDP protocol is implemented"); }
439
440 const auto addresses = [&]()
441 {
442 std::vector<std::string> addr;
443 for(;;)
444 {
445 start = end + 1;
446 end = s.find(' ', start);
447 const auto address = s.substr(start, (end == std::string::npos) ? std::string::npos : end-start);
448 if(address.empty())
449 { return addr; }
450 addr.push_back(address);
451 if(end == std::string::npos)
452 { return addr; }
453 }
454 }
455 ();
456 if(addresses.size() == 0)
457 {
458 throw Decoding_Error(ERROR_MESSAGE);
459 }
460
461 servers.push_back({name, publicKey, std::move(addresses)});
462 }
463 return servers;
464 }
Botan::Decoding_Error
Definition: exceptn.h:200
Botan::Ed25519_PublicKey
Definition: ed25519.h:19
name
std::string name
Definition: commoncrypto_hash.cpp:24
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

References Botan::base64_decode(), and name.

## Variable Documentation

## ◆ request_min_size

const unsigned Botan::Roughtime::request_min_size = 1024

Definition at line 23 of file roughtime.h.