tls,wss,trojan: support certificate pinning (#275)

This commit is contained in:
nadoo committed 2021-08-20 18:47:15 +08:00
1 parent 5578b19f61
commit c86cadb4be
9 files changed
+63 -18

No files matched your search

+16
View File
@@ -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
}
+15
View File
@@ -2,8 +2,10 @@ package trojan
import (
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"os"
"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
@@ -34,6 +36,19 @@ func NewTrojanDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
MinVersion: tls.VersionTLS12,
}
if t.certFile != "" {
certData, err := os.ReadFile(t.certFile)
if err != nil {
return nil, fmt.Errorf("[trojan] read cert file error: %s", err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(certData) {
return nil, fmt.Errorf("[trojan] can not append cert file: %s", t.certFile)
}
t.tlsConfig.RootCAs = certPool
}
return t, err
}
-1
View File
@@ -73,7 +73,6 @@ func StrToUUID(s string) (uuid [16]byte, err error) {
return
}
// GetKey returns the key of AES-128-CFB encrypter.
// Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))
func GetKey(uuid [16]byte) []byte {
+15
View File
@@ -2,11 +2,13 @@ package ws
import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io"
"net"
"net/textproto"
"os"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/proxy"
@@ -34,6 +36,19 @@ func NewWSSDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
MinVersion: tls.VersionTLS12,
}
if w.certFile != "" {
certData, err := os.ReadFile(w.certFile)
if err != nil {
return nil, fmt.Errorf("[wss] read cert file error: %s", err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(certData) {
return nil, fmt.Errorf("[wss] can not append cert file: %s", w.certFile)
}
w.tlsConfig.RootCAs = certPool
}
return w, err
}