mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
tls,wss,trojan: support certificate pinning (#275)
This commit is contained in:
1 parent
5578b19f61
commit
c86cadb4be
9 files changed
+63
-18
No files matched your search
@@ -2,9 +2,12 @@ package tls
|
||||
|
||||
import (
|
||||
stdtls "crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/nadoo/glider/log"
|
||||
@@ -80,6 +83,19 @@ func NewTLSDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
|
||||
MinVersion: stdtls.VersionTLS12,
|
||||
}
|
||||
|
||||
if t.certFile != "" {
|
||||
certData, err := os.ReadFile(t.certFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[tls] read cert file error: %s", err)
|
||||
}
|
||||
|
||||
certPool := x509.NewCertPool()
|
||||
if !certPool.AppendCertsFromPEM(certData) {
|
||||
return nil, fmt.Errorf("[tls] can not append cert file: %s", t.certFile)
|
||||
}
|
||||
t.config.RootCAs = certPool
|
||||
}
|
||||
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user