2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019 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/>.
18 // Python private package repository and caching proxy
28 "golang.org/x/crypto/argon2"
31 type Argon2iAuthData struct {
40 func (ad Argon2iAuthData) Auth(password string) bool {
41 hashedPassword := argon2.Key(
47 uint32(len(ad.password)),
49 return bytes.Equal(hashedPassword, ad.password)
52 func parseArgon2i(params string) (Auther, error) {
53 var time, memory uint32
56 var saltAndPasswordUnitedB64 string
59 "v=%d$m=%d,t=%d,p=%d$%s",
64 &saltAndPasswordUnitedB64,
66 if n != 5 || err != nil {
67 return nil, fmt.Errorf("argon2i parameters %q have wrong format", params)
69 if version != argon2.Version {
70 return nil, errors.New("unsupported argon2i version")
72 saltAndPasswordSplittedB64 := strings.Split(saltAndPasswordUnitedB64, "$")
73 salt, err := base64.RawStdEncoding.DecodeString(saltAndPasswordSplittedB64[0])
75 return nil, errors.New("invalid salt format")
77 password, err := base64.RawStdEncoding.DecodeString(saltAndPasswordSplittedB64[1])
79 return nil, errors.New("invalid password format")
81 return Argon2iAuthData{