Skip to content

Commit 46fafcc

Browse files
authored
[tlscommon] Make genTest and getFingerPrint methods public (#268)
* [tlscommon] Make and public * add suggestions
1 parent e11ce6b commit 46fafcc

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

transport/tlscommon/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// Config defines the user configurable options in the yaml file.
2626
type Config struct {
2727
Enabled *bool `config:"enabled" yaml:"enabled,omitempty"`
28-
VerificationMode TLSVerificationMode `config:"verification_mode" yaml:"verification_mode"` // one of 'none', 'full'
28+
VerificationMode TLSVerificationMode `config:"verification_mode" yaml:"verification_mode"` // one of 'none', 'full', 'certificate' and 'strict'
2929
Versions []TLSVersion `config:"supported_protocols" yaml:"supported_protocols,omitempty"`
3030
CipherSuites []CipherSuite `config:"cipher_suites" yaml:"cipher_suites,omitempty"`
3131
CAs []string `config:"certificate_authorities" yaml:"certificate_authorities,omitempty"`

transport/tlscommon/tls_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (c *TLSConfig) BuildModuleClientConfig(host string) *tls.Config {
143143
// because all slice/pointer fields won't be modified.
144144
cc := *c
145145

146-
// Keep a copy of the host (wheather an IP or hostname)
146+
// Keep a copy of the host (whether an IP or hostname)
147147
// for later validation. It is used by makeVerifyConnection
148148
cc.ServerName = host
149149
config := cc.ToConfig()

transport/tlscommon/tls_config_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
)
4141

4242
func TestMakeVerifyServerConnection(t *testing.T) {
43-
testCerts := genTestCerts(t)
43+
testCerts := GenTestCerts(t)
4444

4545
certPool := x509.NewCertPool()
4646
certPool.AddCert(testCerts["ca"])
@@ -192,13 +192,13 @@ func TestMakeVerifyServerConnection(t *testing.T) {
192192
}
193193

194194
func TestTrustRootCA(t *testing.T) {
195-
certs := genTestCerts(t)
195+
certs := GenTestCerts(t)
196196

197197
nonEmptyCertPool := x509.NewCertPool()
198198
nonEmptyCertPool.AddCert(certs["wildcard"])
199199
nonEmptyCertPool.AddCert(certs["unknown_authority"])
200200

201-
fingerprint := getFingerprint(certs["ca"])
201+
fingerprint := GetCertFingerprint(certs["ca"])
202202

203203
testCases := []struct {
204204
name string
@@ -267,8 +267,8 @@ func TestTrustRootCA(t *testing.T) {
267267
}
268268

269269
func TestMakeVerifyConnectionUsesCATrustedFingerprint(t *testing.T) {
270-
testCerts := genTestCerts(t)
271-
fingerprint := getFingerprint(testCerts["ca"])
270+
testCerts := GenTestCerts(t)
271+
fingerprint := GetCertFingerprint(testCerts["ca"])
272272

273273
testcases := map[string]struct {
274274
verificationMode TLSVerificationMode
@@ -684,12 +684,14 @@ func startTestServer(t *testing.T, serverAddr string, serverCerts []tls.Certific
684684
return *serverURL
685685
}
686686

687-
func getFingerprint(cert *x509.Certificate) string {
687+
// GetCertFingerPrint takes a certificate and returns its HEX encoded SHA-256
688+
func GetCertFingerprint(cert *x509.Certificate) string {
688689
caSHA256 := sha256.Sum256(cert.Raw)
689690
return hex.EncodeToString(caSHA256[:])
690691
}
691692

692-
func genTestCerts(t *testing.T) map[string]*x509.Certificate {
693+
func GenTestCerts(t *testing.T) map[string]*x509.Certificate {
694+
t.Helper()
693695
ca, err := genCA()
694696
if err != nil {
695697
t.Fatalf("cannot generate root CA: %s", err)

transport/tlscommon/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var tlsClientAuthTypes = map[string]TLSClientAuth{
125125
}
126126

127127
// TLSVerificationMode represents the type of verification to do on the remote host:
128-
// `none`, `certificate`, and `full` and we default to `full`.
128+
// `none`, `certificate`, `full` and `strict` - we default to `full`.
129129
// Internally this option is transformed into the `insecure` field in the `tls.Config` struct.
130130
type TLSVerificationMode uint8
131131

0 commit comments

Comments
 (0)