diff options
author | lloyd <[email protected]> | 2010-01-11 22:57:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-01-11 22:57:21 +0000 |
commit | a4124ddf481bfc56859007b34dea646ecb7f8a25 (patch) | |
tree | fd842d8a091c5c529d6c32cd300bc195519ceb46 /doc/examples/tls_server.cpp | |
parent | f5fd85b0ea6a5a6975d595130e029f94fddae9a4 (diff) |
Import latest version of Ajisai into src/ssl; once this hits mainline
I'll officially kill off Ajisai (instead of it just lingering as a zombine
as it is currently).
Apparently I broke something (or multiple things) during the import process;
servers crash and clients gets MAC errors on connect.
Diffstat (limited to 'doc/examples/tls_server.cpp')
-rw-r--r-- | doc/examples/tls_server.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp new file mode 100644 index 000000000..d5cb77a84 --- /dev/null +++ b/doc/examples/tls_server.cpp @@ -0,0 +1,71 @@ +/* +* (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() + { + 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(4433); + + printf("Now listening...\n"); + + while(true) + { + try { + Socket* sock = listener.accept(); + + printf("Got new connection\n"); + + TLS_Server tls(*rng, *sock, cert, key); + + char msg[] = "Foo\nBar\nBaz\nQuux\n"; + tls.write((const byte*)msg, strlen(msg)); + + 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; + } |