diff options
author | lloyd <[email protected]> | 2011-12-30 20:20:42 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-12-30 20:20:42 +0000 |
commit | deb92d7f6d43206c04f332625d6b1e1a2abc444d (patch) | |
tree | 06c331d7f51071750091e013c6f853c015eacd18 /doc | |
parent | 766f5eeb5c99936e7ddcf3e4c82095f087b6e928 (diff) |
Add a function for getting the version number of an active connection.
Add a new callback that is called with the session info when a
handshake completes. Currently only called on the server side as
the client doesn't have session resumption yet.
Rename CipherSuite to TLS_Cipher_Suite.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/examples/tls_client.cpp | 16 | ||||
-rw-r--r-- | doc/examples/tls_server.cpp | 18 |
2 files changed, 33 insertions, 1 deletions
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp index 3fb7f10c6..be72a65e7 100644 --- a/doc/examples/tls_client.cpp +++ b/doc/examples/tls_client.cpp @@ -66,6 +66,16 @@ int connect_to_host(const std::string& host, u16bit port) return fd; } +void handshake_complete(const TLS_Session_Params& session) + { + printf("Handshake complete, protocol=%04X ciphersuite=%04X compression=%d\n", + session.version(), session.ciphersuite(), + session.compression_method()); + + printf("Session id = %s\n", hex_encode(session.session_id()).c_str()); + printf("Master secret = %s\n", hex_encode(session.master_secret()).c_str()); + } + void socket_write(int sockfd, const byte buf[], size_t length) { size_t offset = 0; @@ -123,6 +133,7 @@ int main(int argc, char* argv[]) TLS_Client client(std::tr1::bind(socket_write, sockfd, _1, _2), process_data, + handshake_complete, session_manager, policy, rng, @@ -130,6 +141,8 @@ int main(int argc, char* argv[]) fd_set readfds; + bool version_reported = false; + while(true) { FD_ZERO(&readfds); @@ -141,6 +154,9 @@ int main(int argc, char* argv[]) if(client.is_closed()) break; + if(client.is_active() && !version_reported) + printf("Negotiated version %04X\n", client.protocol_version()); + if(FD_ISSET(sockfd, &readfds)) { byte buf[1024] = { 0 }; diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp index f43af1dcf..0710c35f9 100644 --- a/doc/examples/tls_server.cpp +++ b/doc/examples/tls_server.cpp @@ -15,6 +15,16 @@ using namespace Botan; #include <iostream> #include <memory> +void handshake_complete(const TLS_Session_Params& session) + { + printf("Handshake complete, protocol=%04X ciphersuite=%04X compression=%d\n", + session.version(), session.ciphersuite(), + session.compression_method()); + + printf("Session id = %s\n", hex_encode(session.session_id()).c_str()); + printf("Master secret = %s\n", hex_encode(session.master_secret()).c_str()); + } + class Blocking_TLS_Server { public: @@ -29,6 +39,7 @@ class Blocking_TLS_Server server( output_fn, std::tr1::bind(&Blocking_TLS_Server::reader_fn, std::tr1::ref(*this), _1, _2, _3), + handshake_complete, sessions, policy, rng, @@ -146,7 +157,7 @@ int main(int argc, char* argv[]) //DSA_PrivateKey key(rng, DL_Group("dsa/jce/1024")); X509_Cert_Options options( - "localhost/US/Syn Ack Labs/Mathematical Munitions Dept"); + "localhost/US/Botan Library/Test Server"); X509_Certificate cert = X509::create_self_signed_cert(options, key, "SHA-1", rng); @@ -199,9 +210,14 @@ int main(int argc, char* argv[]) break; } + if(line == "reneg\n") + tls.underlying().renegotiate(); + line.clear(); } } + + delete sock; } catch(std::exception& e) { printf("Connection problem: %s\n", e.what()); } } |