...
1
2
3
4
5 package x509
6
7 import (
8 "internal/godebug"
9 "sync"
10 )
11
12 var (
13 once sync.Once
14 systemRootsMu sync.RWMutex
15 systemRoots *CertPool
16 systemRootsErr error
17 fallbacksSet bool
18 )
19
20 func systemRootsPool() *CertPool {
21 once.Do(initSystemRoots)
22 systemRootsMu.RLock()
23 defer systemRootsMu.RUnlock()
24 return systemRoots
25 }
26
27 func initSystemRoots() {
28 systemRootsMu.Lock()
29 defer systemRootsMu.Unlock()
30 systemRoots, systemRootsErr = loadSystemRoots()
31 if systemRootsErr != nil {
32 systemRoots = nil
33 }
34 }
35
36 var x509usefallbackroots = godebug.New("x509usefallbackroots")
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 func SetFallbackRoots(roots *CertPool) {
52 if roots == nil {
53 panic("roots must be non-nil")
54 }
55
56
57
58 _ = systemRootsPool()
59
60 systemRootsMu.Lock()
61 defer systemRootsMu.Unlock()
62
63 if fallbacksSet {
64 panic("SetFallbackRoots has already been called")
65 }
66 fallbacksSet = true
67
68 if systemRoots != nil && (systemRoots.len() > 0 || systemRoots.systemPool) {
69 if x509usefallbackroots.Value() != "1" {
70 return
71 }
72 x509usefallbackroots.IncNonDefault()
73 }
74 systemRoots, systemRootsErr = roots, nil
75 }
76
View as plain text