-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcerts.go
More file actions
45 lines (35 loc) · 839 Bytes
/
certs.go
File metadata and controls
45 lines (35 loc) · 839 Bytes
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
package awsmocker
import (
"crypto/tls"
"crypto/x509"
_ "embed"
)
//go:embed cacert.pem
var caCert []byte
//go:embed cakey.pem
var caKey []byte
var caKeyPair tls.Certificate
func init() {
keypair, err := tls.X509KeyPair(caCert, caKey)
if err != nil {
panic("Error parsing internal CA " + err.Error())
}
caKeyPair = keypair
cert, err := x509.ParseCertificate(caKeyPair.Certificate[0])
if err != nil {
panic("Error parsing internal CAcert " + err.Error())
}
caKeyPair.Leaf = cert
}
// Exports the PEM Bytes of the CA Certificate (if you need to use it)
func CACertPEM() []byte {
return caCert
}
// Returns the parsed X509 Certificate
func CACert() *x509.Certificate {
// sync.OnceValue()
return caKeyPair.Leaf
}
// func writeCABundle(filePath string) error {
// return os.WriteFile(filePath, caCert, 0o600)
// }