diff --git a/cli/main.c b/cli/main.c index 20b37f1..a2a4e20 100644 --- a/cli/main.c +++ b/cli/main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -71,12 +72,18 @@ static EVP_MD_CTX ss_md_ctx; static const EVP_MD * s_md_256; static EVP_CIPHER_CTX * s_cipher_ctx; +static int s_stop_display = 0; + +static void signal_handler(int signum) +{ + s_stop_display = 1; +} static void display_password(char* password, int time) { int length; - for (; time; time--) + for (; time && !s_stop_display; time--) { printf("\r(%02d) Password found: %s", time, password); fflush(stdout); @@ -85,7 +92,7 @@ static void display_password(char* password, int time) // Clear line printf("\r"); - length = 4 + 17 + strlen(password) + 1; + length = 4 + 17 + strlen(password) + 1 + 1 /* For Ctrl+Z/C */; while (length--) printf(" "); printf("\n"); @@ -695,6 +702,11 @@ int main(int argc, char** argv) params.orig_master_key = strdup(tmp); derive_master_key(¶ms); + // Ctrl+C + signal(SIGINT, signal_handler); + // Ctrl+Z + signal(SIGTSTP, signal_handler); + ret = ask_server(¶ms); // try again with new parameters