aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tls/msg_server_kex.cpp16
-rw-r--r--src/tls/tls_extensions.cpp24
-rw-r--r--src/tls/tls_extensions.h11
-rw-r--r--src/tls/tls_messages.h5
4 files changed, 19 insertions, 37 deletions
diff --git a/src/tls/msg_server_kex.cpp b/src/tls/msg_server_kex.cpp
index 6e238c4fd..f205ba83a 100644
--- a/src/tls/msg_server_kex.cpp
+++ b/src/tls/msg_server_kex.cpp
@@ -32,8 +32,7 @@ Server_Key_Exchange::Server_Key_Exchange(Handshake_IO& io,
const Policy& policy,
Credentials_Manager& creds,
RandomNumberGenerator& rng,
- const Private_Key* signing_key) :
- m_kex_key(nullptr), m_srp_params(nullptr)
+ const Private_Key* signing_key)
{
const std::string hostname = state->client_hello()->sni_hostname();
const std::string kex_algo = state->suite.kex_algo();
@@ -53,7 +52,7 @@ Server_Key_Exchange::Server_Key_Exchange(Handshake_IO& io,
append_tls_length_value(m_params, BigInt::encode(dh->get_domain().get_p()), 2);
append_tls_length_value(m_params, BigInt::encode(dh->get_domain().get_g()), 2);
append_tls_length_value(m_params, dh->public_value(), 2);
- m_kex_key = dh.release();
+ m_kex_key.reset(dh.release());
}
else if(kex_algo == "ECDH" || kex_algo == "ECDHE_PSK")
{
@@ -87,7 +86,7 @@ Server_Key_Exchange::Server_Key_Exchange(Handshake_IO& io,
append_tls_length_value(m_params, ecdh->public_value(), 1);
- m_kex_key = ecdh.release();
+ m_kex_key.reset(ecdh.release());
}
else if(kex_algo == "SRP_SHA")
{
@@ -106,7 +105,7 @@ Server_Key_Exchange::Server_Key_Exchange(Handshake_IO& io,
throw TLS_Exception(Alert::UNKNOWN_PSK_IDENTITY,
"Unknown SRP user " + srp_identifier);
- m_srp_params = new SRP6_Server_Session;
+ m_srp_params.reset(new SRP6_Server_Session);
BigInt B = m_srp_params->step1(v, group_id,
"SHA-1", rng);
@@ -228,12 +227,7 @@ Server_Key_Exchange::Server_Key_Exchange(const std::vector<byte>& buf,
reader.assert_done();
}
-Server_Key_Exchange::~Server_Key_Exchange()
- {
- delete m_kex_key;
- delete m_srp_params;
- }
-
+Server_Key_Exchange::~Server_Key_Exchange() {}
/**
* Serialize a Server Key Exchange message
diff --git a/src/tls/tls_extensions.cpp b/src/tls/tls_extensions.cpp
index d66b055c8..46c8dc5be 100644
--- a/src/tls/tls_extensions.cpp
+++ b/src/tls/tls_extensions.cpp
@@ -70,8 +70,8 @@ Extensions::Extensions(TLS_Data_Reader& reader)
const u16bit extension_size = reader.get_u16bit();
Extension* extn = make_extension(reader,
- extension_code,
- extension_size);
+ extension_code,
+ extension_size);
if(extn)
this->add(extn);
@@ -85,15 +85,14 @@ std::vector<byte> Extensions::serialize() const
{
std::vector<byte> buf(2); // 2 bytes for length field
- for(std::map<Handshake_Extension_Type, Extension*>::const_iterator i = extensions.begin();
- i != extensions.end(); ++i)
+ for(auto& extn : extensions)
{
- if(i->second->empty())
+ if(extn.second->empty())
continue;
- const u16bit extn_code = i->second->type();
+ const u16bit extn_code = extn.second->type();
- std::vector<byte> extn_val = i->second->serialize();
+ std::vector<byte> extn_val = extn.second->serialize();
buf.push_back(get_byte(0, extn_code));
buf.push_back(get_byte(1, extn_code));
@@ -116,17 +115,6 @@ std::vector<byte> Extensions::serialize() const
return buf;
}
-Extensions::~Extensions()
- {
- for(std::map<Handshake_Extension_Type, Extension*>::const_iterator i = extensions.begin();
- i != extensions.end(); ++i)
- {
- delete i->second;
- }
-
- extensions.clear();
- }
-
Server_Name_Indicator::Server_Name_Indicator(TLS_Data_Reader& reader,
u16bit extension_size)
{
diff --git a/src/tls/tls_extensions.h b/src/tls/tls_extensions.h
index 60a375ebe..23f13db83 100644
--- a/src/tls/tls_extensions.h
+++ b/src/tls/tls_extensions.h
@@ -12,6 +12,7 @@
#include <botan/tls_magic.h>
#include <vector>
#include <string>
+#include <memory>
#include <map>
namespace Botan {
@@ -361,18 +362,16 @@ class Extensions
{
Handshake_Extension_Type type = T::static_type();
- std::map<Handshake_Extension_Type, Extension*>::const_iterator i =
- extensions.find(type);
+ auto i = extensions.find(type);
if(i != extensions.end())
- return dynamic_cast<T*>(i->second);
+ return dynamic_cast<T*>(i->second.get());
return nullptr;
}
void add(Extension* extn)
{
- delete extensions[extn->type()]; // or hard error if already exists?
- extensions[extn->type()] = extn;
+ extensions[extn->type()].reset(extn);
}
std::vector<byte> serialize() const;
@@ -386,7 +385,7 @@ class Extensions
Extensions(const Extensions&) {}
Extensions& operator=(const Extensions&) { return (*this); }
- std::map<Handshake_Extension_Type, Extension*> extensions;
+ std::map<Handshake_Extension_Type, std::unique_ptr<Extension>> extensions;
};
}
diff --git a/src/tls/tls_messages.h b/src/tls/tls_messages.h
index 23b1d5634..cca2aa6b0 100644
--- a/src/tls/tls_messages.h
+++ b/src/tls/tls_messages.h
@@ -17,6 +17,7 @@
#include <botan/pkcs8.h>
#include <botan/x509cert.h>
#include <vector>
+#include <memory>
namespace Botan {
@@ -431,8 +432,8 @@ class Server_Key_Exchange : public Handshake_Message
private:
std::vector<byte> serialize() const;
- Private_Key* m_kex_key;
- SRP6_Server_Session* m_srp_params;
+ std::unique_ptr<Private_Key> m_kex_key;
+ std::unique_ptr<SRP6_Server_Session> m_srp_params;
std::vector<byte> m_params;