aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-06-13 18:13:15 +0000
committerlloyd <[email protected]>2012-06-13 18:13:15 +0000
commit8227a598cbbd35f3eced99ae2e437df0826769f9 (patch)
treee6091d1c7292b16c13845be62f796f0efe495e51 /doc/examples
parent6dc2f28174e110427899727690c82a8d230c908e (diff)
Reformat output on the TLS client on handshake completion.
In ASN.1 print values as URL % escaped instead of all hex.
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/GNUmakefile2
-rw-r--r--doc/examples/asn1.cpp51
-rw-r--r--doc/examples/credentials.h2
-rw-r--r--doc/examples/tls_client.cpp17
4 files changed, 49 insertions, 23 deletions
diff --git a/doc/examples/GNUmakefile b/doc/examples/GNUmakefile
index e61c31b0a..fc4755d96 100644
--- a/doc/examples/GNUmakefile
+++ b/doc/examples/GNUmakefile
@@ -2,7 +2,7 @@
BOTAN_CONFIG = botan-config
CXX = g++-4.7.0
-CFLAGS = -O0 -g -ansi -std=c++11 -W -Wall -I../../build/include
+CFLAGS = -O2 -ansi -std=c++11 -W -Wall -I../../build/include
LIBS = -L../.. -lbotan-1.11
SRCS=$(wildcard *.cpp)
diff --git a/doc/examples/asn1.cpp b/doc/examples/asn1.cpp
index aecb688f0..2bb3a620c 100644
--- a/doc/examples/asn1.cpp
+++ b/doc/examples/asn1.cpp
@@ -9,6 +9,7 @@
#include <botan/charset.h>
using namespace Botan;
+#include <sstream>
#include <stdio.h>
#include <ctype.h>
@@ -26,6 +27,21 @@ void decode(BER_Decoder&, size_t);
void emit(const std::string&, size_t, size_t, const std::string& = "");
std::string type_name(ASN1_Tag);
+std::string url_encode(const std::vector<byte>& in)
+ {
+ std::ostringstream out;
+
+ for(size_t i = 0; i != in.size(); ++i)
+ {
+ const int c = in[i];
+ if(isprint((int)c))
+ out << (char)c;
+ else
+ out << "%" << std::hex << (int)c << std::dec;
+ }
+ return out.str();
+ }
+
int main(int argc, char* argv[])
{
if(argc != 2)
@@ -113,16 +129,24 @@ void decode(BER_Decoder& decoder, size_t level)
}
else if((class_tag & APPLICATION) || (class_tag & CONTEXT_SPECIFIC))
{
- bool not_text = false;
-
- for(size_t i = 0; i != bits.size(); ++i)
- if(!isgraph(bits[i]) && !isspace(bits[i]))
- not_text = true;
+#if 0
+ std::vector<byte> bits;
+ data.decode(bits, type_tag);
- Pipe pipe(((not_text) ? new Hex_Encoder : 0));
- pipe.process_msg(obj.value);
+ try
+ {
+ BER_Decoder inner(bits);
+ decode(inner, level + 1);
+ }
+ catch(...)
+ {
+ emit("[" + std::to_string(type_tag) + "]", level, length,
+ url_encode(bits));
+ }
+#else
emit("[" + std::to_string(type_tag) + "]", level, length,
- pipe.read_all_as_string());
+ url_encode(bits));
+#endif
}
else if(type_tag == OBJECT_ID)
{
@@ -173,14 +197,6 @@ void decode(BER_Decoder& decoder, size_t level)
{
std::vector<byte> bits;
data.decode(bits, type_tag);
- bool not_text = false;
-
- for(size_t i = 0; i != bits.size(); ++i)
- if(!isgraph(bits[i]) && !isspace(bits[i]))
- not_text = true;
-
- Pipe pipe(((not_text) ? new Hex_Encoder : 0));
- pipe.process_msg(bits);
try
{
@@ -189,7 +205,8 @@ void decode(BER_Decoder& decoder, size_t level)
}
catch(...)
{
- emit(type_name(type_tag), level, length, pipe.read_all_as_string());
+ emit(type_name(type_tag), level, length,
+ url_encode(bits));
}
}
else if(type_tag == BIT_STRING)
diff --git a/doc/examples/credentials.h b/doc/examples/credentials.h
index 2734b1649..9e3ca741a 100644
--- a/doc/examples/credentials.h
+++ b/doc/examples/credentials.h
@@ -50,11 +50,13 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager
std::vector<Botan::X509_Certificate> certs;
+ /*
if(type == "tls-server" && hostname == "localhost")
{
Botan::X509_Certificate testca("testCA.crt");
certs.push_back(testca);
}
+ */
if(type == "tls-client" && hostname == "twitter.com")
{
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp
index deb0ff460..832234467 100644
--- a/doc/examples/tls_client.cpp
+++ b/doc/examples/tls_client.cpp
@@ -62,11 +62,18 @@ int connect_to_host(const std::string& host, u16bit port)
bool handshake_complete(const TLS::Session& session)
{
- std::cout << "Handshake complete!\n";
- std::cout << "Protocol version " << session.version().to_string() << "\n";
- std::cout << "Ciphersuite " << std::hex << session.ciphersuite().to_string() << "\n";
- std::cout << "Session ID " << hex_encode(session.session_id()) << "\n";
- std::cout << "Session ticket " << hex_encode(session.session_ticket()) << "\n";
+ std::cout << "Handshake complete, " << session.version().to_string()
+ << " using " << session.ciphersuite().to_string() << "\n";
+
+ if(!session.session_id().empty())
+ std::cout << "Session ID " << hex_encode(session.session_id()) << "\n";
+
+ if(!session.session_ticket().empty())
+ std::cout << "Session ticket " << hex_encode(session.session_ticket()) << "\n";
+
+ std::cout << "Secure renegotiation is"
+ << (session.secure_renegotiation() ? "" : " NOT")
+ << " supported\n";
return true;
}