1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package identity
import (
"crypto/ed25519"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"strings"
"testing"
)
func TestFormatFaceHeader(t *testing.T) {
header := FormatFaceHeader(strings.Repeat("A", 200))
for _, line := range strings.Split(header, "\r\n") {
if len(line) > 76 {
t.Fatalf("folded line length = %d", len(line))
}
}
}
func TestGenerateFaceUsesExistingCLI(t *testing.T) {
if _, err := FindCLI(); err != nil {
t.Skip(err)
}
value, err := GenerateFace("reader@example.org")
if err != nil {
t.Fatal(err)
}
if _, err := decodeFacePNG(value); err != nil {
t.Fatal(err)
}
}
func TestGenerateVFaceBindsUsernameEmailAndPublicKey(t *testing.T) {
if _, err := FindCLI(); err != nil {
t.Skip(err)
}
public, _, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
publicKey := base64.StdEncoding.EncodeToString(public)
profile, err := GenerateVFace("pseudonym", "reader@example.org", publicKey)
if err != nil {
t.Fatal(err)
}
input := "pseudonym|reader@example.org|" + publicKey
identityHash := sha256.Sum256([]byte(input))
if profile.Input != input || profile.IdentityHash != hex.EncodeToString(identityHash[:]) {
t.Fatalf("unexpected VFace identity: %#v", profile)
}
if profile.PNGHash == "" || profile.FaceBase64 == "" {
t.Fatalf("VFace image metadata is incomplete: %#v", profile)
}
headers := strings.Join(profile.Headers(), "\n")
for _, want := range []string{"X-VFace-Version: 1", "X-Ed25519-Pub: " + publicKey, "Identity-Hash: " + profile.IdentityHash, "X-VFace-Hash: sha256:" + profile.IdentityHash, "X-VFace-Verify: " + VFaceVerificationURL} {
if !strings.Contains(headers, want) {
t.Fatalf("VFace headers missing %q: %s", want, headers)
}
}
}
|