summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2017-03-20 21:11:22 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2017-03-20 21:11:22 +0000
commitdad85ac7636ad0ecfca47fab24fd2d369724e56f (patch)
tree1ddee33a211032bcbfc58497927a80f2cb073e88
parentac6813f6fac3a8e989ac94db13851cebdb40a23c (diff)
Generate the bogus challenge using arc4random_buf(3) instead of reading
directly from /var/db/host.random and falling back to ctime. Remove the _SKEY_RAND_FILE_PATH_ since it's no longer needed. ok millert, mestre
-rw-r--r--lib/libskey/skey.h5
-rw-r--r--lib/libskey/skeylogin.c40
2 files changed, 8 insertions, 37 deletions
diff --git a/lib/libskey/skey.h b/lib/libskey/skey.h
index 64f5b591c90..54e1f4d8804 100644
--- a/lib/libskey/skey.h
+++ b/lib/libskey/skey.h
@@ -10,7 +10,7 @@
*
* Main client header
*
- * $OpenBSD: skey.h,v 1.20 2014/03/20 20:39:13 naddy Exp $
+ * $OpenBSD: skey.h,v 1.21 2017/03/20 21:11:21 tb Exp $
*/
#ifndef _SKEY_H_
@@ -57,9 +57,6 @@ struct mc {
/* Size of a binary key (not NULL-terminated) */
#define SKEY_BINKEY_SIZE 8
-/* Location of random file for bogus challenges */
-#define _SKEY_RAND_FILE_PATH_ "/var/db/host.random"
-
/* Directory for S/Key per-user files */
#define _PATH_SKEYDIR "/etc/skey"
diff --git a/lib/libskey/skeylogin.c b/lib/libskey/skeylogin.c
index 5e1f509931b..e63412c6f6d 100644
--- a/lib/libskey/skeylogin.c
+++ b/lib/libskey/skeylogin.c
@@ -10,7 +10,7 @@
*
* S/Key verification check, lookups, and authentication.
*
- * $OpenBSD: skeylogin.c,v 1.59 2017/03/20 18:34:52 tedu Exp $
+ * $OpenBSD: skeylogin.c,v 1.60 2017/03/20 21:11:21 tb Exp $
*/
#ifdef QUOTA
@@ -419,9 +419,8 @@ hash_collapse(u_char *s)
static void
skey_fakeprompt(char *username, char *skeyprompt)
{
- char hseed[SKEY_MAX_SEED_LEN], *secret, pbuf[SKEY_MAX_PW_LEN+1], *p, *u;
- u_char flg = 1, *up;
- size_t secretlen;
+ char secret[SKEY_MAX_SEED_LEN], pbuf[SKEY_MAX_PW_LEN+1], *p, *u;
+ u_char *up;
SHA1_CTX ctx;
u_int ptr;
int i;
@@ -443,46 +442,21 @@ skey_fakeprompt(char *username, char *skeyprompt)
/* Hash the username if possible */
if ((up = SHA1Data(username, strlen(username), NULL)) != NULL) {
- struct stat sb;
- time_t t;
- int fd;
-
/* Collapse the hash */
ptr = hash_collapse(up);
explicit_bzero(up, strlen(up));
- /* See if the random file's there, else use ctime */
- if ((fd = open(_SKEY_RAND_FILE_PATH_, O_RDONLY)) != -1 &&
- fstat(fd, &sb) == 0 &&
- sb.st_size > (off_t)SKEY_MAX_SEED_LEN &&
- lseek(fd, ptr % (sb.st_size - SKEY_MAX_SEED_LEN),
- SEEK_SET) != -1 && read(fd, hseed,
- SKEY_MAX_SEED_LEN) == SKEY_MAX_SEED_LEN) {
- close(fd);
- fd = -1;
- secret = hseed;
- secretlen = SKEY_MAX_SEED_LEN;
- flg = 0;
- } else if (!stat(_PATH_MEM, &sb) || !stat("/", &sb)) {
- t = sb.st_ctime;
- secret = ctime(&t);
- secretlen = strlen(secret);
- flg = 0;
- }
- if (fd != -1)
- close(fd);
- }
+ /* Put that in your pipe and smoke it */
+ arc4random_buf(secret, sizeof(secret));
- /* Put that in your pipe and smoke it */
- if (flg == 0) {
/* Hash secret value with username */
SHA1Init(&ctx);
- SHA1Update(&ctx, secret, secretlen);
+ SHA1Update(&ctx, secret, sizeof(secret));
SHA1Update(&ctx, username, strlen(username));
SHA1End(&ctx, up);
/* Zero out */
- explicit_bzero(secret, secretlen);
+ explicit_bzero(secret, sizeof(secret));
/* Now hash the hash */
SHA1Init(&ctx);