2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019 Sergey Matveev <stargrave@stargrave.org>
4 2019 Elena Balakhonova <balakhonova_e@riseup.net>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 var passwords map[string]Auther = make(map[string]Auther)
31 type Auther interface {
32 Auth(password string) bool
35 func strToAuther(verifier string) (string, Auther, error) {
36 st := strings.SplitN(verifier, "$", 3)
37 if len(st) != 3 || st[0] != "" {
38 return "", nil, errors.New("invalid verifier structure")
45 auther, err = parseArgon2i(st[2])
47 auther, err = parseSHA256(st[2])
49 err = errors.New("unknown hashing algorithm")
51 return algorithm, auther, err
54 func refreshPasswd() {
55 passwd, err := ioutil.ReadFile(*passwdPath)
56 if os.IsNotExist(err) {
62 passwordsNew := make(map[string]Auther)
63 for i, credentials := range strings.Split(strings.TrimRight(string(passwd), "\n"), "\n") {
64 if len(credentials) == 0 || strings.HasPrefix(credentials, "#") {
67 splitted := strings.Split(credentials, ":")
68 if len(splitted) != 2 {
69 log.Fatalf("%s:%d: Wrong login:password format", *passwdPath, i)
72 if _, exists := passwordsNew[login]; exists {
73 log.Fatalf("%s:%d: %s: already exists", *passwdPath, i, login)
75 _, auther, err := strToAuther(splitted[1])
77 log.Fatalf("%s:%d: %s: %s", *passwdPath, i, login, err)
79 passwordsNew[login] = auther
80 log.Println("Added password for " + login)
82 passwords = passwordsNew