From 043a673c59b94424a77a353e6acad43dfb0ccef4 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Mon, 2 Dec 2024 17:43:13 +0100 Subject: [PATCH] Add a delay before allowing the next connection if the wrong PIN is entered --- server/driver/wivrn_connection.cpp | 5 ++++- server/driver/wivrn_connection.h | 6 ++++++ server/main.cpp | 31 +++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/server/driver/wivrn_connection.cpp b/server/driver/wivrn_connection.cpp index ab59e059..b13b178c 100644 --- a/server/driver/wivrn_connection.cpp +++ b/server/driver/wivrn_connection.cpp @@ -51,6 +51,9 @@ static std::string clean_key(std::string key) return key; } +wivrn::incorrect_pin::incorrect_pin() : + std::runtime_error("Incorrect PIN") {} + wivrn::wivrn_connection::wivrn_connection(std::stop_token stop_token, encryption_state state, std::string pin, TCP && tcp) : control(std::move(tcp)), stream(-1), @@ -217,7 +220,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function(stop_token, enc_state, pin, std::move(tcp)); g_main_context_invoke(nullptr, &headset_connected_success, nullptr); } + catch (wivrn::incorrect_pin &) + { + std::cerr << "Incorrect PIN" << std::endl; + g_main_context_invoke(nullptr, &headset_connected_incorrect_pin, nullptr); + } catch (std::exception & e) { std::cerr << "Client connection failed: " << e.what() << std::endl;