X-Git-Url: http://www.git.cypherpunks.ru/?p=gocheese.git;a=blobdiff_plain;f=passwd.go;h=dae17a5364b687107f8590caac1231bae71198b3;hp=852192f8b7ea898cb54d7ea3a4e912f884e13bc9;hb=1e4532a9b2f2e3c512be1a63538f79d5ad6749c8;hpb=b144ad5b2dd5d62dd14909afd6696b3137bdf0db diff --git a/passwd.go b/passwd.go index 852192f..dae17a5 100644 --- a/passwd.go +++ b/passwd.go @@ -1,7 +1,7 @@ /* GoCheese -- Python private package repository and caching proxy -Copyright (C) 2019 Sergey Matveev - 2019 Elena Balakhonova +Copyright (C) 2019-2020 Sergey Matveev + 2019-2020 Elena Balakhonova This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,13 +19,43 @@ along with this program. If not, see . package main import ( + "errors" "io/ioutil" "log" + "os" "strings" ) +var passwords map[string]Auther = make(map[string]Auther) + +type Auther interface { + Auth(password string) bool +} + +func strToAuther(verifier string) (string, Auther, error) { + st := strings.SplitN(verifier, "$", 3) + if len(st) != 3 || st[0] != "" { + return "", nil, errors.New("invalid verifier structure") + } + algorithm := st[1] + var auther Auther + var err error + switch algorithm { + case "argon2i": + auther, err = parseArgon2i(st[2]) + case "sha256": + auther, err = parseSHA256(st[2]) + default: + err = errors.New("unknown hashing algorithm") + } + return algorithm, auther, err +} + func refreshPasswd() { passwd, err := ioutil.ReadFile(*passwdPath) + if os.IsNotExist(err) { + return + } if err != nil { log.Fatal(err) } @@ -47,7 +77,7 @@ func refreshPasswd() { log.Fatalf("%s:%d: %s: %s", *passwdPath, i, login, err) } passwordsNew[login] = auther - log.Println("Added password for " + login) + log.Println("added password for " + login) } passwords = passwordsNew }