交付双端基础、实时联系人和隔离浏览器
This commit is contained in:
1 parent
43687d5e7e
commit
67fef3ff87
59 files changed
+5094
-1
No files matched your search
@@ -0,0 +1,37 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user