diff options
author | lloyd <[email protected]> | 2012-02-27 17:11:41 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-02-27 17:11:41 +0000 |
commit | cd8c134bdfc97ea8f1a58672b43349e90f76b6de (patch) | |
tree | a0f40e4ba7c78f125979fba6351cd2fa258deeeb /doc/examples | |
parent | afcb8db8ad2b39c6b80467a3d21d32e440b973d5 (diff) |
Add makefile dependency on credentials.h. Use 1024 bit keys for
RSA/DSA. Add function for choosing thread count.
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/GNUmakefile | 4 | ||||
-rw-r--r-- | doc/examples/asio_tls_server.cpp | 17 | ||||
-rw-r--r-- | doc/examples/credentials.h | 9 |
3 files changed, 19 insertions, 11 deletions
diff --git a/doc/examples/GNUmakefile b/doc/examples/GNUmakefile index 23045961e..ea5c8dfe4 100644 --- a/doc/examples/GNUmakefile +++ b/doc/examples/GNUmakefile @@ -20,5 +20,5 @@ clean: eax_test: eax_test.cpp $(CXX) $(CFLAGS) $? $(LIBS) -lboost_regex -o $@ -asio_tls_server: asio_tls_server.cpp - $(CXX) $(CFLAGS) $? $(LIBS) -lboost_thread -lboost_system -o $@ +asio_tls_server: asio_tls_server.cpp credentials.h + $(CXX) $(CFLAGS) $< $(LIBS) -lboost_thread -lboost_system -o $@ diff --git a/doc/examples/asio_tls_server.cpp b/doc/examples/asio_tls_server.cpp index fff83f5f8..5c606a3f2 100644 --- a/doc/examples/asio_tls_server.cpp +++ b/doc/examples/asio_tls_server.cpp @@ -282,6 +282,16 @@ class tls_server Credentials_Manager_Simple m_creds; }; +size_t choose_thread_count() + { + size_t result = boost::thread::hardware_concurrency(); + + if(result) + return result; + + return 2; + } + int main() { try @@ -289,13 +299,10 @@ int main() Botan::LibraryInitializer init("thread_safe=true"); boost::asio::io_service io_service; - unsigned short port = 4433; + unsigned short port = 4434; tls_server server(io_service, port); - size_t num_threads = boost::thread::hardware_concurrency(); - - if(num_threads == 0) - return num_threads = 2; + const size_t num_threads = choose_thread_count(); std::cout << "Using " << num_threads << " threads\n"; diff --git a/doc/examples/credentials.h b/doc/examples/credentials.h index d6350963c..82a72406d 100644 --- a/doc/examples/credentials.h +++ b/doc/examples/credentials.h @@ -9,6 +9,7 @@ #include <botan/ecdsa.h> #include <iostream> #include <fstream> +#include <memory> bool value_exists(const std::vector<std::string>& vec, const std::string& val) @@ -60,7 +61,7 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager X509_Certificate cert(cert_file_name); Private_Key* key = PKCS8::load_key(key_file_name, rng); - std::cout << "Loaded existing key/cert from " << cert_file_name << " and " << key_file_name << "\n"; + //std::cout << "Loaded existing key/cert from " << cert_file_name << " and " << key_file_name << "\n"; return std::make_pair(cert, key); } @@ -79,16 +80,16 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager std::auto_ptr<Private_Key> key; if(key_type == "rsa") - key.reset(new RSA_PrivateKey(rng, 2048)); + key.reset(new RSA_PrivateKey(rng, 1024)); else if(key_type == "dsa") - key.reset(new DSA_PrivateKey(rng, DL_Group("dsa/botan/2048"))); + key.reset(new DSA_PrivateKey(rng, DL_Group("dsa/jce/1024"))); else if(key_type == "ecdsa") key.reset(new ECDSA_PrivateKey(rng, EC_Group("secp256r1"))); else throw std::runtime_error("Don't know what to do about key type '" + key_type + "'"); X509_Certificate cert = - X509::create_self_signed_cert(opts, *key, "SHA-256", rng); + X509::create_self_signed_cert(opts, *key, "SHA-1", rng); // Now save both |