免费 SSL 最常见的解决方案是LetsEncrypt。
LetsEncrypt 为大多数操作系统提供各种客户端。我推荐使用客户端ACMESharp。
在 Powershell 上执行以下步骤(如official documentation of the project 中所述)
1) 安装 ACMESharp
Import-Module ACMESharp
2) 初始化保管库
Initialize-ACMEVault
3) 使用电子邮件创建新的 ACME 注册
New-ACMERegistration -Contacts mailto:somebody@example.org -AcceptTos
4) 提交域标识符
New-ACMEIdentifier -Dns myserver.example.com -Alias dns1
5) 应对挑战以证明域名所有权
选择一种方法来证明您拥有自己的域,我推荐 HTTP
挑战。
(Complete-ACMEChallenge dns1 -ChallengeType http-01 -Handler manual).Challenge
如果您没有在输出中获得文件路径和内容等挑战详细信息,请尝试以下操作:
(Update-ACMEIdentifier dns1 -ChallengeType http-01).Challenges | Where-Object {$_.Type -eq "http-01"}
您可能必须允许通过 apache 访问隐藏位置,以便挑战可以到达 .well-known 位置。
您可以使用类似以下配置的内容,具体取决于您的自定义需求(如 this post 中所述):
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !.well-known/
RewriteRule "(^|/)\.(?!well-known)" - [F]
</IfModule>
6) 提交质询响应以证明域所有权(HTTP 方法)
Submit-ACMEChallenge dns1 -ChallengeType http-01
挑战不会立即更新,因此请尝试更新结果,直到它有效为止。
(Update-ACMEIdentifier dns1 -ChallengeType http-01).Challenges |Where-Object {$_.Type -eq "http-01"}
一旦有效,请尝试:
Update-ACMEIdentifier dns1
7) 请求和检索证书
New-ACMECertificate dns1 -Generate -Alias cert1
Submit-ACMECertificate cert1
证书可能不会立即颁发,因此请尝试:
Update-ACMECertificate cert1
直到没事为止。
8) 导出公钥和私钥
私钥:
Get-ACMECertificate cert1 -ExportKeyPEM "path\to\cert1.key.pem"
证书签名请求:
Get-ACMECertificate cert1 -ExportCsrPEM "path\to\cert1.csr.pem"
让我们加密公共证书:
Get-ACMECertificate cert1 -ExportCertificatePEM "path\to\cert1.crt.pem" -ExportCertificateDER "path\to\cert1.crt"
发行人的公共证书:
Get-ACMECertificate cert1 -ExportIssuerPEM "path\to\cert1-issuer.crt.pem" -ExportIssuerDER "path\to\cert1-issuer.crt"
无论如何,您实际上并不需要上述所有内容,但私钥是绝对必要的,因此请妥善保管。
如需更多文档,请访问项目的github repo。