From 24150084404523b7b900033f156bdd1deab05e4a Mon Sep 17 00:00:00 2001 From: Joe Williams Date: Tue, 4 Aug 2020 12:42:20 -0700 Subject: [PATCH] use two structs --- v2/examples/spiffe-grpc/client/main.go | 4 +- v2/examples/spiffe-grpc/server/main.go | 4 +- v2/examples/spiffe-http/client/main.go | 4 +- v2/examples/spiffe-http/server/main.go | 4 +- .../spiffe-jwt-using-proxy/proxy/main.go | 4 +- .../spiffe-jwt-using-proxy/server/main.go | 4 +- v2/examples/spiffe-jwt/server/main.go | 4 +- v2/federation/examples_test.go | 4 +- v2/internal/test/fakebundleendpoint/server.go | 4 +- v2/spiffetls/tlsconfig/config.go | 6 +-- v2/spiffetls/tlsconfig/config_test.go | 52 +++++++++---------- v2/spiffetls/tlsconfig/examples_test.go | 8 +-- v2/spiffetls/tlsconfig/trace.go | 13 +++-- 13 files changed, 61 insertions(+), 54 deletions(-) diff --git a/v2/examples/spiffe-grpc/client/main.go b/v2/examples/spiffe-grpc/client/main.go index 7c04a094..e5f8db6d 100644 --- a/v2/examples/spiffe-grpc/client/main.go +++ b/v2/examples/spiffe-grpc/client/main.go @@ -31,10 +31,10 @@ func main() { serverID := spiffeid.Must("example.org", "server") localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-grpc/server/main.go b/v2/examples/spiffe-grpc/server/main.go index b0096644..454065ea 100644 --- a/v2/examples/spiffe-grpc/server/main.go +++ b/v2/examples/spiffe-grpc/server/main.go @@ -42,10 +42,10 @@ func main() { clientID := spiffeid.Must("example.org", "client") localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-http/client/main.go b/v2/examples/spiffe-http/client/main.go index 5bf0ba1a..062d9171 100644 --- a/v2/examples/spiffe-http/client/main.go +++ b/v2/examples/spiffe-http/client/main.go @@ -33,10 +33,10 @@ func main() { serverID := spiffeid.Must("example.org", "server") localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-http/server/main.go b/v2/examples/spiffe-http/server/main.go index 45561b1b..650acb64 100644 --- a/v2/examples/spiffe-http/server/main.go +++ b/v2/examples/spiffe-http/server/main.go @@ -36,10 +36,10 @@ func main() { clientID := spiffeid.Must("example.org", "client") localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-jwt-using-proxy/proxy/main.go b/v2/examples/spiffe-jwt-using-proxy/proxy/main.go index e252a767..d4e167cc 100644 --- a/v2/examples/spiffe-jwt-using-proxy/proxy/main.go +++ b/v2/examples/spiffe-jwt-using-proxy/proxy/main.go @@ -50,10 +50,10 @@ func main() { http.HandleFunc("/", handler(proxy)) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-jwt-using-proxy/server/main.go b/v2/examples/spiffe-jwt-using-proxy/server/main.go index 4e77f10c..9ef0d69e 100644 --- a/v2/examples/spiffe-jwt-using-proxy/server/main.go +++ b/v2/examples/spiffe-jwt-using-proxy/server/main.go @@ -81,10 +81,10 @@ func main() { http.Handle("/", auth.authenticateClient(http.HandlerFunc(index))) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/examples/spiffe-jwt/server/main.go b/v2/examples/spiffe-jwt/server/main.go index 0614fd6f..f0a96c71 100644 --- a/v2/examples/spiffe-jwt/server/main.go +++ b/v2/examples/spiffe-jwt/server/main.go @@ -66,10 +66,10 @@ func main() { defer x509Source.Close() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/federation/examples_test.go b/v2/federation/examples_test.go index e8644cdb..aaf41a79 100644 --- a/v2/federation/examples_test.go +++ b/v2/federation/examples_test.go @@ -144,10 +144,10 @@ func ExampleHandler_sPIFFEAuth() { defer bundleSource.Close() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { log.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { log.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/internal/test/fakebundleendpoint/server.go b/v2/internal/test/fakebundleendpoint/server.go index 03da9652..16bdb826 100644 --- a/v2/internal/test/fakebundleendpoint/server.go +++ b/v2/internal/test/fakebundleendpoint/server.go @@ -128,10 +128,10 @@ func WithTestBundles(bundles ...*spiffebundle.Bundle) ServerOption { func WithSPIFFEAuth(bundle *spiffebundle.Bundle, svid *x509svid.SVID) ServerOption { localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/spiffetls/tlsconfig/config.go b/v2/spiffetls/tlsconfig/config.go index 7616039b..8281e912 100644 --- a/v2/spiffetls/tlsconfig/config.go +++ b/v2/spiffetls/tlsconfig/config.go @@ -177,13 +177,13 @@ func WrapVerifyPeerCertificate(wrapped func([][]byte, [][]*x509.Certificate) err func getTLSCertificate(svid x509svid.Source, trace Trace) (*tls.Certificate, error) { start := time.Now() if trace.GetTLSCertificateStart != nil { - trace.GetTLSCertificateStart(GetTLSCertificate{Start: start}) + trace.GetTLSCertificateStart(GetTLSCertificateStart{Start: start}) } s, err := svid.GetX509SVID() if err != nil { if trace.GetTLSCertificateEnd != nil { - trace.GetTLSCertificateEnd(GetTLSCertificate{Start: start, End: time.Now(), Err: err}) + trace.GetTLSCertificateEnd(GetTLSCertificateEnd{Start: start, End: time.Now(), Err: err}) return nil, err } } @@ -198,7 +198,7 @@ func getTLSCertificate(svid x509svid.Source, trace Trace) (*tls.Certificate, err } if trace.GetTLSCertificateEnd != nil { - trace.GetTLSCertificateEnd(GetTLSCertificate{Start: start, End: time.Now(), Cert: cert}) + trace.GetTLSCertificateEnd(GetTLSCertificateEnd{Start: start, End: time.Now(), Cert: cert}) } return cert, nil diff --git a/v2/spiffetls/tlsconfig/config_test.go b/v2/spiffetls/tlsconfig/config_test.go index b30d8226..de5888bd 100644 --- a/v2/spiffetls/tlsconfig/config_test.go +++ b/v2/spiffetls/tlsconfig/config_test.go @@ -61,10 +61,10 @@ func TestMTLSClientConfig(t *testing.T) { svid := &x509svid.SVID{} localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -89,10 +89,10 @@ func TestHookMTLSClientConfig(t *testing.T) { config := createTestTLSConfig(base) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -115,10 +115,10 @@ func TestMTLSWebClientConfig(t *testing.T) { roots := x509.NewCertPool() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -142,10 +142,10 @@ func TestHookMTLSWebClientConfig(t *testing.T) { roots := x509.NewCertPool() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -168,10 +168,10 @@ func TestTLSServerConfig(t *testing.T) { svid := &x509svid.SVID{} localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -194,10 +194,10 @@ func TestHookTLSServerConfig(t *testing.T) { config := createTestTLSConfig(base) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -221,10 +221,10 @@ func TestMTLSServerConfig(t *testing.T) { svid := &x509svid.SVID{} localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -249,10 +249,10 @@ func TestHookMTLSServerConfig(t *testing.T) { config := createTestTLSConfig(base) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -337,10 +337,10 @@ func TestGetCertificate(t *testing.T) { } localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -394,10 +394,10 @@ func TestGetClientCertificate(t *testing.T) { } localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -568,10 +568,10 @@ func TestTLSHandshake(t *testing.T) { bundle3 := ca3.Bundle() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -643,10 +643,10 @@ func TestMTLSHandshake(t *testing.T) { client3SVID := ca3.CreateX509SVID(svid3ID) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -734,10 +734,10 @@ func TestMTLSWebHandshake(t *testing.T) { client3SVID := ca3.CreateX509SVID(svid3ID) localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/spiffetls/tlsconfig/examples_test.go b/v2/spiffetls/tlsconfig/examples_test.go index d6c0f1cb..5f81cb67 100644 --- a/v2/spiffetls/tlsconfig/examples_test.go +++ b/v2/spiffetls/tlsconfig/examples_test.go @@ -28,10 +28,10 @@ func ExampleMTLSServerConfig_fileSource() { } localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } @@ -54,10 +54,10 @@ func ExampleMTLSServerConfig_workloadAPISource() { defer source.Close() localTrace := tlsconfig.Trace{ - GetTLSCertificateStart: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateStart: func(tlsconfig.GetTLSCertificateStart) { fmt.Printf("got start of GetTLSCertificate\n") }, - GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificate) { + GetTLSCertificateEnd: func(tlsconfig.GetTLSCertificateEnd) { fmt.Printf("got end of GetTLSCertificate\n") }, } diff --git a/v2/spiffetls/tlsconfig/trace.go b/v2/spiffetls/tlsconfig/trace.go index d78f0bec..2e559002 100644 --- a/v2/spiffetls/tlsconfig/trace.go +++ b/v2/spiffetls/tlsconfig/trace.go @@ -5,7 +5,14 @@ import ( "time" ) -type GetTLSCertificate struct { +type GetTLSCertificateStart struct { + Start time.Time + End time.Time + Cert *tls.Certificate + Err error +} + +type GetTLSCertificateEnd struct { Start time.Time End time.Time Cert *tls.Certificate @@ -13,6 +20,6 @@ type GetTLSCertificate struct { } type Trace struct { - GetTLSCertificateStart func(GetTLSCertificate) - GetTLSCertificateEnd func(GetTLSCertificate) + GetTLSCertificateStart func(GetTLSCertificateStart) + GetTLSCertificateEnd func(GetTLSCertificateEnd) }