1 // GoCheese -- Python private package repository and caching proxy
2 // Copyright (C) 2019-2024 Sergey Matveev <stargrave@stargrave.org>
3 // 2019-2024 Elena Balakhonova <balakhonova_e@riseup.net>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, version 3 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
29 Passwords map[string]Auther = make(map[string]Auther)
30 PasswordsM sync.RWMutex
33 type Auther interface {
34 Auth(password string) bool
37 func strToAuther(verifier string) (string, Auther, error) {
38 st := strings.SplitN(verifier, "$", 3)
39 if len(st) != 3 || st[0] != "" {
40 return "", nil, errors.New("invalid verifier structure")
47 auther, err = parseArgon2i(st[2])
49 auther, err = parseSHA256(st[2])
51 err = errors.New("unknown hashing algorithm")
53 return algorithm, auther, err
56 func passwdReader(fd *os.File) bool {
58 scanner := bufio.NewScanner(fd)
64 splitted := strings.Split(t, ":")
65 if len(splitted) != 2 {
66 log.Println("wrong login:password format:", t)
73 log.Println("deleting login:", login)
75 delete(Passwords, login)
79 _, auther, err := strToAuther(passwd)
81 log.Println("login:", login, "invalid password:", err)
85 log.Println("adding password for:", login)
87 Passwords[login] = auther
93 func passwdLister(fd *os.File) {
95 logins := make([]string, 0, len(Passwords))
96 for login := range Passwords {
97 logins = append(logins, login)
100 for _, login := range logins {
101 fd.WriteString(login + "\n")