MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / LoadOrCreateNodeCA

Function LoadOrCreateNodeCA

internal/cert/ca.go:26–53  ·  view source on GitHub ↗
(certPath, keyPath string)

Source from the content-addressed store, hash-verified

24}
25
26func LoadOrCreateNodeCA(certPath, keyPath string) (*NodeCA, error) {
27 if certPath == "" || keyPath == "" {
28 return nil, fmt.Errorf("cert path and key path are required")
29 }
30
31 certInfo, certErr := os.Stat(certPath)
32 keyInfo, keyErr := os.Stat(keyPath)
33 bothExist := certErr == nil && keyErr == nil && !certInfo.IsDir() && !keyInfo.IsDir()
34
35 if bothExist {
36 ca, err := loadNodeCA(certPath, keyPath)
37 if err == nil {
38 return ca, nil
39 }
40 return nil, err
41 }
42 if (certErr == nil) != (keyErr == nil) {
43 return nil, fmt.Errorf("cert file and key file must exist together")
44 }
45 if certErr != nil && !os.IsNotExist(certErr) {
46 return nil, fmt.Errorf("stat cert file: %w", certErr)
47 }
48 if keyErr != nil && !os.IsNotExist(keyErr) {
49 return nil, fmt.Errorf("stat key file: %w", keyErr)
50 }
51
52 return createNodeCA(certPath, keyPath)
53}
54
55func loadNodeCA(certPath, keyPath string) (*NodeCA, error) {
56 certBytes, err := os.ReadFile(certPath)

Callers 13

TestE2E_EnrollAndConnectFunction · 0.92
RunFunction · 0.92
newTestCAFunction · 0.92
newTestCAFunction · 0.92
TestSignCSR_SuccessFunction · 0.85
TestSignCSR_InvalidPEMFunction · 0.85
TestSignCSR_BadSignatureFunction · 0.85

Calls 2

loadNodeCAFunction · 0.85
createNodeCAFunction · 0.85