Kea 2.7.5
openssl_link.cc
Go to the documentation of this file.
1// Copyright (C) 2014-2022 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
7#include <config.h>
8
13
14#include <openssl/crypto.h>
15#include <openssl/rand.h>
16
17namespace isc {
18namespace cryptolink {
19
20// For OpenSSL, we use the CryptoLink class object in RAII style
21class CryptoLinkImpl {
22};
23
24CryptoLink::~CryptoLink() {
25}
26
28class RNGImpl : public RNG {
29public:
30 RNGImpl() { }
31
33
34private:
35 std::vector<uint8_t> random(size_t len) {
36 std::vector<uint8_t> data;
37 if (len > 0) {
38 data.resize(len);
39 if (RAND_bytes(&data[0], len) != 1) {
41 "OpenSSL RAND_bytes() failed");
42 }
43 }
44 return (data);
45 }
46};
47
48void
49CryptoLink::initialize(CryptoLink& c) {
50 if (!c.impl_) {
51 try {
52 c.impl_.reset(new CryptoLinkImpl());
53 } catch (const std::exception &ex) {
54 // Should never happen
55 isc_throw(InitializationError,
56 "Error during OpenSSL initialization:" << ex.what());
57 } catch (...) {
58 // Should never happen
59 isc_throw(InitializationError,
60 "Error during OpenSSL initialization");
61 }
62 }
63 if (!c.rng_) {
64 try {
65 c.rng_.reset(new RNGImpl());
66 } catch (const std::exception &ex) {
67 // Should never happen
68 isc_throw(InitializationError,
69 "Error during OpenSSL RNG initialization:" << ex.what());
70 } catch (...) {
71 // Should never happen
72 isc_throw(InitializationError,
73 "Error during OpenSSL RNG initialization");
74 }
75 }
76}
77
78std::string
80 return (SSLeay_version(SSLEAY_VERSION));
81}
82
83} // namespace cryptolink
84} // namespace isc
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.