feat: 支持局域网 HTTPS 直连并持久化插件连接配置
This commit is contained in:
1 parent
9eba4556db
commit
2203afde3c
15 files changed
+486
-17
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLocalCertificateIdentityAndReuse(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if e := initCertificate("192.168.5.222", dir); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
c := filepath.Join(dir, "server.crt")
|
||||
k := filepath.Join(dir, "server.key")
|
||||
before, _ := os.ReadFile(c)
|
||||
pair, e := tls.LoadX509KeyPair(c, k)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
cert, _ := x509.ParseCertificate(pair.Certificate[0])
|
||||
for _, host := range []string{"192.168.5.222", "localhost", "127.0.0.1"} {
|
||||
if e = cert.VerifyHostname(host); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if cert.VerifyHostname("192.168.5.223") == nil {
|
||||
t.Fatal("wrong IP trusted")
|
||||
}
|
||||
if e = initCertificate("192.168.5.222", dir); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
after, _ := os.ReadFile(c)
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("certificate unexpectedly rotated")
|
||||
}
|
||||
if initCertificate("192.168.5.223", dir) == nil {
|
||||
t.Fatal("existing mismatched certificate accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user