From 35f49d24b32cdbc9b24661373eca3f4580cf3192 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Sat, 6 May 2017 18:13:36 +0200 Subject: [PATCH] CLI: Clear displayed password after 30 seconds (if found) --- cli/main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cli/main.c b/cli/main.c index 50a6e55..20b37f1 100644 --- a/cli/main.c +++ b/cli/main.c @@ -40,6 +40,7 @@ #define SERVER_PROTOCOL 4 #define RESPONSE_SIZE 2048 #define MAX_SUBDOMAINS 10 +#define DISPLAY_TIME 30 // 30 seconds struct gpass_parameters { unsigned pbkdf2_level; @@ -71,6 +72,25 @@ static const EVP_MD * s_md_256; static EVP_CIPHER_CTX * s_cipher_ctx; +static void display_password(char* password, int time) +{ + int length; + + for (; time; time--) + { + printf("\r(%02d) Password found: %s", time, password); + fflush(stdout); + sleep(1); + } + + // Clear line + printf("\r"); + length = 4 + 17 + strlen(password) + 1; + while (length--) + printf(" "); + printf("\n"); +} + static int digest(unsigned char** out, unsigned char* in, unsigned size) { *out = NULL; @@ -434,7 +454,7 @@ static int ask_server(struct gpass_parameters* params) memmove(password, &password[3], len-3); password[len-3] = 0; } - printf("Password found: %s\n", password); + display_password((char*)password, DISPLAY_TIME); ret = 0; goto end; }