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
package mobile
import (
"crypto/sha1"
"crypto/x509"
"encoding/hex"
"encoding/pem"
"testing"
)
func TestExtraRootsAreGlobalSignR46AndE46(t *testing.T) {
want := map[string]string{
"GlobalSign Root R46": "53a2b04bca6bd645e6398a8ec40dd2bf77c3a290",
"GlobalSign Root E46": "39b46cd5fe8006ebe22f4abb0833a0afdbb9dd84",
}
rest := extraRoots
for {
var block *pem.Block
block, rest = pem.Decode(rest)
if block == nil {
break
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
t.Fatal(err)
}
sum := sha1.Sum(cert.Raw)
name := cert.Subject.CommonName
if want[name] != hex.EncodeToString(sum[:]) {
t.Fatalf("unexpected root %q %x", name, sum)
}
if !cert.IsCA {
t.Fatalf("%s is not a CA", name)
}
delete(want, name)
}
if len(want) > 0 {
t.Fatalf("missing roots: %v", want)
}
}
func TestCertDirsPreferTheUpdatableStore(t *testing.T) {
if got := certDirs(true); got != apexCerts+":"+userCerts {
t.Fatal(got)
}
if got := certDirs(false); got != systemCerts+":"+userCerts {
t.Fatal(got)
}
}