summaryrefslogtreecommitdiff
path: root/src/network/tls_policy.cpp
blob: 5439397384f6eeeebdc0961c40294da39dc7d615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "biboumi.h"

#ifdef BOTAN_FOUND

#include <fstream>

#include <utils/tolower.hpp>

#include <network/tls_policy.hpp>
#include <logger/logger.hpp>

bool BiboumiTLSPolicy::load(const std::string& filename)
{
  std::ifstream is(filename.data());
  if (is)
    {
      try {
          this->load(is);
          log_info("Successfully loaded policy file: ", filename);
          return true;
        } catch (const Botan::Exception& e) {
          log_error("Failed to parse policy_file ", filename, ": ", e.what());
          return false;
        }
    }
  log_info("Could not open policy file: ", filename);
  return false;
}

void BiboumiTLSPolicy::load(std::istream& is)
{
  const auto dict = Botan::read_cfg(is);
  for (const auto& pair: dict)
    {
      // Workaround for options that are not overridden in Botan::TLS::Text_Policy
      if (pair.first == "require_cert_revocation_info")
        this->req_cert_revocation_info = !(pair.second == "0" || utils::tolower(pair.second) == "false");
      else
        this->set(pair.first, pair.second);
    }
}

bool BiboumiTLSPolicy::require_cert_revocation_info() const
{
  return this->req_cert_revocation_info;
}

#endif