aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/tls_server.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-04-04 03:43:52 +0000
committerlloyd <[email protected]>2011-04-04 03:43:52 +0000
commit3b9bfbd07c3723662832caf5b1efe04de28b656d (patch)
treeee2a9324f384efead6e5bb87ac8374e7e8734c90 /doc/examples/tls_server.cpp
parent04db054f1ae8de572ee9c0cfe227e76f84096bd6 (diff)
Convert most of the documentation to reStructured Text, adding
a makefile to build it with Sphinx (http://sphinx.pocoo.org/). Previously credits.txt listed public domain code sources; instead directly credit the authors in the relevant files and delete that file. Drop the draft FIPS 140 security policy; I can't imagine FIPS 140 validation will ever happen, and if it does, I don't want anything to do with it. Also drop the internals doc, which was so out of date (and incomplete) as to be worthless. Move the tutorials and InSiTo pdfs into old/ for the time being, until anything relevant from them can be filtered out and converted into RST.
Diffstat (limited to 'doc/examples/tls_server.cpp')
-rw-r--r--doc/examples/tls_server.cpp108
1 files changed, 0 insertions, 108 deletions
diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp
deleted file mode 100644
index da13953f8..000000000
--- a/doc/examples/tls_server.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
-* (C) 2008-2010 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/botan.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>
-
-class Server_TLS_Policy : public TLS_Policy
- {
- public:
- bool check_cert(const std::vector<X509_Certificate>& certs) const
- {
- for(size_t i = 0; i != certs.size(); ++i)
- {
- std::cout << certs[i].to_string();
- }
-
- std::cout << "Warning: not checking cert signatures\n";
-
- return true;
- }
- };
-int main(int argc, char* argv[])
- {
-
- int port = 4433;
-
- if(argc == 2)
- port = to_u32bit(argv[1]);
-
- try
- {
- LibraryInitializer init;
-
- AutoSeeded_RNG rng;
-
- //RSA_PrivateKey key(rng, 1024);
- DSA_PrivateKey key(rng, DL_Group("dsa/jce/1024"));
-
- X509_Cert_Options options(
- "localhost/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);
-
- Server_TLS_Policy policy;
-
- while(true)
- {
- try {
- printf("Listening for new connection on port %d\n", port);
-
- Socket* sock = listener.accept();
-
- printf("Got new connection\n");
-
- TLS_Server tls(
- std::tr1::bind(&Socket::read, std::tr1::ref(sock), _1, _2),
- std::tr1::bind(&Socket::write, std::tr1::ref(sock), _1, _2),
- policy,
- rng,
- cert,
- key);
-
- std::string hostname = tls.requested_hostname();
-
- if(hostname != "")
- printf("Client requested host '%s'\n", hostname.c_str());
-
- 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[1024] = { 0 };
- u32bit got = tls.read((byte*)buf, sizeof(buf)-1);
- 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;
- }