diff options
author | lloyd <[email protected]> | 2015-03-20 04:32:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-03-20 04:32:15 +0000 |
commit | b01ce65e09e50ec624bdbf62bf2c1433f0d6f637 (patch) | |
tree | 8aa46632eb381b44de64d106b62f8efad49c173d /src/cmd | |
parent | 181e75b66d5fbffdce04d37014c260b4fab5dec8 (diff) |
Add ALPN (RFC 7301) and remove NPN
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/tls_client.cpp | 24 | ||||
-rw-r--r-- | src/cmd/tls_server.cpp | 13 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp index 903824a78..a1a6c0c5f 100644 --- a/src/cmd/tls_client.cpp +++ b/src/cmd/tls_client.cpp @@ -138,9 +138,6 @@ int tls_client(int argc, char* argv[]) return 1; } - const bool request_protocol = true; - const std::string use_protocol = "http/1.1"; - try { AutoSeeded_RNG rng; @@ -165,13 +162,9 @@ int tls_client(int argc, char* argv[]) const bool use_tcp = (transport == "tcp"); - int sockfd = connect_to_host(host, port, use_tcp); + const std::vector<std::string> protocols_to_offer = { "test/9.9", "http/1.1", "echo/9.1" }; - auto protocol_chooser = [use_protocol](const std::vector<std::string>& protocols) -> std::string { - for(size_t i = 0; i != protocols.size(); ++i) - std::cout << "Server offered protocol " << i << " = " << protocols[i] << "\n"; - return use_protocol; - }; + int sockfd = connect_to_host(host, port, use_tcp); auto socket_write = use_tcp ? @@ -190,7 +183,9 @@ int tls_client(int argc, char* argv[]) rng, TLS::Server_Information(host, port), version, - protocol_chooser); + protocols_to_offer); + + bool first_active = true; while(!client.is_closed()) { @@ -199,7 +194,16 @@ int tls_client(int argc, char* argv[]) FD_SET(sockfd, &readfds); if(client.is_active()) + { FD_SET(STDIN_FILENO, &readfds); + if(first_active && !protocols_to_offer.empty()) + { + std::string app = client.application_protocol(); + if(app != "") + std::cout << "Server choose protocol: " << client.application_protocol() << "\n"; + first_active = false; + } + } struct timeval timeout = { 1, 0 }; diff --git a/src/cmd/tls_server.cpp b/src/cmd/tls_server.cpp index fc8499be1..ee72ba5ac 100644 --- a/src/cmd/tls_server.cpp +++ b/src/cmd/tls_server.cpp @@ -146,12 +146,11 @@ int tls_server(int argc, char* argv[]) Basic_Credentials_Manager creds(rng, server_crt, server_key); - /* - * These are the protocols we advertise to the client, but the - * client will send back whatever it actually plans on talking, - * which may or may not take into account what we advertise. - */ - const std::vector<std::string> protocols = { "echo/1.0", "echo/1.1" }; + auto protocol_chooser = [](const std::vector<std::string>& protocols) -> std::string { + for(size_t i = 0; i != protocols.size(); ++i) + std::cout << "Client offered protocol " << i << " = " << protocols[i] << "\n"; + return "echo/1.0"; // too bad + }; std::cout << "Listening for new connections on " << transport << " port " << port << "\n"; @@ -210,7 +209,7 @@ int tls_server(int argc, char* argv[]) creds, policy, rng, - protocols, + protocol_chooser, !is_tcp); while(!server.is_closed()) |