Kea 2.5.8
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
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
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
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
TLS API.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool isDir(string const &path)
Check if there is a directory at the given path.
Definition: filesystem.cc:55
Defines the logger used by the top-level component of kea-lfc.