forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
providers.go
46 lines (38 loc) · 1 KB
/
providers.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
45
46
package providers
import (
"crypto/tls"
"fmt"
"github.com/pydio/cells/common/proto/install"
)
type CertProvider interface {
LoadCertificates(config *install.ProxyConfig) (certFile string, certKey string, err error)
}
func LoadCertificates(config *install.ProxyConfig) (certFile string, certKey string, err error) {
if !config.HasTLS() {
return "", "", fmt.Errorf("no TLS config found")
}
if config.GetSelfSigned() != nil {
return GetMkCertCache().LoadCertificates(config)
} else if config.GetCertificate() != nil {
cert := config.GetCertificate()
return cert.CertFile, cert.KeyFile, nil
}
return
}
func LoadTLSServerConfig(config *install.ProxyConfig) (*tls.Config, error) {
if !config.HasTLS() {
return nil, fmt.Errorf("no TLS config found")
}
c, k, e := LoadCertificates(config)
if e != nil {
return nil, e
}
// Directly provided in conf
cert, err := tls.LoadX509KeyPair(c, k)
if err != nil {
return nil, err
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
}, nil
}