Skip to content

Commit

Permalink
修复Banner特殊字符
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Nov 15, 2023
1 parent aa2b898 commit 3879c3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 46 deletions.
58 changes: 12 additions & 46 deletions server/handler/dtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,14 @@ import (
"github.com/pion/logging"
)

const (
dtlsSigneRsa = 1
dtlsSigneEcdsa = 2
)

var dtlsSigneType = dtlsSigneRsa

func startDtls() {
if !base.Cfg.ServerDTLS {
return
}

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()
}
priv, _ := rsa.GenerateKey(rand.Reader, 2048)
certificate, err := selfsign.SelfSign(priv)
if err != nil {
panic(err)
}
Expand All @@ -61,10 +43,8 @@ func startDtls() {
ExtendedMasterSecret: dtls.DisableExtendedMasterSecret,
CipherSuites: func() []dtls.CipherSuiteID {
var cs = []dtls.CipherSuiteID{}
for _, v := range dtlsCipherSuites {
for _, vv := range v {
cs = append(cs, vv)
}
for _, vv := range dtlsCipherSuites {
cs = append(cs, vv)
}
return cs
}(),
Expand Down Expand Up @@ -131,35 +111,21 @@ func (ms *sessionStore) Del(key []byte) error {
}

// 客户端和服务端映射 X-DTLS12-CipherSuite
var dtlsCipherSuites = map[string]map[string]dtls.CipherSuiteID{
"ECDSA": {
"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,
},
"RSA": {
"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,
},
var dtlsCipherSuites = 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,
}

func checkDtls12Ciphersuite(ciphersuite string) string {
csArr := strings.Split(ciphersuite, ",")
// ECDSA
if dtlsSigneType == dtlsSigneEcdsa {
for _, v := range csArr {
if _, ok := dtlsCipherSuites["ECDSA"][v]; ok {
return v
}
}
// 返回默认值
return "ECDHE-ECDSA-AES256-GCM-SHA384"
}
csArr := strings.Split(ciphersuite, ":")

for _, v := range csArr {
if _, ok := dtlsCipherSuites["RSA"][v]; ok {
if _, ok := dtlsCipherSuites[v]; ok {
return v
}
}
// 返回默认值
return "ECDHE-RSA-AES256-GCM-SHA384"
return "ECDHE-RSA-AES128-GCM-SHA256"
}
2 changes: 2 additions & 0 deletions server/handler/link_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/bjdgyc/anylink/base"
"github.com/bjdgyc/anylink/dbdata"
"github.com/bjdgyc/anylink/sessdata"
"golang.org/x/net/html"
)

var profileHash = ""
Expand Down Expand Up @@ -157,6 +158,7 @@ func tplRequest(typ int, w io.Writer, data RequestData) {
if strings.Contains(data.Banner, "\n") {
// 替换xml文件的换行符
data.Banner = strings.ReplaceAll(data.Banner, "\n", "
")
data.Banner = html.EscapeString(data.Banner)
}
t, _ := template.New("auth_complete").Parse(auth_complete)
_ = t.Execute(w, data)
Expand Down

0 comments on commit 3879c3a

Please sign in to comment.