修复外部证书签发与续期文件命名不一致
This commit is contained in:
1 parent
d0e8ce0639
commit
460033a7f8
5 files changed
+21
-16
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/utils/atomicfile"
|
||||
)
|
||||
@@ -38,7 +39,7 @@ func ExportProjectTLS(root, destination string) error {
|
||||
}
|
||||
|
||||
// PublishExternalTLS 仅由部署管理员显式提供外部续期目录,不从网页配置读取高权限源路径。
|
||||
// 外部工具统一使用 smail 文件名;校验失败时不替换入口的有效证书。
|
||||
// 外部工具使用邮件主域名作为文件名,与续期读取规则一致;校验失败时保留入口证书。
|
||||
func PublishExternalTLS(root, sourceDirectory, destination string) error {
|
||||
if runtime.GOOS != "linux" {
|
||||
return errors.New("本机 Nginx 证书同步仅支持 Linux")
|
||||
@@ -57,7 +58,11 @@ func PublishExternalTLS(root, sourceDirectory, destination string) error {
|
||||
if filepath.Dir(destination) == sourceDirectory {
|
||||
return ErrUnsafeSSLFile
|
||||
}
|
||||
return exportTLSBundle(sourceDirectory, "smail.crt", "smail.key", destination, validationCertificateDomains(&runtime))
|
||||
domain := runtime.Root.Domains.Primary
|
||||
if domain == "" || domain == "." || domain == ".." || strings.ContainsAny(domain, `/\:`) {
|
||||
return ErrUnsafeSSLFile
|
||||
}
|
||||
return exportTLSBundle(sourceDirectory, domain+".crt", domain+".key", destination, validationCertificateDomains(&runtime))
|
||||
}
|
||||
|
||||
func exportTLSBundle(sourceDirectory, certificateName, privateKeyName, destination string, domains []string) error {
|
||||
|
||||
@@ -35,8 +35,8 @@ func TestPublishExternalTLSValidatesBeforeReplacingBundle(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("smail.crt", certificate)
|
||||
write("smail.key", key)
|
||||
write("example.com.crt", certificate)
|
||||
write("example.com.key", key)
|
||||
destination := filepath.Join(output, "tls.pem")
|
||||
if err := PublishExternalTLS(root, source, destination); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -69,22 +69,22 @@ func TestPublishExternalTLSValidatesBeforeReplacingBundle(t *testing.T) {
|
||||
t.Fatal("failed publication replaced the previous bundle")
|
||||
}
|
||||
}
|
||||
write("smail.key", []byte("invalid"))
|
||||
write("example.com.key", []byte("invalid"))
|
||||
assertRejected()
|
||||
wrongKey, wrongCertificate := testManagedCertificate(t, "other.example", time.Now().Add(-time.Hour), time.Now().Add(time.Hour), 2048)
|
||||
write("smail.key", wrongKey)
|
||||
write("smail.crt", wrongCertificate)
|
||||
write("example.com.key", wrongKey)
|
||||
write("example.com.crt", wrongCertificate)
|
||||
assertRejected()
|
||||
write("smail.key", key)
|
||||
write("smail.crt", certificate)
|
||||
if err := os.Chmod(filepath.Join(source, "smail.key"), 0644); err != nil {
|
||||
write("example.com.key", key)
|
||||
write("example.com.crt", certificate)
|
||||
if err := os.Chmod(filepath.Join(source, "example.com.key"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertRejected()
|
||||
if err := os.Chmod(filepath.Join(source, "smail.key"), 0600); err != nil {
|
||||
if err := os.Chmod(filepath.Join(source, "example.com.key"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := PublishExternalTLS(root, source, filepath.Join(source, "smail.crt")); err == nil {
|
||||
if err := PublishExternalTLS(root, source, filepath.Join(source, "example.com.crt")); err == nil {
|
||||
t.Fatal("source overwrite allowed")
|
||||
}
|
||||
candidate.Root.HTTP.TLSMode = HTTPSTLSModeDirect
|
||||
|
||||
Reference in new issue
Block a user