diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-02-26 03:47:46 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-02-26 03:47:46 +0100 |
commit | 009bec07521287ebfc9f4dcfddac18d8f27f1fb9 (patch) | |
tree | ee6c2b2f6eec0848495d65933cd59dd7c9372945 /sys | |
parent | 27498dd63a199bb634bbf23e62edb345814626c9 (diff) |
authsrv: salt the keyseed from /adm/keyseed file
change the keyseed key derivation to hkdf sha256
using the hostowners des key plus 256 bit random
salt from /adm/keyseed.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/cmd/auth/authsrv.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/sys/src/cmd/auth/authsrv.c b/sys/src/cmd/auth/authsrv.c index 2b9409c51..cd6bd05fd 100644 --- a/sys/src/cmd/auth/authsrv.c +++ b/sys/src/cmd/auth/authsrv.c @@ -1007,13 +1007,33 @@ initkeyseed(void) { static char info[] = "PRF key for generation of dummy user keys"; char k[DESKEYLEN], *u; + int fd; + + genrandom(keyseed, sizeof(keyseed)); u = getuser(); if(!finddeskey(KEYDB, u, k)){ - syslog(0, AUTHLOG, "can't generate keyseed: user %s not in keydb", u); - exits(0); + syslog(0, AUTHLOG, "initkeyseed: user %s not in keydb", u); + return; + } + + if((fd = create("/adm/keyseed", OWRITE|OEXCL, 0600)) >= 0){ + write(fd, keyseed, sizeof(keyseed)); + } else if((fd = open("/adm/keyseed", OREAD)) >= 0){ + read(fd, keyseed, sizeof(keyseed)); + } else{ + syslog(0, AUTHLOG, "initkeyseed: no seed file: %r"); + memset(k, 0, sizeof(k)); + return; } - hmac_sha2_256((uchar*)info, sizeof(info)-1, (uchar*)k, sizeof(k), keyseed, nil); + close(fd); + + hkdf_x( keyseed, sizeof(keyseed), + (uchar*)info, sizeof(info)-1, + (uchar*)k, sizeof(k), + keyseed, sizeof(keyseed), + hmac_sha2_256, SHA2_256dlen); + memset(k, 0, sizeof(k)); } |