Kea
2.7.5
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
15
using namespace
isc::cryptolink
;
16
using namespace
isc::util
;
17
18
namespace
isc
{
19
namespace
asiolink
{
20
21
void
22
TlsContextBase::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::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition
exceptions/exceptions.cc:32
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
asiolink
A wrapper interface for the ASIO library.
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:52
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
src
lib
asiolink
common_tls.cc
Generated on Wed Nov 20 2024 11:53:23 for Kea by
1.10.0