aboutsummaryrefslogtreecommitdiffstats
path: root/src/ssl
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-08 15:36:18 +0000
committerlloyd <[email protected]>2010-03-08 15:36:18 +0000
commit8a47f6f2bbf169a2ea0853234f81b49070c770df (patch)
tree2633ed0d927faf23a067aa88d6cceb9de29f0be4 /src/ssl
parent05f6d6c8edec9907778f362c927f368140fee6a2 (diff)
Modify pubkey classes to take names instead of object pointers.
Remove use of look_pk from the source and examples, instead instantiate classes directly.
Diffstat (limited to 'src/ssl')
-rw-r--r--src/ssl/c_kex.cpp22
-rw-r--r--src/ssl/cert_ver.cpp52
-rw-r--r--src/ssl/s_kex.cpp62
3 files changed, 71 insertions, 65 deletions
diff --git a/src/ssl/c_kex.cpp b/src/ssl/c_kex.cpp
index 59cfa6547..7140bf35c 100644
--- a/src/ssl/c_kex.cpp
+++ b/src/ssl/c_kex.cpp
@@ -6,10 +6,10 @@
*/
#include <botan/tls_messages.h>
+#include <botan/pubkey.h>
#include <botan/dh.h>
#include <botan/rsa.h>
#include <botan/rng.h>
-#include <botan/look_pk.h>
#include <botan/loadstor.h>
#include <memory>
@@ -31,9 +31,9 @@ Client_Key_Exchange::Client_Key_Exchange(RandomNumberGenerator& rng,
{
DH_PrivateKey priv_key(rng, dh_pub->get_domain());
- std::auto_ptr<PK_Key_Agreement> ka(get_pk_kas(priv_key, "Raw"));
+ PK_Key_Agreement ka(priv_key, "Raw");
- pre_master = ka->derive_key(0, dh_pub->public_value()).bits_of();
+ pre_master = ka.derive_key(0, dh_pub->public_value()).bits_of();
key_material = priv_key.public_value();
}
@@ -44,10 +44,9 @@ Client_Key_Exchange::Client_Key_Exchange(RandomNumberGenerator& rng,
pre_master[0] = (pref_version >> 8) & 0xFF;
pre_master[1] = (pref_version ) & 0xFF;
- std::auto_ptr<PK_Encryptor> encryptor(get_pk_encryptor(*rsa_pub,
- "PKCS1v15"));
+ PK_Encryptor_MR_with_EME encryptor(*rsa_pub, "PKCS1v15");
- key_material = encryptor->encrypt(pre_master, rng);
+ key_material = encryptor.encrypt(pre_master, rng);
if(using_version == SSL_V3)
include_length = false;
@@ -125,9 +124,9 @@ Client_Key_Exchange::pre_master_secret(RandomNumberGenerator& rng,
if(const DH_PrivateKey* dh_priv = dynamic_cast<const DH_PrivateKey*>(priv_key))
{
try {
- std::auto_ptr<PK_Key_Agreement> ka(get_pk_kas(*dh_priv, "Raw"));
+ PK_Key_Agreement ka(*dh_priv, "Raw");
- pre_master = ka->derive_key(0, key_material).bits_of();
+ pre_master = ka.derive_key(0, key_material).bits_of();
}
catch(...)
{
@@ -139,17 +138,16 @@ Client_Key_Exchange::pre_master_secret(RandomNumberGenerator& rng,
}
else if(const RSA_PrivateKey* rsa_priv = dynamic_cast<const RSA_PrivateKey*>(priv_key))
{
- std::auto_ptr<PK_Decryptor> decryptor(get_pk_decryptor(*rsa_priv,
- "PKCS1v15"));
+ PK_Decryptor_MR_with_EME decryptor(*rsa_priv, "PKCS1v15");
try {
- pre_master = decryptor->decrypt(key_material);
+ pre_master = decryptor.decrypt(key_material);
if(pre_master.size() != 48 ||
make_u16bit(pre_master[0], pre_master[1]) != version)
throw Decoding_Error("Client_Key_Exchange: Secret corrupted");
}
- catch(std::exception)
+ catch(...)
{
pre_master.resize(48);
rng.randomize(pre_master, pre_master.size());
diff --git a/src/ssl/cert_ver.cpp b/src/ssl/cert_ver.cpp
index 22dae8350..7e17dbfab 100644
--- a/src/ssl/cert_ver.cpp
+++ b/src/ssl/cert_ver.cpp
@@ -1,12 +1,12 @@
/**
-* Certificate Verify Message
-* (C) 2004-2006 Jack Lloyd
+* Certificate Verify Message
+* (C) 2004-2010 Jack Lloyd
*
* Released under the terms of the Botan license
*/
#include <botan/tls_messages.h>
-#include <botan/look_pk.h>
+#include <botan/pubkey.h>
#include <botan/rsa.h>
#include <botan/dsa.h>
#include <botan/loadstor.h>
@@ -22,21 +22,23 @@ Certificate_Verify::Certificate_Verify(RandomNumberGenerator& rng,
HandshakeHash& hash,
const Private_Key* priv_key)
{
- std::auto_ptr<PK_Signer> signer;
+ std::string padding = "";
+ Signature_Format format = IEEE_1363;
- if(const RSA_PrivateKey* rsa = dynamic_cast<const RSA_PrivateKey*>(priv_key))
+ if(priv_key->algo_name() == "RSA")
+ padding = "EMSA3(TLS.Digest.0)";
+ else if(priv_key->algo_name() == "DSA")
{
- signer.reset(get_pk_signer(*rsa, "EMSA3(TLS.Digest.0)"));
- }
- else if(const DSA_PrivateKey* dsa =
- dynamic_cast<const DSA_PrivateKey*>(priv_key))
- {
- signer.reset(get_pk_signer(*dsa, "EMSA1(SHA-1)"));
+ padding == "EMSA1(SHA-1)";
+ format = DER_SEQUENCE;
}
else
- throw Invalid_Argument("Unknown PK algo for TLS signature");
+ throw Invalid_Argument(priv_key->algo_name() +
+ " is invalid/unknown for TLS signatures");
+
+ PK_Signer signer(*priv_key, padding, format);
- signature = signer->sign_message(hash.final(), rng);
+ signature = signer.sign_message(hash.final(), rng);
send(writer, hash);
}
@@ -80,20 +82,22 @@ bool Certificate_Verify::verify(const X509_Certificate& cert,
std::auto_ptr<Public_Key> key(cert.subject_public_key());
- DSA_PublicKey* dsa_pub = dynamic_cast<DSA_PublicKey*>(key.get());
- RSA_PublicKey* rsa_pub = dynamic_cast<RSA_PublicKey*>(key.get());
+ std::string padding = "";
+ Signature_Format format = IEEE_1363;
- std::auto_ptr<PK_Verifier> verifier;
-
- if(dsa_pub)
- verifier.reset(get_pk_verifier(*dsa_pub, "EMSA1(SHA-1)", DER_SEQUENCE));
- else if(rsa_pub)
- verifier.reset(get_pk_verifier(*rsa_pub, "EMSA3(TLS.Digest.0)"));
+ if(key->algo_name() == "RSA")
+ padding = "EMSA3(TLS.Digest.0)";
+ else if(key->algo_name() == "DSA")
+ {
+ padding == "EMSA1(SHA-1)";
+ format = DER_SEQUENCE;
+ }
else
- throw Invalid_Argument("Client did not provide a RSA/DSA cert");
+ throw Invalid_Argument(key->algo_name() +
+ " is invalid/unknown for TLS signatures");
- // FIXME: WRONG
- return verifier->verify_message(hash.final(), signature);
+ PK_Verifier verifier(*key, padding, format);
+ return verifier.verify_message(hash.final(), signature);
}
}
diff --git a/src/ssl/s_kex.cpp b/src/ssl/s_kex.cpp
index d568ef14f..94b17cb7e 100644
--- a/src/ssl/s_kex.cpp
+++ b/src/ssl/s_kex.cpp
@@ -6,10 +6,10 @@
*/
#include <botan/tls_messages.h>
+#include <botan/pubkey.h>
#include <botan/dh.h>
#include <botan/rsa.h>
#include <botan/dsa.h>
-#include <botan/look_pk.h>
#include <botan/loadstor.h>
#include <memory>
@@ -43,25 +43,27 @@ Server_Key_Exchange::Server_Key_Exchange(RandomNumberGenerator& rng,
else
throw Invalid_Argument("Bad key for TLS key exchange: not DH or RSA");
- std::auto_ptr<PK_Signer> signer;
- if(const RSA_PrivateKey* rsa = dynamic_cast<const RSA_PrivateKey*>(priv_key))
- {
- signer.reset(get_pk_signer(*rsa, "EMSA3(TLS.Digest.0)"));
- }
- else if(const DSA_PrivateKey* dsa =
- dynamic_cast<const DSA_PrivateKey*>(priv_key))
+ std::string padding = "";
+ Signature_Format format = IEEE_1363;
+
+ if(priv_key->algo_name() == "RSA")
+ padding = "EMSA3(TLS.Digest.0)";
+ else if(priv_key->algo_name() == "DSA")
{
- signer.reset(get_pk_signer(*dsa, "EMSA1(SHA-1)"));
- signer->set_output_format(DER_SEQUENCE);
+ padding == "EMSA1(SHA-1)";
+ format = DER_SEQUENCE;
}
else
- throw Invalid_Argument("Bad key for TLS signature: not RSA or DSA");
+ throw Invalid_Argument(priv_key->algo_name() +
+ " is invalid/unknown for TLS signatures");
+
+ PK_Signer signer(*priv_key, padding, format);
- signer->update(c_random);
- signer->update(s_random);
- signer->update(serialize_params());
- signature = signer->signature(rng);
+ signer.update(c_random);
+ signer.update(s_random);
+ signer.update(serialize_params());
+ signature = signer.signature(rng);
send(writer, hash);
}
@@ -154,29 +156,31 @@ bool Server_Key_Exchange::verify(const X509_Certificate& cert,
const MemoryRegion<byte>& c_random,
const MemoryRegion<byte>& s_random) const
{
- std::auto_ptr<Public_Key> key(cert.subject_public_key());
- DSA_PublicKey* dsa_pub = dynamic_cast<DSA_PublicKey*>(key.get());
- RSA_PublicKey* rsa_pub = dynamic_cast<RSA_PublicKey*>(key.get());
+ std::auto_ptr<Public_Key> key(cert.subject_public_key());
- std::auto_ptr<PK_Verifier> verifier;
+ std::string padding = "";
+ Signature_Format format = IEEE_1363;
- if(dsa_pub)
+ if(key->algo_name() == "RSA")
+ padding = "EMSA3(TLS.Digest.0)";
+ else if(key->algo_name() == "DSA")
{
- verifier.reset(get_pk_verifier(*dsa_pub, "EMSA1(SHA-1)", DER_SEQUENCE));
- verifier->set_input_format(DER_SEQUENCE);
+ padding == "EMSA1(SHA-1)";
+ format = DER_SEQUENCE;
}
- else if(rsa_pub)
- verifier.reset(get_pk_verifier(*rsa_pub, "EMSA3(TLS.Digest.0)"));
else
- throw Invalid_Argument("Server did not provide a RSA/DSA cert");
+ throw Invalid_Argument(key->algo_name() +
+ " is invalid/unknown for TLS signatures");
+
+ PK_Verifier verifier(*key, padding, format);
SecureVector<byte> params_got = serialize_params();
- verifier->update(c_random);
- verifier->update(s_random);
- verifier->update(params_got);
+ verifier.update(c_random);
+ verifier.update(s_random);
+ verifier.update(params_got);
- return verifier->check_signature(signature, signature.size());
+ return verifier.check_signature(signature, signature.size());
}
}