@@ -50,7 +50,7 @@ func (cfg *Config) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certif
50
50
}
51
51
52
52
func (cfg * Config ) GetCertificateWithContext (ctx context.Context , clientHello * tls.ClientHelloInfo ) (* tls.Certificate , error ) {
53
- if err := cfg .emit (ctx , "tls_get_certificate" , map [string ]any {"client_hello" : clientHello }); err != nil {
53
+ if err := cfg .emit (ctx , "tls_get_certificate" , map [string ]any {"client_hello" : clientHelloWithoutConn ( clientHello ) }); err != nil {
54
54
cfg .Logger .Error ("TLS handshake aborted by event handler" ,
55
55
zap .String ("server_name" , clientHello .ServerName ),
56
56
zap .String ("remote" , clientHello .Conn .RemoteAddr ().String ()),
@@ -882,6 +882,45 @@ var (
882
882
certLoadWaitChansMu sync.Mutex
883
883
)
884
884
885
+ type serializableClientHello struct {
886
+ CipherSuites []uint16
887
+ ServerName string
888
+ SupportedCurves []tls.CurveID
889
+ SupportedPoints []uint8
890
+ SignatureSchemes []tls.SignatureScheme
891
+ SupportedProtos []string
892
+ SupportedVersions []uint16
893
+
894
+ RemoteAddr , LocalAddr net.Addr // values copied from the Conn as they are still useful/needed
895
+ conn net.Conn // unexported so it's not serialized
896
+ }
897
+
898
+ // clientHelloWithoutConn returns the data from the ClientHelloInfo without the
899
+ // pesky exported Conn field, which often causes an error when serializing because
900
+ // the underlying type may be unserializable.
901
+ func clientHelloWithoutConn (hello * tls.ClientHelloInfo ) serializableClientHello {
902
+ if hello == nil {
903
+ return serializableClientHello {}
904
+ }
905
+ var remote , local net.Addr
906
+ if hello .Conn != nil {
907
+ remote = hello .Conn .RemoteAddr ()
908
+ local = hello .Conn .LocalAddr ()
909
+ }
910
+ return serializableClientHello {
911
+ CipherSuites : hello .CipherSuites ,
912
+ ServerName : hello .ServerName ,
913
+ SupportedCurves : hello .SupportedCurves ,
914
+ SupportedPoints : hello .SupportedPoints ,
915
+ SignatureSchemes : hello .SignatureSchemes ,
916
+ SupportedProtos : hello .SupportedProtos ,
917
+ SupportedVersions : hello .SupportedVersions ,
918
+ RemoteAddr : remote ,
919
+ LocalAddr : local ,
920
+ conn : hello .Conn ,
921
+ }
922
+ }
923
+
885
924
type helloInfoCtxKey string
886
925
887
926
// ClientHelloInfoCtxKey is the key by which the ClientHelloInfo can be extracted from
0 commit comments