Kea: common_tls.cc Source File

| Kea 3.0.0

common_tls.cc
Go to the documentation of this file.
1// Copyright (C) 2021-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
8
9#include <config.h>
10
11#include <asiolink/asio_wrapper.h>
12#include <asiolink/crypto_tls.h>
13#include <util/filesystem.h>
14
15using namespace isc::cryptolink;
16using namespace isc::util;
17
18namespace isc {
19namespace asiolink {
20
21void
22TlsContextBase::configure(TlsContextPtr& context,
23 TlsRole role,
24 const std::string& ca_file,
25 const std::string& cert_file,
26 const std::string& key_file,
27 bool cert_required) {
28 try {
29 context.reset(new TlsContext(role));
30 context->setCertRequired(cert_required);
31 if (file::isDir(ca_file)) {
32 try {
33 context->loadCaPath(ca_file);
34 } catch (const std::exception& ex) {
35 isc_throw(isc::BadValue, "load of CA directory '"
36 << ca_file << "' failed: " << ex.what());
37 }
38 } else {
39 try {
40 context->loadCaFile(ca_file);
41 } catch (const std::exception& ex) {
42 isc_throw(isc::BadValue, "load of CA file '"
43 << ca_file << "' failed: " << ex.what());
44 }
45 }
46 try {
47 context->loadCertFile(cert_file);
48 } catch (const std::exception& ex) {
49 isc_throw(isc::BadValue, "load of cert file '"
50 << cert_file << "' failed: " << ex.what());
51 }
52 try {
53 context->loadKeyFile(key_file);
54 } catch (const std::exception& ex) {
55 isc_throw(isc::BadValue, "load of private key file '"
56 << key_file << "' failed: " << ex.what());
57 }
58 } catch (...) {
59 context.reset();
60 throw;
61 }
62}
63
64} // namespace asiolink
65} // namespace isc
asio_wrapper.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::asiolink::TlsContextBase::configure
static void configure(TlsContextPtr &context, TlsRole role, const std::string &ca_file, const std::string &cert_file, const std::string &key_file, bool cert_required=true)
Configure.
Definition common_tls.cc:22
crypto_tls.h
TLS API.
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
filesystem.h
isc::asiolink
Definition addr_utilities.cc:170
isc::asiolink::TlsContextPtr
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
Definition common_tls.h:37
isc::asiolink::TlsRole
TlsRole
Client and server roles.
Definition common_tls.h:31
isc::cryptolink
Definition botan_common.h:8
isc::util::file::isDir
bool isDir(string const &path)
Check if there is a directory at the given path.
Definition filesystem.cc:70
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148