mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-23 19:20:24 +08:00
SSL证书支持IP地址
This commit is contained in:
@@ -132,6 +132,16 @@ func (this *SSLCertConfig) Init(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, ipAddress := range c.IPAddresses {
|
||||||
|
if ipAddress == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var ipAddressString = ipAddress.String()
|
||||||
|
if !lists.ContainsString(dnsNames, ipAddressString) {
|
||||||
|
dnsNames = append(dnsNames, ipAddressString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commonNames = append(commonNames, c.Issuer.CommonName)
|
commonNames = append(commonNames, c.Issuer.CommonName)
|
||||||
|
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
package sslconfigs
|
package sslconfigs_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -10,9 +11,22 @@ import (
|
|||||||
func TestSSLCertConfig_MatchDomain(t *testing.T) {
|
func TestSSLCertConfig_MatchDomain(t *testing.T) {
|
||||||
var a = assert.NewAssertion(t)
|
var a = assert.NewAssertion(t)
|
||||||
|
|
||||||
var cert = &SSLCertConfig{
|
var cert = &sslconfigs.SSLCertConfig{
|
||||||
DNSNames: []string{"a.com", "b.com"},
|
DNSNames: []string{"a.com", "b.com"},
|
||||||
}
|
}
|
||||||
a.IsTrue(cert.MatchDomain("a.com"))
|
a.IsTrue(cert.MatchDomain("a.com"))
|
||||||
a.IsFalse(cert.MatchDomain("z.com"))
|
a.IsFalse(cert.MatchDomain("z.com"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**func TestSSLCertConfig_DNSNames(t *testing.T) {
|
||||||
|
var config = sslconfigs.SSLCertConfig{}
|
||||||
|
config.CertData = []byte(`YOUR CERT DATA`)
|
||||||
|
config.KeyData = []byte(`YOUR KEY DATA`)
|
||||||
|
|
||||||
|
err := config.Init(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(config.DNSNames)
|
||||||
|
}**/
|
||||||
|
|||||||
Reference in New Issue
Block a user