-
Notifications
You must be signed in to change notification settings - Fork 8
/
tls.go
27 lines (22 loc) · 960 Bytes
/
tls.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
package config
import (
"crypto/tls"
"errors"
"path/filepath"
)
// LoadPrivateKeyPair loads the private key pair for the SSLConfig
func (s *SSLConfig) LoadPrivateKeyPair(rootPath string) (*tls.Certificate, error) {
if s.PrivateCRT == "" || s.PrivateKey == "" {
return nil, errors.New("missing private key or cert. Ensure config.yaml is up to date with the latest changes")
}
pair, err := tls.LoadX509KeyPair(filepath.Join(rootPath, s.PrivateCRT), filepath.Join(rootPath, s.PrivateKey))
return &pair, err
}
// LoadPublicKeyPair loads the public key pair for the SSLConfig
func (s *SSLConfig) LoadPublicKeyPair(rootPath string) (*tls.Certificate, error) {
if s.PublicCRT == "" || s.PublicKey == "" {
return nil, errors.New("missing public key or cert. Ensure config.yaml is up to date with the latest changes")
}
pair, err := tls.LoadX509KeyPair(filepath.Join(rootPath, s.PublicCRT), filepath.Join(rootPath, s.PublicKey))
return &pair, err
}