aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-11-03 22:16:51 +0000
committerlloyd <[email protected]>2014-11-03 22:16:51 +0000
commitbcd83686c3daed38974d1f9b533c07d35c5a7476 (patch)
tree3203d6f30423ebf3b7b5b3d4aa2b9ecc9ce5ba5e /src/cmd
parentd623823e7e0d2754343ab498f48976e91180d24f (diff)
Various small fixes and cleanups, new is_prime util
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/apps.h1
-rw-r--r--src/cmd/asn1.cpp5
-rw-r--r--src/cmd/is_prime.cpp33
-rw-r--r--src/cmd/main.cpp3
-rw-r--r--src/cmd/tls_client.cpp25
5 files changed, 58 insertions, 9 deletions
diff --git a/src/cmd/apps.h b/src/cmd/apps.h
index 0cb514aca..48f1f770e 100644
--- a/src/cmd/apps.h
+++ b/src/cmd/apps.h
@@ -25,6 +25,7 @@ DEFINE_APP(dsa_verify);
DEFINE_APP(factor);
DEFINE_APP(fpe);
DEFINE_APP(hash);
+DEFINE_APP(is_prime);
DEFINE_APP(keygen);
DEFINE_APP(ocsp_check);
DEFINE_APP(pkcs10);
diff --git a/src/cmd/asn1.cpp b/src/cmd/asn1.cpp
index f9baae902..02b73e415 100644
--- a/src/cmd/asn1.cpp
+++ b/src/cmd/asn1.cpp
@@ -231,7 +231,10 @@ void decode(BER_Decoder& decoder, size_t level)
for(size_t i = 0; i != bits.size(); ++i)
for(size_t j = 0; j != 8; ++j)
- bit_set.push_back((bool)((bits[bits.size()-i-1] >> (7-j)) & 1));
+ {
+ const bool bit = static_cast<bool>((bits[bits.size()-i-1] >> (7-j)) & 1);
+ bit_set.push_back(bit);
+ }
std::string bit_str;
for(size_t i = 0; i != bit_set.size(); ++i)
diff --git a/src/cmd/is_prime.cpp b/src/cmd/is_prime.cpp
new file mode 100644
index 000000000..658401690
--- /dev/null
+++ b/src/cmd/is_prime.cpp
@@ -0,0 +1,33 @@
+#include "apps.h"
+#include <botan/numthry.h>
+
+int is_prime_main(int argc, char* argv[])
+ {
+ if(argc != 2 && argc != 3)
+ {
+ std::cerr << "Usage: " << argv[0] << " n <prob>\n";
+ return 2;
+ }
+
+ BigInt n(argv[1]);
+
+ size_t prob = 56;
+
+ if(argc == 3)
+ prob = to_u32bit(argv[2]);
+
+ AutoSeeded_RNG rng;
+
+ const bool prime = is_prime(n, rng, prob);
+
+ if(prime)
+ {
+ std::cout << n << " is prime\n";
+ return 0;
+ }
+ else
+ {
+ std::cout << n << " is not prime\n";
+ return 1;
+ }
+ }
diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp
index 92ecc051e..f04c7daee 100644
--- a/src/cmd/main.cpp
+++ b/src/cmd/main.cpp
@@ -160,9 +160,10 @@ int main(int argc, char* argv[])
CALL_APP(factor);
CALL_APP(fpe);
CALL_APP(hash);
+ CALL_APP(is_prime);
CALL_APP(keygen);
- CALL_APP(rng);
CALL_APP(read_ssh);
+ CALL_APP(rng);
CALL_APP(speed);
#if defined(BOTAN_HAS_TLS)
diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp
index 9130cd085..5ab015c33 100644
--- a/src/cmd/tls_client.cpp
+++ b/src/cmd/tls_client.cpp
@@ -4,6 +4,11 @@
#include <botan/tls_client.h>
#include <botan/pkcs8.h>
#include <botan/hex.h>
+
+#if defined(BOTAN_HAS_TLS_SQLITE3_SESSION_MANAGER)
+ #include <botan/tls_session_manager_sqlite.h>
+#endif
+
#include <string>
#include <iostream>
#include <memory>
@@ -21,10 +26,6 @@
#define MSG_NOSIGNAL 0
#endif
-#if defined(BOTAN_HAS_TLS_SQLITE3_SESSION_MANAGER)
- #include <botan/tls_session_manager_sqlite.h>
-#endif
-
#include "credentials.h"
using namespace Botan;
@@ -147,9 +148,12 @@ int tls_client_main(int argc, char* argv[])
TLS::Policy policy;
#if defined(BOTAN_HAS_TLS_SQLITE3_SESSION_MANAGER)
- TLS::Session_Manager_SQLite session_manager("my secret passphrase",
+ const std::string passphrase = "correct horse battery staple";
+ const std::string sessions_db = "sessions.db";
+
+ TLS::Session_Manager_SQLite session_manager(passphrase,
rng,
- "sessions.db");
+ sessions_db);
#else
TLS::Session_Manager_In_Memory session_manager(rng);
#endif
@@ -188,7 +192,9 @@ int tls_client_main(int argc, char* argv[])
FD_SET(sockfd, &readfds);
FD_SET(STDIN_FILENO, &readfds);
- ::select(sockfd + 1, &readfds, nullptr, nullptr, nullptr);
+ struct timeval timeout = { 1, 0 };
+
+ ::select(sockfd + 1, &readfds, nullptr, nullptr, &timeout);
if(FD_ISSET(sockfd, &readfds))
{
@@ -247,6 +253,11 @@ int tls_client_main(int argc, char* argv[])
else
client.send(buf, got);
}
+ else
+ {
+ if(client.timeout_check())
+ std::cerr << "Timeout detected\n";
+ }
}
::close(sockfd);