aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/tls/tls_callbacks.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-21 20:13:15 -0500
committerJack Lloyd <[email protected]>2016-11-23 08:31:07 -0500
commit33e855853886193867b32da847b8b77f7bc102ee (patch)
treeed8d4d93f247832f7768b5fe1e92cde7109e4352 /src/lib/tls/tls_callbacks.cpp
parent987fcef3f93fe06500b81da2706b358cff85d53a (diff)
Move TLS cert verification callback from Credentials_Manager to TLS::Callbacks
It is the only function in C_M which is called on to process session-specific (and adversarially provided) inputs, rather than passively returning some credential which is typically not session specific.
Diffstat (limited to 'src/lib/tls/tls_callbacks.cpp')
-rw-r--r--src/lib/tls/tls_callbacks.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/lib/tls/tls_callbacks.cpp b/src/lib/tls/tls_callbacks.cpp
new file mode 100644
index 000000000..1bf1af6a3
--- /dev/null
+++ b/src/lib/tls/tls_callbacks.cpp
@@ -0,0 +1,53 @@
+/*
+* TLS Callbacks
+* (C) 2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/tls_callbacks.h>
+#include <botan/x509path.h>
+#include <botan/ocsp.h>
+#include <botan/certstor.h>
+
+namespace Botan {
+
+TLS::Callbacks::~Callbacks() {}
+
+void TLS::Callbacks::tls_inspect_handshake_msg(const Handshake_Message&)
+ {
+ // default is no op
+ }
+
+std::string TLS::Callbacks::tls_server_choose_app_protocol(const std::vector<std::string>&)
+ {
+ return "";
+ }
+
+void TLS::Callbacks::tls_verify_cert_chain(
+ const std::vector<X509_Certificate>& cert_chain,
+ const std::vector<Certificate_Store*>& trusted_roots,
+ Usage_Type usage,
+ const std::string& hostname)
+ {
+ if(cert_chain.empty())
+ throw Invalid_Argument("Certificate chain was empty");
+
+ Path_Validation_Restrictions restrictions;
+
+ auto ocsp_timeout = std::chrono::milliseconds(300);
+
+ Path_Validation_Result result =
+ x509_path_validate(cert_chain,
+ restrictions,
+ trusted_roots,
+ (usage == Usage_Type::TLS_SERVER_AUTH ? hostname : ""),
+ usage,
+ std::chrono::system_clock::now(),
+ ocsp_timeout);
+
+ if(!result.successful_validation())
+ throw Exception("Certificate validation failure: " + result.result_string());
+ }
+
+}