mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-03 04:10:25 +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)
|
||||
|
||||
if index == 0 {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package sslconfigs
|
||||
package sslconfigs_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
@@ -10,9 +11,22 @@ import (
|
||||
func TestSSLCertConfig_MatchDomain(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
|
||||
var cert = &SSLCertConfig{
|
||||
var cert = &sslconfigs.SSLCertConfig{
|
||||
DNSNames: []string{"a.com", "b.com"},
|
||||
}
|
||||
a.IsTrue(cert.MatchDomain("a.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