aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-24 02:22:10 +0000
committerlloyd <[email protected]>2010-02-24 02:22:10 +0000
commit928367615d7f8a3b316b1878415b27ada8cc72eb (patch)
tree93ffb504602fcb9671b4b51384ad96936ba87a9c /doc
parenta0a7c9ecf94a7168cf8ef642fdeef1f59eab95c9 (diff)
parent9137016d1bfac98b5fb88026d7cf3c965ff66f0e (diff)
propagate from branch 'net.randombit.botan' (head 35d3e3deb02b47f98e4937f8eab77f019a0f4b97)
to branch 'net.randombit.botan.ssl' (head f923e7583e760a9a224cc5b1fc40015776d85eb9)
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/tls_client.cpp51
-rw-r--r--doc/examples/tls_server.cpp81
2 files changed, 132 insertions, 0 deletions
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp
new file mode 100644
index 000000000..9e6b510f2
--- /dev/null
+++ b/doc/examples/tls_client.cpp
@@ -0,0 +1,51 @@
+/*
+* (C) 2008 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/init.h>
+#include <botan/tls_client.h>
+#include <botan/unx_sock.h>
+
+using namespace Botan;
+
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <memory>
+
+int main()
+ {
+ try
+ {
+ LibraryInitializer init;
+
+ Unix_Socket sock("www.randombit.net", 443);
+
+ std::auto_ptr<Botan::RandomNumberGenerator> rng(
+ Botan::RandomNumberGenerator::make_rng());
+
+ TLS_Client tls(*rng, sock);
+
+ std::string http_command = "GET /bitbashing\r\n";
+ tls.write((const byte*)http_command.c_str(), http_command.length());
+
+ while(true)
+ {
+ if(tls.is_closed())
+ break;
+
+ byte buf[16+1] = { 0 };
+ u32bit got = tls.read(buf, sizeof(buf)-1);
+ printf("%s", buf);
+ fflush(0);
+ }
+ }
+ catch(std::exception& e)
+ {
+ printf("%s\n", e.what());
+ return 1;
+ }
+ return 0;
+ }
diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp
new file mode 100644
index 000000000..39453dbfd
--- /dev/null
+++ b/doc/examples/tls_server.cpp
@@ -0,0 +1,81 @@
+/*
+* (C) 2008 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/init.h>
+#include <botan/tls_server.h>
+#include <botan/unx_sock.h>
+
+#include <botan/rsa.h>
+#include <botan/dsa.h>
+#include <botan/x509self.h>
+
+using namespace Botan;
+
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <memory>
+
+int main(int argc, char* argv[])
+ {
+
+ int port = 4433;
+
+ if(argc == 2)
+ port = to_u32bit(argv[1]);
+
+ try
+ {
+ LibraryInitializer init;
+
+ std::auto_ptr<RandomNumberGenerator> rng(
+ RandomNumberGenerator::make_rng());
+
+ RSA_PrivateKey key(*rng, 512);
+ //DSA_PrivateKey key(get_dl_group("DSA-1024"));
+
+ X509_Cert_Options options(
+ "www.randombit.net/US/Syn Ack Labs/Mathematical Munitions Dept");
+
+ X509_Certificate cert =
+ X509::create_self_signed_cert(options, key, "SHA-1", *rng);
+
+ Unix_Server_Socket listener(port);
+
+ printf("Now listening on port %d...\n", port);
+
+ while(true)
+ {
+ try {
+ Socket* sock = listener.accept();
+
+ printf("Got new connection\n");
+
+ TLS_Server tls(*rng, *sock, cert, key);
+
+ printf("Writing some text\n");
+
+ char msg[] = "Foo\nBar\nBaz\nQuux\n";
+ tls.write((const byte*)msg, strlen(msg));
+
+ printf("Now trying a read...\n");
+
+ char buf[10] = { 0 };
+ u32bit got = tls.read((byte*)buf, 9);
+ printf("%d: '%s'\n", got, buf);
+
+ tls.close();
+ }
+ catch(std::exception& e) { printf("%s\n", e.what()); }
+ }
+ }
+ catch(std::exception& e)
+ {
+ printf("%s\n", e.what());
+ return 1;
+ }
+ return 0;
+ }