aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_client.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-23 16:31:40 +0000
committerlloyd <[email protected]>2011-12-23 16:31:40 +0000
commit917bf37104eb039a97ef989306954dd8bc05f400 (patch)
tree74c64d0ae3755115b2be9a4463e0a340add442d6 /src/tls/tls_client.h
parentb1a36938a25baf867123c1d6619d191e089135ff (diff)
parent67c1645ae151f5dd0f2bafce926ff8690fd97f19 (diff)
propagate from branch 'net.randombit.botan' (head 6c2809f0c11ba10a137601a2e7eed7ac1f083002)
to branch 'net.randombit.botan.tls-state-machine' (head a302f3e8a1d2571835d461a7af7b4e8e805de446)
Diffstat (limited to 'src/tls/tls_client.h')
-rw-r--r--src/tls/tls_client.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/tls/tls_client.h b/src/tls/tls_client.h
new file mode 100644
index 000000000..6d613be33
--- /dev/null
+++ b/src/tls/tls_client.h
@@ -0,0 +1,87 @@
+/*
+* TLS Client
+* (C) 2004-2011 Jack Lloyd
+*
+* Released under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TLS_CLIENT_H__
+#define BOTAN_TLS_CLIENT_H__
+
+#include <botan/tls_policy.h>
+#include <botan/tls_record.h>
+#include <vector>
+#include <string>
+
+namespace Botan {
+
+/**
+* SSL/TLS Client
+*/
+class BOTAN_DLL TLS_Client
+ {
+ public:
+ /**
+ * Set up a new TLS client session
+ */
+ TLS_Client(std::tr1::function<void (const byte[], size_t)> socket_output_fn,
+ std::tr1::function<void (const byte[], size_t, u16bit)> proc_fn,
+ const TLS_Policy& policy,
+ RandomNumberGenerator& rng);
+
+ /**
+ * Inject TLS traffic received from counterparty
+
+ * @return a hint as the how many more bytes we need to process the
+ current record (this may be 0 if on a record boundary)
+ */
+ size_t received_data(const byte buf[], size_t buf_size);
+
+ /**
+ * Inject plaintext intended for counterparty
+ */
+ void queue_for_sending(const byte buf[], size_t buf_size);
+
+ void close();
+
+ bool handshake_complete() const { return active; }
+
+ std::vector<X509_Certificate> peer_cert_chain() const { return peer_certs; }
+
+ void add_client_cert(const X509_Certificate& cert,
+ Private_Key* cert_key);
+
+ ~TLS_Client();
+ private:
+ void close(Alert_Level, Alert_Type);
+
+ size_t get_pending_socket_input(byte output[], size_t length);
+
+ void initialize();
+ void do_handshake();
+
+ void state_machine();
+ void read_handshake(byte, const MemoryRegion<byte>&);
+ void process_handshake_msg(Handshake_Type, const MemoryRegion<byte>&);
+
+ const TLS_Policy& policy;
+ RandomNumberGenerator& rng;
+
+ std::tr1::function<void (const byte[], size_t, u16bit)> proc_fn;
+
+ Record_Writer writer;
+ Record_Reader reader;
+
+ SecureQueue pre_handshake_write_queue;
+
+ std::vector<X509_Certificate> peer_certs;
+ std::vector<std::pair<X509_Certificate, Private_Key*> > certs;
+
+ class Handshake_State* state;
+ //SecureVector<byte> session_id;
+ bool active;
+ };
+
+}
+
+#endif