1 parent
a2748e7664
commit
8b72f56ace
8 files changed
+59
-17
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# 仅为阿里云 DNS 配置示例,实际服务商和授权范围必须先确认。
|
||||
# 正式文件位于 /etc/smail/acme-dns.env,归 root 所有,权限为 0600。
|
||||
# 禁止将填写后的文件、密钥或环境变量输出提交到仓库。
|
||||
SMAIL_ACME_DNS_PROVIDER=alidns
|
||||
SMAIL_ACME_DNS_PROVIDER=
|
||||
ALICLOUD_ACCESS_KEY=
|
||||
ALICLOUD_SECRET_KEY=
|
||||
@@ -2,4 +2,6 @@
|
||||
# 正式文件为 /etc/smail/acme-renew.env,root 所有,权限 0600。
|
||||
# HTTP 模式复用 Nginx 的 /var/lib/smail-acme,不监听新端口,不停止服务。
|
||||
# 使用 DNS 模式时设为 dns,并在 acme-dns.env 中配置专用服务商凭据。
|
||||
SMAIL_ACME_CHALLENGE=http
|
||||
SMAIL_MAIL_DOMAIN=
|
||||
SMAIL_WEB_DOMAIN=
|
||||
SMAIL_ACME_CHALLENGE=dns
|
||||
@@ -8,6 +8,7 @@ import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import pwd
|
||||
import re
|
||||
import shlex
|
||||
import socket
|
||||
import ssl
|
||||
@@ -17,10 +18,25 @@ import time
|
||||
import uuid
|
||||
|
||||
|
||||
DOMAINS = ('cdis.cn', '*.cdis.cn')
|
||||
VERIFY_HOSTNAMES = ('cdis.cn', 'web.cdis.cn', 'mail.cdis.cn', 'smtp.cdis.cn',
|
||||
'imap.cdis.cn', 'pop.cdis.cn')
|
||||
CERTIFICATE_SNI = 'web.cdis.cn'
|
||||
def configured_domain(name):
|
||||
value = os.environ[name].strip().lower()
|
||||
labels = value.split('.')
|
||||
if (len(value) > 253 or len(labels) < 2
|
||||
or any(not re.fullmatch(r'[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?', label)
|
||||
for label in labels)):
|
||||
raise ValueError(name)
|
||||
return value
|
||||
|
||||
|
||||
MAIL_DOMAIN = configured_domain('SMAIL_MAIL_DOMAIN')
|
||||
CERTIFICATE_SNI = configured_domain('SMAIL_WEB_DOMAIN')
|
||||
if (CERTIFICATE_SNI != MAIL_DOMAIN
|
||||
and (not CERTIFICATE_SNI.endswith('.' + MAIL_DOMAIN)
|
||||
or CERTIFICATE_SNI.count('.') != MAIL_DOMAIN.count('.') + 1)):
|
||||
raise ValueError('SMAIL_WEB_DOMAIN')
|
||||
DOMAINS = (MAIL_DOMAIN, '*.' + MAIL_DOMAIN)
|
||||
VERIFY_HOSTNAMES = (MAIL_DOMAIN, CERTIFICATE_SNI,
|
||||
*(prefix + '.' + MAIL_DOMAIN for prefix in ('mail', 'smtp', 'imap', 'pop')))
|
||||
LINEAGE = Path('/var/lib/smail-acme-tls/certificates')
|
||||
TARGET = Path('/opt/smail/ssl')
|
||||
BACKUPS = Path('/var/backups')
|
||||
@@ -147,9 +163,9 @@ def publish():
|
||||
check_nginx_paths()
|
||||
run('systemctl', 'is-active', '--quiet', 'nginx')
|
||||
identity = pwd.getpwnam('smail')
|
||||
sources = {'candidate.crt': read_file(LINEAGE / 'cdis.cn.crt', 0),
|
||||
'candidate.key': read_file(LINEAGE / 'cdis.cn.key', 0),
|
||||
'candidate.issuer.crt': read_file(LINEAGE / 'cdis.cn.issuer.crt', 0),
|
||||
sources = {'candidate.crt': read_file(LINEAGE / (MAIL_DOMAIN + '.crt'), 0),
|
||||
'candidate.key': read_file(LINEAGE / (MAIL_DOMAIN + '.key'), 0),
|
||||
'candidate.issuer.crt': read_file(LINEAGE / (MAIL_DOMAIN + '.issuer.crt'), 0),
|
||||
'previous.crt': read_file(TARGET / 'custom.crt', identity.pw_uid),
|
||||
'previous.key': read_file(TARGET / 'custom.key', identity.pw_uid)}
|
||||
stamp = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%S') + '-' + uuid.uuid4().hex[:8]
|
||||
|
||||
@@ -29,7 +29,7 @@ def challenge_arguments():
|
||||
return ['--dns', dns_provider()]
|
||||
if method != 'http':
|
||||
raise RuntimeError('验证方式必须为 dns 或 http,不允许自动回退到停机验证')
|
||||
if '*.cdis.cn' in DOMAINS:
|
||||
if any(domain.startswith('*.') for domain in DOMAINS):
|
||||
raise RuntimeError('泛域名证书必须使用 DNS 验证,不能使用 HTTP 验证')
|
||||
private = ROOT.lstat()
|
||||
if (ROOT.resolve(strict=True) != ROOT or not stat.S_ISDIR(private.st_mode)
|
||||
|
||||
Reference in new issue
Block a user