mirror of https://github.com/bjdgyc/anylink.git
修改dtls加密套件
This commit is contained in:
parent
6eea265b15
commit
43ca09e985
|
@ -2,6 +2,8 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/rsa"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -15,31 +17,55 @@ import (
|
||||||
"github.com/pion/logging"
|
"github.com/pion/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
dtlsSigneRsa = 1
|
||||||
|
dtlsSigneEcdsa = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var dtlsSigneType = dtlsSigneRsa
|
||||||
|
|
||||||
func startDtls() {
|
func startDtls() {
|
||||||
if !base.Cfg.ServerDTLS {
|
if !base.Cfg.ServerDTLS {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
certificate, err := selfsign.GenerateSelfSigned()
|
var (
|
||||||
|
err error
|
||||||
|
certificate tls.Certificate
|
||||||
|
)
|
||||||
|
|
||||||
|
//rsa 兼容 open connect
|
||||||
|
if dtlsSigneType == dtlsSigneRsa {
|
||||||
|
priv, _ := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
|
certificate, err = selfsign.SelfSign(priv)
|
||||||
|
}
|
||||||
|
//ecdsa
|
||||||
|
if dtlsSigneType == dtlsSigneEcdsa {
|
||||||
|
certificate, err = selfsign.GenerateSelfSigned()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logf := logging.NewDefaultLoggerFactory()
|
logf := logging.NewDefaultLoggerFactory()
|
||||||
logf.Writer = base.GetBaseLw()
|
logf.Writer = base.GetBaseLw()
|
||||||
// logf.DefaultLogLevel = logging.LogLevelTrace
|
//logf.DefaultLogLevel = logging.LogLevelTrace
|
||||||
logf.DefaultLogLevel = logging.LogLevelInfo
|
logf.DefaultLogLevel = logging.LogLevelInfo
|
||||||
|
|
||||||
// https://github.com/pion/dtls/pull/369
|
// https://github.com/pion/dtls/pull/369
|
||||||
sessStore := &sessionStore{}
|
sessStore := &sessionStore{}
|
||||||
|
|
||||||
config := &dtls.Config{
|
config := &dtls.Config{
|
||||||
Certificates: []tls.Certificate{certificate},
|
Certificates: []tls.Certificate{certificate},
|
||||||
InsecureSkipVerify: true,
|
//InsecureSkipVerify: true,
|
||||||
ExtendedMasterSecret: dtls.DisableExtendedMasterSecret,
|
ExtendedMasterSecret: dtls.DisableExtendedMasterSecret,
|
||||||
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
|
CipherSuites: []dtls.CipherSuiteID{
|
||||||
LoggerFactory: logf,
|
dtls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||||
MTU: BufferSize,
|
dtls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||||
SessionStore: sessStore,
|
},
|
||||||
|
LoggerFactory: logf,
|
||||||
|
MTU: BufferSize,
|
||||||
|
SessionStore: sessStore,
|
||||||
ConnectContextMaker: func() (context.Context, func()) {
|
ConnectContextMaker: func() (context.Context, func()) {
|
||||||
return context.WithTimeout(context.Background(), 5*time.Second)
|
return context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
},
|
},
|
||||||
|
@ -98,3 +124,18 @@ func (ms *sessionStore) Get(key []byte) (dtls.Session, error) {
|
||||||
func (ms *sessionStore) Del(key []byte) error {
|
func (ms *sessionStore) Del(key []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkDtls12Ciphersuite(ciphersuite string) string {
|
||||||
|
if dtlsSigneType == dtlsSigneEcdsa {
|
||||||
|
return "ECDHE-ECDSA-AES256-GCM-SHA384"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "ECDHE-RSA-AES256-GCM-SHA384"
|
||||||
|
|
||||||
|
//var str2ciphersuite = map[string]dtls.CipherSuiteID{
|
||||||
|
// "ECDHE-ECDSA-AES256-GCM-SHA384": dtls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
// "ECDHE-ECDSA-AES128-GCM-SHA256": dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
// "ECDHE-RSA-AES256-GCM-SHA384": dtls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
// "ECDHE-RSA-AES128-GCM-SHA256": dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
|
@ -92,6 +92,10 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
base.Debug(cSess.IpAddr, cSess.MacHw, sess.Username, mobile)
|
base.Debug(cSess.IpAddr, cSess.MacHw, sess.Username, mobile)
|
||||||
|
|
||||||
|
//检测密码套件
|
||||||
|
dtlsCiphersuite := checkDtls12Ciphersuite(r.Header.Get("X-Dtls12-Ciphersuite"))
|
||||||
|
base.Debug("dtlsCiphersuite", dtlsCiphersuite)
|
||||||
|
|
||||||
// 压缩
|
// 压缩
|
||||||
if cmpName, ok := cSess.SetPickCmp("cstp", r.Header.Get("X-Cstp-Accept-Encoding")); ok {
|
if cmpName, ok := cSess.SetPickCmp("cstp", r.Header.Get("X-Cstp-Accept-Encoding")); ok {
|
||||||
HttpSetHeader(w, "X-CSTP-Content-Encoding", cmpName)
|
HttpSetHeader(w, "X-CSTP-Content-Encoding", cmpName)
|
||||||
|
@ -164,7 +168,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||||
HttpSetHeader(w, "X-DTLS-Port", dtlsPort)
|
HttpSetHeader(w, "X-DTLS-Port", dtlsPort)
|
||||||
HttpSetHeader(w, "X-DTLS-DPD", fmt.Sprintf("%d", cstpDpd))
|
HttpSetHeader(w, "X-DTLS-DPD", fmt.Sprintf("%d", cstpDpd))
|
||||||
HttpSetHeader(w, "X-DTLS-Keepalive", fmt.Sprintf("%d", cstpKeepalive))
|
HttpSetHeader(w, "X-DTLS-Keepalive", fmt.Sprintf("%d", cstpKeepalive))
|
||||||
HttpSetHeader(w, "X-DTLS12-CipherSuite", "ECDHE-ECDSA-AES128-GCM-SHA256")
|
HttpSetHeader(w, "X-DTLS12-CipherSuite", dtlsCiphersuite)
|
||||||
|
|
||||||
HttpSetHeader(w, "X-CSTP-License", "accept")
|
HttpSetHeader(w, "X-CSTP-License", "accept")
|
||||||
HttpSetHeader(w, "X-CSTP-Routing-Filtering-Ignore", "false")
|
HttpSetHeader(w, "X-CSTP-Routing-Filtering-Ignore", "false")
|
||||||
|
|
Loading…
Reference in New Issue