summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2019-01-23 14:32:35 +0000
committerTor Brede Vekterli <vekterli@oath.com>2019-01-24 12:29:20 +0000
commit12d45f5d8025e9412116a1f254cbe27efe893763 (patch)
tree38bcc584f107667134daa90e74661fd1a8f5f3f1 /vespalib
parent04f493deab394c70d57472f7971a10e4a6a4e85b (diff)
Erase private key data after use
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp11
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/transport_security_options.h5
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp4
3 files changed, 17 insertions, 3 deletions
diff --git a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp
index d4fa2ede559..089b56d177a 100644
--- a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp
+++ b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.cpp
@@ -36,11 +36,18 @@ TransportSecurityOptions::TransportSecurityOptions(vespalib::string ca_certs_pem
{
}
+void secure_memzero(void* buf, size_t size) noexcept {
+ OPENSSL_cleanse(buf, size);
+}
+
TransportSecurityOptions::Builder::Builder() = default;
-TransportSecurityOptions::Builder::~Builder() = default;
+
+TransportSecurityOptions::Builder::~Builder() {
+ secure_memzero(&_private_key_pem[0], _private_key_pem.size());
+}
TransportSecurityOptions::~TransportSecurityOptions() {
- OPENSSL_cleanse(&_private_key_pem[0], _private_key_pem.size());
+ secure_memzero(&_private_key_pem[0], _private_key_pem.size());
}
} // vespalib::net::tls
diff --git a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h
index 647e290d985..fe0c7ead840 100644
--- a/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h
+++ b/vespalib/src/vespa/vespalib/net/tls/transport_security_options.h
@@ -61,4 +61,9 @@ public:
const std::vector<vespalib::string>& accepted_ciphers() const noexcept { return _accepted_ciphers; }
};
+// Zeroes out `size` bytes in `buf` in a way that shall never be optimized
+// away by an eager compiler.
+// TODO move to own crypto utility library
+void secure_memzero(void* buf, size_t size) noexcept;
+
} // vespalib::net::tls
diff --git a/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp b/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
index 0c29932699e..288d80010f7 100644
--- a/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
+++ b/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
@@ -124,13 +124,15 @@ std::unique_ptr<TransportSecurityOptions> load_from_input(Input& input) {
auto authorized_peers = parse_authorized_peers(root["authorized-peers"]);
auto accepted_ciphers = parse_accepted_ciphers(root["accepted-ciphers"]);
- return std::make_unique<TransportSecurityOptions>(
+ auto options = std::make_unique<TransportSecurityOptions>(
TransportSecurityOptions::Builder()
.ca_certs_pem(ca_certs)
.cert_chain_pem(certs)
.private_key_pem(priv_key)
.authorized_peers(std::move(authorized_peers))
.accepted_ciphers(std::move(accepted_ciphers)));
+ secure_memzero(&priv_key[0], priv_key.size());
+ return options;
}
} // anon ns