aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp
blob: 52f822d7593a3af63d58404a4809ab2e3ec555b3 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "transport_security_options.h"
#include <openssl/crypto.h>
#include <cassert>

namespace vespalib::net::tls {

TransportSecurityOptions::TransportSecurityOptions(Params params)
    : _ca_certs_pem(std::move(params._ca_certs_pem)),
      _cert_chain_pem(std::move(params._cert_chain_pem)),
      _private_key_pem(std::move(params._private_key_pem)),
      _authorized_peers(std::move(params._authorized_peers)),
      _accepted_ciphers(std::move(params._accepted_ciphers)),
      _disable_hostname_validation(params._disable_hostname_validation)
{
}

TransportSecurityOptions::TransportSecurityOptions(vespalib::string ca_certs_pem,
                                                   vespalib::string cert_chain_pem,
                                                   vespalib::string private_key_pem,
                                                   AuthorizedPeers authorized_peers,
                                                   bool disable_hostname_validation)
    : _ca_certs_pem(std::move(ca_certs_pem)),
      _cert_chain_pem(std::move(cert_chain_pem)),
      _private_key_pem(std::move(private_key_pem)),
      _authorized_peers(std::move(authorized_peers)),
      _disable_hostname_validation(disable_hostname_validation)
{
}

TransportSecurityOptions::TransportSecurityOptions(const TransportSecurityOptions&) = default;
TransportSecurityOptions::TransportSecurityOptions(TransportSecurityOptions&&) noexcept = default;
TransportSecurityOptions& TransportSecurityOptions::operator=(TransportSecurityOptions&&) noexcept = default;

TransportSecurityOptions::~TransportSecurityOptions() {
    secure_memzero(&_private_key_pem[0], _private_key_pem.size());
}

TransportSecurityOptions TransportSecurityOptions::copy_without_private_key() const {
    return TransportSecurityOptions(_ca_certs_pem, _cert_chain_pem, "",
                                    _authorized_peers, _disable_hostname_validation);
}

void secure_memzero(void* buf, size_t size) noexcept {
    OPENSSL_cleanse(buf, size);
}

TransportSecurityOptions::Params::Params()
    : _ca_certs_pem(),
      _cert_chain_pem(),
      _private_key_pem(),
      _authorized_peers(),
      _accepted_ciphers(),
      _disable_hostname_validation(false)
{
}

TransportSecurityOptions::Params::~Params() {
    secure_memzero(&_private_key_pem[0], _private_key_pem.size());
}

TransportSecurityOptions::Params::Params(const Params&) = default;

TransportSecurityOptions::Params::Params(Params&&) noexcept = default;

TransportSecurityOptions::Params&
TransportSecurityOptions::Params::operator=(TransportSecurityOptions::Params&&) noexcept = default;

} // vespalib::net::tls