44 "bufio"
55 "bytes"
66 "context"
7+ "crypto/tls"
78 "encoding/hex"
89 "errors"
910 "fmt"
@@ -16,9 +17,10 @@ import (
1617 "time"
1718
1819 clog "github.com/SenseUnit/dumbproxy/log"
19- "github.com/hashicorp/go-multierror "
20+ "github.com/SenseUnit/dumbproxy/tlsutil "
2021
2122 us "github.com/Snawoot/uniqueslice"
23+ "github.com/hashicorp/go-multierror"
2224)
2325
2426type serialNumberSetFile struct {
@@ -94,10 +96,26 @@ func (auth *CertAuth) handleReject(ctx context.Context, wr http.ResponseWriter,
9496}
9597
9698func (auth * CertAuth ) Validate (ctx context.Context , wr http.ResponseWriter , req * http.Request ) (string , bool ) {
97- if req .TLS == nil || len (req .TLS .VerifiedChains ) < 1 || len (req .TLS .VerifiedChains [0 ]) < 1 {
99+ cs := req .TLS
100+ if cs == nil {
101+ auth .logger .Debug ("resorting to workaround for go bug #81384" )
102+ // could be issue https://go.dev/issue/81384
103+ conn , ok := tlsutil .ConnFromContext (ctx )
104+ if ok {
105+ if cstater , ok := conn .(interface { ConnectionState () tls.ConnectionState }); ok {
106+ cs = new (tls.ConnectionState )
107+ * cs = cstater .ConnectionState ()
108+ } else {
109+ auth .logger .Debug ("...and conn does not support required interface!" )
110+ }
111+ } else {
112+ auth .logger .Debug ("...and conn was not recovered from context!" )
113+ }
114+ }
115+ if cs == nil || len (cs .VerifiedChains ) < 1 || len (cs .VerifiedChains [0 ]) < 1 {
98116 return auth .handleReject (ctx , wr , req )
99117 }
100- eeCert := req . TLS .VerifiedChains [0 ][0 ]
118+ eeCert := cs .VerifiedChains [0 ][0 ]
101119 if auth .blacklist .Load ().file .Has (eeCert .SerialNumber ) {
102120 return auth .handleReject (ctx , wr , req )
103121 }
0 commit comments