aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/tls_client.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-30 20:20:42 +0000
committerlloyd <[email protected]>2011-12-30 20:20:42 +0000
commitdeb92d7f6d43206c04f332625d6b1e1a2abc444d (patch)
tree06c331d7f51071750091e013c6f853c015eacd18 /doc/examples/tls_client.cpp
parent766f5eeb5c99936e7ddcf3e4c82095f087b6e928 (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/examples/tls_client.cpp')
-rw-r--r--doc/examples/tls_client.cpp16
1 files changed, 16 insertions, 0 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 };