2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2022 Sergey Matveev <stargrave@stargrave.org>
4 2019-2022 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/>.
31 Passwords map[string]Auther = make(map[string]Auther)
32 PasswordsM sync.RWMutex
35 type Auther interface {
36 Auth(password string) bool
39 func strToAuther(verifier string) (string, Auther, error) {
40 st := strings.SplitN(verifier, "$", 3)
41 if len(st) != 3 || st[0] != "" {
42 return "", nil, errors.New("invalid verifier structure")
49 auther, err = parseArgon2i(st[2])
51 auther, err = parseSHA256(st[2])
53 err = errors.New("unknown hashing algorithm")
55 return algorithm, auther, err
58 func passwdReader(fd *os.File) bool {
60 scanner := bufio.NewScanner(fd)
66 splitted := strings.Split(t, ":")
67 if len(splitted) != 2 {
68 log.Println("wrong login:password format:", t)
75 log.Println("deleting login:", login)
77 delete(Passwords, login)
81 _, auther, err := strToAuther(passwd)
83 log.Println("login:", login, "invalid password:", err)
87 log.Println("adding password for:", login)
89 Passwords[login] = auther
95 func passwdLister(fd *os.File) {
97 logins := make([]string, 0, len(Passwords))
98 for login := range Passwords {
99 logins = append(logins, login)
102 for _, login := range logins {
103 fd.WriteString(login + "\n")