38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package account
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"testing"
|
|
)
|
|
|
|
func TestDeviceProof(t *testing.T) {
|
|
public, private, err := ed25519.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
challenge := Secret()
|
|
signature := Encoding.EncodeToString(ed25519.Sign(private, []byte(deviceProof+challenge)))
|
|
key := Encoding.EncodeToString(public)
|
|
if _, ok := Proof(key, challenge, signature); !ok {
|
|
t.Fatal("valid signature rejected")
|
|
}
|
|
if _, ok := Proof(key, Secret(), signature); ok {
|
|
t.Fatal("signature accepted for a different challenge")
|
|
}
|
|
if _, ok := Proof("invalid", challenge, signature); ok {
|
|
t.Fatal("invalid public key accepted")
|
|
}
|
|
}
|
|
|
|
func TestPasswordHash(t *testing.T) {
|
|
const password = "test password with sufficient length"
|
|
hash := PasswordHash(password)
|
|
if hash == PasswordHash(password) {
|
|
t.Fatal("salt was reused")
|
|
}
|
|
if !VerifyPassword(password, hash) || VerifyPassword("wrong", hash) || VerifyPassword(password, "malformed") {
|
|
t.Fatal("unexpected password verification result")
|
|
}
|
|
}
|