mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 22:56:48 +00:00
We build too many walls and not enough bridges
This commit is contained in:
107
pkg/srp/hash.go
Normal file
107
pkg/srp/hash.go
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package srp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5" //nolint[gosec]
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/jameskeane/bcrypt"
|
||||
)
|
||||
|
||||
// BCryptHash function bcrypt algorithm to hash password with salt
|
||||
func BCryptHash(password string, salt string) (string, error) {
|
||||
return bcrypt.Hash(password, salt)
|
||||
}
|
||||
|
||||
// ExpandHash extends the byte data for SRP flow
|
||||
func ExpandHash(data []byte) []byte {
|
||||
part0 := sha512.Sum512(append(data, 0))
|
||||
part1 := sha512.Sum512(append(data, 1))
|
||||
part2 := sha512.Sum512(append(data, 2))
|
||||
part3 := sha512.Sum512(append(data, 3))
|
||||
return bytes.Join([][]byte{
|
||||
part0[:],
|
||||
part1[:],
|
||||
part2[:],
|
||||
part3[:],
|
||||
}, []byte{})
|
||||
}
|
||||
|
||||
// HashPassword returns the hash of password argument. Based on version number
|
||||
// following arguments are used in addition to password:
|
||||
// * 0, 1, 2: userName and modulus
|
||||
// * 3, 4: salt and modulus
|
||||
func HashPassword(authVersion int, password, userName string, salt, modulus []byte) ([]byte, error) {
|
||||
switch authVersion {
|
||||
case 4, 3:
|
||||
return hashPasswordVersion3(password, salt, modulus)
|
||||
case 2:
|
||||
return hashPasswordVersion2(password, userName, modulus)
|
||||
case 1:
|
||||
return hashPasswordVersion1(password, userName, modulus)
|
||||
case 0:
|
||||
return hashPasswordVersion0(password, userName, modulus)
|
||||
default:
|
||||
return nil, errors.New("pmapi: unsupported auth version")
|
||||
}
|
||||
}
|
||||
|
||||
// CleanUserName returns the input string in lower-case without characters `_`,
|
||||
// `.` and `-`.
|
||||
func CleanUserName(userName string) string {
|
||||
userName = strings.Replace(userName, "-", "", -1)
|
||||
userName = strings.Replace(userName, ".", "", -1)
|
||||
userName = strings.Replace(userName, "_", "", -1)
|
||||
return strings.ToLower(userName)
|
||||
}
|
||||
|
||||
func hashPasswordVersion3(password string, salt, modulus []byte) (res []byte, err error) {
|
||||
encodedSalt := base64.NewEncoding("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789").WithPadding(base64.NoPadding).EncodeToString(append(salt, []byte("proton")...))
|
||||
crypted, err := BCryptHash(password, "$2y$10$"+encodedSalt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return ExpandHash(append([]byte(crypted), modulus...)), nil
|
||||
}
|
||||
|
||||
func hashPasswordVersion2(password, userName string, modulus []byte) (res []byte, err error) {
|
||||
return hashPasswordVersion1(password, CleanUserName(userName), modulus)
|
||||
}
|
||||
|
||||
func hashPasswordVersion1(password, userName string, modulus []byte) (res []byte, err error) {
|
||||
prehashed := md5.Sum([]byte(strings.ToLower(userName))) //nolint[gosec]
|
||||
encodedSalt := hex.EncodeToString(prehashed[:])
|
||||
crypted, err := BCryptHash(password, "$2y$10$"+encodedSalt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return ExpandHash(append([]byte(crypted), modulus...)), nil
|
||||
}
|
||||
|
||||
func hashPasswordVersion0(password, userName string, modulus []byte) (res []byte, err error) {
|
||||
prehashed := sha512.Sum512([]byte(password))
|
||||
return hashPasswordVersion1(base64.StdEncoding.EncodeToString(prehashed[:]), userName, modulus)
|
||||
}
|
||||
219
pkg/srp/srp.go
Normal file
219
pkg/srp/srp.go
Normal file
@ -0,0 +1,219 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package srp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"golang.org/x/crypto/openpgp"
|
||||
"golang.org/x/crypto/openpgp/clearsign"
|
||||
)
|
||||
|
||||
//nolint[gochecknoglobals]
|
||||
var (
|
||||
ErrDataAfterModulus = errors.New("pm-srp: extra data after modulus")
|
||||
ErrInvalidSignature = errors.New("pm-srp: invalid modulus signature")
|
||||
RandReader = rand.Reader
|
||||
)
|
||||
|
||||
// Store random reader in a variable to be able to overwrite it in tests
|
||||
|
||||
// Amored pubkey for modulus verification
|
||||
const modulusPubkey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
xjMEXAHLgxYJKwYBBAHaRw8BAQdAFurWXXwjTemqjD7CXjXVyKf0of7n9Ctm
|
||||
L8v9enkzggHNEnByb3RvbkBzcnAubW9kdWx1c8J3BBAWCgApBQJcAcuDBgsJ
|
||||
BwgDAgkQNQWFxOlRjyYEFQgKAgMWAgECGQECGwMCHgEAAPGRAP9sauJsW12U
|
||||
MnTQUZpsbJb53d0Wv55mZIIiJL2XulpWPQD/V6NglBd96lZKBmInSXX/kXat
|
||||
Sv+y0io+LR8i2+jV+AbOOARcAcuDEgorBgEEAZdVAQUBAQdAeJHUz1c9+KfE
|
||||
kSIgcBRE3WuXC4oj5a2/U3oASExGDW4DAQgHwmEEGBYIABMFAlwBy4MJEDUF
|
||||
hcTpUY8mAhsMAAD/XQD8DxNI6E78meodQI+wLsrKLeHn32iLvUqJbVDhfWSU
|
||||
WO4BAMcm1u02t4VKw++ttECPt+HUgPUq5pqQWe5Q2cW4TMsE
|
||||
=Y4Mw
|
||||
-----END PGP PUBLIC KEY BLOCK-----`
|
||||
|
||||
// ReadClearSignedMessage reads the clear text from signed message and verifies
|
||||
// signature. There must be no data appended after signed message in input string.
|
||||
// The message must be sign by key corresponding to `modulusPubkey`.
|
||||
func ReadClearSignedMessage(signedMessage string) (string, error) {
|
||||
modulusBlock, rest := clearsign.Decode([]byte(signedMessage))
|
||||
if len(rest) != 0 {
|
||||
return "", ErrDataAfterModulus
|
||||
}
|
||||
|
||||
modulusKeyring, err := openpgp.ReadArmoredKeyRing(bytes.NewReader([]byte(modulusPubkey)))
|
||||
if err != nil {
|
||||
return "", errors.New("pm-srp: can not read modulus pubkey")
|
||||
}
|
||||
|
||||
_, err = openpgp.CheckDetachedSignature(modulusKeyring, bytes.NewReader(modulusBlock.Bytes), modulusBlock.ArmoredSignature.Body, nil)
|
||||
if err != nil {
|
||||
return "", ErrInvalidSignature
|
||||
}
|
||||
|
||||
return string(modulusBlock.Bytes), nil
|
||||
}
|
||||
|
||||
// SrpProofs object
|
||||
type SrpProofs struct { //nolint[golint]
|
||||
ClientProof, ClientEphemeral, ExpectedServerProof []byte
|
||||
}
|
||||
|
||||
// SrpAuth stores byte data for the calculation of SRP proofs
|
||||
type SrpAuth struct { //nolint[golint]
|
||||
Modulus, ServerEphemeral, HashedPassword []byte
|
||||
}
|
||||
|
||||
// NewSrpAuth creates new SrpAuth from strings input. Salt and server ephemeral are in
|
||||
// base64 format. Modulus is base64 with signature attached. The signature is
|
||||
// verified against server key. The version controls password hash algorithm.
|
||||
func NewSrpAuth(version int, username, password, salt, signedModulus, serverEphemeral string) (auth *SrpAuth, err error) {
|
||||
data := &SrpAuth{}
|
||||
|
||||
// Modulus
|
||||
var modulus string
|
||||
modulus, err = ReadClearSignedMessage(signedModulus)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
data.Modulus, err = base64.StdEncoding.DecodeString(modulus)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Password
|
||||
var decodedSalt []byte
|
||||
if version >= 3 {
|
||||
decodedSalt, err = base64.StdEncoding.DecodeString(salt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
data.HashedPassword, err = HashPassword(version, password, username, decodedSalt, data.Modulus)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Server ephermeral
|
||||
data.ServerEphemeral, err = base64.StdEncoding.DecodeString(serverEphemeral)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GenerateSrpProofs calculates SPR proofs.
|
||||
func (s *SrpAuth) GenerateSrpProofs(length int) (res *SrpProofs, err error) { //nolint[funlen]
|
||||
toInt := func(arr []byte) *big.Int {
|
||||
var reversed = make([]byte, len(arr))
|
||||
for i := 0; i < len(arr); i++ {
|
||||
reversed[len(arr)-i-1] = arr[i]
|
||||
}
|
||||
return big.NewInt(0).SetBytes(reversed)
|
||||
}
|
||||
|
||||
fromInt := func(num *big.Int) []byte {
|
||||
var arr = num.Bytes()
|
||||
var reversed = make([]byte, length/8)
|
||||
for i := 0; i < len(arr); i++ {
|
||||
reversed[len(arr)-i-1] = arr[i]
|
||||
}
|
||||
return reversed
|
||||
}
|
||||
|
||||
generator := big.NewInt(2)
|
||||
multiplier := toInt(ExpandHash(append(fromInt(generator), s.Modulus...)))
|
||||
|
||||
modulus := toInt(s.Modulus)
|
||||
serverEphemeral := toInt(s.ServerEphemeral)
|
||||
hashedPassword := toInt(s.HashedPassword)
|
||||
|
||||
modulusMinusOne := big.NewInt(0).Sub(modulus, big.NewInt(1))
|
||||
|
||||
if modulus.BitLen() != length {
|
||||
return nil, errors.New("pm-srp: SRP modulus has incorrect size")
|
||||
}
|
||||
|
||||
multiplier = multiplier.Mod(multiplier, modulus)
|
||||
|
||||
if multiplier.Cmp(big.NewInt(1)) <= 0 || multiplier.Cmp(modulusMinusOne) >= 0 {
|
||||
return nil, errors.New("pm-srp: SRP multiplier is out of bounds")
|
||||
}
|
||||
|
||||
if generator.Cmp(big.NewInt(1)) <= 0 || generator.Cmp(modulusMinusOne) >= 0 {
|
||||
return nil, errors.New("pm-srp: SRP generator is out of bounds")
|
||||
}
|
||||
|
||||
if serverEphemeral.Cmp(big.NewInt(1)) <= 0 || serverEphemeral.Cmp(modulusMinusOne) >= 0 {
|
||||
return nil, errors.New("pm-srp: SRP server ephemeral is out of bounds")
|
||||
}
|
||||
|
||||
// Check primality
|
||||
// Doing exponentiation here is faster than a full call to ProbablyPrime while
|
||||
// still perfectly accurate by Pocklington's theorem
|
||||
if big.NewInt(0).Exp(big.NewInt(2), modulusMinusOne, modulus).Cmp(big.NewInt(1)) != 0 {
|
||||
return nil, errors.New("pm-srp: SRP modulus is not prime")
|
||||
}
|
||||
|
||||
// Check safe primality
|
||||
if !big.NewInt(0).Rsh(modulus, 1).ProbablyPrime(10) {
|
||||
return nil, errors.New("pm-srp: SRP modulus is not a safe prime")
|
||||
}
|
||||
|
||||
var clientSecret, clientEphemeral, scramblingParam *big.Int
|
||||
for {
|
||||
for {
|
||||
clientSecret, err = rand.Int(RandReader, modulusMinusOne)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if clientSecret.Cmp(big.NewInt(int64(length*2))) > 0 { // Very likely
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
clientEphemeral = big.NewInt(0).Exp(generator, clientSecret, modulus)
|
||||
scramblingParam = toInt(ExpandHash(append(fromInt(clientEphemeral), fromInt(serverEphemeral)...)))
|
||||
if scramblingParam.Cmp(big.NewInt(0)) != 0 { // Very likely
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
subtracted := big.NewInt(0).Sub(serverEphemeral, big.NewInt(0).Mod(big.NewInt(0).Mul(big.NewInt(0).Exp(generator, hashedPassword, modulus), multiplier), modulus))
|
||||
if subtracted.Cmp(big.NewInt(0)) < 0 {
|
||||
subtracted.Add(subtracted, modulus)
|
||||
}
|
||||
exponent := big.NewInt(0).Mod(big.NewInt(0).Add(big.NewInt(0).Mul(scramblingParam, hashedPassword), clientSecret), modulusMinusOne)
|
||||
sharedSession := big.NewInt(0).Exp(subtracted, exponent, modulus)
|
||||
|
||||
clientProof := ExpandHash(bytes.Join([][]byte{fromInt(clientEphemeral), fromInt(serverEphemeral), fromInt(sharedSession)}, []byte{}))
|
||||
serverProof := ExpandHash(bytes.Join([][]byte{fromInt(clientEphemeral), clientProof, fromInt(sharedSession)}, []byte{}))
|
||||
|
||||
return &SrpProofs{ClientEphemeral: fromInt(clientEphemeral), ClientProof: clientProof, ExpectedServerProof: serverProof}, nil
|
||||
}
|
||||
|
||||
// GenerateVerifier verifier for update pwds and create accounts
|
||||
func (s *SrpAuth) GenerateVerifier(length int) ([]byte, error) {
|
||||
return nil, errors.New("pm-srp: the client doesn't need SRP GenerateVerifier")
|
||||
}
|
||||
111
pkg/srp/srp_test.go
Normal file
111
pkg/srp/srp_test.go
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package srp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
testServerEphemeral = "l13IQSVFBEV0ZZREuRQ4ZgP6OpGiIfIjbSDYQG3Yp39FkT2B/k3n1ZhwqrAdy+qvPPFq/le0b7UDtayoX4aOTJihoRvifas8Hr3icd9nAHqd0TUBbkZkT6Iy6UpzmirCXQtEhvGQIdOLuwvy+vZWh24G2ahBM75dAqwkP961EJMh67/I5PA5hJdQZjdPT5luCyVa7BS1d9ZdmuR0/VCjUOdJbYjgtIH7BQoZs+KacjhUN8gybu+fsycvTK3eC+9mCN2Y6GdsuCMuR3pFB0RF9eKae7cA6RbJfF1bjm0nNfWLXzgKguKBOeF3GEAsnCgK68q82/pq9etiUDizUlUBcA=="
|
||||
testServerProof = "ffYFIhnhZJAflFJr9FfXbtdsBLkDGH+TUR5sj98wg0iVHyIhIVT6BeZD8tZA75tYlz7uYIanswweB3bjrGfITXfxERgQysQSoPUB284cX4VQm1IfTB/9LPma618MH8OULNluXVu2eizPWnvIn9VLXCaIX+38Xd6xOjmCQgfkpJy3Sh3ndikjqNCGWiKyvERVJi0nTmpAbHmcdeEp1K++ZRbebRhm2d018o/u4H2gu+MF39Hx12zMzEGNMwkNkgKSEQYlqmj57S6tW9JuB30zVZFnw6Krftg1QfJR6zCT1/J57OGp0A/7X/lC6Xz/I33eJvXOpG9GCRCbNiozFg9IXQ=="
|
||||
|
||||
testClientProof = "8dQtp6zIeEmu3D93CxPdEiCWiAE86uDmK33EpxyqReMwUrm/bTL+zCkWa/X7QgLNrt2FBAriyROhz5TEONgZq/PqZnBEBym6Rvo708KHu6S4LFdZkVc0+lgi7yQpNhU8bqB0BCqdSWd3Fjd3xbOYgO7/vnFK+p9XQZKwEh2RmGv97XHwoxefoyXK6BB+VVMkELd4vL7vdqBiOBU3ufOlSp+0XBMVltQ4oi5l1y21pzOA9cw5WTPIPMcQHffNFq/rReHYnqbBqiLlSLyw6K0PcVuN3bvr3rVYfdS1CsM/Rv1DzXlBUl39B2j82y6hdyGcTeplGyAnAcu0CimvynKBvQ=="
|
||||
testModulus = "W2z5HBi8RvsfYzZTS7qBaUxxPhsfHJFZpu3Kd6s1JafNrCCH9rfvPLrfuqocxWPgWDH2R8neK7PkNvjxto9TStuY5z7jAzWRvFWN9cQhAKkdWgy0JY6ywVn22+HFpF4cYesHrqFIKUPDMSSIlWjBVmEJZ/MusD44ZT29xcPrOqeZvwtCffKtGAIjLYPZIEbZKnDM1Dm3q2K/xS5h+xdhjnndhsrkwm9U9oyA2wxzSXFL+pdfj2fOdRwuR5nW0J2NFrq3kJjkRmpO/Genq1UW+TEknIWAb6VzJJJA244K/H8cnSx2+nSNZO3bbo6Ys228ruV9A8m6DhxmS+bihN3ttQ=="
|
||||
testModulusClearSign = `-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA256
|
||||
|
||||
W2z5HBi8RvsfYzZTS7qBaUxxPhsfHJFZpu3Kd6s1JafNrCCH9rfvPLrfuqocxWPgWDH2R8neK7PkNvjxto9TStuY5z7jAzWRvFWN9cQhAKkdWgy0JY6ywVn22+HFpF4cYesHrqFIKUPDMSSIlWjBVmEJZ/MusD44ZT29xcPrOqeZvwtCffKtGAIjLYPZIEbZKnDM1Dm3q2K/xS5h+xdhjnndhsrkwm9U9oyA2wxzSXFL+pdfj2fOdRwuR5nW0J2NFrq3kJjkRmpO/Genq1UW+TEknIWAb6VzJJJA244K/H8cnSx2+nSNZO3bbo6Ys228ruV9A8m6DhxmS+bihN3ttQ==
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: ProtonMail
|
||||
Comment: https://protonmail.com
|
||||
|
||||
wl4EARYIABAFAlwB1j0JEDUFhcTpUY8mAAD8CgEAnsFnF4cF0uSHKkXa1GIa
|
||||
GO86yMV4zDZEZcDSJo0fgr8A/AlupGN9EdHlsrZLmTA1vhIx+rOgxdEff28N
|
||||
kvNM7qIK
|
||||
=q6vu
|
||||
-----END PGP SIGNATURE-----`
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Only for tests, replace the default random reader by something that always
|
||||
// return the same thing
|
||||
RandReader = rand.New(rand.NewSource(42))
|
||||
}
|
||||
|
||||
func TestReadClearSigned(t *testing.T) {
|
||||
cleartext, err := ReadClearSignedMessage(testModulusClearSign)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error but have ", err)
|
||||
}
|
||||
if cleartext != testModulus {
|
||||
t.Fatalf("Expected message\n\t'%s'\nbut have\n\t'%s'", testModulus, cleartext)
|
||||
}
|
||||
|
||||
lastChar := len(testModulusClearSign)
|
||||
wrongSignature := testModulusClearSign[:lastChar-100]
|
||||
wrongSignature += "c"
|
||||
wrongSignature += testModulusClearSign[lastChar-99:]
|
||||
_, err = ReadClearSignedMessage(wrongSignature)
|
||||
if err != ErrInvalidSignature {
|
||||
t.Fatal("Expected the ErrInvalidSignature but have ", err)
|
||||
}
|
||||
|
||||
wrongSignature = testModulusClearSign + "data after modulus"
|
||||
_, err = ReadClearSignedMessage(wrongSignature)
|
||||
if err != ErrDataAfterModulus {
|
||||
t.Fatal("Expected the ErrDataAfterModulus but have ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSRPauth(t *testing.T) {
|
||||
srp, err := NewSrpAuth(4, "bridgetest", "test", "yKlc5/CvObfoiw==", testModulusClearSign, testServerEphemeral)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error but have ", err)
|
||||
}
|
||||
|
||||
proofs, err := srp.GenerateSrpProofs(2048)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error but have ", err)
|
||||
}
|
||||
|
||||
expectedProof, err := base64.StdEncoding.DecodeString(testServerProof)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error but have ", err)
|
||||
}
|
||||
if !bytes.Equal(proofs.ExpectedServerProof, expectedProof) {
|
||||
t.Fatalf("Expected server proof\n\t'%s'\nbut have\n\t'%s'",
|
||||
testServerProof,
|
||||
base64.StdEncoding.EncodeToString(proofs.ExpectedServerProof),
|
||||
)
|
||||
}
|
||||
|
||||
expectedProof, err = base64.StdEncoding.DecodeString(testClientProof)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error but have ", err)
|
||||
}
|
||||
if !bytes.Equal(proofs.ClientProof, expectedProof) {
|
||||
t.Fatalf("Expected client proof\n\t'%s'\nbut have\n\t'%s'",
|
||||
testClientProof,
|
||||
base64.StdEncoding.EncodeToString(proofs.ClientProof),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user