credentials_manager.hpp 1.76 KB
Newer Older
1
#pragma once
2

louiz’'s avatar
louiz’ committed
3
#include "biboumi.h"
4 5 6

#ifdef BOTAN_FOUND

7 8
#include <botan/credentials_manager.h>
#include <botan/certstor.h>
9 10
#include <botan/tls_client.h>

11 12
class TCPSocketHandler;

13 14 15 16 17 18 19 20 21 22
/**
 * If the given cert isn’t valid, based on the given hostname
 * and fingerprint, then throws the exception if it’s non-empty.
 *
 * Must be called after the standard (from Botan) way of
 * checking the certificate, if we want to also accept certificates based
 * on a trusted fingerprint.
 */
void check_tls_certificate(const std::vector<Botan::X509_Certificate>& certs,
                           const std::string& hostname, const std::string& trusted_fingerprint,
23
                           const std::exception_ptr& exc);
24

louiz’'s avatar
louiz’ committed
25
class BasicCredentialsManager: public Botan::Credentials_Manager
26 27
{
public:
louiz’'s avatar
louiz’ committed
28
  BasicCredentialsManager(const TCPSocketHandler* const socket_handler);
louiz’'s avatar
louiz’ committed
29 30 31 32 33 34

  BasicCredentialsManager(BasicCredentialsManager&&) = delete;
  BasicCredentialsManager(const BasicCredentialsManager&) = delete;
  BasicCredentialsManager& operator=(const BasicCredentialsManager&) = delete;
  BasicCredentialsManager& operator=(BasicCredentialsManager&&) = delete;

35 36
  std::vector<Botan::Certificate_Store*> trusted_certificate_authorities(const std::string& type,
                                                                         const std::string& context) override final;
37
  void set_trusted_fingerprint(const std::string& fingerprint);
38
  const std::string& get_trusted_fingerprint() const;
39 40

private:
41 42
  const TCPSocketHandler* const socket_handler;

louiz’'s avatar
louiz’ committed
43
  static bool try_to_open_one_ca_bundle(const std::vector<std::string>& paths);
44 45 46
  static void load_certs();
  static Botan::Certificate_Store_In_Memory certificate_store;
  static bool certs_loaded;
47
  std::string trusted_fingerprint;
48 49
};

50
#endif //BOTAN_FOUND
51