-
Notifications
You must be signed in to change notification settings - Fork 4
/
config_options.go
40 lines (31 loc) · 999 Bytes
/
config_options.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
package tls
import (
"crypto/tls"
"fmt"
)
// ConfigOptions encapsulates the available options for creating a new TLS config.
type ConfigOptions struct {
ClientCert []byte
ClientKey []byte
Password []byte
IgnoreUnusedPassword bool
ClientAuthType tls.ClientAuthType
ClientCAs []byte
RootCAs []byte
NoSSLVerify bool
CipherSuites []uint16
MinVersion uint16
}
// Validate returns an error if the given TLS config is invalid for some reason.
func (t *ConfigOptions) Validate() error {
if len(t.Password) != 0 && (t.ClientCert == nil && t.ClientKey == nil) {
return fmt.Errorf("password provided without a client cert/key")
}
if t.ClientCert == nil && t.ClientKey != nil {
return fmt.Errorf("client key provided without a certificate")
}
if t.ClientCert != nil && t.ClientKey == nil && len(t.Password) == 0 {
return fmt.Errorf("client cert/key file provided without a password; expect an encrypted PKCS#12 file")
}
return nil
}