aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/cert_ver.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-23 16:17:29 +0000
committerlloyd <[email protected]>2011-12-23 16:17:29 +0000
commit67c1645ae151f5dd0f2bafce926ff8690fd97f19 (patch)
tree9af9c1c22ab58093328cdfd00dbe42292d8b5ed6 /src/tls/cert_ver.cpp
parentd363602f95f1514b4b595d9912fba2e503edcb21 (diff)
Rename ssl module to tls
Diffstat (limited to 'src/tls/cert_ver.cpp')
-rw-r--r--src/tls/cert_ver.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/tls/cert_ver.cpp b/src/tls/cert_ver.cpp
new file mode 100644
index 000000000..3220a8c9e
--- /dev/null
+++ b/src/tls/cert_ver.cpp
@@ -0,0 +1,98 @@
+/*
+* Certificate Verify Message
+* (C) 2004-2010 Jack Lloyd
+*
+* Released under the terms of the Botan license
+*/
+
+#include <botan/internal/tls_messages.h>
+#include <botan/internal/tls_reader.h>
+#include <botan/pubkey.h>
+#include <botan/rsa.h>
+#include <botan/dsa.h>
+#include <botan/loadstor.h>
+#include <memory>
+
+namespace Botan {
+
+/**
+* Create a new Certificate Verify message
+*/
+Certificate_Verify::Certificate_Verify(RandomNumberGenerator& rng,
+ Record_Writer& writer,
+ HandshakeHash& hash,
+ const Private_Key* 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")
+ {
+ padding == "EMSA1(SHA-1)";
+ format = DER_SEQUENCE;
+ }
+ else
+ 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);
+ send(writer, hash);
+ }
+
+/**
+* Serialize a Certificate Verify message
+*/
+SecureVector<byte> Certificate_Verify::serialize() const
+ {
+ SecureVector<byte> buf;
+
+ const u16bit sig_len = signature.size();
+ buf.push_back(get_byte(0, sig_len));
+ buf.push_back(get_byte(1, sig_len));
+ buf += signature;
+
+ return buf;
+ }
+
+/**
+* Deserialize a Certificate Verify message
+*/
+void Certificate_Verify::deserialize(const MemoryRegion<byte>& buf)
+ {
+ TLS_Data_Reader reader(buf);
+ signature = reader.get_range<byte>(2, 0, 65535);
+ }
+
+/**
+* Verify a Certificate Verify message
+*/
+bool Certificate_Verify::verify(const X509_Certificate& cert,
+ HandshakeHash& hash)
+ {
+ // FIXME: duplicate of Server_Key_Exchange::verify
+
+ std::auto_ptr<Public_Key> key(cert.subject_public_key());
+
+ std::string padding = "";
+ Signature_Format format = IEEE_1363;
+
+ 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(key->algo_name() +
+ " is invalid/unknown for TLS signatures");
+
+ PK_Verifier verifier(*key, padding, format);
+ return verifier.verify_message(hash.final(), signature);
+ }
+
+}