-
Notifications
You must be signed in to change notification settings - Fork 2
/
specifics_unix.go
46 lines (35 loc) · 940 Bytes
/
specifics_unix.go
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
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
package main
import (
"crypto/x509"
"errors"
"golang.org/x/sys/unix"
"io/ioutil"
)
// loadRootCertPool builds a trust store (cert pool) containing our CA's root
// certificate.
func loadRootCertPool(rootCertPath string) (*x509.CertPool, error) {
pool, err := x509.SystemCertPool()
if err != nil {
return nil, errors.New("cannot load system certs")
}
if rootCertPath != "" {
root, err := ioutil.ReadFile(rootCertPath)
if err != nil {
return nil, err
}
if ok := pool.AppendCertsFromPEM(root); !ok {
return nil, errors.New("missing or invalid root certificate")
}
}
return pool, nil
}
func WritePrivateKeyToFile(outputFileName, privateKeyPEM string) error {
umask := unix.Umask(0)
defer unix.Umask(umask)
err := ioutil.WriteFile(outputFileName, []byte(privateKeyPEM), 0600)
if err != nil{
return err
}
return nil
}