From c2f2c9591480ee19781e43f7b187900698afb26b Mon Sep 17 00:00:00 2001 From: htang555 Date: Fri, 5 Apr 2019 11:54:15 -0400 Subject: [PATCH] basic sha1 auth --- src/otp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/otp.c b/src/otp.c index 09f5489..266a009 100644 --- a/src/otp.c +++ b/src/otp.c @@ -376,6 +376,21 @@ static int otp_verify(const char *vpn_username, const char *vpn_secret) } goto done; } + + if (!strncasecmp(user_entry.secret, "sha1:", sizeof("sha1:") - 1)) { + const char *password = user_entry.secret + sizeof("sha1:") - 1; + unsigned char hash[SHA_DIGEST_LENGTH]; + char hexdigest[SHA_DIGEST_LENGTH*2]; + SHA1(vpn_secret, strlen(vpn_secret), hash); + for (i = 0; i < 20; i++) { + sprintf(&hexdigest[i*2], "%02x", hash[i]); + } + if (!strcmp (vpn_username, user_entry.name) + && password && !strcmp (password, hexdigest)) { + ok = 1; + } + goto done; + } if (split_secret(user_entry.secret, &otp_params)) { goto done;