Compare commits
384 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d46dab4fdd | ||
|
|
d44849c53c | ||
|
|
dbc5a3c6b3 | ||
|
|
4a5fa767ed | ||
|
|
1b7debc6a4 | ||
|
|
19a6b94680 | ||
|
|
65a72b8d60 | ||
|
|
7f61cab101 | ||
|
|
37caef38ad | ||
|
|
9cc01db1d5 | ||
|
|
9172440f79 | ||
|
|
e0eb3a4413 | ||
|
|
ae0f16bf35 | ||
|
|
6c9ed162e3 | ||
|
|
3849b52cdf | ||
|
|
9ecfcb5814 | ||
|
|
54ad09f755 | ||
|
|
6ee4dc165b | ||
|
|
8e2eb89696 | ||
|
|
9d397cc8be | ||
|
|
cbfb0755b3 | ||
|
|
d8d127ee9d | ||
|
|
0ed5430e80 | ||
|
|
878c1f52fa | ||
|
|
6900452b49 | ||
|
|
b97e0e512d | ||
|
|
f740ff517f | ||
|
|
e5989fe023 | ||
|
|
4323156fbe | ||
|
|
3c721901c5 | ||
|
|
5c2c50839a | ||
|
|
fd54c2ffac | ||
|
|
7e483e6091 | ||
|
|
80c48e9acd | ||
|
|
b98f1c0dd0 | ||
|
|
b53874a0b8 | ||
|
|
c4c9adb8bf | ||
|
|
eed265faf1 | ||
|
|
3dc6dd403d | ||
|
|
deb9ba0c43 | ||
|
|
fa33ff499d | ||
|
|
2ed4967744 | ||
|
|
ad360e81cb | ||
|
|
f95f5188b4 | ||
|
|
17d1efa395 | ||
|
|
732cbc5e92 | ||
|
|
5d2d0955b1 | ||
|
|
20feacea12 | ||
|
|
575bf2b73b | ||
|
|
934e6e2bd0 | ||
|
|
fbb9a47e8f | ||
|
|
368132daae | ||
|
|
3d54d04017 | ||
|
|
5b1494b3ce | ||
|
|
ebf2a820cc | ||
|
|
9caa4cd1d4 | ||
|
|
91fd80d44f | ||
|
|
f932e553b0 | ||
|
|
0dd4953197 | ||
|
|
aaea6aa1f3 | ||
|
|
ab4a0aea70 | ||
|
|
29f923537e | ||
|
|
24aa416740 | ||
|
|
08e517ff00 | ||
|
|
29f65389bd | ||
|
|
960a1964c7 | ||
|
|
760d54ba85 | ||
|
|
b1b21d3efc | ||
|
|
5acd7f6fb6 | ||
|
|
a31f1c7f5e | ||
|
|
660ae7333b | ||
|
|
6cf699b25f | ||
|
|
7e5dea51a5 | ||
|
|
92446c3399 | ||
|
|
d9eb927b0a | ||
|
|
39ad7597fa | ||
|
|
83d1bda56a | ||
|
|
20bc5aa6c7 | ||
|
|
162e10909b | ||
|
|
0f1ae6ccd9 | ||
|
|
dd730f6beb | ||
|
|
c9d5cda953 | ||
|
|
33fb1a6bf3 | ||
|
|
a1344245cd | ||
|
|
fe2ca6bed3 | ||
|
|
19a3c7874a | ||
|
|
83e40836eb | ||
|
|
4304c9443a | ||
|
|
b72f8e796c | ||
|
|
7c15f52368 | ||
|
|
adf569eb62 | ||
|
|
340801e743 | ||
|
|
80f96b5b26 | ||
|
|
6646ec888f | ||
|
|
e6cab51031 | ||
|
|
3449a4d6af | ||
|
|
588de02be6 | ||
|
|
422e011d31 | ||
|
|
56a1f8158a | ||
|
|
a3c375ede5 | ||
|
|
754e76d9b9 | ||
|
|
feb7bfc724 | ||
|
|
f84dc771c4 | ||
|
|
d8a52c0be3 | ||
|
|
b50739e064 | ||
|
|
f8e320e2bd | ||
|
|
bac74dc650 | ||
|
|
103f28f6ba | ||
|
|
72fb20abf3 | ||
|
|
d9efc3d4d8 | ||
|
|
836d18f07e | ||
|
|
485ae3514c | ||
|
|
2fa6489153 | ||
|
|
e02d9716f5 | ||
|
|
154409b1df | ||
|
|
98177a5b1e | ||
|
|
8d44171875 | ||
|
|
5b576112d1 | ||
|
|
e1b372c33b | ||
|
|
ce49dce8c6 | ||
|
|
09c9b42cab | ||
|
|
370a12e88a | ||
|
|
c2f1f5c549 | ||
|
|
090e03fac1 | ||
|
|
b745712791 | ||
|
|
7ee753ac85 | ||
|
|
eea6b8ab5d | ||
|
|
a135f5742c | ||
|
|
04adbb45d8 | ||
|
|
62efb22f37 | ||
|
|
5e98f05036 | ||
|
|
292a7ecbe3 | ||
|
|
4cea45bd87 | ||
|
|
7f0b075529 | ||
|
|
8c7ff5e0e8 | ||
|
|
afea5a1623 | ||
|
|
c60dd7f151 | ||
|
|
92f9371156 | ||
|
|
c5714ec6d9 | ||
|
|
dd16386317 | ||
|
|
7cf1f75eb9 | ||
|
|
cf28a00ccd | ||
|
|
9e48474f11 | ||
|
|
c327c0c995 | ||
|
|
bb567da8c6 | ||
|
|
960f61d158 | ||
|
|
80cd1bfc8e | ||
|
|
a6bf198604 | ||
|
|
7e8842b452 | ||
|
|
fc9e71bed2 | ||
|
|
3e3373b8c7 | ||
|
|
7d45db89bf | ||
|
|
08c1f338d5 | ||
|
|
18865f0931 | ||
|
|
d22a25d260 | ||
|
|
849c145926 | ||
|
|
36a773df0b | ||
|
|
b2abf1490b | ||
|
|
fd5aa63ef3 | ||
|
|
7e024cbcf7 | ||
|
|
7050ee2354 | ||
|
|
024e97d632 | ||
|
|
61479cd5fb | ||
|
|
aaa322464d | ||
|
|
02bfbd5019 | ||
|
|
282f8b4e02 | ||
|
|
3393bde820 | ||
|
|
2277c87908 | ||
|
|
2ea0c48853 | ||
|
|
28cbefde04 | ||
|
|
4e13843c78 | ||
|
|
a929f8429d | ||
|
|
40f3f06ed3 | ||
|
|
0a79c4c717 | ||
|
|
712d789992 | ||
|
|
8de8b1a32e | ||
|
|
c2f565c73a | ||
|
|
1df036a811 | ||
|
|
9910a4fc7b | ||
|
|
9933afc8b7 | ||
|
|
1d89d4b0bc | ||
|
|
a8a84d58d9 | ||
|
|
80fee524a8 | ||
|
|
4ca2ee52b7 | ||
|
|
6638be81a0 | ||
|
|
6ced0e5e43 | ||
|
|
e36518dbe5 | ||
|
|
70d8bb60e7 | ||
|
|
3c919f6b23 | ||
|
|
0cb566d2f3 | ||
|
|
e137b6baaa | ||
|
|
58faeea838 | ||
|
|
47200e9f35 | ||
|
|
5ad8cc668f | ||
|
|
e7704171f7 | ||
|
|
c43718652a | ||
|
|
461a12e909 | ||
|
|
afb682e3eb | ||
|
|
31384fbce5 | ||
|
|
c7cfd7a8a0 | ||
|
|
717e50fd5c | ||
|
|
2ffc7d19f1 | ||
|
|
d857021df5 | ||
|
|
2ee864ccaf | ||
|
|
018dfed128 | ||
|
|
90e4545210 | ||
|
|
4a4b16b010 | ||
|
|
8701303012 | ||
|
|
9788aefcc1 | ||
|
|
ed08ef1604 | ||
|
|
adce70a5e5 | ||
|
|
d5978f64e1 | ||
|
|
45215debcc | ||
|
|
919eef55a1 | ||
|
|
8c529eed46 | ||
|
|
7909c2cd46 | ||
|
|
b1ac396bf1 | ||
|
|
d5eb4a1900 | ||
|
|
b8eb27441c | ||
|
|
de1494710a | ||
|
|
e3b05ac77f | ||
|
|
32c8e9482c | ||
|
|
4d3c86dba1 | ||
|
|
28449c348e | ||
|
|
bb9cf7b93c | ||
|
|
eb861083ad | ||
|
|
b133505086 | ||
|
|
0f0cae713a | ||
|
|
56cfce86e4 | ||
|
|
e950322232 | ||
|
|
14de21ee64 | ||
|
|
22712eae96 | ||
|
|
86d1033324 | ||
|
|
b4c4dc2c2e | ||
|
|
671f0142bc | ||
|
|
ab4bdc7be6 | ||
|
|
0859e60b23 | ||
|
|
e69c2d8b0c | ||
|
|
186e058f3d | ||
|
|
ed5af59040 | ||
|
|
0da312f755 | ||
|
|
dc646d9a45 | ||
|
|
109e01bb60 | ||
|
|
657fad06fb | ||
|
|
3e014c876d | ||
|
|
d14dd51359 | ||
|
|
70f876c445 | ||
|
|
9d8d51d88d | ||
|
|
57037f20cc | ||
|
|
4f2f509819 | ||
|
|
474fd77970 | ||
|
|
d2fad719fa | ||
|
|
6a3955a1d6 | ||
|
|
dceb33006a | ||
|
|
a096a43c56 | ||
|
|
8114a33d20 | ||
|
|
9f3adddd41 | ||
|
|
05f74ab654 | ||
|
|
0317118cd9 | ||
|
|
461de8d269 | ||
|
|
b258e92620 | ||
|
|
f6148ef1fb | ||
|
|
457da594be | ||
|
|
891a43ae67 | ||
|
|
bc65c0a786 | ||
|
|
3eeb1f77aa | ||
|
|
91be6826b9 | ||
|
|
f87eee3b9f | ||
|
|
b4e17691c4 | ||
|
|
cce372aeba | ||
|
|
b5a8a9e08a | ||
|
|
35632da284 | ||
|
|
02a9b0d16c | ||
|
|
d1809e0f7d | ||
|
|
abb4a7c0f9 | ||
|
|
cd6fa8b15c | ||
|
|
ecfcada802 | ||
|
|
f8ec5ae253 | ||
|
|
832ba5c8fb | ||
|
|
6fda0d6896 | ||
|
|
a8edaf4dfa | ||
|
|
e11b7802c2 | ||
|
|
aa0c5972fb | ||
|
|
fa8e91cdcd | ||
|
|
e5d902663b | ||
|
|
042535536e | ||
|
|
6d3063437c | ||
|
|
3db4d04e4c | ||
|
|
96f9eab5cd | ||
|
|
1e641b83c1 | ||
|
|
3791d92d67 | ||
|
|
2bcab76f5a | ||
|
|
f5493c542b | ||
|
|
68eb4198f1 | ||
|
|
ef94607728 | ||
|
|
4ccadbd2be | ||
|
|
0643063b80 | ||
|
|
d6c6ab932a | ||
|
|
46004d2db8 | ||
|
|
620d1d4092 | ||
|
|
f30afac47e | ||
|
|
1779e34773 | ||
|
|
28f535f41c | ||
|
|
e921f58d2f | ||
|
|
301f6cc273 | ||
|
|
f04e497999 | ||
|
|
8db438d76b | ||
|
|
af75e607ec | ||
|
|
cd4b9527c3 | ||
|
|
ea8dc446ae | ||
|
|
ba6270990b | ||
|
|
df55f1066c | ||
|
|
b562d661db | ||
|
|
aede78a0ec | ||
|
|
7e8c3fbab7 | ||
|
|
6621601155 | ||
|
|
1fbd585a46 | ||
|
|
5a51c14de5 | ||
|
|
27a4c81c6d | ||
|
|
fdc25dc0d7 | ||
|
|
99522fb49a | ||
|
|
671d273e2f | ||
|
|
2851a33eb2 | ||
|
|
937e3fac19 | ||
|
|
47cb00857c | ||
|
|
7904e05b4a | ||
|
|
c4fe19f2e6 | ||
|
|
9db57f0517 | ||
|
|
64afebecd4 | ||
|
|
4c324960e6 | ||
|
|
164b90a22f | ||
|
|
dc735a8aa2 | ||
|
|
f516b0931f | ||
|
|
2297121eff | ||
|
|
0c2684d1cf | ||
|
|
4b4c5dba73 | ||
|
|
7b9d70e093 | ||
|
|
71a289b009 | ||
|
|
ddf98ff593 | ||
|
|
db8043ecb6 | ||
|
|
ea756cf0a4 | ||
|
|
8446a6d813 | ||
|
|
a18aaeacf7 | ||
|
|
58a43b3785 | ||
|
|
dd06f12582 | ||
|
|
d7dcc01c9f | ||
|
|
66f56740b7 | ||
|
|
5bd042d9bc | ||
|
|
02466ea0bd | ||
|
|
59f22ab17e | ||
|
|
2db9343e0f | ||
|
|
36b3a53ab2 | ||
|
|
dc8c42a820 | ||
|
|
2bd5d0bd8e | ||
|
|
c9ac5ae963 | ||
|
|
49487419d2 | ||
|
|
508fe69cf8 | ||
|
|
3e4a8f230f | ||
|
|
a62230c195 | ||
|
|
1173fb1e90 | ||
|
|
529648a30c | ||
|
|
82b6b9ccb2 | ||
|
|
71244a4eb8 | ||
|
|
32fd424295 | ||
|
|
5746042d68 | ||
|
|
e76fb235aa | ||
|
|
47e13312b1 | ||
|
|
55e05afe0e | ||
|
|
aebce2f241 | ||
|
|
aa3207fca5 | ||
|
|
ce8df34b49 | ||
|
|
8aa8c5d8ae | ||
|
|
e7628bdbdd | ||
|
|
b9dd4a35db | ||
|
|
040b2e8a53 | ||
|
|
af25254628 | ||
|
|
0c673a54cd | ||
|
|
9f1f36774d | ||
|
|
6ec697b010 | ||
|
|
f344c58f26 | ||
|
|
263b0fa455 | ||
|
|
a634c8f2d1 | ||
|
|
336faa46b2 | ||
|
|
52a167c647 |
2
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
./packages/core/lego
|
||||
# IntelliJ project files
|
||||
.vscode/
|
||||
node_modules/
|
||||
@@ -32,3 +33,4 @@ gen
|
||||
/pnpm-lock.yaml
|
||||
|
||||
docker/image/workspace
|
||||
/packages/core/lego
|
||||
|
||||
166
CHANGELOG.md
@@ -3,6 +3,172 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.20.16](https://github.com/certd/certd/compare/v1.20.15...v1.20.16) (2024-07-01)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复配置了cdn cname后申请失败的bug ([4a5fa76](https://github.com/certd/certd/commit/4a5fa767edc347d03d29a467e86c9a4d70b0220c))
|
||||
|
||||
## [1.20.15](https://github.com/certd/certd/compare/v1.20.14...v1.20.15) (2024-06-28)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复无法强制取消任务的bug ([9cc01db](https://github.com/certd/certd/commit/9cc01db1d569a5c45bb3e731f35d85df324a8e62))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 腾讯云dns provider 支持腾讯云的accessId ([e0eb3a4](https://github.com/certd/certd/commit/e0eb3a441384d474fe2923c69b25318264bdc9df))
|
||||
* 支持windows文件上传 ([7f61cab](https://github.com/certd/certd/commit/7f61cab101fa13b4e88234e9ad47434e6130fed2))
|
||||
|
||||
## [1.20.14](https://github.com/certd/certd/compare/v1.20.13...v1.20.14) (2024-06-23)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复修改密码功能异常问题 ([f740ff5](https://github.com/certd/certd/commit/f740ff517f521dce361284c2c54bccc68aee0ea2))
|
||||
|
||||
## [1.20.13](https://github.com/certd/certd/compare/v1.20.12...v1.20.13) (2024-06-18)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 日志高度越界 ([c4c9adb](https://github.com/certd/certd/commit/c4c9adb8bfd513f57252e523794e3799a9b220f8))
|
||||
* 修复邮箱设置页面SMTP拼写错误的问题 ([b98f1c0](https://github.com/certd/certd/commit/b98f1c0dd0bc6c6b4f814c578692afdf6d90b88d))
|
||||
* 修复logo问题 ([7e483e6](https://github.com/certd/certd/commit/7e483e60913d509b113148c735fe13ba1d72dddf))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 增加警告,修复一些样式错乱问题 ([fd54c2f](https://github.com/certd/certd/commit/fd54c2ffac492222e85ff2f5f49a9ee5cfc73588))
|
||||
* ssh登录支持openssh格式私钥、支持私钥密码 ([5c2c508](https://github.com/certd/certd/commit/5c2c50839a9076004f9034d754ac6deb531acdfb))
|
||||
|
||||
## [1.20.12](https://github.com/certd/certd/compare/v1.20.10...v1.20.12) (2024-06-17)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复aliyun域名超过100个找不到域名的bug ([5b1494b](https://github.com/certd/certd/commit/5b1494b3ce93d1026dc56ee741342fbb8bf7be24))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 增加系统设置,可以关闭自助注册功能 ([20feace](https://github.com/certd/certd/commit/20feacea12d43386540db6a600f391d786be4014))
|
||||
* 增加cloudflare access token说明 ([934e6e2](https://github.com/certd/certd/commit/934e6e2bd05387cd50ffab95f230933543954098))
|
||||
* 支持重置管理员密码,忘记密码的补救方案 ([732cbc5](https://github.com/certd/certd/commit/732cbc5e927b526850724594830392b2f10c6705))
|
||||
* 支持cloudflare域名 ([fbb9a47](https://github.com/certd/certd/commit/fbb9a47e8f7bb805289b9ee64bd46ffee0f01c06))
|
||||
|
||||
## [1.20.10](https://github.com/certd/certd/compare/v1.20.9...v1.20.10) (2024-05-30)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 增加权限相关helper说明 ([83e4083](https://github.com/certd/certd/commit/83e40836ebff10bec60efe8933183e1ba1c22bf9))
|
||||
* 增加权限相关helper说明 ([4304c94](https://github.com/certd/certd/commit/4304c9443ad9248f63dd6d8c512d8d6f32f90d37))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 上传到主机插件支持复制到本机路径 ([92446c3](https://github.com/certd/certd/commit/92446c339936f98f08f654b8971a7393d8435224))
|
||||
* 优化文件下载包名 ([d9eb927](https://github.com/certd/certd/commit/d9eb927b0a1445feab08b1958aa9ea80637a5ae6))
|
||||
* 增加任务复制功能 ([39ad759](https://github.com/certd/certd/commit/39ad7597fa0e19cc1f7631bbd6fea0a9e05a62c9))
|
||||
|
||||
## [1.20.9](https://github.com/certd/certd/compare/v1.20.8...v1.20.9) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.20.8](https://github.com/certd/certd/compare/v1.20.7...v1.20.8) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.20.7](https://github.com/certd/certd/compare/v1.20.6...v1.20.7) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.20.6](https://github.com/certd/certd/compare/v1.20.5...v1.20.6) (2024-03-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 调整按钮图标到居中位置 ([836d18f](https://github.com/certd/certd/commit/836d18f07e22d00faf2f213bc3301a6672b5bafc))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 插件贡献文档及示例 ([72fb20a](https://github.com/certd/certd/commit/72fb20abf3ba5bdd862575d2907703a52fd7eb17))
|
||||
|
||||
## [1.20.5](https://github.com/certd/certd/compare/v1.20.2...v1.20.5) (2024-03-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复腾讯云cdn部署无法选择端点的bug ([154409b](https://github.com/certd/certd/commit/154409b1dfee3ea1caae740ad9c1f99a6e7a9814))
|
||||
|
||||
## [1.20.2](https://github.com/certd/certd/compare/v1.2.1...v1.20.2) (2024-02-28)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 临时修复阿里云domainlist接口返回域名列表不全的问题,后续还需要增加翻页查询 ([849c145](https://github.com/certd/certd/commit/849c145926984762bd9dbec87bd91cd047fc0855))
|
||||
|
||||
## [1.2.1](https://github.com/certd/certd/compare/v1.2.0...v1.2.1) (2023-12-12)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复邮箱设置无效的bug ([aaa3224](https://github.com/certd/certd/commit/aaa322464d0f65e924d1850995540d396ee24d25))
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
# [1.2.0](https://github.com/certd/certd/compare/v1.1.6...v1.2.0) (2023-10-27)
|
||||
|
||||
* 🔱: [client] sync upgrade with 2 commits [trident-sync] ([aa3207f](https://github.com/certd/certd/commit/aa3207fca5f15f7c3da789989d99c8ae7d1c4551))
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* search支持自定义布局,search.layout、search.collapse转移到 search.container之下。如果想使用原来的search组件,请配置search.is=fs-search-v1
|
||||
|
||||
## [1.1.6](https://github.com/certd/certd/compare/v1.1.5...v1.1.6) (2023-07-10)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复上传证书到腾讯云失败的bug ([e950322](https://github.com/certd/certd/commit/e950322232e19d1263b8552eefa5b0150fd7864e))
|
||||
|
||||
## [1.1.5](https://github.com/certd/certd/compare/v1.1.4...v1.1.5) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.1.4](https://github.com/certd/certd/compare/v1.1.3...v1.1.4) (2023-07-03)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 成功图标转动的问题 ([f87eee3](https://github.com/certd/certd/commit/f87eee3b9ff1ef9874e79a81fe0ed7104cb9ee8c))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* cancel task ([bc65c0a](https://github.com/certd/certd/commit/bc65c0a786360c087fe95cad93ec6a87804cc5ee))
|
||||
* flush log ([891a43a](https://github.com/certd/certd/commit/891a43ae6716ff98ed06643f7da2e35199ee195c))
|
||||
* flush logger ([91be682](https://github.com/certd/certd/commit/91be6826b902e0f302b1a6cbdb1d24e15914c18d))
|
||||
* timeout ([3eeb1f7](https://github.com/certd/certd/commit/3eeb1f77aa2922f3545f3d2067f561d95621d54f))
|
||||
|
||||
## [1.1.3](https://github.com/certd/certd/compare/v1.1.2...v1.1.3) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.1.2](https://github.com/certd/certd/compare/v1.1.1...v1.1.2) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.1.1](https://github.com/certd/certd/compare/v1.1.0...v1.1.1) (2023-06-28)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
# [1.1.0](https://github.com/certd/certd/compare/v1.0.6...v1.1.0) (2023-06-28)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复access选择类型trigger ([2851a33](https://github.com/certd/certd/commit/2851a33eb2510f038fadb55da29512597a4ba512))
|
||||
|
||||
### Features
|
||||
|
||||
* 权限控制 ([27a4c81](https://github.com/certd/certd/commit/27a4c81c6d70e70abb3892c3ea58d4719988808a))
|
||||
* 邮件通知 ([937e3fa](https://github.com/certd/certd/commit/937e3fac19cd03b8aa91db8ba03fda7fcfbacea2))
|
||||
* cert download ([5a51c14](https://github.com/certd/certd/commit/5a51c14de521cb8075a80d2ae41a16e6d5281259))
|
||||
* config merge ([fdc25dc](https://github.com/certd/certd/commit/fdc25dc0d795555cffacc4572648ec158988fbbb))
|
||||
* save files ([99522fb](https://github.com/certd/certd/commit/99522fb49adb42c1dfdf7bec3dd52d641158285b))
|
||||
* save files ([671d273](https://github.com/certd/certd/commit/671d273e2f9136d16896536b0ca127cf372f1619))
|
||||
|
||||
## [1.0.6](https://github.com/certd/certd/compare/v1.0.5...v1.0.6) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
## [1.0.5](https://github.com/certd/certd/compare/v1.0.4...v1.0.5) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
265
README.md
@@ -1,139 +1,174 @@
|
||||
# CertD
|
||||
|
||||
CertD 是一个帮助你全自动申请和部署SSL证书的工具。
|
||||
CertD 是一个免费全自动申请和部署SSL证书的工具。
|
||||
后缀D取自linux守护进程的命名风格,意为证书守护进程。
|
||||
|
||||
## 特性
|
||||
## 一、特性
|
||||
本项目不仅支持证书申请过程自动化,还可以自动化部署证书,让你的证书永不过期。
|
||||
|
||||
* 全自动申请证书
|
||||
* 全自动部署证书(目前支持服务器上传部署、阿里云、腾讯云等)
|
||||
* 可与CI/DI工具结合使用
|
||||
* 全自动申请证书(支持阿里云、腾讯云、华为云、Cloudflare注册的域名)
|
||||
* 全自动部署证书(目前支持服务器上传部署、部署到阿里云、腾讯云等)
|
||||
* 支持通配符域名
|
||||
* 支持多个域名打到一个证书上
|
||||
* 邮件通知
|
||||
* 证书自动更新
|
||||
* 免费、免费、免费([阿里云单个通配符域名证书最便宜也要1800/年](https://yundun.console.aliyun.com/?p=cas#/certExtend/buy/cn-hangzhou))
|
||||
|
||||
## 免费证书申请说明
|
||||
|
||||
|
||||
## 二、在线体验
|
||||
|
||||
官方Demo地址,自助注册后体验
|
||||
|
||||
https://certd.handsfree.work/
|
||||
|
||||
> 注意数据将不定期清理,生产使用请自行部署
|
||||
> 包含敏感信息,务必自己本地部署进行生产使用
|
||||
|
||||
## 三、使用教程
|
||||
本案例演示,如何配置自动申请证书,并部署到阿里云CDN,然后快要到期前自动更新证书并重新部署
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
|
||||
-------> [点我查看详细使用步骤演示](./step.md) <--------
|
||||
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
|
||||
|
||||
## 四、本地docker部署
|
||||
|
||||
### 1. 安装docker、docker-compose
|
||||
|
||||
1.1 准备一台云服务器
|
||||
* 【阿里云】云服务器2核2G,新老用户同享,99元/年,续费同价!【 [立即购买](https://www.aliyun.com/benefit?scm=20140722.M_10244282._.V_1&source=5176.11533457&userCode=qya11txb )】
|
||||
* 【腾讯云】云服务器2核2G,新老用户同享,99元/年,续费同价!【 [立即购买](https://cloud.tencent.com/act/cps/redirect?redirect=6094&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9&from=console)】
|
||||
|
||||
|
||||
1.2 安装docker
|
||||
https://docs.docker.com/engine/install/
|
||||
选择对应的操作系统,按照官方文档执行命令即可
|
||||
|
||||
|
||||
### 2. 下载docker-compose.yaml文件
|
||||
|
||||
[docker-compose.yaml下载](https://gitee.com/certd/certd/raw/v2/docker/run/docker-compose.yaml)
|
||||
|
||||
```bash
|
||||
mkdir certd
|
||||
cd certd
|
||||
# wget下载docker-compose.yaml文件
|
||||
wget https://raw.githubusercontent.com/certd/certd/v2/docker/run/docker-compose.yaml
|
||||
# 或者使用gitee地址
|
||||
wget https://gitee.com/certd/certd/raw/v2/docker/run/docker-compose.yaml
|
||||
|
||||
# 根据需要修改里面的配置
|
||||
# 1.修改镜像版本号【可选】
|
||||
# 2.配置数据保存路径【可选】
|
||||
# 3.配置certd_auth_jwt_secret【必须】
|
||||
vi docker-compose.yaml
|
||||
|
||||
|
||||
```
|
||||
> 镜像版本号与release版本号同步:
|
||||
https://github.com/certd/certd/releases
|
||||
|
||||
|
||||
### 3. 运行
|
||||
```bash
|
||||
# 如果docker compose是插件化安装
|
||||
export CERTD_VERSION=latest
|
||||
docker compose up -d
|
||||
```
|
||||
如果提示 没有compose命令,请安装docker-compose
|
||||
https://docs.docker.com/compose/install/linux/
|
||||
|
||||
|
||||
|
||||
### 4. 访问
|
||||
|
||||
http://your_server_ip:7001
|
||||
默认账号密码:admin/123456
|
||||
记得修改密码
|
||||
|
||||
|
||||
### 5. 升级
|
||||
|
||||
* 修改版本号,重新运行 `docker compose up -d` 即可
|
||||
* 数据存在`/data/certd`目录下,不用担心数据丢失
|
||||
|
||||
|
||||
|
||||
## 五、一些说明
|
||||
* 本项目ssl证书提供商为letencrypt
|
||||
* 申请过程遵循acme协议
|
||||
* 需要验证域名所有权,一般有两种方式(目前本项目仅支持dns-01)
|
||||
* http-01: 在网站根目录下放置一份txt文件
|
||||
* dns-01: 需要给域名添加txt解析记录,泛域名只能用这种方式
|
||||
* 需要验证域名所有权,一般有两种方式(目前本项目仅支持dns-01)
|
||||
* http-01: 在网站根目录下放置一份txt文件
|
||||
* dns-01: 需要给域名添加txt解析记录,通配符域名只能用这种方式
|
||||
* 证书续期:
|
||||
* 实际上acme并没有续期概念。
|
||||
* 我们所说的续期,其实就是按照全套流程重新申请一份新证书。
|
||||
* 免费证书过期时间90天,以后可能还会缩短,所以自动化部署必不可少
|
||||
* 设置每天自动运行,当证书过期前20天,会自动重新申请证书并部署
|
||||
|
||||
## 六、不同平台的设置说明
|
||||
|
||||
* [Cloudflare](./doc/cf/cf.md)
|
||||
* [腾讯云](./doc/tencent/tencent.md)
|
||||
* [windows主机](./doc/host/host.md)
|
||||
|
||||
|
||||
|
||||
## 快速开始
|
||||
本案例演示,如何配置自动申请证书,并部署到阿里云CDN,然后快要到期前自动更新证书并重新部署
|
||||
|
||||
|
||||
1. 环境准备
|
||||
安装[nodejs](https://nodejs.org/zh-cn/)
|
||||
|
||||
|
||||
2. 生成node项目
|
||||
|
||||
通过ui生成: https://certd.docmirror.cn/
|
||||
|
||||
开始生成证书,先填写域名,支持将多个域名打到一个证书上
|
||||

|
||||
|
||||
配置证书详细信息
|
||||

|
||||
|
||||
配置证书部署流程
|
||||

|
||||
|
||||
配置好之后,点击导出按钮,导出一个node项目包
|
||||
|
||||
4. 运行
|
||||
将导出的压缩包解压,然后执行如下命令,即可开始申请证书并部署
|
||||
## 七、问题处理
|
||||
### 7.1 忘记管理员密码
|
||||
解决方法如下:
|
||||
1. 修改docker-compose.yaml文件,将环境变量`certd_system_resetAdminPassword`改为`true`
|
||||
```yaml
|
||||
services:
|
||||
certd:
|
||||
environment: # 环境变量
|
||||
- certd_system_resetAdminPassword=false
|
||||
```
|
||||
npm install
|
||||
npm run certd
|
||||
2. 重启容器
|
||||
```shell
|
||||
docker compose up -d
|
||||
docker logs -f --tail 500 certd
|
||||
# 观察日志,当日志中输出“重置1号管理员用户的密码完成”,即可操作下一步
|
||||
```
|
||||
5. 执行效果
|
||||
生成的证书默认会存储在 `${home}/.certd/${email}/certs/${domain}/current`目录下
|
||||
3. 修改docker-compose.yaml,将`certd_system_resetAdminPassword`改回`false`
|
||||
4. 再次重启容器
|
||||
```shell
|
||||
docker compose up -d
|
||||
```
|
||||
[2021-01-08T16:15:04.681] [INFO] certd - 任务完成
|
||||
[2021-01-08T16:15:04.681] [INFO] certd - ---------------------------任务结果总览--------------------------
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - 【更新证书】--------------------------------------- [success]
|
||||
证书申请成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - 【流程1-部署到阿里云CDN】---------------------------- [success] 执行成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - └【上传到阿里云】-------------------------------- [success] 执行成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - └【部署证书到CDN】------------------------------- [success] 执行成功
|
||||
```
|
||||
6. 证书续期
|
||||
实际上没有证书续期的概念,只有重新生成一份新的证书,然后重新部署证书
|
||||
所以每天定时运行即可,当证书过期日前20天时,会重新申请新的证书,然后执行部署任务。
|
||||
5. 使用admin/123456登录系统,请及时修改管理员密码
|
||||
|
||||
7. 其他说明
|
||||
证书的部署任务执行后会记录执行结果,已经成功过的不会重复执行
|
||||
所以当你临时需要将证书部署到其他地方时,直接追加部署任务,然后再次运行即可
|
||||
|
||||
## CI/DI集成与自动续期重新部署
|
||||
集成前,将以上导出的node项目提交到内网git仓库,或者私有git仓库(由于包含敏感信息,不要提交到公开git仓库)
|
||||
|
||||
### jenkins任务
|
||||
1. 创建任务
|
||||
选择构建自由风格的任务
|
||||
|
||||
2. 配置git
|
||||
配置cert-run的git地址
|
||||
|
||||
3. 构建触发器
|
||||
配置 `H 3 * * *` ,每天凌晨3点-4点执行一次
|
||||
|
||||
4. 构建环境
|
||||
勾选 `Provide Node & npm bin/ folder to PATH`,提供nodejs运行环境
|
||||
如果没有此选项,需要jenkins安装`nodejs`插件
|
||||
|
||||
5. 构建
|
||||
执行shell
|
||||
```
|
||||
npm install --production #执行过一次之后,就可以注释掉,加快执行速度
|
||||
npm run post
|
||||
```
|
||||
6. 构建后操作
|
||||
邮件通知
|
||||
配置你的邮箱地址,可以在执行失败时收到邮件通知。
|
||||
## 八、联系作者
|
||||
如有疑问,欢迎加入群聊(请备注certd)
|
||||
* QQ群:141236433
|
||||
* 微信群:
|
||||

|
||||
|
||||
|
||||
## API
|
||||
先列个提纲,待完善
|
||||
加作者好友
|
||||
<p align="center">
|
||||
<img height="230" src="./doc/images/me.png">
|
||||
</p>
|
||||
|
||||
参数示例参考:https://gitee.com/certd/certd/blob/master/test/options.js
|
||||
|
||||
### 授权提供者
|
||||
用于dns验证接口调用
|
||||
#### aliyun
|
||||
|
||||
#### dnspod
|
||||
|
||||
### deploy插件
|
||||
部署任务插件
|
||||
#### 阿里云
|
||||
##### 上传到阿里云
|
||||
type = uploadCertToAliyun
|
||||
##### 部署到阿里云DNS
|
||||
type = deployCertToAliyunCDN
|
||||
|
||||
##### 部署到阿里云CLB
|
||||
type = deployCertToAliyunCLB
|
||||
|
||||
#### 腾讯云
|
||||
##### 上传到腾讯云
|
||||
type = uploadCertToTencent
|
||||
|
||||
##### 部署到腾讯云DNS
|
||||
type = deployCertToTencentDNS
|
||||
|
||||
##### 部署到腾讯云CLB
|
||||
type = deployCertToTencentCLB
|
||||
|
||||
##### 部署到腾讯云TKE-ingress
|
||||
type = deployCertToTencentTKEIngress
|
||||
## 九、捐赠
|
||||
媳妇儿说:“一天到晚搞开源,也不管管老婆孩子!😡😡😡”
|
||||
拜托各位捐赠支持一下,让媳妇儿开心开心,我也能有更多时间进行开源项目,感谢🙏🙏🙏
|
||||
<p align="center">
|
||||
<img height="380" src="./doc/images/donate.png">
|
||||
</p>
|
||||
|
||||
|
||||
### 更多部署插件
|
||||
等你来提需求
|
||||
## 十、贡献代码
|
||||
|
||||
[贡献插件教程](./plugin.md)
|
||||
|
||||
|
||||
## 十一、我的其他项目
|
||||
* [袖手GPT](https://ai.handsfree.work/) ChatGPT,国内可用,无需FQ,每日免费额度
|
||||
* [fast-crud](https://gitee.com/fast-crud/fast-crud/) 基于vue3的crud快速开发框架
|
||||
* [dev-sidecar](https://github.com/docmirror/dev-sidecar/) 直连访问github工具,无需FQ,解决github无法访问的问题
|
||||
|
||||
106
deploy.js
@@ -1,70 +1,96 @@
|
||||
const http = require("axios")
|
||||
const exec = require('child_process').exec;
|
||||
import http from 'axios'
|
||||
import fs from 'fs'
|
||||
|
||||
//builder
|
||||
function execute(cmd){
|
||||
return new Promise((resolve,reject)=>{
|
||||
console.log("cmd executing: " + cmd)
|
||||
exec(cmd, function(error, stdout, stderr) {
|
||||
if(error){
|
||||
console.error(error);
|
||||
console.info(stderr)
|
||||
reject(error)
|
||||
}
|
||||
else{
|
||||
console.info(stdout)
|
||||
console.log("success");
|
||||
resolve(true)
|
||||
//读取 packages/core/pipline/package.json的版本号
|
||||
import {default as packageJson} from './packages/core/pipeline/package.json' assert { type: "json" };
|
||||
|
||||
const certdVersion = packageJson.version
|
||||
console.log("certdVersion", certdVersion)
|
||||
|
||||
// 同步npmmirror的包
|
||||
async function getPackages(directoryPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 读取目录下的文件和目录列表
|
||||
fs.readdir(directoryPath, {withFileTypes: true}, (err, files) => {
|
||||
if (err) {
|
||||
console.log('无法读取目录:', err);
|
||||
reject(err)
|
||||
return;
|
||||
}
|
||||
|
||||
// 过滤仅保留目录
|
||||
const directories = files
|
||||
.filter(file => file.isDirectory())
|
||||
.map(directory => directory.name);
|
||||
|
||||
console.log('目录列表:', directories);
|
||||
resolve(directories)
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function build(){
|
||||
await execute("cd ./packages/fast-admin/fs-admin-antdv/ && npm run build")
|
||||
await execute("cd ./packages/fast-admin/fs-admin-element/ && npm run build")
|
||||
await execute("cd ./packages/fast-admin/fs-admin-naive-ui/ && npm run build")
|
||||
await execute("npm run docs:build")
|
||||
async function getAllPackages() {
|
||||
const base = await getPackages("./packages/core")
|
||||
const plugins = await getPackages("./packages/plugins")
|
||||
|
||||
return base.concat(plugins)
|
||||
}
|
||||
|
||||
async function sync() {
|
||||
const packages = await getAllPackages()
|
||||
for (const pkg of packages) {
|
||||
await http({
|
||||
url: `http://registry-direct.npmmirror.com/@certd/${pkg}/sync?sync_upstream=true`,
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: {}
|
||||
})
|
||||
console.log(`sync success:${pkg}`)
|
||||
await sleep(100*1000)
|
||||
}
|
||||
}
|
||||
|
||||
// curl -X PUT https://registry-direct.npmmirror.com/@certd/plugin-cert/sync?sync_upstream=true
|
||||
|
||||
// trigger
|
||||
const certdImageBuild = "http://flow-openapi.aliyun.com/pipeline/webhook/4zgFk3i4RZEMGuQzlOcI"
|
||||
const certdImageRun = "http://flow-openapi.aliyun.com/pipeline/webhook/lzCzlGrLCOHQaTMMt0mG"
|
||||
const webhooks = [certdImageBuild,certdImageRun]
|
||||
|
||||
const naive = "http://flow-openapi.aliyun.com/pipeline/webhook/Zm3TJyDtyFZgV4dtJiD1"
|
||||
const doc = "http://flow-openapi.aliyun.com/pipeline/webhook/soOYdQ5sF3kLjTPJGmIO"
|
||||
const antdv = "http://flow-openapi.aliyun.com/pipeline/webhook/HiL0uVYxfUnBzIMJZVXB"
|
||||
const element = "http://flow-openapi.aliyun.com/pipeline/webhook/uFTI0XJ9RgqnofX7jpRD"
|
||||
|
||||
const webhooks = [doc,naive,antdv,element]
|
||||
|
||||
async function sleep(time){
|
||||
async function sleep(time) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve,time)
|
||||
setTimeout(resolve, time)
|
||||
})
|
||||
}
|
||||
|
||||
async function trigger(){
|
||||
async function triggerBuild() {
|
||||
await sleep(60000)
|
||||
for (const webhook of webhooks) {
|
||||
await http({
|
||||
url:webhook,
|
||||
method:'POST',
|
||||
headers:{
|
||||
url: webhook,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data:{}
|
||||
data: {
|
||||
'CERTD_VERSION': certdVersion
|
||||
}
|
||||
})
|
||||
console.log(`webhook success:${webhook}`)
|
||||
await sleep(1000)
|
||||
await sleep(10*60*1000)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function start(){
|
||||
async function start() {
|
||||
// await build()
|
||||
console.log("等待60秒")
|
||||
await sleep(60*1000)
|
||||
await trigger()
|
||||
await sleep(200 * 1000)
|
||||
await sync()
|
||||
await sleep(60 * 1000)
|
||||
await triggerBuild()
|
||||
}
|
||||
|
||||
start()
|
||||
|
||||
15
doc/cf/cf.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Cloudflare
|
||||
|
||||
|
||||
## CF Token申请
|
||||
|
||||
### 申请地址:
|
||||
https://dash.cloudflare.com/profile/api-tokens
|
||||
|
||||
### 权限设置:
|
||||
需要设置权限和资源范围
|
||||
权限包括:Zone.Zone.edit, Zone.DNS.edit
|
||||
资源范围:要包含对应域名,推荐直接设置为All Zones
|
||||
最终效果如下,可以切换语言为英文对比如下图检查
|
||||
|
||||

|
||||
BIN
doc/cf/cf_token.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
24
doc/host/host.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# 远程主机
|
||||
|
||||
远程主机基于ssh协议,通过ssh连接远程主机,执行命令。
|
||||
|
||||
## windows开启OpenSSH Server
|
||||
1. 安装OpenSSH Server
|
||||
请前往Microsoft官方文档查看如何开启openSSH
|
||||
https://learn.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui#install-openssh-for-windows
|
||||
|
||||
2. 启动OpenSSH Server服务
|
||||
```
|
||||
win+R 弹出运行对话框,输入 services.msc 打开服务管理器
|
||||
找到 OpenSSH SSH Server
|
||||
启动ssh server服务,并且设置为自动启动
|
||||
```
|
||||
|
||||
3. 测试ssh登录
|
||||
使用你常用的ssh客户端,连接你的windows主机,进行测试
|
||||
|
||||
```cmd
|
||||
# 如何确定你用户名
|
||||
C:\Users\xiaoj>
|
||||
↑↑↑↑---------这个就是windows ssh的登录用户名
|
||||
```
|
||||
BIN
doc/images/1-add.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
doc/images/10-1-log.png
Normal file
|
After Width: | Height: | Size: 124 KiB |
BIN
doc/images/11-1-error.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
doc/images/11-2-error.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
doc/images/12-1-log-success.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
doc/images/12-2-skip-log.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
doc/images/13-1-result.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
doc/images/13-2-result.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
doc/images/13-3-download.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
doc/images/14-timer.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
doc/images/15-1-email.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
doc/images/15-2-email.png
Normal file
|
After Width: | Height: | Size: 145 KiB |
BIN
doc/images/2-access-provider.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
doc/images/3-add-access.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
doc/images/4-add-success.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
doc/images/5-view.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
doc/images/6-1-add-task.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
doc/images/6-2-add-task.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
doc/images/6-3-add-task.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
doc/images/7-1-add-host-task.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
doc/images/7-2-add-host-task.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
doc/images/7-3-add-host-task.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
doc/images/8-1-add-host-task.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
doc/images/8-2-add-host-task.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
doc/images/8-4-add-host-task.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
doc/images/8-5-add-host-task.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
doc/images/9-start.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
doc/images/donate.png
Normal file
|
After Width: | Height: | Size: 169 KiB |
BIN
doc/images/me.png
Normal file
|
After Width: | Height: | Size: 374 KiB |
BIN
doc/step1.png
|
Before Width: | Height: | Size: 12 KiB |
BIN
doc/step2.png
|
Before Width: | Height: | Size: 44 KiB |
BIN
doc/step3.png
|
Before Width: | Height: | Size: 92 KiB |
BIN
doc/tasks.png
|
Before Width: | Height: | Size: 18 KiB |
BIN
doc/tencent/dnspod-token.png
Normal file
|
After Width: | Height: | Size: 149 KiB |
BIN
doc/tencent/tencent-access.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
16
doc/tencent/tencent.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# 腾讯云
|
||||
|
||||
|
||||
## DNSPOD 授权设置
|
||||
目前腾讯云管理的域名的dns暂时只支持从DNSPOD进行设置
|
||||
打开 https://console.dnspod.cn/account/token/apikey
|
||||
然后按如下方式获取DNSPOD的授权
|
||||

|
||||
|
||||
|
||||
## 腾讯云API密钥设置
|
||||
|
||||
腾讯云其他部署需要API密钥,需要在腾讯云控制台进行设置
|
||||
打开 https://console.cloud.tencent.com/cam/capi
|
||||
然后按如下方式获取腾讯云的API密钥
|
||||

|
||||
@@ -1,9 +1,20 @@
|
||||
FROM registry.cn-shenzhen.aliyuncs.com/handsfree/node:16-alpine
|
||||
RUN npm install -g pnpm && npm install -g cross-env
|
||||
ADD ./workspace/certd-server/ /app/
|
||||
FROM registry.cn-shenzhen.aliyuncs.com/handsfree/node:18-alpine
|
||||
EXPOSE 7001
|
||||
ENV NODE_ENV production
|
||||
ENV MIDWAY_SERVER_ENV production
|
||||
WORKDIR /app/
|
||||
RUN pnpm install -P
|
||||
CMD ["npm","run","start"]
|
||||
#RUN npm install -g pnpm
|
||||
#RUN npm install cross-env -g --registry=https://registry.npmmirror.com
|
||||
#RUN npm install pm2 -g --registry=https://registry.npmmirror.com
|
||||
#RUN pm2 install pm2-logrotate
|
||||
ADD ./workspace/certd-server/ /app/
|
||||
RUN sed -i "s/workspace://g" "/app/package.json"
|
||||
RUN yarn install --production --registry=https://registry.npmmirror.com
|
||||
#RUN yarn install --production
|
||||
RUN npm run build
|
||||
#CMD ["pm2-runtime", "start", "./bootstrap.js","--name", "certd","-i","1"]
|
||||
CMD ["npm", "run","start"]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
9
docker/image/build.sh
Normal file → Executable file
@@ -1,16 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
echo "请先输入一个版本号:"
|
||||
read version
|
||||
|
||||
echo "您输入的版本号是: $version"
|
||||
echo "登录aliyun镜像仓库"
|
||||
docker login --username=252959493@qq.com registry.cn-shenzhen.aliyuncs.com
|
||||
sudo docker login --username=252959493@qq.com registry.cn-shenzhen.aliyuncs.com
|
||||
|
||||
build=$(pwd)
|
||||
cd ../../
|
||||
root=$(pwd)
|
||||
echo "安装依赖"
|
||||
#pnpm install --registry=https://registry.npmmirror.com
|
||||
pnpm install
|
||||
|
||||
echo "client build"
|
||||
@@ -31,4 +32,6 @@ mkdir -p $build/workspace/certd-server
|
||||
\cp ./* $build/workspace/certd-server -rf
|
||||
\cp ../certd-client/dist/* $build/workspace/certd-server/public/ -rf
|
||||
|
||||
|
||||
#export TAG=$version
|
||||
#sudo -E docker compose build
|
||||
#sudo -E docker compose push
|
||||
|
||||
@@ -11,4 +11,5 @@ services: # 要拉起的服务们
|
||||
- "7001:7001"
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3
|
||||
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
version: '3.3' # 指定docker-compose 版本
|
||||
services: # 要拉起的服务们
|
||||
version: '3.3'
|
||||
services:
|
||||
certd:
|
||||
image: registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest
|
||||
# 镜像 # ↓↓↓↓↓ --- 1、 修改镜像版本号,或者干脆写成latest, 如果设置了环境变量 export CERTD_VERSION=latest,这里可以不修改
|
||||
image: registry.cn-shenzhen.aliyuncs.com/handsfree/certd:${CERTD_VERSION}
|
||||
container_name: certd # 容器名
|
||||
restart: unless-stopped # 重启
|
||||
volumes: # 挂载目录
|
||||
restart: unless-stopped # 自动重启
|
||||
volumes:
|
||||
# ↓↓↓↓↓ ------------------------------------------------------- 2、 修改数据库以及证书存储路径【可选】
|
||||
- /data/certd:/app/data
|
||||
ports: # 端口映射
|
||||
# ↓↓↓↓ 如果端口有冲突,可以修改第一个7001为其他不冲突的端口号
|
||||
- "7001:7001"
|
||||
environment:
|
||||
environment: # 环境变量
|
||||
- TZ=Asia/Shanghai
|
||||
- CERTD_AUTH_JWT_KEY=changeme
|
||||
#注意修改成你的自定义密钥 ↑↑↑↑↑
|
||||
- certd_auth_jwt_secret=changeme
|
||||
# ↑↑↑↑↑ ---------------------------------- 3、 修改成你的自定义密钥【必须,安全需要】
|
||||
- certd_system_resetAdminPassword=false
|
||||
# ↑↑↑↑↑ 如果忘记管理员密码,可以设置为true,重启之后,管理员密码将改成123456,然后请及时修改回false
|
||||
# 设置环境变量即可自定义certd配置
|
||||
# 服务端配置项见: packages/ui/certd-server/src/config/config.default.ts
|
||||
# 服务端配置规则: certd_ + 配置项, 点号用_代替
|
||||
# 如jwt密钥配置为: auth.jwt.secret,则设置环境变量 certd_auth_jwt_secret=changeme
|
||||
|
||||
# 客户端配置项见: packages/ui/certd-client/.env
|
||||
# 按实际名称配置环境变量即可,如: VITE_APP_API=http://localhost:7001
|
||||
|
||||
13
docker/run/run.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
# 判断$CERTD_VERSION 是否存在
|
||||
if [ -n "$CERTD_VERSION" ]; then
|
||||
echo "CERTD_VERSION is set = $CERTD_VERSION"
|
||||
else
|
||||
echo "CERTD_VERSION is not set"
|
||||
echo "请先输入一个版本号(如 1.0.6):"
|
||||
read CERTD_VERSION
|
||||
fi
|
||||
|
||||
echo "您输入的版本号是: $CERTD_VERSION"
|
||||
sudo -E docker compose up -d
|
||||
@@ -9,5 +9,5 @@
|
||||
}
|
||||
},
|
||||
"npmClient": "pnpm",
|
||||
"version": "1.0.5"
|
||||
"version": "1.20.16"
|
||||
}
|
||||
|
||||
18
package.json
@@ -1,24 +1,26 @@
|
||||
{
|
||||
"name": "root",
|
||||
"version": "1.0.3",
|
||||
"version": "1.20.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@lerna-lite/cli": "^2.4.0",
|
||||
"@lerna-lite/run": "^2.4.0",
|
||||
"@lerna-lite/publish": "^2.4.0"
|
||||
"@lerna-lite/cli": "^3.2.1",
|
||||
"@lerna-lite/publish": "^3.2.1",
|
||||
"@lerna-lite/run": "^3.2.1",
|
||||
"@lerna-lite/version": "^3.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "lerna bootstrap --hoist",
|
||||
"i-all": "lerna link && lerna exec npm install ",
|
||||
"publish": "npm run proxy && npm run prepublishOnly1 && lerna publish --conventional-commits && npm run afterpublishOnly",
|
||||
"publish": "npm run prepublishOnly1 && lerna publish --conventional-commits && npm run afterpublishOnly && npm run deploy1",
|
||||
"afterpublishOnly": "",
|
||||
"proxy": "npm config set proxy=http://127.0.0.1:10809",
|
||||
"prepublishOnly1": "npm run before-build && lerna run build ",
|
||||
"before-build": "cd ./packages/core/acme-client && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\""
|
||||
"before-build": "cd ./packages/core/acme-client && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\"",
|
||||
"deploy1": "node --experimental-json-modules deploy.js "
|
||||
},
|
||||
"license": "MIT",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"workspaces": [
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
.temp.yml
|
||||
@@ -1,133 +0,0 @@
|
||||
---
|
||||
version: 2.1
|
||||
|
||||
commands:
|
||||
pre:
|
||||
steps:
|
||||
- run: node --version
|
||||
- run: npm --version
|
||||
- run: yarn --version
|
||||
- checkout
|
||||
|
||||
enable-eab:
|
||||
steps:
|
||||
- run:
|
||||
name: Enable EAB through environment
|
||||
command: |
|
||||
echo 'export ACME_CAP_EAB_ENABLED=1' >> $BASH_ENV
|
||||
|
||||
install-cts:
|
||||
steps:
|
||||
- run:
|
||||
name: Install Pebble Challenge Test Server
|
||||
command: sudo -E /bin/bash ./scripts/test-suite-install-cts.sh
|
||||
environment:
|
||||
PEBBLECTS_VERSION: 2.3.1
|
||||
|
||||
- run:
|
||||
name: Start Pebble Challenge Test Server
|
||||
command: pebble-challtestsrv -dns01 ":8053" -tlsalpn01 ":5001" -http01 ":5002" -https01 ":5003" -defaultIPv4 "127.0.0.1" -defaultIPv6 ""
|
||||
background: true
|
||||
|
||||
install-pebble:
|
||||
steps:
|
||||
- run:
|
||||
name: Install Pebble
|
||||
command: sudo -E /bin/bash ./scripts/test-suite-install-pebble.sh
|
||||
environment:
|
||||
PEBBLE_VERSION: 2.3.1
|
||||
|
||||
- run:
|
||||
name: Start Pebble
|
||||
command: pebble -strict -config /etc/pebble/pebble.json -dnsserver "127.0.0.1:53"
|
||||
background: true
|
||||
environment:
|
||||
PEBBLE_ALTERNATE_ROOTS: 2
|
||||
|
||||
- run:
|
||||
name: Set up environment
|
||||
command: |
|
||||
echo 'export NODE_EXTRA_CA_CERTS="/etc/pebble/ca.cert.pem"' >> $BASH_ENV
|
||||
echo 'export ACME_CA_CERT_PATH="/etc/pebble/ca.cert.pem"' >> $BASH_ENV
|
||||
echo 'export ACME_DIRECTORY_URL="https://127.0.0.1:14000/dir"' >> $BASH_ENV
|
||||
echo 'export ACME_PEBBLE_MANAGEMENT_URL="https://127.0.0.1:15000"' >> $BASH_ENV
|
||||
|
||||
- run:
|
||||
name: Wait for Pebble
|
||||
command: /bin/bash ./scripts/test-suite-wait-for-ca.sh
|
||||
|
||||
install-step:
|
||||
steps:
|
||||
- run:
|
||||
name: Install Step Certificates
|
||||
command: /bin/bash ./scripts/test-suite-install-step.sh
|
||||
environment:
|
||||
STEPCA_VERSION: 0.18.0
|
||||
STEPCLI_VERSION: 0.18.0
|
||||
|
||||
- run:
|
||||
name: Start Step CA
|
||||
command: /usr/bin/step-ca --resolver="127.0.0.1:53" --password-file="/tmp/password" ~/.step/config/ca.json
|
||||
background: true
|
||||
|
||||
- run:
|
||||
name: Set up environment
|
||||
command: |
|
||||
echo 'export NODE_EXTRA_CA_CERTS="/home/circleci/.step/certs/root_ca.crt"' >> $BASH_ENV
|
||||
echo 'export ACME_CA_CERT_PATH="/home/circleci/.step/certs/root_ca.crt"' >> $BASH_ENV
|
||||
echo 'export ACME_DIRECTORY_URL="https://localhost:8443/acme/acme/directory"' >> $BASH_ENV
|
||||
|
||||
echo 'export ACME_CAP_META_TOS_FIELD=0' >> $BASH_ENV
|
||||
echo 'export ACME_CAP_UPDATE_ACCOUNT_KEY=0' >> $BASH_ENV
|
||||
echo 'export ACME_CAP_ALTERNATE_CERT_ROOTS=0' >> $BASH_ENV
|
||||
|
||||
- run:
|
||||
name: Wait for Step CA
|
||||
command: /bin/bash ./scripts/test-suite-wait-for-ca.sh
|
||||
|
||||
install-coredns:
|
||||
steps:
|
||||
- run:
|
||||
name: Install CoreDNS
|
||||
command: sudo -E /bin/bash ./scripts/test-suite-install-coredns.sh
|
||||
environment:
|
||||
COREDNS_VERSION: 1.8.6
|
||||
PEBBLECTS_DNS_PORT: 8053
|
||||
|
||||
- run:
|
||||
name: Start CoreDNS
|
||||
command: sudo coredns -p 53 -conf /etc/coredns/Corefile
|
||||
background: true
|
||||
|
||||
test:
|
||||
steps:
|
||||
- run: yarn --color
|
||||
- run: yarn run lint --color
|
||||
- run: yarn run lint-types
|
||||
- run: yarn run build-docs
|
||||
|
||||
- run:
|
||||
command: yarn run test --color
|
||||
environment:
|
||||
ACME_DOMAIN_NAME: test.example.com
|
||||
ACME_CHALLTESTSRV_URL: http://127.0.0.1:8055
|
||||
ACME_DNS_RESOLVER: 127.0.0.1
|
||||
ACME_TLSALPN_PORT: 5001
|
||||
ACME_HTTP_PORT: 5002
|
||||
ACME_HTTPS_PORT: 5003
|
||||
|
||||
jobs:
|
||||
v16: { docker: [{ image: cimg/node:16.16 }], steps: [ pre, install-cts, install-pebble, install-coredns, test ]}
|
||||
v18: { docker: [{ image: cimg/node:18.4 }], steps: [ pre, install-cts, install-pebble, install-coredns, test ]}
|
||||
eab-v16: { docker: [{ image: cimg/node:16.16 }], steps: [ pre, enable-eab, install-cts, install-pebble, install-coredns, test ]}
|
||||
eab-v18: { docker: [{ image: cimg/node:18.4 }], steps: [ pre, enable-eab, install-cts, install-pebble, install-coredns, test ]}
|
||||
# step-v12: { docker: [{ image: cimg/node:12.22 }], steps: [ pre, install-cts, install-step, install-coredns, test ]}
|
||||
|
||||
workflows:
|
||||
test-suite:
|
||||
jobs:
|
||||
- v16
|
||||
- v18
|
||||
- eab-v16
|
||||
- eab-v18
|
||||
# - step-v12
|
||||
@@ -5,7 +5,7 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = spaces
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
|
||||
@@ -9,15 +9,8 @@ env:
|
||||
rules:
|
||||
indent: [2, 4, { SwitchCase: 1, VariableDeclarator: 1 }]
|
||||
brace-style: [2, 'stroustrup', { allowSingleLine: true }]
|
||||
space-before-function-paren: [2, { anonymous: 'never', named: 'never' }]
|
||||
func-names: 0
|
||||
prefer-destructuring: 0
|
||||
object-curly-newline: 0
|
||||
class-methods-use-this: 0
|
||||
wrap-iife: [2, 'inside']
|
||||
no-param-reassign: 0
|
||||
comma-dangle: [2, 'never']
|
||||
max-len: [1, 200, 2, { ignoreUrls: true, ignoreComments: false }]
|
||||
no-multiple-empty-lines: [2, { max: 2, maxBOF: 0, maxEOF: 0 }]
|
||||
prefer-object-spread: 0
|
||||
import/no-useless-path-segments: 0
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# Install CoreDNS for testing.
|
||||
#
|
||||
set -eu
|
||||
set -euo pipefail
|
||||
|
||||
# Download and install
|
||||
wget -nv "https://github.com/coredns/coredns/releases/download/v${COREDNS_VERSION}/coredns_${COREDNS_VERSION}_linux_amd64.tgz" -O /tmp/coredns.tgz
|
||||
@@ -39,18 +39,21 @@ tee /etc/coredns/Corefile << EOF
|
||||
example.com {
|
||||
errors
|
||||
log
|
||||
bind 127.53.53.53
|
||||
file /etc/coredns/db.example.com
|
||||
}
|
||||
|
||||
test.example.com {
|
||||
errors
|
||||
log
|
||||
bind 127.53.53.53
|
||||
forward . 127.0.0.1:${PEBBLECTS_DNS_PORT}
|
||||
}
|
||||
|
||||
. {
|
||||
errors
|
||||
log
|
||||
bind 127.53.53.53
|
||||
forward . 8.8.8.8
|
||||
}
|
||||
EOF
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# Install Pebble Challenge Test Server for testing.
|
||||
#
|
||||
set -eu
|
||||
set -euo pipefail
|
||||
|
||||
# Download and install
|
||||
wget -nv "https://github.com/letsencrypt/pebble/releases/download/v${PEBBLECTS_VERSION}/pebble-challtestsrv_linux-amd64" -O /usr/local/bin/pebble-challtestsrv
|
||||
@@ -2,14 +2,14 @@
|
||||
#
|
||||
# Install Pebble for testing.
|
||||
#
|
||||
set -eu
|
||||
set -euo pipefail
|
||||
|
||||
config_name="pebble-config.json"
|
||||
CONFIG_NAME="pebble-config.json"
|
||||
|
||||
# Use Pebble EAB config if enabled
|
||||
set +u
|
||||
if [[ ! -z $ACME_CAP_EAB_ENABLED ]] && [[ $ACME_CAP_EAB_ENABLED -eq 1 ]]; then
|
||||
config_name="pebble-config-external-account-bindings.json"
|
||||
if [[ -n $ACME_CAP_EAB_ENABLED ]] && [[ $ACME_CAP_EAB_ENABLED -eq 1 ]]; then
|
||||
CONFIG_NAME="pebble-config-external-account-bindings.json"
|
||||
fi
|
||||
set -u
|
||||
|
||||
@@ -19,7 +19,7 @@ mkdir -p /etc/pebble
|
||||
wget -nv "https://raw.githubusercontent.com/letsencrypt/pebble/v${PEBBLE_VERSION}/test/certs/pebble.minica.pem" -O /etc/pebble/ca.cert.pem
|
||||
wget -nv "https://raw.githubusercontent.com/letsencrypt/pebble/v${PEBBLE_VERSION}/test/certs/localhost/cert.pem" -O /etc/pebble/cert.pem
|
||||
wget -nv "https://raw.githubusercontent.com/letsencrypt/pebble/v${PEBBLE_VERSION}/test/certs/localhost/key.pem" -O /etc/pebble/key.pem
|
||||
wget -nv "https://raw.githubusercontent.com/letsencrypt/pebble/v${PEBBLE_VERSION}/test/config/${config_name}" -O /etc/pebble/pebble.json
|
||||
wget -nv "https://raw.githubusercontent.com/letsencrypt/pebble/v${PEBBLE_VERSION}/test/config/${CONFIG_NAME}" -O /etc/pebble/pebble.json
|
||||
|
||||
# Download and install Pebble
|
||||
wget -nv "https://github.com/letsencrypt/pebble/releases/download/v${PEBBLE_VERSION}/pebble_linux-amd64" -O /usr/local/bin/pebble
|
||||
@@ -28,6 +28,6 @@ chown root:root /usr/local/bin/pebble
|
||||
chmod 0755 /usr/local/bin/pebble
|
||||
|
||||
# Config
|
||||
sed -i 's/test\/certs\/localhost/\/etc\/pebble/' /etc/pebble/pebble.json
|
||||
sed -i 's#test/certs/localhost#/etc/pebble#' /etc/pebble/pebble.json
|
||||
|
||||
exit 0
|
||||
@@ -2,13 +2,13 @@
|
||||
#
|
||||
# Wait for ACME server to accept connections.
|
||||
#
|
||||
set -eu
|
||||
set -euo pipefail
|
||||
|
||||
MAX_ATTEMPTS=15
|
||||
ATTEMPT=0
|
||||
|
||||
# Loop until ready
|
||||
while ! $(curl --cacert "${ACME_CA_CERT_PATH}" -s -D - "${ACME_DIRECTORY_URL}" | grep '^HTTP.*200' > /dev/null 2>&1); do
|
||||
while ! curl --cacert "${ACME_CA_CERT_PATH}" -s -D - "${ACME_DIRECTORY_URL}" | grep '^HTTP.*200' > /dev/null 2>&1; do
|
||||
ATTEMPT=$((ATTEMPT + 1))
|
||||
|
||||
# Max attempts
|
||||
91
packages/core/acme-client/.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
name: test
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: node=${{matrix.node}} eab=${{matrix.eab}}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node: [16, 18, 20, 22]
|
||||
eab: [0, 1]
|
||||
|
||||
#
|
||||
# Environment
|
||||
#
|
||||
|
||||
env:
|
||||
FORCE_COLOR: 1
|
||||
NPM_CONFIG_COLOR: always
|
||||
|
||||
PEBBLE_VERSION: 2.3.1
|
||||
PEBBLE_ALTERNATE_ROOTS: 2
|
||||
PEBBLECTS_VERSION: 2.3.1
|
||||
PEBBLECTS_DNS_PORT: 8053
|
||||
COREDNS_VERSION: 1.11.1
|
||||
|
||||
NODE_EXTRA_CA_CERTS: /etc/pebble/ca.cert.pem
|
||||
ACME_CA_CERT_PATH: /etc/pebble/ca.cert.pem
|
||||
|
||||
ACME_DIRECTORY_URL: https://127.0.0.1:14000/dir
|
||||
ACME_CHALLTESTSRV_URL: http://127.0.0.1:8055
|
||||
ACME_PEBBLE_MANAGEMENT_URL: https://127.0.0.1:15000
|
||||
|
||||
ACME_DOMAIN_NAME: test.example.com
|
||||
ACME_CAP_EAB_ENABLED: ${{matrix.eab}}
|
||||
|
||||
ACME_TLSALPN_PORT: 5001
|
||||
ACME_HTTP_PORT: 5002
|
||||
ACME_HTTPS_PORT: 5003
|
||||
|
||||
#
|
||||
# Pipeline
|
||||
#
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
|
||||
# Pebble Challenge Test Server
|
||||
- name: Install Pebble Challenge Test Server
|
||||
run: sudo -E /bin/bash ./.github/scripts/tests-install-cts.sh
|
||||
|
||||
- name: Start Pebble Challenge Test Server
|
||||
run: |-
|
||||
nohup bash -c "pebble-challtestsrv \
|
||||
-dns01 :${PEBBLECTS_DNS_PORT} \
|
||||
-tlsalpn01 :${ACME_TLSALPN_PORT} \
|
||||
-http01 :${ACME_HTTP_PORT} \
|
||||
-https01 :${ACME_HTTPS_PORT} \
|
||||
-defaultIPv4 127.0.0.1 \
|
||||
-defaultIPv6 \"\" &"
|
||||
|
||||
# Pebble
|
||||
- name: Install Pebble
|
||||
run: sudo -E /bin/bash ./.github/scripts/tests-install-pebble.sh
|
||||
|
||||
- name: Start Pebble
|
||||
run: nohup bash -c "pebble -strict -config /etc/pebble/pebble.json -dnsserver 127.53.53.53:53 &"
|
||||
|
||||
- name: Wait for Pebble
|
||||
run: /bin/bash ./.github/scripts/tests-wait-for-ca.sh
|
||||
|
||||
# CoreDNS
|
||||
- name: Install CoreDNS
|
||||
run: sudo -E /bin/bash ./.github/scripts/tests-install-coredns.sh
|
||||
|
||||
- name: Start CoreDNS
|
||||
run: nohup bash -c "sudo coredns -p 53 -conf /etc/coredns/Corefile &"
|
||||
|
||||
- name: Use CoreDNS for DNS resolution
|
||||
run: echo "nameserver 127.53.53.53" | sudo tee /etc/resolv.conf
|
||||
|
||||
# Run tests
|
||||
- run: npm i
|
||||
- run: npm run lint
|
||||
- run: npm run lint-types
|
||||
- run: npm run build-docs
|
||||
- run: npm run test
|
||||
3
packages/core/acme-client/.gitignore
vendored
@@ -1,7 +1,6 @@
|
||||
.actrc
|
||||
.vscode/
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
/.idea/
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
ignore-engines true
|
||||
ignore-optional true
|
||||
@@ -3,33 +3,86 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.5](https://github.com/publishlab/node-acme-client/compare/v1.0.4...v1.0.5) (2023-05-25)
|
||||
## [1.20.16](https://github.com/publishlab/node-acme-client/compare/v1.20.15...v1.20.16) (2024-07-01)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复配置了cdn cname后申请失败的bug ([4a5fa76](https://github.com/publishlab/node-acme-client/commit/4a5fa767edc347d03d29a467e86c9a4d70b0220c))
|
||||
|
||||
## [1.20.15](https://github.com/publishlab/node-acme-client/compare/v1.20.14...v1.20.15) (2024-06-28)
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 腾讯云dns provider 支持腾讯云的accessId ([e0eb3a4](https://github.com/publishlab/node-acme-client/commit/e0eb3a441384d474fe2923c69b25318264bdc9df))
|
||||
|
||||
## [1.20.14](https://github.com/publishlab/node-acme-client/compare/v1.20.13...v1.20.14) (2024-06-23)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.0.4](https://github.com/publishlab/node-acme-client/compare/v1.0.3...v1.0.4) (2023-05-25)
|
||||
## [1.20.13](https://github.com/publishlab/node-acme-client/compare/v1.20.12...v1.20.13) (2024-06-18)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.0.3](https://github.com/publishlab/node-acme-client/compare/v1.0.2...v1.0.3) (2023-05-25)
|
||||
## [1.20.12](https://github.com/publishlab/node-acme-client/compare/v1.20.10...v1.20.12) (2024-06-17)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复aliyun域名超过100个找不到域名的bug ([5b1494b](https://github.com/publishlab/node-acme-client/commit/5b1494b3ce93d1026dc56ee741342fbb8bf7be24))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* 支持cloudflare域名 ([fbb9a47](https://github.com/publishlab/node-acme-client/commit/fbb9a47e8f7bb805289b9ee64bd46ffee0f01c06))
|
||||
|
||||
## [1.20.10](https://github.com/publishlab/node-acme-client/compare/v1.20.9...v1.20.10) (2024-05-30)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.0.2](https://github.com/publishlab/node-acme-client/compare/v1.0.1...v1.0.2) (2023-05-24)
|
||||
## [1.20.9](https://github.com/publishlab/node-acme-client/compare/v1.20.8...v1.20.9) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.0.1](https://github.com/publishlab/node-acme-client/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
## [1.20.8](https://github.com/publishlab/node-acme-client/compare/v1.20.7...v1.20.8) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.20.7](https://github.com/publishlab/node-acme-client/compare/v1.20.6...v1.20.7) (2024-03-22)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.20.6](https://github.com/publishlab/node-acme-client/compare/v1.20.5...v1.20.6) (2024-03-21)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
## [1.20.5](https://github.com/publishlab/node-acme-client/compare/v1.20.2...v1.20.5) (2024-03-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复腾讯云cdn部署无法选择端点的bug ([154409b](https://github.com/publishlab/node-acme-client/commit/154409b1dfee3ea1caae740ad9c1f99a6e7a9814))
|
||||
|
||||
# Changelog
|
||||
|
||||
## Important upgrade notice
|
||||
## v5.3.1 (2024-05-22)
|
||||
|
||||
On September 15, 2022, Let's Encrypt will stop accepting Certificate Signing Requests signed using the obsolete SHA-1 hash. This change affects all `acme-client` versions lower than `3.3.2` and `4.2.4`. Please upgrade ASAP to ensure that your certificates can still be issued following this date.
|
||||
* `fixed` Allow `client.auto()` being called with an empty CSR common name
|
||||
* `fixed` Bug when calling `updateAccountKey()` with external account binding
|
||||
|
||||
A more detailed explanation can be found [at the Let's Encrypt forums](https://community.letsencrypt.org/t/rejecting-sha-1-csrs-and-validation-using-tls-1-0-1-1-urls/175144).
|
||||
## v5.3.0 (2024-02-05)
|
||||
|
||||
* `added` Support and tests for satisfying `tls-alpn-01` challenges
|
||||
* `changed` Replace `jsrsasign` with `@peculiar/x509` for certificate and CSR generation and parsing
|
||||
* `changed` Method `getChallengeKeyAuthorization()` now returns `$token.$thumbprint` when called with a `tls-alpn-01` challenge
|
||||
* Previously returned base64url encoded SHA256 digest of `$token.$thumbprint` erroneously
|
||||
* This change is not considered breaking since the previous behavior was incorrect
|
||||
|
||||
## v5.2.0 (2024-01-22)
|
||||
|
||||
* `fixed` Allow self-signed or invalid certs when validating `http-01` challenges that redirect to HTTPS - [#65](https://github.com/publishlab/node-acme-client/issues/65)
|
||||
* `fixed` Wait for all challenge promises to settle before rejecting `client.auto()` - [#75](https://github.com/publishlab/node-acme-client/issues/75)
|
||||
|
||||
## v5.1.0 (2024-01-20)
|
||||
|
||||
* `fixed` Upgrade `jsrsasign@11.0.0` - [GHSA-rh63-9qcf-83gf](https://github.com/kjur/jsrsasign/security/advisories/GHSA-rh63-9qcf-83gf)
|
||||
* `fixed` Upgrade `axios@1.6.5` - [CVE-2023-45857](https://cve.mitre.org/cgi-bin/cvename.cgi?name=2023-45857)
|
||||
|
||||
## v5.0.0 (2022-07-28)
|
||||
|
||||
@@ -45,7 +98,7 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `fixed` Upgrade `axios@0.26.1`
|
||||
* `fixed` Upgrade `node-forge@1.3.0` - [CVE-2022-24771](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24771), [CVE-2022-24772](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24772), [CVE-2022-24773](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24773)
|
||||
|
||||
## 4.2.4 (2022-03-19)
|
||||
## v4.2.4 (2022-03-19)
|
||||
|
||||
* `fixed` Use SHA-256 when signing CSRs
|
||||
|
||||
@@ -68,13 +121,13 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
|
||||
## v4.2.0 (2022-01-06)
|
||||
|
||||
* `added` Support for external account binding - [RFC 8555 Section 7.3.4](https://tools.ietf.org/html/rfc8555#section-7.3.4)
|
||||
* `added` Support for external account binding - [RFC 8555 Section 7.3.4](https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.4)
|
||||
* `added` Ability to pass through custom logger function
|
||||
* `changed` Increase default `backoffAttempts` to 10
|
||||
* `fixed` Deactivate authorizations where challenges can not be completed
|
||||
* `fixed` Attempt authoritative name servers when verifying `dns-01` challenges
|
||||
* `fixed` Error verbosity when failing to read ACME directory
|
||||
* `fixed` Correctly recognize `ready` and `processing` states - [RFC 8555 Section 7.1.6](https://tools.ietf.org/html/rfc8555#section-7.1.6)
|
||||
* `fixed` Correctly recognize `ready` and `processing` states - [RFC 8555 Section 7.1.6](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.6)
|
||||
|
||||
## v4.1.4 (2021-12-23)
|
||||
|
||||
@@ -124,7 +177,7 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
## v3.3.0 (2019-12-19)
|
||||
|
||||
* `added` TypeScript definitions
|
||||
* `fixed` Allow missing ACME directory meta field - [RFC 8555 Section 7.1.1](https://tools.ietf.org/html/rfc8555#section-7.1.1)
|
||||
* `fixed` Allow missing ACME directory meta field - [RFC 8555 Section 7.1.1](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.1)
|
||||
|
||||
## v3.2.1 (2019-11-14)
|
||||
|
||||
@@ -135,10 +188,10 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `added` More extensive testing using [letsencrypt/pebble](https://github.com/letsencrypt/pebble)
|
||||
* `changed` When creating a CSR, `commonName` no longer defaults to `'localhost'`
|
||||
* This change is not considered breaking since `commonName: 'localhost'` will result in an error when ordering a certificate
|
||||
* `fixed` Retry signed API requests on `urn:ietf:params:acme:error:badNonce` - [RFC 8555 Section 6.5](https://tools.ietf.org/html/rfc8555#section-6.5)
|
||||
* `fixed` Retry signed API requests on `urn:ietf:params:acme:error:badNonce` - [RFC 8555 Section 6.5](https://datatracker.ietf.org/doc/html/rfc8555#section-6.5)
|
||||
* `fixed` Minor bugs related to `POST-as-GET` when calling `updateAccount()`
|
||||
* `fixed` Ensure subject common name is present in SAN when creating a CSR - [CAB v1.2.3 Section 9.2.2](https://cabforum.org/wp-content/uploads/BRv1.2.3.pdf)
|
||||
* `fixed` Send empty JSON body when responding to challenges - [RFC 8555 Section 7.5.1](https://tools.ietf.org/html/rfc8555#section-7.5.1)
|
||||
* `fixed` Send empty JSON body when responding to challenges - [RFC 8555 Section 7.5.1](https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1)
|
||||
|
||||
## v2.3.1 (2019-08-26)
|
||||
|
||||
@@ -147,8 +200,8 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
|
||||
## v3.1.0 (2019-08-21)
|
||||
|
||||
* `added` UTF-8 support when generating a CSR subject using forge - [RFC 5280](https://tools.ietf.org/html/rfc5280)
|
||||
* `fixed` Implement `POST-as-GET` for all ACME API requests - [RFC 8555 Section 6.3](https://tools.ietf.org/html/rfc8555#section-6.3)
|
||||
* `added` UTF-8 support when generating a CSR subject using forge - [RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280)
|
||||
* `fixed` Implement `POST-as-GET` for all ACME API requests - [RFC 8555 Section 6.3](https://datatracker.ietf.org/doc/html/rfc8555#section-6.3)
|
||||
|
||||
## v2.3.0 (2019-08-21)
|
||||
|
||||
@@ -185,7 +238,7 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
|
||||
## v2.0.1 (2018-08-17)
|
||||
|
||||
* `fixed` Key rollover in compliance with [draft-ietf-acme-13](https://tools.ietf.org/html/draft-ietf-acme-acme-13)
|
||||
* `fixed` Key rollover in compliance with [draft-ietf-acme-13](https://datatracker.ietf.org/doc/html/draft-ietf-acme-acme-13)
|
||||
|
||||
## v2.0.0 (2018-04-02)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2022 Publish Lab
|
||||
Copyright (c) 2017-2024 Labrador CMS AS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,32 +1,23 @@
|
||||
# acme-client [](https://circleci.com/gh/publishlab/node-acme-client)
|
||||
# acme-client [](https://github.com/publishlab/node-acme-client/actions/workflows/tests.yml)
|
||||
|
||||
*A simple and unopinionated ACME client.*
|
||||
|
||||
This module is written to handle communication with a Boulder/Let's Encrypt-style ACME API.
|
||||
|
||||
* RFC 8555 - Automatic Certificate Management Environment (ACME): [https://tools.ietf.org/html/rfc8555](https://tools.ietf.org/html/rfc8555)
|
||||
* RFC 8555 - Automatic Certificate Management Environment (ACME): [https://datatracker.ietf.org/doc/html/rfc8555](https://datatracker.ietf.org/doc/html/rfc8555)
|
||||
* Boulder divergences from ACME: [https://github.com/letsencrypt/boulder/blob/master/docs/acme-divergences.md](https://github.com/letsencrypt/boulder/blob/master/docs/acme-divergences.md)
|
||||
|
||||
## Compatibility
|
||||
|
||||
## Important upgrade notice
|
||||
| acme-client | Node.js | |
|
||||
| ----------- | ------- | ----------------------------------------- |
|
||||
| v5.x | >= v16 | [Upgrade guide](docs/upgrade-v5.md) |
|
||||
| v4.x | >= v10 | [Changelog](CHANGELOG.md#v400-2020-05-29) |
|
||||
| v3.x | >= v8 | [Changelog](CHANGELOG.md#v300-2019-07-13) |
|
||||
| v2.x | >= v4 | [Changelog](CHANGELOG.md#v200-2018-04-02) |
|
||||
| v1.x | >= v4 | [Changelog](CHANGELOG.md#v100-2017-10-20) |
|
||||
|
||||
On September 15, 2022, Let's Encrypt will stop accepting Certificate Signing Requests signed using the obsolete SHA-1 hash. This change affects all `acme-client` versions lower than `3.3.2` and `4.2.4`. Please upgrade ASAP to ensure that your certificates can still be issued following this date.
|
||||
|
||||
A more detailed explanation can be found [at the Let's Encrypt forums](https://community.letsencrypt.org/t/rejecting-sha-1-csrs-and-validation-using-tls-1-0-1-1-urls/175144).
|
||||
|
||||
|
||||
### Compatibility
|
||||
|
||||
| acme-client | Node.js | |
|
||||
| ------------- | --------- | ----------------------------------------- |
|
||||
| v5.x | >= v16 | [Upgrade guide](docs/upgrade-v5.md) |
|
||||
| v4.x | >= v10 | [Changelog](CHANGELOG.md#v400-2020-05-29) |
|
||||
| v3.x | >= v8 | [Changelog](CHANGELOG.md#v300-2019-07-13) |
|
||||
| v2.x | >= v4 | [Changelog](CHANGELOG.md#v200-2018-04-02) |
|
||||
| v1.x | >= v4 | [Changelog](CHANGELOG.md#v100-2017-10-20) |
|
||||
|
||||
|
||||
### Table of contents
|
||||
## Table of contents
|
||||
|
||||
* [Installation](#installation)
|
||||
* [Usage](#usage)
|
||||
@@ -43,14 +34,12 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* [Debugging](#debugging)
|
||||
* [License](#license)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install acme-client
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
@@ -60,11 +49,10 @@ const accountPrivateKey = '<PEM encoded private key>';
|
||||
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: accountPrivateKey
|
||||
accountKey: accountPrivateKey,
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Directory URLs
|
||||
|
||||
```js
|
||||
@@ -77,10 +65,9 @@ acme.directory.letsencrypt.production;
|
||||
acme.directory.zerossl.production;
|
||||
```
|
||||
|
||||
|
||||
### External account binding
|
||||
|
||||
To enable [external account binding](https://tools.ietf.org/html/rfc8555#section-7.3.4) when creating your ACME account, provide your KID and HMAC key to the client constructor.
|
||||
To enable [external account binding](https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.4) when creating your ACME account, provide your KID and HMAC key to the client constructor.
|
||||
|
||||
```js
|
||||
const client = new acme.Client({
|
||||
@@ -88,12 +75,11 @@ const client = new acme.Client({
|
||||
accountKey: accountPrivateKey,
|
||||
externalAccountBinding: {
|
||||
kid: 'YOUR-EAB-KID',
|
||||
hmacKey: 'YOUR-EAB-HMAC-KEY'
|
||||
}
|
||||
hmacKey: 'YOUR-EAB-HMAC-KEY',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Specifying the account URL
|
||||
|
||||
During the ACME account creation process, the server will check the supplied account key and either create a new account if the key is unused, or return the existing ACME account bound to that key.
|
||||
@@ -104,7 +90,7 @@ In some cases, for example with some EAB providers, this account creation step m
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: accountPrivateKey,
|
||||
accountUrl: 'https://acme-v02.api.letsencrypt.org/acme/acct/12345678'
|
||||
accountUrl: 'https://acme-v02.api.letsencrypt.org/acme/acct/12345678',
|
||||
});
|
||||
```
|
||||
|
||||
@@ -114,41 +100,37 @@ You can fetch the clients current account URL, either after creating an account
|
||||
const myAccountUrl = client.getAccountUrl();
|
||||
```
|
||||
|
||||
|
||||
## Cryptography
|
||||
|
||||
For key pairs `acme-client` utilizes native Node.js cryptography APIs, supporting signing and generation of both RSA and ECDSA keys. The module [jsrsasign](https://www.npmjs.com/package/jsrsasign) is used to generate and parse Certificate Signing Requests.
|
||||
For key pairs `acme-client` utilizes native Node.js cryptography APIs, supporting signing and generation of both RSA and ECDSA keys. The module [@peculiar/x509](https://www.npmjs.com/package/@peculiar/x509) is used to generate and parse Certificate Signing Requests.
|
||||
|
||||
These utility methods are exposed through `.crypto`.
|
||||
|
||||
* __Documentation: [docs/crypto.md](docs/crypto.md)__
|
||||
* **Documentation: [docs/crypto.md](docs/crypto.md)**
|
||||
|
||||
```js
|
||||
const privateRsaKey = await acme.crypto.createPrivateRsaKey();
|
||||
const privateEcdsaKey = await acme.crypto.createPrivateEcdsaKey();
|
||||
|
||||
const [certificateKey, certificateCsr] = await acme.crypto.createCsr({
|
||||
commonName: '*.example.com',
|
||||
altNames: ['example.com']
|
||||
altNames: ['example.com', '*.example.com'],
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Legacy `.forge` interface
|
||||
|
||||
The legacy `node-forge` crypto interface is still available for backward compatibility, however this interface is now considered deprecated and will be removed in a future major version of `acme-client`.
|
||||
|
||||
You should consider migrating to the new `.crypto` API at your earliest convenience. More details can be found in the [acme-client v5 upgrade guide](docs/upgrade-v5.md).
|
||||
|
||||
* __Documentation: [docs/forge.md](docs/forge.md)__
|
||||
|
||||
* **Documentation: [docs/forge.md](docs/forge.md)**
|
||||
|
||||
## Auto mode
|
||||
|
||||
For convenience an `auto()` method is included in the client that takes a single config object. This method will handle the entire process of getting a certificate for one or multiple domains.
|
||||
|
||||
* __Documentation: [docs/client.md#AcmeClient+auto](docs/client.md#AcmeClient+auto)__
|
||||
* __Full example: [examples/auto.js](examples/auto.js)__
|
||||
* **Documentation: [docs/client.md#AcmeClient+auto](docs/client.md#AcmeClient+auto)**
|
||||
* **Full example: [examples/auto.js](examples/auto.js)**
|
||||
|
||||
```js
|
||||
const autoOpts = {
|
||||
@@ -156,29 +138,27 @@ const autoOpts = {
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: true,
|
||||
challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
|
||||
challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
|
||||
challengeRemoveFn: async (authz, challenge, keyAuthorization) => {},
|
||||
};
|
||||
|
||||
const certificate = await client.auto(autoOpts);
|
||||
```
|
||||
|
||||
|
||||
### Challenge priority
|
||||
|
||||
When ordering a certificate using auto mode, `acme-client` uses a priority list when selecting challenges to respond to. Its default value is `['http-01', 'dns-01']` which translates to "use `http-01` if any challenges exist, otherwise fall back to `dns-01`".
|
||||
|
||||
While most challenges can be validated using the method of your choosing, please note that __wildcard certificates can only be validated through `dns-01`__. More information regarding Let's Encrypt challenge types [can be found here](https://letsencrypt.org/docs/challenge-types/).
|
||||
While most challenges can be validated using the method of your choosing, please note that **wildcard certificates can only be validated through `dns-01`**. More information regarding Let's Encrypt challenge types [can be found here](https://letsencrypt.org/docs/challenge-types/).
|
||||
|
||||
To modify challenge priority, provide a list of challenge types in `challengePriority`:
|
||||
|
||||
```js
|
||||
await client.auto({
|
||||
...,
|
||||
challengePriority: ['http-01', 'dns-01']
|
||||
challengePriority: ['http-01', 'dns-01'],
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Internal challenge verification
|
||||
|
||||
When using auto mode, `acme-client` will first validate that challenges are satisfied internally before completing the challenge at the ACME provider. In some cases (firewalls, etc) this internal challenge verification might not be possible to complete.
|
||||
@@ -190,33 +170,31 @@ To completely disable `acme-client`s internal challenge verification, enable `sk
|
||||
```js
|
||||
await client.auto({
|
||||
...,
|
||||
skipChallengeVerification: true
|
||||
skipChallengeVerification: true,
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
For more fine-grained control you can interact with the ACME API using the methods documented below.
|
||||
|
||||
* __Documentation: [docs/client.md](docs/client.md)__
|
||||
* __Full example: [examples/api.js](examples/api.js)__
|
||||
* **Documentation: [docs/client.md](docs/client.md)**
|
||||
* **Full example: [examples/api.js](examples/api.js)**
|
||||
|
||||
```js
|
||||
const account = await client.createAccount({
|
||||
termsOfServiceAgreed: true,
|
||||
contact: ['mailto:test@example.com']
|
||||
contact: ['mailto:test@example.com'],
|
||||
});
|
||||
|
||||
const order = await client.createOrder({
|
||||
identifiers: [
|
||||
{ type: 'dns', value: 'example.com' },
|
||||
{ type: 'dns', value: '*.example.com' }
|
||||
]
|
||||
{ type: 'dns', value: '*.example.com' },
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## HTTP client defaults
|
||||
|
||||
This module uses [axios](https://github.com/axios/axios) when communicating with the ACME HTTP API, and exposes the client instance through `.axios`.
|
||||
@@ -228,7 +206,7 @@ const acme = require('acme-client');
|
||||
|
||||
acme.axios.defaults.proxy = {
|
||||
host: '127.0.0.1',
|
||||
port: 9000
|
||||
port: 9000,
|
||||
};
|
||||
```
|
||||
|
||||
@@ -237,7 +215,6 @@ A complete list of axios options and documentation can be found at:
|
||||
* [https://github.com/axios/axios#request-config](https://github.com/axios/axios#request-config)
|
||||
* [https://github.com/axios/axios#custom-instance-defaults](https://github.com/axios/axios#custom-instance-defaults)
|
||||
|
||||
|
||||
## Debugging
|
||||
|
||||
To get a better grasp of what `acme-client` is doing behind the scenes, you can either pass it a logger function, or enable debugging through an environment variable.
|
||||
@@ -256,7 +233,6 @@ Debugging to the console can also be enabled through [debug](https://www.npmjs.c
|
||||
DEBUG=acme-client node index.js
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
@@ -1 +1 @@
|
||||
22:57
|
||||
00:35
|
||||
|
||||
@@ -63,7 +63,7 @@ Create ACME client instance
|
||||
```js
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: 'Private key goes here'
|
||||
accountKey: 'Private key goes here',
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
@@ -75,7 +75,7 @@ const client = new acme.Client({
|
||||
accountUrl: 'Optional account URL goes here',
|
||||
backoffAttempts: 10,
|
||||
backoffMin: 5000,
|
||||
backoffMax: 30000
|
||||
backoffMax: 30000,
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
@@ -86,8 +86,8 @@ const client = new acme.Client({
|
||||
accountKey: 'Private key goes here',
|
||||
externalAccountBinding: {
|
||||
kid: 'YOUR-EAB-KID',
|
||||
hmacKey: 'YOUR-EAB-HMAC-KEY'
|
||||
}
|
||||
hmacKey: 'YOUR-EAB-HMAC-KEY',
|
||||
},
|
||||
});
|
||||
```
|
||||
<a name="AcmeClient+getTermsOfServiceUrl"></a>
|
||||
@@ -132,7 +132,7 @@ catch (e) {
|
||||
### acmeClient.createAccount([data]) ⇒ <code>Promise.<object></code>
|
||||
Create a new account
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.3
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.3
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Account
|
||||
@@ -145,7 +145,7 @@ https://tools.ietf.org/html/rfc8555#section-7.3
|
||||
Create a new account
|
||||
```js
|
||||
const account = await client.createAccount({
|
||||
termsOfServiceAgreed: true
|
||||
termsOfServiceAgreed: true,
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
@@ -153,7 +153,7 @@ Create a new account with contact info
|
||||
```js
|
||||
const account = await client.createAccount({
|
||||
termsOfServiceAgreed: true,
|
||||
contact: ['mailto:test@example.com']
|
||||
contact: ['mailto:test@example.com'],
|
||||
});
|
||||
```
|
||||
<a name="AcmeClient+updateAccount"></a>
|
||||
@@ -161,7 +161,7 @@ const account = await client.createAccount({
|
||||
### acmeClient.updateAccount([data]) ⇒ <code>Promise.<object></code>
|
||||
Update existing account
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.3.2
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.2
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Account
|
||||
@@ -174,7 +174,7 @@ https://tools.ietf.org/html/rfc8555#section-7.3.2
|
||||
Update existing account
|
||||
```js
|
||||
const account = await client.updateAccount({
|
||||
contact: ['mailto:foo@example.com']
|
||||
contact: ['mailto:foo@example.com'],
|
||||
});
|
||||
```
|
||||
<a name="AcmeClient+updateAccountKey"></a>
|
||||
@@ -182,7 +182,7 @@ const account = await client.updateAccount({
|
||||
### acmeClient.updateAccountKey(newAccountKey, [data]) ⇒ <code>Promise.<object></code>
|
||||
Update account private key
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.3.5
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.5
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Account
|
||||
@@ -203,7 +203,7 @@ const result = await client.updateAccountKey(newAccountKey);
|
||||
### acmeClient.createOrder(data) ⇒ <code>Promise.<object></code>
|
||||
Create a new order
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Order
|
||||
@@ -218,8 +218,8 @@ Create a new order
|
||||
const order = await client.createOrder({
|
||||
identifiers: [
|
||||
{ type: 'dns', value: 'example.com' },
|
||||
{ type: 'dns', value: 'test.example.com' }
|
||||
]
|
||||
{ type: 'dns', value: 'test.example.com' },
|
||||
],
|
||||
});
|
||||
```
|
||||
<a name="AcmeClient+getOrder"></a>
|
||||
@@ -227,7 +227,7 @@ const order = await client.createOrder({
|
||||
### acmeClient.getOrder(order) ⇒ <code>Promise.<object></code>
|
||||
Refresh order object from CA
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Order
|
||||
@@ -246,7 +246,7 @@ const result = await client.getOrder(order);
|
||||
### acmeClient.finalizeOrder(order, csr) ⇒ <code>Promise.<object></code>
|
||||
Finalize order
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Order
|
||||
@@ -268,7 +268,7 @@ const result = await client.finalizeOrder(order, csr);
|
||||
### acmeClient.getAuthorizations(order) ⇒ <code>Promise.<Array.<object>></code>
|
||||
Get identifier authorizations from order
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.5
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.5
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<Array.<object>></code> - Authorizations
|
||||
@@ -292,7 +292,7 @@ authorizations.forEach((authz) => {
|
||||
### acmeClient.deactivateAuthorization(authz) ⇒ <code>Promise.<object></code>
|
||||
Deactivate identifier authorization
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.2
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Authorization
|
||||
@@ -312,7 +312,7 @@ const result = await client.deactivateAuthorization(authz);
|
||||
### acmeClient.getChallengeKeyAuthorization(challenge) ⇒ <code>Promise.<string></code>
|
||||
Get key authorization for ACME challenge
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-8.1
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-8.1
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<string></code> - Key authorization
|
||||
@@ -353,7 +353,7 @@ await client.verifyChallenge(authz, challenge);
|
||||
### acmeClient.completeChallenge(challenge) ⇒ <code>Promise.<object></code>
|
||||
Notify CA that challenge has been completed
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.5.1
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Challenge
|
||||
@@ -373,7 +373,7 @@ const result = await client.completeChallenge(challenge);
|
||||
### acmeClient.waitForValidStatus(item) ⇒ <code>Promise.<object></code>
|
||||
Wait for ACME provider to verify status on a order, authorization or challenge
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.5.1
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<object></code> - Valid order, authorization or challenge
|
||||
@@ -389,7 +389,7 @@ const challenge = { ... };
|
||||
await client.waitForValidStatus(challenge);
|
||||
```
|
||||
**Example**
|
||||
Wait for valid authoriation status
|
||||
Wait for valid authorization status
|
||||
```js
|
||||
const authz = { ... };
|
||||
await client.waitForValidStatus(authz);
|
||||
@@ -405,7 +405,7 @@ await client.waitForValidStatus(order);
|
||||
### acmeClient.getCertificate(order, [preferredChain]) ⇒ <code>Promise.<string></code>
|
||||
Get certificate from ACME order
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.4.2
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.4.2
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
**Returns**: <code>Promise.<string></code> - Certificate
|
||||
@@ -432,7 +432,7 @@ const certificate = await client.getCertificate(order, 'DST Root CA X3');
|
||||
### acmeClient.revokeCertificate(cert, [data]) ⇒ <code>Promise</code>
|
||||
Revoke certificate
|
||||
|
||||
https://tools.ietf.org/html/rfc8555#section-7.6
|
||||
https://datatracker.ietf.org/doc/html/rfc8555#section-7.6
|
||||
|
||||
**Kind**: instance method of [<code>AcmeClient</code>](#AcmeClient)
|
||||
|
||||
@@ -452,7 +452,7 @@ Revoke certificate with reason
|
||||
```js
|
||||
const certificate = { ... }; // Previously created certificate
|
||||
const result = await client.revokeCertificate(certificate, {
|
||||
reason: 4
|
||||
reason: 4,
|
||||
});
|
||||
```
|
||||
<a name="AcmeClient+auto"></a>
|
||||
@@ -479,7 +479,7 @@ Auto mode
|
||||
Order a certificate using auto mode
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
});
|
||||
|
||||
const certificate = await client.auto({
|
||||
@@ -491,14 +491,14 @@ const certificate = await client.auto({
|
||||
},
|
||||
challengeRemoveFn: async (authz, challenge, keyAuthorization) => {
|
||||
// Clean up challenge here
|
||||
}
|
||||
},
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
Order a certificate using auto mode with preferred chain
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
});
|
||||
|
||||
const certificate = await client.auto({
|
||||
@@ -507,7 +507,7 @@ const certificate = await client.auto({
|
||||
termsOfServiceAgreed: true,
|
||||
preferredChain: 'DST Root CA X3',
|
||||
challengeCreateFn: async () => {},
|
||||
challengeRemoveFn: async () => {}
|
||||
challengeRemoveFn: async () => {},
|
||||
});
|
||||
```
|
||||
<a name="Client"></a>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<dd><p>Get a JSON Web Key derived from a RSA or ECDSA key</p>
|
||||
<p><a href="https://datatracker.ietf.org/doc/html/rfc7517">https://datatracker.ietf.org/doc/html/rfc7517</a></p>
|
||||
</dd>
|
||||
<dt><a href="#splitPemChain">splitPemChain(chainPem)</a> ⇒ <code>array</code></dt>
|
||||
<dt><a href="#splitPemChain">splitPemChain(chainPem)</a> ⇒ <code>Array.<string></code></dt>
|
||||
<dd><p>Split chain of PEM encoded objects from string into array</p>
|
||||
</dd>
|
||||
<dt><a href="#getPemBodyAsB64u">getPemBodyAsB64u(pem)</a> ⇒ <code>string</code></dt>
|
||||
@@ -42,6 +42,13 @@ If multiple certificates are chained, the first will be read</p>
|
||||
<dt><a href="#createCsr">createCsr(data, [keyPem])</a> ⇒ <code>Promise.<Array.<buffer>></code></dt>
|
||||
<dd><p>Create a Certificate Signing Request</p>
|
||||
</dd>
|
||||
<dt><a href="#createAlpnCertificate">createAlpnCertificate(authz, keyAuthorization, [keyPem])</a> ⇒ <code>Promise.<Array.<buffer>></code></dt>
|
||||
<dd><p>Create a self-signed ALPN certificate for TLS-ALPN-01 challenges</p>
|
||||
<p><a href="https://datatracker.ietf.org/doc/html/rfc8737">https://datatracker.ietf.org/doc/html/rfc8737</a></p>
|
||||
</dd>
|
||||
<dt><a href="#isAlpnCertificateAuthorizationValid">isAlpnCertificateAuthorizationValid(certPem, keyAuthorization)</a> ⇒ <code>boolean</code></dt>
|
||||
<dd><p>Validate that a ALPN certificate contains the expected key authorization</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<a name="crypto"></a>
|
||||
@@ -138,11 +145,11 @@ const jwk = acme.crypto.getJwk(privateKey);
|
||||
```
|
||||
<a name="splitPemChain"></a>
|
||||
|
||||
## splitPemChain(chainPem) ⇒ <code>array</code>
|
||||
## splitPemChain(chainPem) ⇒ <code>Array.<string></code>
|
||||
Split chain of PEM encoded objects from string into array
|
||||
|
||||
**Kind**: global function
|
||||
**Returns**: <code>array</code> - Array of PEM objects including headers
|
||||
**Returns**: <code>Array.<string></code> - Array of PEM objects including headers
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
@@ -219,42 +226,43 @@ Create a Certificate Signing Request
|
||||
| data | <code>object</code> | |
|
||||
| [data.keySize] | <code>number</code> | Size of newly created RSA private key modulus in bits, default: `2048` |
|
||||
| [data.commonName] | <code>string</code> | FQDN of your server |
|
||||
| [data.altNames] | <code>array</code> | SAN (Subject Alternative Names), default: `[]` |
|
||||
| [data.altNames] | <code>Array.<string></code> | SAN (Subject Alternative Names), default: `[]` |
|
||||
| [data.country] | <code>string</code> | 2 letter country code |
|
||||
| [data.state] | <code>string</code> | State or province |
|
||||
| [data.locality] | <code>string</code> | City |
|
||||
| [data.organization] | <code>string</code> | Organization name |
|
||||
| [data.organizationUnit] | <code>string</code> | Organizational unit name |
|
||||
| [data.emailAddress] | <code>string</code> | Email address |
|
||||
| [keyPem] | <code>string</code> | PEM encoded CSR private key |
|
||||
| [keyPem] | <code>buffer</code> \| <code>string</code> | PEM encoded CSR private key |
|
||||
|
||||
**Example**
|
||||
Create a Certificate Signing Request
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
Certificate Signing Request with both common and alternative names
|
||||
> *Warning*: Certificate subject common name has been [deprecated](https://letsencrypt.org/docs/glossary/#def-CN) and its use is [discouraged](https://cabforum.org/uploads/BRv1.2.3.pdf).
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
keySize: 4096,
|
||||
commonName: 'test.example.com',
|
||||
altNames: ['foo.example.com', 'bar.example.com']
|
||||
altNames: ['foo.example.com', 'bar.example.com'],
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
Certificate Signing Request with additional information
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
commonName: 'test.example.com',
|
||||
altNames: ['test.example.com'],
|
||||
country: 'US',
|
||||
state: 'California',
|
||||
locality: 'Los Angeles',
|
||||
organization: 'The Company Inc.',
|
||||
organizationUnit: 'IT Department',
|
||||
emailAddress: 'contact@example.com'
|
||||
emailAddress: 'contact@example.com',
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
@@ -263,5 +271,46 @@ Certificate Signing Request with ECDSA private key
|
||||
const certificateKey = await acme.crypto.createPrivateEcdsaKey();
|
||||
|
||||
const [, certificateRequest] = await acme.crypto.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
}, certificateKey);
|
||||
```
|
||||
<a name="createAlpnCertificate"></a>
|
||||
|
||||
## createAlpnCertificate(authz, keyAuthorization, [keyPem]) ⇒ <code>Promise.<Array.<buffer>></code>
|
||||
Create a self-signed ALPN certificate for TLS-ALPN-01 challenges
|
||||
|
||||
https://datatracker.ietf.org/doc/html/rfc8737
|
||||
|
||||
**Kind**: global function
|
||||
**Returns**: <code>Promise.<Array.<buffer>></code> - [privateKey, certificate]
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| authz | <code>object</code> | Identifier authorization |
|
||||
| keyAuthorization | <code>string</code> | Challenge key authorization |
|
||||
| [keyPem] | <code>buffer</code> \| <code>string</code> | PEM encoded CSR private key |
|
||||
|
||||
**Example**
|
||||
Create a ALPN certificate
|
||||
```js
|
||||
const [alpnKey, alpnCertificate] = await acme.crypto.createAlpnCertificate(authz, keyAuthorization);
|
||||
```
|
||||
**Example**
|
||||
Create a ALPN certificate with ECDSA private key
|
||||
```js
|
||||
const alpnKey = await acme.crypto.createPrivateEcdsaKey();
|
||||
const [, alpnCertificate] = await acme.crypto.createAlpnCertificate(authz, keyAuthorization, alpnKey);
|
||||
```
|
||||
<a name="isAlpnCertificateAuthorizationValid"></a>
|
||||
|
||||
## isAlpnCertificateAuthorizationValid(certPem, keyAuthorization) ⇒ <code>boolean</code>
|
||||
Validate that a ALPN certificate contains the expected key authorization
|
||||
|
||||
**Kind**: global function
|
||||
**Returns**: <code>boolean</code> - True when valid
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| certPem | <code>buffer</code> \| <code>string</code> | PEM encoded certificate |
|
||||
| keyAuthorization | <code>string</code> | Expected challenge key authorization |
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ Create a Certificate Signing Request
|
||||
| data | <code>object</code> | |
|
||||
| [data.keySize] | <code>number</code> | Size of newly created private key, default: `2048` |
|
||||
| [data.commonName] | <code>string</code> | |
|
||||
| [data.altNames] | <code>array</code> | default: `[]` |
|
||||
| [data.altNames] | <code>Array.<string></code> | default: `[]` |
|
||||
| [data.country] | <code>string</code> | |
|
||||
| [data.state] | <code>string</code> | |
|
||||
| [data.locality] | <code>string</code> | |
|
||||
@@ -222,29 +222,30 @@ Create a Certificate Signing Request
|
||||
Create a Certificate Signing Request
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
Certificate Signing Request with both common and alternative names
|
||||
> *Warning*: Certificate subject common name has been [deprecated](https://letsencrypt.org/docs/glossary/#def-CN) and its use is [discouraged](https://cabforum.org/uploads/BRv1.2.3.pdf).
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
keySize: 4096,
|
||||
commonName: 'test.example.com',
|
||||
altNames: ['foo.example.com', 'bar.example.com']
|
||||
altNames: ['foo.example.com', 'bar.example.com'],
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
Certificate Signing Request with additional information
|
||||
```js
|
||||
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
commonName: 'test.example.com',
|
||||
altNames: ['test.example.com'],
|
||||
country: 'US',
|
||||
state: 'California',
|
||||
locality: 'Los Angeles',
|
||||
organization: 'The Company Inc.',
|
||||
organizationUnit: 'IT Department',
|
||||
emailAddress: 'contact@example.com'
|
||||
emailAddress: 'contact@example.com',
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
@@ -253,5 +254,5 @@ Certificate Signing Request with predefined private key
|
||||
const certificateKey = await acme.forge.createPrivateKey();
|
||||
|
||||
const [, certificateRequest] = await acme.forge.createCsr({
|
||||
commonName: 'test.example.com'
|
||||
altNames: ['test.example.com'],
|
||||
}, certificateKey);
|
||||
|
||||
@@ -4,10 +4,9 @@ This document outlines the breaking changes introduced in v5 of `acme-client`, w
|
||||
|
||||
First off this release drops support for Node LTS v10, v12 and v14, and the reason for that is a new native crypto interface - more on that below. Since Node v14 is still currently in maintenance mode, `acme-client` v4 will continue to receive security updates and bugfixes until (at least) Node v14 reaches its end-of-line.
|
||||
|
||||
|
||||
## New native crypto interface
|
||||
|
||||
A new crypto interface has been introduced with v5, which you can find under `acme.crypto`. It uses native Node.js cryptography APIs to generate private keys, JSON Web Keys and signatures, and finally enables support for ECC/ECDSA (P-256, P384 and P521), both for account private keys and certificates. The [jsrsasign](https://www.npmjs.com/package/jsrsasign) module is used to handle generation and parsing of Certificate Signing Requests.
|
||||
A new crypto interface has been introduced with v5, which you can find under `acme.crypto`. It uses native Node.js cryptography APIs to generate private keys, JSON Web Keys and signatures, and finally enables support for ECC/ECDSA (P-256, P384 and P521), both for account private keys and certificates. The [@peculiar/x509](https://www.npmjs.com/package/@peculiar/x509) module is used to handle generation and parsing of Certificate Signing Requests.
|
||||
|
||||
Full documentation of `acme.crypto` can be [found here](crypto.md).
|
||||
|
||||
@@ -17,9 +16,9 @@ Below you will find a table summarizing the current `acme.forge` methods, and th
|
||||
|
||||
*Note: The now deprecated `acme.forge` interface is still available for use in v5, and will not be removed until a future major version, most likely v6. Should you not wish to change to the new interface right away, the following breaking changes will not immediately affect you.*
|
||||
|
||||
- :green_circle: = API functionality unchanged between `acme.forge` and `acme.crypto`
|
||||
- :orange_circle: = Slight API changes, like depromising or renaming, action may be required
|
||||
- :red_circle: = Breaking API changes or removal, action required if using these methods
|
||||
* :green_circle: = API functionality unchanged between `acme.forge` and `acme.crypto`
|
||||
* :orange_circle: = Slight API changes, like depromising or renaming, action may be required
|
||||
* :red_circle: = Breaking API changes or removal, action required if using these methods
|
||||
|
||||
| Deprecated `.forge` API | New `.crypto` API | State |
|
||||
| ----------------------------- | ----------------------------- | --------------------- |
|
||||
@@ -33,7 +32,6 @@ Below you will find a table summarizing the current `acme.forge` methods, and th
|
||||
| `await readCertificateInfo()` | `readCertificateInfo()` | :orange_circle: (4) |
|
||||
| `await createCsr()` | `await createCsr()` | :green_circle: |
|
||||
|
||||
|
||||
### 1. `createPublicKey` renamed and depromised
|
||||
|
||||
* The method `createPublicKey()` has been renamed to `getPublicKey()`
|
||||
@@ -49,7 +47,6 @@ const publicKey = await acme.forge.createPublicKey(privateKey);
|
||||
const publicKey = acme.crypto.getPublicKey(privateKey);
|
||||
```
|
||||
|
||||
|
||||
### 2. `getPemBody` renamed, now returns Base64URL
|
||||
|
||||
* Method `getPemBody()` has been renamed to `getPemBodyAsB64u()`
|
||||
@@ -64,7 +61,6 @@ const body = acme.forge.getPemBody(pem);
|
||||
const body = acme.crypto.getPemBodyAsB64u(pem);
|
||||
```
|
||||
|
||||
|
||||
### 3. `getModulus` and `getPublicExponent` merged into `getJwk`
|
||||
|
||||
* Methods `getModulus()` and `getPublicExponent()` have been removed
|
||||
@@ -80,7 +76,6 @@ const exp = await acme.forge.getPublicExponent(key);
|
||||
const { e, n } = acme.crypto.getJwk(key);
|
||||
```
|
||||
|
||||
|
||||
### 4. `readCsrDomains` and `readCertificateInfo` depromised
|
||||
|
||||
* Methods `readCsrDomains()` and `readCertificateInfo()` no longer return promises, but their resulting payloads directly
|
||||
|
||||
19
packages/core/acme-client/examples/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Disclaimer
|
||||
|
||||
These examples should not be used as is for any production environment, as they are just proof of concepts meant for testing and to get you started. The examples are naively written and purposefully avoids important topics since they will be specific to your application and how you choose to use `acme-client`, like for example:
|
||||
|
||||
1. **Concurrency control**
|
||||
* If implementing on-demand certificate generation
|
||||
* What happens when multiple requests hit your domain at the same time?
|
||||
* Ensure your application does not place multiple cert orders for the same domain at the same time by implementing some sort of exclusive lock
|
||||
2. **Domain allow lists**
|
||||
* If implementing on-demand certificate generation
|
||||
* What happens when someone manipulates the `ServerName` or `Host` header to your service?
|
||||
* Ensure your application is unable to place certificate orders for domains you do not intend, as this can quickly rate limit your account and cause a DoS
|
||||
3. **Clustering**
|
||||
* If using `acme-client` across a cluster of servers
|
||||
* Ensure challenge responses are known to all servers in your cluster, perhaps using a database or shared storage
|
||||
4. **Certificate and key storage**
|
||||
* Where and how should the account key be stored and read?
|
||||
* Where and how should certificates and cert keys be stored and read?
|
||||
* How and when should they be renewed?
|
||||
@@ -4,12 +4,10 @@
|
||||
|
||||
const acme = require('./../');
|
||||
|
||||
|
||||
function log(m) {
|
||||
process.stdout.write(`${m}\n`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function used to satisfy an ACME challenge
|
||||
*
|
||||
@@ -26,7 +24,6 @@ async function challengeCreateFn(authz, challenge, keyAuthorization) {
|
||||
log(keyAuthorization);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function used to remove an ACME challenge response
|
||||
*
|
||||
@@ -42,30 +39,29 @@ async function challengeRemoveFn(authz, challenge, keyAuthorization) {
|
||||
log(keyAuthorization);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
module.exports = async function() {
|
||||
module.exports = async () => {
|
||||
/* Init client */
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: await acme.crypto.createPrivateKey()
|
||||
accountKey: await acme.crypto.createPrivateKey(),
|
||||
});
|
||||
|
||||
/* Register account */
|
||||
await client.createAccount({
|
||||
termsOfServiceAgreed: true,
|
||||
contact: ['mailto:test@example.com']
|
||||
contact: ['mailto:test@example.com'],
|
||||
});
|
||||
|
||||
/* Place new order */
|
||||
const order = await client.createOrder({
|
||||
identifiers: [
|
||||
{ type: 'dns', value: 'example.com' },
|
||||
{ type: 'dns', value: '*.example.com' }
|
||||
]
|
||||
{ type: 'dns', value: '*.example.com' },
|
||||
],
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -139,8 +135,7 @@ module.exports = async function() {
|
||||
|
||||
/* Finalize order */
|
||||
const [key, csr] = await acme.crypto.createCsr({
|
||||
commonName: '*.example.com',
|
||||
altNames: ['example.com']
|
||||
altNames: ['example.com', '*.example.com'],
|
||||
});
|
||||
|
||||
const finalized = await client.finalizeOrder(order, csr);
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
// const fs = require('fs').promises;
|
||||
const acme = require('./../');
|
||||
|
||||
|
||||
function log(m) {
|
||||
process.stdout.write(`${m}\n`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function used to satisfy an ACME challenge
|
||||
*
|
||||
@@ -48,7 +46,6 @@ async function challengeCreateFn(authz, challenge, keyAuthorization) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function used to remove an ACME challenge response
|
||||
*
|
||||
@@ -81,25 +78,24 @@ async function challengeRemoveFn(authz, challenge, keyAuthorization) {
|
||||
|
||||
/* Replace this */
|
||||
log(`Would remove TXT record "${dnsRecord}" with value "${recordValue}"`);
|
||||
// await dnsProvider.removeRecord(dnsRecord, 'TXT');
|
||||
// await dnsProvider.removeRecord(dnsRecord, 'TXT', recordValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
module.exports = async function() {
|
||||
module.exports = async () => {
|
||||
/* Init client */
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: await acme.crypto.createPrivateKey()
|
||||
accountKey: await acme.crypto.createPrivateKey(),
|
||||
});
|
||||
|
||||
/* Create CSR */
|
||||
const [key, csr] = await acme.crypto.createCsr({
|
||||
commonName: 'example.com'
|
||||
altNames: ['example.com'],
|
||||
});
|
||||
|
||||
/* Certificate */
|
||||
@@ -108,7 +104,7 @@ module.exports = async function() {
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: true,
|
||||
challengeCreateFn,
|
||||
challengeRemoveFn
|
||||
challengeRemoveFn,
|
||||
});
|
||||
|
||||
/* Done */
|
||||
|
||||
21
packages/core/acme-client/examples/dns-01/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# dns-01
|
||||
|
||||
The greatest benefit of `dns-01` is that it is the only challenge type that can be used to issue ACME wildcard certificates, however it also has a few downsides. Your DNS provider needs to offer some sort of API you can use to automate adding and removing the required `TXT` DNS records. Additionally, solving DNS challenges will be much slower than the other challenge types because of DNS propagation delays.
|
||||
|
||||
## How it works
|
||||
|
||||
When solving `dns-01` challenges, you prove ownership of a domain by serving a specific payload within a specific DNS `TXT` record from the domains authoritative nameservers. The ACME authority provides the client with a token that, along with a thumbprint of your account key, is used to generate a `base64url` encoded `SHA256` digest. This payload is then placed as a `TXT` record under DNS name `_acme-challenge.$YOUR_DOMAIN`.
|
||||
|
||||
Once the order is finalized, the ACME authority will lookup your domains DNS record to verify that the payload is correct. `CNAME` and `NS` records are followed, should you wish to delegate challenge response to another DNS zone or record.
|
||||
|
||||
## Pros and cons
|
||||
|
||||
* Only challenge type that can be used to issue wildcard certificates
|
||||
* Your DNS provider needs to supply an API that can be used
|
||||
* DNS propagation time may be slow
|
||||
* Useful in instances where both port 80 and 443 are unavailable
|
||||
|
||||
## External links
|
||||
|
||||
* [https://letsencrypt.org/docs/challenge-types/#dns-01-challenge](https://letsencrypt.org/docs/challenge-types/#dns-01-challenge)
|
||||
* [https://datatracker.ietf.org/doc/html/rfc8555#section-8.4](https://datatracker.ietf.org/doc/html/rfc8555#section-8.4)
|
||||
88
packages/core/acme-client/examples/dns-01/dns-01.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Example using dns-01 challenge to generate certificates
|
||||
*
|
||||
* NOTE: This example is incomplete as the DNS challenge response implementation
|
||||
* will be specific to your DNS providers API.
|
||||
*
|
||||
* NOTE: This example does not order certificates on-demand, as solving dns-01
|
||||
* will likely be too slow for it to make sense. Instead, it orders a wildcard
|
||||
* certificate on init before starting the HTTPS server as a demonstration.
|
||||
*/
|
||||
|
||||
const https = require('https');
|
||||
const acme = require('./../../');
|
||||
|
||||
const HTTPS_SERVER_PORT = 443;
|
||||
const WILDCARD_DOMAIN = 'example.com';
|
||||
|
||||
function log(m) {
|
||||
process.stdout.write(`${(new Date()).toISOString()} ${m}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
/**
|
||||
* Initialize ACME client
|
||||
*/
|
||||
|
||||
log('Initializing ACME client');
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: await acme.crypto.createPrivateKey(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Order wildcard certificate
|
||||
*/
|
||||
|
||||
log(`Creating CSR for ${WILDCARD_DOMAIN}`);
|
||||
const [key, csr] = await acme.crypto.createCsr({
|
||||
altNames: [WILDCARD_DOMAIN, `*.${WILDCARD_DOMAIN}`],
|
||||
});
|
||||
|
||||
log(`Ordering certificate for ${WILDCARD_DOMAIN}`);
|
||||
const cert = await client.auto({
|
||||
csr,
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: true,
|
||||
challengePriority: ['dns-01'],
|
||||
challengeCreateFn: (authz, challenge, keyAuthorization) => {
|
||||
/* TODO: Implement this */
|
||||
log(`[TODO] Add TXT record key=_acme-challenge.${authz.identifier.value} value=${keyAuthorization}`);
|
||||
},
|
||||
challengeRemoveFn: (authz, challenge, keyAuthorization) => {
|
||||
/* TODO: Implement this */
|
||||
log(`[TODO] Remove TXT record key=_acme-challenge.${authz.identifier.value} value=${keyAuthorization}`);
|
||||
},
|
||||
});
|
||||
|
||||
log(`Certificate for ${WILDCARD_DOMAIN} created successfully`);
|
||||
|
||||
/**
|
||||
* HTTPS server
|
||||
*/
|
||||
|
||||
const requestListener = (req, res) => {
|
||||
log(`HTTP 200 ${req.headers.host}${req.url}`);
|
||||
res.writeHead(200);
|
||||
res.end('Hello world\n');
|
||||
};
|
||||
|
||||
const httpsServer = https.createServer({
|
||||
key,
|
||||
cert,
|
||||
}, requestListener);
|
||||
|
||||
httpsServer.listen(HTTPS_SERVER_PORT, () => {
|
||||
log(`HTTPS server listening on port ${HTTPS_SERVER_PORT}`);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
log(`[FATAL] ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
19
packages/core/acme-client/examples/fallback.crt
Normal file
@@ -0,0 +1,19 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDCTCCAfGgAwIBAgIUGwI6ZLE3HN7oRZ9BvWLde0Tsu7EwDQYJKoZIhvcNAQEL
|
||||
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIyMDgwMTAwNTMzMVoXDTIyMDgz
|
||||
MTAwNTMzMVowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF
|
||||
AAOCAQ8AMIIBCgKCAQEA4c7zSiY6OEp9xYZHY42FUfOLREm03NstZhd9IxFFePwe
|
||||
CTTirJjmi5teKQwzBmEok0SJkanJUaMsMlOHjEykWSc4SBO4QjD349Q60044i9WS
|
||||
7KHzeSqpWTG+V9jF3HOJPw843VG9hXy3ulXKcysTXzumTVQwfatCODBNkpWqMju2
|
||||
N33biLgmpqwLbDSfKXS3uSVTfoHAKGT/oRepko7/0Hwr5oEmjXEbpRWRhU09KYjH
|
||||
7jokRaiQRn0h216a0r4AKzSNGihNQtKJZIuwJvLFPMQYafsu9qBaCLPqDBXCwQWG
|
||||
aYh6Cm3kTkADKzG1LVPB/7/Uh2d4Fck/ejR9qXRK3QIDAQABo1MwUTAdBgNVHQ4E
|
||||
FgQUvyceAVDMPbW7wHwNF9px5dWfgd4wHwYDVR0jBBgwFoAUvyceAVDMPbW7wHwN
|
||||
F9px5dWfgd4wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAaYkz
|
||||
AOHrRirPwfkwjb+uMliGHfANrmak8r5VDQA73RLTQLRhMpf1yrb1uhH7p/CUYKap
|
||||
x1C8RGQAXujoQbQOslyZA7cVLA9ASSZS6Noq7NerfGBiqxeuye+x3lIIk1EOL/rH
|
||||
aBu9rrYGmlU49PlGAQSfFHkwzXti2Mp1VQv8eMOBLR49ezZIXHiPE8S3gjNymZ0G
|
||||
UA13wzZCT7SG1BLmQ/cBVASG2wvhlC8IG/4vF0Xe+boSOb1vGWUtHS+MnvvRK4n5
|
||||
TMUtrnxSQ/LA8AtobvzqgvQVKBSPLK6RzLE7I+Q9pWsbKTBqfyStuQrQFqafBOqN
|
||||
eYfPUgiID9uvfrxLvA==
|
||||
-----END CERTIFICATE-----
|
||||
28
packages/core/acme-client/examples/fallback.key
Normal file
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDhzvNKJjo4Sn3F
|
||||
hkdjjYVR84tESbTc2y1mF30jEUV4/B4JNOKsmOaLm14pDDMGYSiTRImRqclRoywy
|
||||
U4eMTKRZJzhIE7hCMPfj1DrTTjiL1ZLsofN5KqlZMb5X2MXcc4k/DzjdUb2FfLe6
|
||||
VcpzKxNfO6ZNVDB9q0I4ME2SlaoyO7Y3fduIuCamrAtsNJ8pdLe5JVN+gcAoZP+h
|
||||
F6mSjv/QfCvmgSaNcRulFZGFTT0piMfuOiRFqJBGfSHbXprSvgArNI0aKE1C0olk
|
||||
i7Am8sU8xBhp+y72oFoIs+oMFcLBBYZpiHoKbeROQAMrMbUtU8H/v9SHZ3gVyT96
|
||||
NH2pdErdAgMBAAECggEBAImI0FxQblOM45AkmmTDdPmWWjPspNGEWeF92wU55tOq
|
||||
0+yNnqa7tmg/6JkdyhJPqTQRoazr+ifUN/4rLDtDDzMSFVCpWihOxR2qTW4YjY52
|
||||
NjgU6EPbvSwLhUDiUplUcbrL3bnHqKSecxV2XYnKKdFudntRFPvmDL5GhWkL6Y8P
|
||||
9KiQaYuPf4av8PR0NlWBMiZs+CBjLlnSTMAWRYj5mRSyFSEOMT7+Lvr3TqrO2/nh
|
||||
0H30LXxrXXXuCbQXnVy3oSNf7TrathT2ADIrUUTdRHsLscvkEA35VtFQtWdJLtEg
|
||||
sso1J7viV9YDU4niPSdHPj3ubBjAExej4qCOzatsIQ0CgYEA8L5S3ojy89g7q6vB
|
||||
QuusIrjGkyM1yebDWqhEnjvlMpfrU1hCS90BM1ozZ28bjz/7PBimKL+A8BO+W0m4
|
||||
2s9YbZP5aGwo18Iq86XEdtDgWtQ3NXbYkb8F8LNtyevC/UlAI/xyIRr7hDYlr/1v
|
||||
jJg16DXiNLyk+uj4Q3EuwzNl8n8CgYEA8B5UUkOiufPtm+ZOq9AlBpIa+NYaahZM
|
||||
h52jzMTKsFB18xsZU/ufvpKvXEu1sTeCDRo3JAHmiA6AG292Zc7W+uWRtMtlmQWE
|
||||
wnoZ6hKvEkFnArLCY6Nm5Qqm1wipLwDVO3dD/CDL86siHrXK4wU7Q+bp6xbt8lDi
|
||||
itz5F7p7HKMCgYAoj8iimexlTU9wczXSsqaECyHZ9JrBc9ICWkuFZY4OYi5SEpLI
|
||||
+WmUX2Q9zyiTkDIiQ/zq7KkqygjOlLNCmqDJhZ8GCwMupxZZitp5MmQ6qXrL1URT
|
||||
+h1kGrcqyEBIMKlP5t7L2SH7eqwK5OaAh7y9bSa5v/cEF3CM3GsGlIhevQKBgBGU
|
||||
RtwW84zlnNmzDMNrY6qNe8gH9LsbktLC6cEOD0DFQz1fGIWbgGB1YL1DFbQ5uh23
|
||||
c54BPZ1sYlif2m0trXOE5xvzYCbJzqRmSAto/sQ5YY9DAxREXD4cf4ZyreAxEWtf
|
||||
Ge0VgZj/SGozKP1h3qrj9vAtJ5J79XnxH5NrJaQ9AoGBAM2rQrt8H2kizg4wMGRZ
|
||||
0G3709W7xxlbPdm+i/jFVDayJswCr0+eMm4gGyyZL3135D0fcijxytKgg3/OpOJF
|
||||
jC9vsHsE2K1ATp6eYvYjrhqJHI1m44aq/h46SfajytZQjwMT/jaApULDP2/fCBm5
|
||||
6eS2WCyHyrYJyrgoYQF56nsT
|
||||
-----END PRIVATE KEY-----
|
||||
21
packages/core/acme-client/examples/http-01/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# http-01
|
||||
|
||||
The `http-01` challenge type is the simplest to implement and should likely be your default choice, unless you either require wildcard certificates or if port 80 is unavailable for use.
|
||||
|
||||
## How it works
|
||||
|
||||
When solving `http-01` challenges, you prove ownership of a domain name by serving a specific payload from a specific URL. The ACME authority provides the client with a token that is used to generate the URL and file contents. The file must exist at `http://$YOUR_DOMAIN/.well-known/acme-challenge/$TOKEN` and contain the token and a thumbprint of your account key.
|
||||
|
||||
Once the order is finalized, the ACME authority will verify that the URL responds with the correct payload by sending HTTP requests before the challenge is valid. HTTP redirects are followed, and Let's Encrypt allows redirecting to HTTPS although this diverges from the ACME spec.
|
||||
|
||||
## Pros and cons
|
||||
|
||||
* Challenge must be satisfied using port 80 (HTTP)
|
||||
* The simplest challenge type to implement
|
||||
* Can not be used to issue wildcard certificates
|
||||
* If using multiple web servers, all of them need to respond with the correct token
|
||||
|
||||
## External links
|
||||
|
||||
* [https://letsencrypt.org/docs/challenge-types/#http-01-challenge](https://letsencrypt.org/docs/challenge-types/#http-01-challenge)
|
||||
* [https://datatracker.ietf.org/doc/html/rfc8555#section-8.3](https://datatracker.ietf.org/doc/html/rfc8555#section-8.3)
|
||||
168
packages/core/acme-client/examples/http-01/http-01.js
Normal file
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Example using http-01 challenge to generate certificates on-demand
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const tls = require('tls');
|
||||
const acme = require('./../../');
|
||||
|
||||
const HTTP_SERVER_PORT = 80;
|
||||
const HTTPS_SERVER_PORT = 443;
|
||||
const VALID_DOMAINS = ['example.com', 'example.org'];
|
||||
const FALLBACK_KEY = fs.readFileSync(path.join(__dirname, '..', 'fallback.key'));
|
||||
const FALLBACK_CERT = fs.readFileSync(path.join(__dirname, '..', 'fallback.crt'));
|
||||
|
||||
const pendingDomains = {};
|
||||
const challengeResponses = {};
|
||||
const certificateStore = {};
|
||||
|
||||
function log(m) {
|
||||
process.stdout.write(`${(new Date()).toISOString()} ${m}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* On-demand certificate generation using http-01
|
||||
*/
|
||||
|
||||
async function getCertOnDemand(client, servername, attempt = 0) {
|
||||
/* Invalid domain */
|
||||
if (!VALID_DOMAINS.includes(servername)) {
|
||||
throw new Error(`Invalid domain: ${servername}`);
|
||||
}
|
||||
|
||||
/* Certificate exists */
|
||||
if (servername in certificateStore) {
|
||||
return certificateStore[servername];
|
||||
}
|
||||
|
||||
/* Waiting on certificate order to go through */
|
||||
if (servername in pendingDomains) {
|
||||
if (attempt >= 10) {
|
||||
throw new Error(`Gave up waiting on certificate for ${servername}`);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => { setTimeout(resolve, 1000); });
|
||||
return getCertOnDemand(client, servername, (attempt + 1));
|
||||
}
|
||||
|
||||
/* Create CSR */
|
||||
log(`Creating CSR for ${servername}`);
|
||||
const [key, csr] = await acme.crypto.createCsr({
|
||||
altNames: [servername],
|
||||
});
|
||||
|
||||
/* Order certificate */
|
||||
log(`Ordering certificate for ${servername}`);
|
||||
const cert = await client.auto({
|
||||
csr,
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: true,
|
||||
challengePriority: ['http-01'],
|
||||
challengeCreateFn: (authz, challenge, keyAuthorization) => {
|
||||
challengeResponses[challenge.token] = keyAuthorization;
|
||||
},
|
||||
challengeRemoveFn: (authz, challenge) => {
|
||||
delete challengeResponses[challenge.token];
|
||||
},
|
||||
});
|
||||
|
||||
/* Done, store certificate */
|
||||
log(`Certificate for ${servername} created successfully`);
|
||||
certificateStore[servername] = [key, cert];
|
||||
delete pendingDomains[servername];
|
||||
return certificateStore[servername];
|
||||
}
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
/**
|
||||
* Initialize ACME client
|
||||
*/
|
||||
|
||||
log('Initializing ACME client');
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: await acme.crypto.createPrivateKey(),
|
||||
});
|
||||
|
||||
/**
|
||||
* HTTP server
|
||||
*/
|
||||
|
||||
const httpServer = http.createServer((req, res) => {
|
||||
if (req.url.match(/\/\.well-known\/acme-challenge\/.+/)) {
|
||||
const token = req.url.split('/').pop();
|
||||
log(`Received challenge request for token=${token}`);
|
||||
|
||||
/* ACME challenge response */
|
||||
if (token in challengeResponses) {
|
||||
log(`Serving challenge response HTTP 200 token=${token}`);
|
||||
res.writeHead(200);
|
||||
res.end(challengeResponses[token]);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Challenge response not found */
|
||||
log(`Oops, challenge response not found for token=${token}`);
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
/* HTTP 302 redirect */
|
||||
log(`HTTP 302 ${req.headers.host}${req.url}`);
|
||||
res.writeHead(302, { Location: `https://${req.headers.host}${req.url}` });
|
||||
res.end();
|
||||
});
|
||||
|
||||
httpServer.listen(HTTP_SERVER_PORT, () => {
|
||||
log(`HTTP server listening on port ${HTTP_SERVER_PORT}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* HTTPS server
|
||||
*/
|
||||
|
||||
const requestListener = (req, res) => {
|
||||
log(`HTTP 200 ${req.headers.host}${req.url}`);
|
||||
res.writeHead(200);
|
||||
res.end('Hello world\n');
|
||||
};
|
||||
|
||||
const httpsServer = https.createServer({
|
||||
/* Fallback certificate */
|
||||
key: FALLBACK_KEY,
|
||||
cert: FALLBACK_CERT,
|
||||
|
||||
/* Serve certificate based on servername */
|
||||
SNICallback: async (servername, cb) => {
|
||||
try {
|
||||
log(`Handling SNI request for ${servername}`);
|
||||
const [key, cert] = await getCertOnDemand(client, servername);
|
||||
|
||||
log(`Found certificate for ${servername}, serving secure context`);
|
||||
cb(null, tls.createSecureContext({ key, cert }));
|
||||
}
|
||||
catch (e) {
|
||||
log(`[ERROR] ${e.message}`);
|
||||
cb(e.message);
|
||||
}
|
||||
},
|
||||
}, requestListener);
|
||||
|
||||
httpsServer.listen(HTTPS_SERVER_PORT, () => {
|
||||
log(`HTTPS server listening on port ${HTTPS_SERVER_PORT}`);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
log(`[FATAL] ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
44
packages/core/acme-client/examples/tls-alpn-01/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# tls-alpn-01
|
||||
|
||||
Responding to `tls-alpn-01` challenges using Node.js is a bit more involved than the other two challenge types, and requires a proxy (f.ex. [Nginx](https://nginx.org) or [HAProxy](https://www.haproxy.org)) in front of the Node.js service. The reason for this is that `tls-alpn-01` is solved by responding to the ACME challenge using self-signed certificates with an ALPN extension containing the challenge response.
|
||||
|
||||
Since we don't want users of our application to be served with these self-signed certificates, we need to split the HTTPS traffic into two different Node.js backends - one that only serves ALPN certificates for challenge responses, and the other for actual end-user traffic that serves certificates retrieved from the ACME provider. As far as I *(library author)* know, routing HTTPS traffic based on ALPN protocol can not be done purely using Node.js.
|
||||
|
||||
The end result should look something like this:
|
||||
|
||||
```text
|
||||
Nginx or HAProxy (0.0.0.0:443)
|
||||
*inspect requests SSL ALPN protocol*
|
||||
If ALPN == acme-tls/1
|
||||
-> Node.js ALPN responder (127.0.0.1:4444)
|
||||
Else
|
||||
-> Node.js HTTPS server (127.0.0.1:4443)
|
||||
```
|
||||
|
||||
Example proxy configuration:
|
||||
|
||||
* [haproxy.cfg](haproxy.cfg) *(requires HAProxy >= v1.9.1)*
|
||||
* [nginx.conf](nginx.conf) *(requires [ngx_stream_ssl_preread_module](https://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html))*
|
||||
|
||||
Big thanks to [acme.sh](https://github.com/acmesh-official/acme.sh) and [dehydrated](https://github.com/dehydrated-io/dehydrated) for doing the legwork and providing Nginx and HAProxy config examples.
|
||||
|
||||
## How it works
|
||||
|
||||
When solving `tls-alpn-01` challenges, you prove ownership of a domain name by serving a specially crafted certificate over HTTPS. The ACME authority provides the client with a token that is placed into the certificates `id-pe-acmeIdentifier` extension along with a thumbprint of your account key.
|
||||
|
||||
Once the order is finalized, the ACME authority will verify by sending HTTPS requests to your domain with the `acme-tls/1` ALPN protocol, indicating to the server that it should serve the challenge response certificate. If the `id-pe-acmeIdentifier` extension contains the correct payload, the challenge is valid.
|
||||
|
||||
## Pros and cons
|
||||
|
||||
* Challenge must be satisfied using port 443 (HTTPS)
|
||||
* Useful in instances where port 80 is unavailable
|
||||
* Can not be used to issue wildcard certificates
|
||||
* More complex than `http-01`, can not be solved purely using Node.js
|
||||
* If using multiple web servers, all of them need to respond with the correct certificate
|
||||
|
||||
## External links
|
||||
|
||||
* [https://letsencrypt.org/docs/challenge-types/#tls-alpn-01](https://letsencrypt.org/docs/challenge-types/#tls-alpn-01)
|
||||
* [https://github.com/dehydrated-io/dehydrated/blob/master/docs/tls-alpn.md](https://github.com/dehydrated-io/dehydrated/blob/master/docs/tls-alpn.md)
|
||||
* [https://github.com/acmesh-official/acme.sh/wiki/TLS-ALPN-without-downtime](https://github.com/acmesh-official/acme.sh/wiki/TLS-ALPN-without-downtime)
|
||||
* [https://datatracker.ietf.org/doc/html/rfc8737](https://datatracker.ietf.org/doc/html/rfc8737)
|
||||
23
packages/core/acme-client/examples/tls-alpn-01/haproxy.cfg
Normal file
@@ -0,0 +1,23 @@
|
||||
##
|
||||
# HTTPS listener
|
||||
# - Send to ALPN responder port 4444 if protocol is acme-tls/1
|
||||
# - Default to HTTPS backend port 4443
|
||||
##
|
||||
|
||||
frontend https
|
||||
mode tcp
|
||||
bind :443
|
||||
tcp-request inspect-delay 5s
|
||||
tcp-request content accept if { req_ssl_hello_type 1 }
|
||||
use_backend alpnresp if { req.ssl_alpn acme-tls/1 }
|
||||
default_backend https
|
||||
|
||||
# Default HTTPS backend
|
||||
backend https
|
||||
mode tcp
|
||||
server https 127.0.0.1:4443
|
||||
|
||||
# ACME tls-alpn-01 responder backend
|
||||
backend alpnresp
|
||||
mode tcp
|
||||
server acmesh 127.0.0.1:4444
|
||||
19
packages/core/acme-client/examples/tls-alpn-01/nginx.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
##
|
||||
# HTTPS server
|
||||
# - Send to ALPN responder port 4444 if protocol is acme-tls/1
|
||||
# - Default to HTTPS backend port 4443
|
||||
##
|
||||
|
||||
stream {
|
||||
map $ssl_preread_alpn_protocols $tls_port {
|
||||
~\bacme-tls/1\b 4444;
|
||||
default 4443;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443;
|
||||
listen [::]:443;
|
||||
proxy_pass 127.0.0.1:$tls_port;
|
||||
ssl_preread on;
|
||||
}
|
||||
}
|
||||
176
packages/core/acme-client/examples/tls-alpn-01/tls-alpn-01.js
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* Example using tls-alpn-01 challenge to generate certificates on-demand
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const tls = require('tls');
|
||||
const acme = require('./../../');
|
||||
|
||||
const HTTPS_SERVER_PORT = 4443;
|
||||
const ALPN_RESPONDER_PORT = 4444;
|
||||
const VALID_DOMAINS = ['example.com', 'example.org'];
|
||||
const FALLBACK_KEY = fs.readFileSync(path.join(__dirname, '..', 'fallback.key'));
|
||||
const FALLBACK_CERT = fs.readFileSync(path.join(__dirname, '..', 'fallback.crt'));
|
||||
|
||||
const pendingDomains = {};
|
||||
const alpnResponses = {};
|
||||
const certificateStore = {};
|
||||
|
||||
function log(m) {
|
||||
process.stdout.write(`${(new Date()).toISOString()} ${m}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* On-demand certificate generation using tls-alpn-01
|
||||
*/
|
||||
|
||||
async function getCertOnDemand(client, servername, attempt = 0) {
|
||||
/* Invalid domain */
|
||||
if (!VALID_DOMAINS.includes(servername)) {
|
||||
throw new Error(`Invalid domain: ${servername}`);
|
||||
}
|
||||
|
||||
/* Certificate exists */
|
||||
if (servername in certificateStore) {
|
||||
return certificateStore[servername];
|
||||
}
|
||||
|
||||
/* Waiting on certificate order to go through */
|
||||
if (servername in pendingDomains) {
|
||||
if (attempt >= 10) {
|
||||
throw new Error(`Gave up waiting on certificate for ${servername}`);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => { setTimeout(resolve, 1000); });
|
||||
return getCertOnDemand(client, servername, (attempt + 1));
|
||||
}
|
||||
|
||||
/* Create CSR */
|
||||
log(`Creating CSR for ${servername}`);
|
||||
const [key, csr] = await acme.crypto.createCsr({
|
||||
altNames: [servername],
|
||||
});
|
||||
|
||||
/* Order certificate */
|
||||
log(`Ordering certificate for ${servername}`);
|
||||
const cert = await client.auto({
|
||||
csr,
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: true,
|
||||
challengePriority: ['tls-alpn-01'],
|
||||
challengeCreateFn: async (authz, challenge, keyAuthorization) => {
|
||||
alpnResponses[authz.identifier.value] = await acme.crypto.createAlpnCertificate(authz, keyAuthorization);
|
||||
},
|
||||
challengeRemoveFn: (authz) => {
|
||||
delete alpnResponses[authz.identifier.value];
|
||||
},
|
||||
});
|
||||
|
||||
/* Done, store certificate */
|
||||
log(`Certificate for ${servername} created successfully`);
|
||||
certificateStore[servername] = [key, cert];
|
||||
delete pendingDomains[servername];
|
||||
return certificateStore[servername];
|
||||
}
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
/**
|
||||
* Initialize ACME client
|
||||
*/
|
||||
|
||||
log('Initializing ACME client');
|
||||
const client = new acme.Client({
|
||||
directoryUrl: acme.directory.letsencrypt.staging,
|
||||
accountKey: await acme.crypto.createPrivateKey(),
|
||||
});
|
||||
|
||||
/**
|
||||
* ALPN responder
|
||||
*/
|
||||
|
||||
const alpnResponder = https.createServer({
|
||||
/* Fallback cert */
|
||||
key: FALLBACK_KEY,
|
||||
cert: FALLBACK_CERT,
|
||||
|
||||
/* Allow acme-tls/1 ALPN protocol */
|
||||
ALPNProtocols: ['acme-tls/1'],
|
||||
|
||||
/* Serve ALPN certificate based on servername */
|
||||
SNICallback: async (servername, cb) => {
|
||||
try {
|
||||
log(`Handling ALPN SNI request for ${servername}`);
|
||||
if (!Object.keys(alpnResponses).includes(servername)) {
|
||||
throw new Error(`No ALPN certificate found for ${servername}`);
|
||||
}
|
||||
|
||||
/* Serve ALPN challenge response */
|
||||
log(`Found ALPN certificate for ${servername}, serving secure context`);
|
||||
cb(null, tls.createSecureContext({
|
||||
key: alpnResponses[servername][0],
|
||||
cert: alpnResponses[servername][1],
|
||||
}));
|
||||
}
|
||||
catch (e) {
|
||||
log(`[ERROR] ${e.message}`);
|
||||
cb(e.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/* Terminate once TLS handshake has been established */
|
||||
alpnResponder.on('secureConnection', (socket) => {
|
||||
socket.end();
|
||||
});
|
||||
|
||||
alpnResponder.listen(ALPN_RESPONDER_PORT, () => {
|
||||
log(`ALPN responder listening on port ${ALPN_RESPONDER_PORT}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* HTTPS server
|
||||
*/
|
||||
|
||||
const requestListener = (req, res) => {
|
||||
log(`HTTP 200 ${req.headers.host}${req.url}`);
|
||||
res.writeHead(200);
|
||||
res.end('Hello world\n');
|
||||
};
|
||||
|
||||
const httpsServer = https.createServer({
|
||||
/* Fallback cert */
|
||||
key: FALLBACK_KEY,
|
||||
cert: FALLBACK_CERT,
|
||||
|
||||
/* Serve certificate based on servername */
|
||||
SNICallback: async (servername, cb) => {
|
||||
try {
|
||||
log(`Handling SNI request for ${servername}`);
|
||||
const [key, cert] = await getCertOnDemand(client, servername);
|
||||
|
||||
log(`Found certificate for ${servername}, serving secure context`);
|
||||
cb(null, tls.createSecureContext({ key, cert }));
|
||||
}
|
||||
catch (e) {
|
||||
log(`[ERROR] ${e.message}`);
|
||||
cb(e.message);
|
||||
}
|
||||
},
|
||||
}, requestListener);
|
||||
|
||||
httpsServer.listen(HTTPS_SERVER_PORT, () => {
|
||||
log(`HTTPS server listening on port ${HTTPS_SERVER_PORT}`);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
log(`[FATAL] ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
@@ -3,9 +3,9 @@
|
||||
"description": "Simple and unopinionated ACME client",
|
||||
"private": false,
|
||||
"author": "nmorsman",
|
||||
"version": "1.0.5",
|
||||
"version": "1.20.16",
|
||||
"main": "src/index.js",
|
||||
"types": "types",
|
||||
"types": "types/index.d.ts",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/publishlab/node-acme-client",
|
||||
"engines": {
|
||||
@@ -16,32 +16,33 @@
|
||||
"types"
|
||||
],
|
||||
"dependencies": {
|
||||
"axios": "0.27.2",
|
||||
"@peculiar/x509": "^1.10.0",
|
||||
"asn1js": "^3.0.5",
|
||||
"axios": "^1.7.2",
|
||||
"debug": "^4.1.1",
|
||||
"jsrsasign": "^10.5.26",
|
||||
"https-proxy-agent": "^7.0.4",
|
||||
"node-forge": "^1.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.6.1",
|
||||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"dtslint": "^4.2.1",
|
||||
"eslint": "^8.11.0",
|
||||
"@types/node": "^20.12.12",
|
||||
"chai": "^4.4.1",
|
||||
"chai-as-promised": "^7.1.2",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
"mocha": "^10.0.0",
|
||||
"nock": "^13.2.4",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"jsdoc-to-markdown": "^8.0.1",
|
||||
"mocha": "^10.4.0",
|
||||
"nock": "^13.5.4",
|
||||
"tsd": "^0.31.0",
|
||||
"typescript": "^4.8.4",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build-docs": "jsdoc2md src/client.js > docs/client.md && jsdoc2md src/crypto/index.js > docs/crypto.md && jsdoc2md src/crypto/forge.js > docs/forge.md",
|
||||
"lint": "eslint .",
|
||||
"lint-types": "dtslint types",
|
||||
"lint-types": "tsd",
|
||||
"prepublishOnly": "npm run build-docs",
|
||||
"test": "mocha -t 60000 \"test/setup.js\" \"test/**/*.spec.js\"",
|
||||
"test-local": "/bin/bash scripts/run-tests.sh"
|
||||
"test": "mocha -t 60000 \"test/setup.js\" \"test/**/*.spec.js\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -58,5 +59,5 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/publishlab/node-acme-client/issues"
|
||||
},
|
||||
"gitHead": "5950e1cae7cf30ebfc5128c15c7d1b0d101cbbb8"
|
||||
"gitHead": "a31f1c7f5e71fa946de9bf0283e11d6ce049b3e9"
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Run test suite locally using CircleCI CLI.
|
||||
#
|
||||
set -eu
|
||||
|
||||
JOBS=("$@")
|
||||
|
||||
CIRCLECI_CLI_URL="https://github.com/CircleCI-Public/circleci-cli/releases/download/v0.1.16947/circleci-cli_0.1.16947_linux_amd64.tar.gz"
|
||||
CIRCLECI_CLI_SHASUM="c6f9a3276445c69ae40439acfed07e2c53502216a96bfacc4556e1d862d1019a"
|
||||
CIRCLECI_CLI_PATH="/tmp/circleci-cli"
|
||||
CIRCLECI_CLI_BIN="${CIRCLECI_CLI_PATH}/circleci"
|
||||
|
||||
PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && cd .. && pwd )"
|
||||
CONFIG_PATH="${PROJECT_DIR}/.circleci/.temp.yml"
|
||||
|
||||
# Run all jobs by default
|
||||
if [[ ${#JOBS[@]} -eq 0 ]]; then
|
||||
JOBS=(
|
||||
"v16"
|
||||
"v18"
|
||||
"eab-v16"
|
||||
"eab-v18"
|
||||
)
|
||||
fi
|
||||
|
||||
# Download CircleCI CLI
|
||||
if [[ ! -f "${CIRCLECI_CLI_BIN}" ]]; then
|
||||
echo "[-] Downloading CircleCI cli"
|
||||
mkdir -p "${CIRCLECI_CLI_PATH}"
|
||||
wget -nv "${CIRCLECI_CLI_URL}" -O "${CIRCLECI_CLI_PATH}/circleci-cli.tar.gz"
|
||||
echo "${CIRCLECI_CLI_SHASUM} *${CIRCLECI_CLI_PATH}/circleci-cli.tar.gz" | sha256sum -c
|
||||
tar zxvf "${CIRCLECI_CLI_PATH}/circleci-cli.tar.gz" -C "${CIRCLECI_CLI_PATH}" --strip-components=1
|
||||
fi
|
||||
|
||||
# Skip CircleCI update checks
|
||||
export CIRCLECI_CLI_SKIP_UPDATE_CHECK="true"
|
||||
|
||||
# Run test suite
|
||||
echo "[-] Running test suite"
|
||||
$CIRCLECI_CLI_BIN config process "${PROJECT_DIR}/.circleci/config.yml" > "${CONFIG_PATH}"
|
||||
$CIRCLECI_CLI_BIN config validate -c "${CONFIG_PATH}"
|
||||
|
||||
for job in "${JOBS[@]}"; do
|
||||
echo "[-] Running job: ${job}"
|
||||
$CIRCLECI_CLI_BIN local execute -c "${CONFIG_PATH}" --job "${job}" --skip-checkout
|
||||
echo "[+] ${job} completed successfully"
|
||||
done
|
||||
|
||||
# Clean up
|
||||
if [[ -f "${CONFIG_PATH}" ]]; then
|
||||
rm "${CONFIG_PATH}"
|
||||
fi
|
||||
|
||||
echo "[+] Test suite ran successfully!"
|
||||
exit 0
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Install and init step-ca for testing.
|
||||
#
|
||||
set -eu
|
||||
|
||||
# Download and install
|
||||
wget -nv "https://dl.step.sm/gh-release/certificates/gh-release-header/v${STEPCA_VERSION}/step-ca_${STEPCA_VERSION}_amd64.deb" -O /tmp/step-ca.deb
|
||||
wget -nv "https://dl.step.sm/gh-release/cli/gh-release-header/v${STEPCLI_VERSION}/step-cli_${STEPCLI_VERSION}_amd64.deb" -O /tmp/step-cli.deb
|
||||
|
||||
sudo dpkg -i /tmp/step-ca.deb
|
||||
sudo dpkg -i /tmp/step-cli.deb
|
||||
|
||||
# Initialize
|
||||
echo "hunter2" > /tmp/password
|
||||
|
||||
step ca init --name="Example Inc." --dns="localhost" --address="127.0.0.1:8443" --provisioner="test@example.com" --password-file="/tmp/password"
|
||||
step ca provisioner add acme --type ACME
|
||||
|
||||
exit 0
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
const util = require('./util');
|
||||
|
||||
|
||||
/**
|
||||
* AcmeApi
|
||||
*
|
||||
@@ -18,7 +17,6 @@ class AcmeApi {
|
||||
this.accountUrl = accountUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get account URL
|
||||
*
|
||||
@@ -34,14 +32,13 @@ class AcmeApi {
|
||||
return this.accountUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ACME API request
|
||||
*
|
||||
* @private
|
||||
* @param {string} url Request URL
|
||||
* @param {object} [payload] Request payload, default: `null`
|
||||
* @param {array} [validStatusCodes] Array of valid HTTP response status codes, default: `[]`
|
||||
* @param {number[]} [validStatusCodes] Array of valid HTTP response status codes, default: `[]`
|
||||
* @param {object} [opts]
|
||||
* @param {boolean} [opts.includeJwsKid] Include KID instead of JWK in JWS header, default: `true`
|
||||
* @param {boolean} [opts.includeExternalAccountBinding] Include EAB in request, default: `false`
|
||||
@@ -59,14 +56,13 @@ class AcmeApi {
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ACME API request by resource name helper
|
||||
*
|
||||
* @private
|
||||
* @param {string} resource Request resource name
|
||||
* @param {object} [payload] Request payload, default: `null`
|
||||
* @param {array} [validStatusCodes] Array of valid HTTP response status codes, default: `[]`
|
||||
* @param {number[]} [validStatusCodes] Array of valid HTTP response status codes, default: `[]`
|
||||
* @param {object} [opts]
|
||||
* @param {boolean} [opts.includeJwsKid] Include KID instead of JWK in JWS header, default: `true`
|
||||
* @param {boolean} [opts.includeExternalAccountBinding] Include EAB in request, default: `false`
|
||||
@@ -78,11 +74,10 @@ class AcmeApi {
|
||||
return this.apiRequest(resourceUrl, payload, validStatusCodes, { includeJwsKid, includeExternalAccountBinding });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Terms of Service URL if available
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.1.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.1
|
||||
*
|
||||
* @returns {Promise<string|null>} ToS URL
|
||||
*/
|
||||
@@ -91,11 +86,10 @@ class AcmeApi {
|
||||
return this.http.getMetaField('termsOfService');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new account
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3
|
||||
*
|
||||
* @param {object} data Request payload
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -104,7 +98,7 @@ class AcmeApi {
|
||||
async createAccount(data) {
|
||||
const resp = await this.apiResourceRequest('newAccount', data, [200, 201], {
|
||||
includeJwsKid: false,
|
||||
includeExternalAccountBinding: (data.onlyReturnExisting !== true)
|
||||
includeExternalAccountBinding: (data.onlyReturnExisting !== true),
|
||||
});
|
||||
|
||||
/* Set account URL */
|
||||
@@ -115,11 +109,10 @@ class AcmeApi {
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update account
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.2
|
||||
*
|
||||
* @param {object} data Request payload
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -129,11 +122,10 @@ class AcmeApi {
|
||||
return this.apiRequest(this.getAccountUrl(), data, [200, 202]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update account key
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3.5
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.5
|
||||
*
|
||||
* @param {object} data Request payload
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -143,11 +135,10 @@ class AcmeApi {
|
||||
return this.apiResourceRequest('keyChange', data, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {object} data Request payload
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -157,11 +148,10 @@ class AcmeApi {
|
||||
return this.apiResourceRequest('newOrder', data, [201]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {string} url Order URL
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -171,11 +161,10 @@ class AcmeApi {
|
||||
return this.apiRequest(url, null, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finalize order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {string} url Finalization URL
|
||||
* @param {object} data Request payload
|
||||
@@ -186,11 +175,10 @@ class AcmeApi {
|
||||
return this.apiRequest(url, data, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get identifier authorization
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5
|
||||
*
|
||||
* @param {string} url Authorization URL
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -200,11 +188,10 @@ class AcmeApi {
|
||||
return this.apiRequest(url, null, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update identifier authorization
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.2
|
||||
*
|
||||
* @param {string} url Authorization URL
|
||||
* @param {object} data Request payload
|
||||
@@ -215,11 +202,10 @@ class AcmeApi {
|
||||
return this.apiRequest(url, data, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Complete challenge
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1
|
||||
*
|
||||
* @param {string} url Challenge URL
|
||||
* @param {object} data Request payload
|
||||
@@ -230,11 +216,10 @@ class AcmeApi {
|
||||
return this.apiRequest(url, data, [200]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Revoke certificate
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.6
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.6
|
||||
*
|
||||
* @param {object} data Request payload
|
||||
* @returns {Promise<object>} HTTP response
|
||||
@@ -245,6 +230,5 @@ class AcmeApi {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Export API */
|
||||
module.exports = AcmeApi;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
const { readCsrDomains } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
const { wait } = require('./wait');
|
||||
|
||||
const defaultOpts = {
|
||||
csr: null,
|
||||
@@ -13,10 +14,9 @@ const defaultOpts = {
|
||||
skipChallengeVerification: false,
|
||||
challengePriority: ['http-01', 'dns-01'],
|
||||
challengeCreateFn: async () => { throw new Error('Missing challengeCreateFn()'); },
|
||||
challengeRemoveFn: async () => { throw new Error('Missing challengeRemoveFn()'); }
|
||||
challengeRemoveFn: async () => { throw new Error('Missing challengeRemoveFn()'); },
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ACME client auto mode
|
||||
*
|
||||
@@ -25,8 +25,8 @@ const defaultOpts = {
|
||||
* @returns {Promise<buffer>} Certificate
|
||||
*/
|
||||
|
||||
module.exports = async function(client, userOpts) {
|
||||
const opts = Object.assign({}, defaultOpts, userOpts);
|
||||
module.exports = async (client, userOpts) => {
|
||||
const opts = { ...defaultOpts, ...userOpts };
|
||||
const accountPayload = { termsOfServiceAgreed: opts.termsOfServiceAgreed };
|
||||
|
||||
if (!Buffer.isBuffer(opts.csr)) {
|
||||
@@ -37,7 +37,6 @@ module.exports = async function(client, userOpts) {
|
||||
accountPayload.contact = [`mailto:${opts.email}`];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register account
|
||||
*/
|
||||
@@ -53,19 +52,16 @@ module.exports = async function(client, userOpts) {
|
||||
await client.createAccount(accountPayload);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse domains from CSR
|
||||
*/
|
||||
|
||||
log('[auto] Parsing domains from Certificate Signing Request');
|
||||
const csrDomains = readCsrDomains(opts.csr);
|
||||
const domains = [csrDomains.commonName].concat(csrDomains.altNames);
|
||||
const uniqueDomains = Array.from(new Set(domains));
|
||||
const { commonName, altNames } = readCsrDomains(opts.csr);
|
||||
const uniqueDomains = Array.from(new Set([commonName].concat(altNames).filter((d) => d)));
|
||||
|
||||
log(`[auto] Resolved ${uniqueDomains.length} unique domains from parsing the Certificate Signing Request`);
|
||||
|
||||
|
||||
/**
|
||||
* Place order
|
||||
*/
|
||||
@@ -77,13 +73,14 @@ module.exports = async function(client, userOpts) {
|
||||
|
||||
log(`[auto] Placed certificate order successfully, received ${authorizations.length} identity authorizations`);
|
||||
|
||||
|
||||
/**
|
||||
* Resolve and satisfy challenges
|
||||
*/
|
||||
|
||||
log('[auto] Resolving and satisfying authorization challenges');
|
||||
|
||||
const clearTasks = [];
|
||||
|
||||
const challengeFunc = async (authz) => {
|
||||
const d = authz.identifier.value;
|
||||
let challengeCompleted = false;
|
||||
@@ -117,7 +114,19 @@ module.exports = async function(client, userOpts) {
|
||||
let recordItem = null;
|
||||
try {
|
||||
recordItem = await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
||||
|
||||
log(`[auto] [${d}] challengeCreateFn success`);
|
||||
log(`[auto] [${d}] add challengeRemoveFn()`);
|
||||
clearTasks.push(async () => {
|
||||
/* Trigger challengeRemoveFn(), suppress errors */
|
||||
log(`[auto] [${d}] Trigger challengeRemoveFn()`);
|
||||
try {
|
||||
await opts.challengeRemoveFn(authz, challenge, keyAuthorization, recordItem);
|
||||
}
|
||||
catch (e) {
|
||||
log(`[auto] [${d}] challengeRemoveFn threw error: ${e.message}`);
|
||||
}
|
||||
});
|
||||
// throw new Error('测试异常');
|
||||
/* Challenge verification */
|
||||
if (opts.skipChallengeVerification === true) {
|
||||
log(`[auto] [${d}] Skipping challenge verification since skipChallengeVerification=true`);
|
||||
@@ -138,17 +147,6 @@ module.exports = async function(client, userOpts) {
|
||||
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
/* Trigger challengeRemoveFn(), suppress errors */
|
||||
log(`[auto] [${d}] Trigger challengeRemoveFn()`);
|
||||
|
||||
try {
|
||||
await opts.challengeRemoveFn(authz, challenge, keyAuthorization, recordItem);
|
||||
}
|
||||
catch (e) {
|
||||
log(`[auto] [${d}] challengeRemoveFn threw error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
/* Deactivate pending authz when unable to complete challenge */
|
||||
@@ -173,27 +171,63 @@ module.exports = async function(client, userOpts) {
|
||||
await challengeFunc(authz);
|
||||
});
|
||||
|
||||
log('开始challenge');
|
||||
let promise = Promise.resolve();
|
||||
function runPromisesSerially(tasks) {
|
||||
function runAllPromise(tasks) {
|
||||
let promise = Promise.resolve();
|
||||
tasks.forEach((task) => {
|
||||
promise = promise.then(task);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
await runPromisesSerially(challengePromises);
|
||||
log('challenge结束');
|
||||
async function runPromisePa(tasks) {
|
||||
const results = [];
|
||||
// eslint-disable-next-line no-await-in-loop,no-restricted-syntax
|
||||
for (const task of tasks) {
|
||||
results.push(task());
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await wait(10000);
|
||||
}
|
||||
return Promise.all(results);
|
||||
}
|
||||
|
||||
// log('[auto] Waiting for challenge valid status');
|
||||
// await Promise.all(challengePromises);
|
||||
try {
|
||||
log('开始challenge');
|
||||
await runPromisePa(challengePromises);
|
||||
|
||||
log('challenge结束');
|
||||
|
||||
/**
|
||||
* Finalize order and download certificate
|
||||
*/
|
||||
// log('[auto] Waiting for challenge valid status');
|
||||
// await Promise.all(challengePromises);
|
||||
|
||||
log('[auto] Finalizing order and downloading certificate');
|
||||
const finalized = await client.finalizeOrder(order, opts.csr);
|
||||
return client.getCertificate(finalized, opts.preferredChain);
|
||||
/**
|
||||
* Finalize order and download certificate
|
||||
*/
|
||||
|
||||
log('[auto] Finalizing order and downloading certificate');
|
||||
const finalized = await client.finalizeOrder(order, opts.csr);
|
||||
return await client.getCertificate(finalized, opts.preferredChain);
|
||||
}
|
||||
catch (e) {
|
||||
log('证书申请失败');
|
||||
log(e);
|
||||
throw new Error(`证书申请失败:${e.message}`);
|
||||
}
|
||||
finally {
|
||||
log(`清理challenge痕迹,length:${clearTasks.length}`);
|
||||
try {
|
||||
await runAllPromise(clearTasks);
|
||||
}
|
||||
catch (e) {
|
||||
log('清理challenge失败');
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
// try {
|
||||
// await Promise.allSettled(challengePromises);
|
||||
// }
|
||||
// finally {
|
||||
// log('清理challenge');
|
||||
// await Promise.allSettled(clearTasks);
|
||||
// }
|
||||
};
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
*/
|
||||
|
||||
const axios = require('axios');
|
||||
const adapter = require('axios/lib/adapters/http');
|
||||
const pkg = require('./../package.json');
|
||||
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*/
|
||||
@@ -19,10 +17,13 @@ instance.defaults.headers.common['User-Agent'] = `node-${pkg.name}/${pkg.version
|
||||
/* Default ACME settings */
|
||||
instance.defaults.acmeSettings = {
|
||||
httpChallengePort: 80,
|
||||
bypassCustomDnsResolver: false
|
||||
httpsChallengePort: 443,
|
||||
tlsAlpnChallengePort: 443,
|
||||
};
|
||||
|
||||
|
||||
// instance.defaults.proxy = {
|
||||
// host: '192.168.34.139',
|
||||
// port: 10811
|
||||
// };
|
||||
/**
|
||||
* Explicitly set Node as default HTTP adapter
|
||||
*
|
||||
@@ -30,8 +31,7 @@ instance.defaults.acmeSettings = {
|
||||
* https://stackoverflow.com/questions/42677387
|
||||
*/
|
||||
|
||||
instance.defaults.adapter = adapter;
|
||||
|
||||
instance.defaults.adapter = 'http';
|
||||
|
||||
/**
|
||||
* Export instance
|
||||
|
||||
@@ -13,7 +13,6 @@ const verify = require('./verify');
|
||||
const util = require('./util');
|
||||
const auto = require('./auto');
|
||||
|
||||
|
||||
/**
|
||||
* ACME states
|
||||
*
|
||||
@@ -24,7 +23,6 @@ const validStates = ['ready', 'valid'];
|
||||
const pendingStates = ['pending', 'processing'];
|
||||
const invalidStates = ['invalid'];
|
||||
|
||||
|
||||
/**
|
||||
* Default options
|
||||
*
|
||||
@@ -38,10 +36,9 @@ const defaultOpts = {
|
||||
externalAccountBinding: {},
|
||||
backoffAttempts: 10,
|
||||
backoffMin: 5000,
|
||||
backoffMax: 30000
|
||||
backoffMax: 30000,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AcmeClient
|
||||
*
|
||||
@@ -61,7 +58,7 @@ const defaultOpts = {
|
||||
* ```js
|
||||
* const client = new acme.Client({
|
||||
* directoryUrl: acme.directory.letsencrypt.staging,
|
||||
* accountKey: 'Private key goes here'
|
||||
* accountKey: 'Private key goes here',
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
@@ -73,7 +70,7 @@ const defaultOpts = {
|
||||
* accountUrl: 'Optional account URL goes here',
|
||||
* backoffAttempts: 10,
|
||||
* backoffMin: 5000,
|
||||
* backoffMax: 30000
|
||||
* backoffMax: 30000,
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
@@ -84,8 +81,8 @@ const defaultOpts = {
|
||||
* accountKey: 'Private key goes here',
|
||||
* externalAccountBinding: {
|
||||
* kid: 'YOUR-EAB-KID',
|
||||
* hmacKey: 'YOUR-EAB-HMAC-KEY'
|
||||
* }
|
||||
* hmacKey: 'YOUR-EAB-HMAC-KEY',
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -96,19 +93,17 @@ class AcmeClient {
|
||||
opts.accountKey = Buffer.from(opts.accountKey);
|
||||
}
|
||||
|
||||
this.opts = Object.assign({}, defaultOpts, opts);
|
||||
|
||||
this.opts = { ...defaultOpts, ...opts };
|
||||
this.backoffOpts = {
|
||||
attempts: this.opts.backoffAttempts,
|
||||
min: this.opts.backoffMin,
|
||||
max: this.opts.backoffMax
|
||||
max: this.opts.backoffMax,
|
||||
};
|
||||
|
||||
this.http = new HttpClient(this.opts.directoryUrl, this.opts.accountKey, this.opts.externalAccountBinding);
|
||||
this.api = new AcmeApi(this.http, this.opts.accountUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Terms of Service URL if available
|
||||
*
|
||||
@@ -128,7 +123,6 @@ class AcmeClient {
|
||||
return this.api.getTermsOfServiceUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current account URL
|
||||
*
|
||||
@@ -150,11 +144,10 @@ class AcmeClient {
|
||||
return this.api.getAccountUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new account
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3
|
||||
*
|
||||
* @param {object} [data] Request data
|
||||
* @returns {Promise<object>} Account
|
||||
@@ -162,7 +155,7 @@ class AcmeClient {
|
||||
* @example Create a new account
|
||||
* ```js
|
||||
* const account = await client.createAccount({
|
||||
* termsOfServiceAgreed: true
|
||||
* termsOfServiceAgreed: true,
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
@@ -170,7 +163,7 @@ class AcmeClient {
|
||||
* ```js
|
||||
* const account = await client.createAccount({
|
||||
* termsOfServiceAgreed: true,
|
||||
* contact: ['mailto:test@example.com']
|
||||
* contact: ['mailto:test@example.com'],
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -196,11 +189,10 @@ class AcmeClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update existing account
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.2
|
||||
*
|
||||
* @param {object} [data] Request data
|
||||
* @returns {Promise<object>} Account
|
||||
@@ -208,7 +200,7 @@ class AcmeClient {
|
||||
* @example Update existing account
|
||||
* ```js
|
||||
* const account = await client.updateAccount({
|
||||
* contact: ['mailto:foo@example.com']
|
||||
* contact: ['mailto:foo@example.com'],
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -236,11 +228,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update account private key
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.3.5
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.5
|
||||
*
|
||||
* @param {buffer|string} newAccountKey New PEM encoded private key
|
||||
* @param {object} [data] Additional request data
|
||||
@@ -261,7 +252,7 @@ class AcmeClient {
|
||||
const accountUrl = this.api.getAccountUrl();
|
||||
|
||||
/* Create new HTTP and API clients using new key */
|
||||
const newHttpClient = new HttpClient(this.opts.directoryUrl, newAccountKey);
|
||||
const newHttpClient = new HttpClient(this.opts.directoryUrl, newAccountKey, this.opts.externalAccountBinding);
|
||||
const newApiClient = new AcmeApi(newHttpClient, accountUrl);
|
||||
|
||||
/* Get old JWK */
|
||||
@@ -282,11 +273,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {object} data Request data
|
||||
* @returns {Promise<object>} Order
|
||||
@@ -296,8 +286,8 @@ class AcmeClient {
|
||||
* const order = await client.createOrder({
|
||||
* identifiers: [
|
||||
* { type: 'dns', value: 'example.com' },
|
||||
* { type: 'dns', value: 'test.example.com' }
|
||||
* ]
|
||||
* { type: 'dns', value: 'test.example.com' },
|
||||
* ],
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -314,11 +304,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refresh order object from CA
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {object} order Order object
|
||||
* @returns {Promise<object>} Order
|
||||
@@ -345,7 +334,7 @@ class AcmeClient {
|
||||
/**
|
||||
* Finalize order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4
|
||||
*
|
||||
* @param {object} order Order object
|
||||
* @param {buffer|string} csr PEM encoded Certificate Signing Request
|
||||
@@ -376,11 +365,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get identifier authorizations from order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5
|
||||
*
|
||||
* @param {object} order Order
|
||||
* @returns {Promise<object[]>} Authorizations
|
||||
@@ -406,11 +394,10 @@ class AcmeClient {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deactivate identifier authorization
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.2
|
||||
*
|
||||
* @param {object} authz Identifier authorization
|
||||
* @returns {Promise<object>} Authorization
|
||||
@@ -427,10 +414,7 @@ class AcmeClient {
|
||||
throw new Error('Unable to deactivate identifier authorization, URL not found');
|
||||
}
|
||||
|
||||
const data = {
|
||||
status: 'deactivated'
|
||||
};
|
||||
|
||||
const data = { status: 'deactivated' };
|
||||
const resp = await this.api.updateAuthorization(authz.url, data);
|
||||
|
||||
/* Add URL to response */
|
||||
@@ -438,11 +422,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get key authorization for ACME challenge
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-8.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-8.1
|
||||
*
|
||||
* @param {object} challenge Challenge object returned by API
|
||||
* @returns {Promise<string>} Key authorization
|
||||
@@ -462,28 +445,24 @@ class AcmeClient {
|
||||
const thumbprint = keysum.digest('base64url');
|
||||
const result = `${challenge.token}.${thumbprint}`;
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc8555#section-8.3
|
||||
*/
|
||||
|
||||
/* https://datatracker.ietf.org/doc/html/rfc8555#section-8.3 */
|
||||
if (challenge.type === 'http-01') {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc8555#section-8.4
|
||||
* https://tools.ietf.org/html/draft-ietf-acme-tls-alpn-01
|
||||
*/
|
||||
/* https://datatracker.ietf.org/doc/html/rfc8555#section-8.4 */
|
||||
if (challenge.type === 'dns-01') {
|
||||
return createHash('sha256').update(result).digest('base64url');
|
||||
}
|
||||
|
||||
if ((challenge.type === 'dns-01') || (challenge.type === 'tls-alpn-01')) {
|
||||
const shasum = createHash('sha256').update(result);
|
||||
return shasum.digest('base64url');
|
||||
/* https://datatracker.ietf.org/doc/html/rfc8737 */
|
||||
if (challenge.type === 'tls-alpn-01') {
|
||||
return result;
|
||||
}
|
||||
|
||||
throw new Error(`Unable to produce key authorization, unknown challenge type: ${challenge.type}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify that ACME challenge is satisfied
|
||||
*
|
||||
@@ -518,11 +497,10 @@ class AcmeClient {
|
||||
return util.retry(verifyFn, this.backoffOpts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify CA that challenge has been completed
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1
|
||||
*
|
||||
* @param {object} challenge Challenge object returned by API
|
||||
* @returns {Promise<object>} Challenge
|
||||
@@ -539,11 +517,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wait for ACME provider to verify status on a order, authorization or challenge
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.5.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.1
|
||||
*
|
||||
* @param {object} item An order, authorization or challenge object
|
||||
* @returns {Promise<object>} Valid order, authorization or challenge
|
||||
@@ -554,7 +531,7 @@ class AcmeClient {
|
||||
* await client.waitForValidStatus(challenge);
|
||||
* ```
|
||||
*
|
||||
* @example Wait for valid authoriation status
|
||||
* @example Wait for valid authorization status
|
||||
* ```js
|
||||
* const authz = { ... };
|
||||
* await client.waitForValidStatus(authz);
|
||||
@@ -596,11 +573,10 @@ class AcmeClient {
|
||||
return util.retry(verifyFn, this.backoffOpts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get certificate from ACME order
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.4.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.4.2
|
||||
*
|
||||
* @param {object} order Order object
|
||||
* @param {string} [preferredChain] Indicate which certificate chain is preferred if a CA offers multiple, by exact issuer common name, default: `null`
|
||||
@@ -643,11 +619,10 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Revoke certificate
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.6
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.6
|
||||
*
|
||||
* @param {buffer|string} cert PEM encoded certificate
|
||||
* @param {object} [data] Additional request data
|
||||
@@ -663,7 +638,7 @@ class AcmeClient {
|
||||
* ```js
|
||||
* const certificate = { ... }; // Previously created certificate
|
||||
* const result = await client.revokeCertificate(certificate, {
|
||||
* reason: 4
|
||||
* reason: 4,
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -674,7 +649,6 @@ class AcmeClient {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Auto mode
|
||||
*
|
||||
@@ -692,7 +666,7 @@ class AcmeClient {
|
||||
* @example Order a certificate using auto mode
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* });
|
||||
*
|
||||
* const certificate = await client.auto({
|
||||
@@ -704,14 +678,14 @@ class AcmeClient {
|
||||
* },
|
||||
* challengeRemoveFn: async (authz, challenge, keyAuthorization) => {
|
||||
* // Clean up challenge here
|
||||
* }
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example Order a certificate using auto mode with preferred chain
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* });
|
||||
*
|
||||
* const certificate = await client.auto({
|
||||
@@ -720,7 +694,7 @@ class AcmeClient {
|
||||
* termsOfServiceAgreed: true,
|
||||
* preferredChain: 'DST Root CA X3',
|
||||
* challengeCreateFn: async () => {},
|
||||
* challengeRemoveFn: async () => {}
|
||||
* challengeRemoveFn: async () => {},
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -730,6 +704,5 @@ class AcmeClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Export client */
|
||||
module.exports = AcmeClient;
|
||||
|
||||
@@ -13,7 +13,6 @@ const forge = require('node-forge');
|
||||
|
||||
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to parse forge object from PEM encoded string
|
||||
*
|
||||
@@ -54,7 +53,6 @@ function forgeObjectFromPem(input) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse domain names from a certificate or CSR
|
||||
*
|
||||
@@ -93,11 +91,10 @@ function parseDomains(obj) {
|
||||
|
||||
return {
|
||||
commonName,
|
||||
altNames
|
||||
altNames,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a private RSA key
|
||||
*
|
||||
@@ -123,7 +120,6 @@ async function createPrivateKey(size = 2048) {
|
||||
|
||||
exports.createPrivateKey = createPrivateKey;
|
||||
|
||||
|
||||
/**
|
||||
* Create public key from a private RSA key
|
||||
*
|
||||
@@ -136,14 +132,13 @@ exports.createPrivateKey = createPrivateKey;
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.createPublicKey = async function(key) {
|
||||
exports.createPublicKey = async (key) => {
|
||||
const privateKey = forge.pki.privateKeyFromPem(key);
|
||||
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
||||
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
||||
return Buffer.from(pemKey);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse body of PEM encoded object from buffer or string
|
||||
* If multiple objects are chained, the first body will be returned
|
||||
@@ -157,7 +152,6 @@ exports.getPemBody = (str) => {
|
||||
return forge.util.encode64(msg.body);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Split chain of PEM encoded objects from buffer or string into array
|
||||
*
|
||||
@@ -167,7 +161,6 @@ exports.getPemBody = (str) => {
|
||||
|
||||
exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||
|
||||
|
||||
/**
|
||||
* Get modulus
|
||||
*
|
||||
@@ -182,7 +175,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.getModulus = async function(input) {
|
||||
exports.getModulus = async (input) => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
@@ -191,7 +184,6 @@ exports.getModulus = async function(input) {
|
||||
return Buffer.from(forge.util.hexToBytes(obj.n.toString(16)), 'binary');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get public exponent
|
||||
*
|
||||
@@ -206,7 +198,7 @@ exports.getModulus = async function(input) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.getPublicExponent = async function(input) {
|
||||
exports.getPublicExponent = async (input) => {
|
||||
if (!Buffer.isBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
@@ -215,7 +207,6 @@ exports.getPublicExponent = async function(input) {
|
||||
return Buffer.from(forge.util.hexToBytes(obj.e.toString(16)), 'binary');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read domains from a Certificate Signing Request
|
||||
*
|
||||
@@ -231,7 +222,7 @@ exports.getPublicExponent = async function(input) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.readCsrDomains = async function(csr) {
|
||||
exports.readCsrDomains = async (csr) => {
|
||||
if (!Buffer.isBuffer(csr)) {
|
||||
csr = Buffer.from(csr);
|
||||
}
|
||||
@@ -240,7 +231,6 @@ exports.readCsrDomains = async function(csr) {
|
||||
return parseDomains(obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read information from a certificate
|
||||
*
|
||||
@@ -260,7 +250,7 @@ exports.readCsrDomains = async function(csr) {
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.readCertificateInfo = async function(cert) {
|
||||
exports.readCertificateInfo = async (cert) => {
|
||||
if (!Buffer.isBuffer(cert)) {
|
||||
cert = Buffer.from(cert);
|
||||
}
|
||||
@@ -270,18 +260,17 @@ exports.readCertificateInfo = async function(cert) {
|
||||
|
||||
return {
|
||||
issuer: {
|
||||
commonName: issuerCn ? issuerCn.value : null
|
||||
commonName: issuerCn ? issuerCn.value : null,
|
||||
},
|
||||
domains: parseDomains(obj),
|
||||
notAfter: obj.validity.notAfter,
|
||||
notBefore: obj.validity.notBefore
|
||||
notBefore: obj.validity.notBefore,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine ASN.1 type for CSR subject short name
|
||||
* Note: https://tools.ietf.org/html/rfc5280
|
||||
* Note: https://datatracker.ietf.org/doc/html/rfc5280
|
||||
*
|
||||
* @private
|
||||
* @param {string} shortName CSR subject short name
|
||||
@@ -299,7 +288,6 @@ function getCsrValueTagClass(shortName) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create array of short names and values for Certificate Signing Request subjects
|
||||
*
|
||||
@@ -319,7 +307,6 @@ function createCsrSubject(subjectObj) {
|
||||
}, []);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create array of alt names for Certificate Signing Requests
|
||||
* Note: https://github.com/digitalbazaar/forge/blob/dfdde475677a8a25c851e33e8f81dca60d90cfb9/lib/x509.js#L1444-L1454
|
||||
@@ -336,14 +323,13 @@ function formatCsrAltNames(altNames) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Certificate Signing Request
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {number} [data.keySize] Size of newly created private key, default: `2048`
|
||||
* @param {string} [data.commonName]
|
||||
* @param {array} [data.altNames] default: `[]`
|
||||
* @param {string[]} [data.altNames] default: `[]`
|
||||
* @param {string} [data.country]
|
||||
* @param {string} [data.state]
|
||||
* @param {string} [data.locality]
|
||||
@@ -356,29 +342,30 @@ function formatCsrAltNames(altNames) {
|
||||
* @example Create a Certificate Signing Request
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example Certificate Signing Request with both common and alternative names
|
||||
* > *Warning*: Certificate subject common name has been [deprecated](https://letsencrypt.org/docs/glossary/#def-CN) and its use is [discouraged](https://cabforum.org/uploads/BRv1.2.3.pdf).
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
* keySize: 4096,
|
||||
* commonName: 'test.example.com',
|
||||
* altNames: ['foo.example.com', 'bar.example.com']
|
||||
* altNames: ['foo.example.com', 'bar.example.com'],
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example Certificate Signing Request with additional information
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||
* commonName: 'test.example.com',
|
||||
* altNames: ['test.example.com'],
|
||||
* country: 'US',
|
||||
* state: 'California',
|
||||
* locality: 'Los Angeles',
|
||||
* organization: 'The Company Inc.',
|
||||
* organizationUnit: 'IT Department',
|
||||
* emailAddress: 'contact@example.com'
|
||||
* emailAddress: 'contact@example.com',
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
@@ -387,11 +374,11 @@ function formatCsrAltNames(altNames) {
|
||||
* const certificateKey = await acme.forge.createPrivateKey();
|
||||
*
|
||||
* const [, certificateRequest] = await acme.forge.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* }, certificateKey);
|
||||
*/
|
||||
|
||||
exports.createCsr = async function(data, key = null) {
|
||||
exports.createCsr = async (data, key = null) => {
|
||||
if (!key) {
|
||||
key = await createPrivateKey(data.keySize);
|
||||
}
|
||||
@@ -423,7 +410,7 @@ exports.createCsr = async function(data, key = null) {
|
||||
L: data.locality,
|
||||
O: data.organization,
|
||||
OU: data.organizationUnit,
|
||||
E: data.emailAddress
|
||||
E: data.emailAddress,
|
||||
});
|
||||
|
||||
csr.setSubject(subject);
|
||||
@@ -434,8 +421,8 @@ exports.createCsr = async function(data, key = null) {
|
||||
name: 'extensionRequest',
|
||||
extensions: [{
|
||||
name: 'subjectAltName',
|
||||
altNames: formatCsrAltNames(data.altNames)
|
||||
}]
|
||||
altNames: formatCsrAltNames(data.altNames),
|
||||
}],
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,20 @@
|
||||
const net = require('net');
|
||||
const { promisify } = require('util');
|
||||
const crypto = require('crypto');
|
||||
const jsrsasign = require('jsrsasign');
|
||||
const asn1js = require('asn1js');
|
||||
const x509 = require('@peculiar/x509');
|
||||
|
||||
const randomInt = promisify(crypto.randomInt);
|
||||
const generateKeyPair = promisify(crypto.generateKeyPair);
|
||||
|
||||
/* Use Node.js Web Crypto API */
|
||||
x509.cryptoProvider.set(crypto.webcrypto);
|
||||
|
||||
/* id-ce-subjectAltName - https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6 */
|
||||
const subjectAltNameOID = '2.5.29.17';
|
||||
|
||||
/* id-pe-acmeIdentifier - https://datatracker.ietf.org/doc/html/rfc8737#section-6.1 */
|
||||
const alpnAcmeIdentifierOID = '1.3.6.1.5.5.7.1.31';
|
||||
|
||||
/**
|
||||
* Determine key type and info by attempting to derive public key
|
||||
@@ -24,17 +34,14 @@ function getKeyInfo(keyPem) {
|
||||
const result = {
|
||||
isRSA: false,
|
||||
isECDSA: false,
|
||||
signatureAlgorithm: null,
|
||||
publicKey: crypto.createPublicKey(keyPem)
|
||||
publicKey: crypto.createPublicKey(keyPem),
|
||||
};
|
||||
|
||||
if (result.publicKey.asymmetricKeyType === 'rsa') {
|
||||
result.isRSA = true;
|
||||
result.signatureAlgorithm = 'SHA256withRSA';
|
||||
}
|
||||
else if (result.publicKey.asymmetricKeyType === 'ec') {
|
||||
result.isECDSA = true;
|
||||
result.signatureAlgorithm = 'SHA256withECDSA';
|
||||
}
|
||||
else {
|
||||
throw new Error('Unable to parse key information, unknown format');
|
||||
@@ -43,7 +50,6 @@ function getKeyInfo(keyPem) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a private RSA key
|
||||
*
|
||||
@@ -66,8 +72,8 @@ async function createPrivateRsaKey(modulusLength = 2048) {
|
||||
modulusLength,
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem'
|
||||
}
|
||||
format: 'pem',
|
||||
},
|
||||
});
|
||||
|
||||
return Buffer.from(pair.privateKey);
|
||||
@@ -75,7 +81,6 @@ async function createPrivateRsaKey(modulusLength = 2048) {
|
||||
|
||||
exports.createPrivateRsaKey = createPrivateRsaKey;
|
||||
|
||||
|
||||
/**
|
||||
* Alias of `createPrivateRsaKey()`
|
||||
*
|
||||
@@ -84,7 +89,6 @@ exports.createPrivateRsaKey = createPrivateRsaKey;
|
||||
|
||||
exports.createPrivateKey = createPrivateRsaKey;
|
||||
|
||||
|
||||
/**
|
||||
* Generate a private ECDSA key
|
||||
*
|
||||
@@ -107,14 +111,13 @@ exports.createPrivateEcdsaKey = async (namedCurve = 'P-256') => {
|
||||
namedCurve,
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem'
|
||||
}
|
||||
format: 'pem',
|
||||
},
|
||||
});
|
||||
|
||||
return Buffer.from(pair.privateKey);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get a public key derived from a RSA or ECDSA key
|
||||
*
|
||||
@@ -132,13 +135,12 @@ exports.getPublicKey = (keyPem) => {
|
||||
|
||||
const publicKey = info.publicKey.export({
|
||||
type: info.isECDSA ? 'spki' : 'pkcs1',
|
||||
format: 'pem'
|
||||
format: 'pem',
|
||||
});
|
||||
|
||||
return Buffer.from(publicKey);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get a JSON Web Key derived from a RSA or ECDSA key
|
||||
*
|
||||
@@ -155,7 +157,7 @@ exports.getPublicKey = (keyPem) => {
|
||||
|
||||
function getJwk(keyPem) {
|
||||
const jwk = crypto.createPublicKey(keyPem).export({
|
||||
format: 'jwk'
|
||||
format: 'jwk',
|
||||
});
|
||||
|
||||
/* Sort keys */
|
||||
@@ -167,34 +169,50 @@ function getJwk(keyPem) {
|
||||
|
||||
exports.getJwk = getJwk;
|
||||
|
||||
|
||||
/**
|
||||
* Fix missing support for NIST curve names in jsrsasign
|
||||
* Produce CryptoKeyPair and signing algorithm from a PEM encoded private key
|
||||
*
|
||||
* @private
|
||||
* @param {string} crv NIST curve name
|
||||
* @returns {string} SECG curve name
|
||||
* @param {buffer|string} keyPem PEM encoded private key
|
||||
* @returns {Promise<array>} [keyPair, signingAlgorithm]
|
||||
*/
|
||||
|
||||
function convertNistCurveNameToSecg(nistName) {
|
||||
switch (nistName) {
|
||||
case 'P-256':
|
||||
return 'secp256r1';
|
||||
case 'P-384':
|
||||
return 'secp384r1';
|
||||
case 'P-521':
|
||||
return 'secp521r1';
|
||||
default:
|
||||
return nistName;
|
||||
}
|
||||
}
|
||||
async function getWebCryptoKeyPair(keyPem) {
|
||||
const info = getKeyInfo(keyPem);
|
||||
const jwk = getJwk(keyPem);
|
||||
|
||||
/* Signing algorithm */
|
||||
const sigalg = {
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: { name: 'SHA-256' },
|
||||
};
|
||||
|
||||
if (info.isECDSA) {
|
||||
sigalg.name = 'ECDSA';
|
||||
sigalg.namedCurve = jwk.crv;
|
||||
|
||||
if (jwk.crv === 'P-384') {
|
||||
sigalg.hash.name = 'SHA-384';
|
||||
}
|
||||
|
||||
if (jwk.crv === 'P-521') {
|
||||
sigalg.hash.name = 'SHA-512';
|
||||
}
|
||||
}
|
||||
|
||||
/* Decode PEM and import into CryptoKeyPair */
|
||||
const privateKeyDec = x509.PemConverter.decodeFirst(keyPem.toString());
|
||||
const privateKey = await crypto.webcrypto.subtle.importKey('pkcs8', privateKeyDec, sigalg, true, ['sign']);
|
||||
const publicKey = await crypto.webcrypto.subtle.importKey('jwk', jwk, sigalg, true, ['verify']);
|
||||
|
||||
return [{ privateKey, publicKey }, sigalg];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split chain of PEM encoded objects from string into array
|
||||
*
|
||||
* @param {buffer|string} chainPem PEM encoded object chain
|
||||
* @returns {array} Array of PEM objects including headers
|
||||
* @returns {string[]} Array of PEM objects including headers
|
||||
*/
|
||||
|
||||
function splitPemChain(chainPem) {
|
||||
@@ -202,20 +220,13 @@ function splitPemChain(chainPem) {
|
||||
chainPem = chainPem.toString();
|
||||
}
|
||||
|
||||
return chainPem
|
||||
/* Split chain into chunks, starting at every header */
|
||||
.split(/\s*(?=-----BEGIN [A-Z0-9- ]+-----\r?\n?)/g)
|
||||
/* Match header, PEM body and footer */
|
||||
.map((pem) => pem.match(/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\S\s]+)\r?\n?-----END \1-----/))
|
||||
/* Filter out non-matches or empty bodies */
|
||||
.filter((pem) => pem && pem[2] && pem[2].replace(/[\r\n]+/g, '').trim())
|
||||
/* Decode to hex, and back to PEM for formatting etc */
|
||||
.map(([pem, header]) => jsrsasign.hextopem(jsrsasign.pemtohex(pem, header), header));
|
||||
/* Decode into array and re-encode */
|
||||
return x509.PemConverter.decodeWithHeaders(chainPem)
|
||||
.map((params) => x509.PemConverter.encode([params]));
|
||||
}
|
||||
|
||||
exports.splitPemChain = splitPemChain;
|
||||
|
||||
|
||||
/**
|
||||
* Parse body of PEM encoded object and return a Base64URL string
|
||||
* If multiple objects are chained, the first body will be returned
|
||||
@@ -231,52 +242,35 @@ exports.getPemBodyAsB64u = (pem) => {
|
||||
throw new Error('Unable to parse PEM body from string');
|
||||
}
|
||||
|
||||
/* First object, hex and back to b64 without new lines */
|
||||
return jsrsasign.hextob64u(jsrsasign.pemtohex(chain[0]));
|
||||
/* Select first object, extract body and convert to b64u */
|
||||
const dec = x509.PemConverter.decodeFirst(chain[0]);
|
||||
return Buffer.from(dec).toString('base64url');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse common name from a subject object
|
||||
*
|
||||
* @private
|
||||
* @param {object} subj Subject returned from jsrsasign
|
||||
* @returns {string} Common name value
|
||||
*/
|
||||
|
||||
function parseCommonName(subj) {
|
||||
const subjectArr = (subj && subj.array) ? subj.array : [];
|
||||
const cnArr = subjectArr.find((s) => (s[0] && s[0].type && s[0].value && (s[0].type === 'CN')));
|
||||
return (cnArr && cnArr.length && cnArr[0].value) ? cnArr[0].value : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse domains from a certificate or CSR
|
||||
*
|
||||
* @private
|
||||
* @param {object} params Certificate or CSR params returned from jsrsasign
|
||||
* @param {object} input x509.Certificate or x509.Pkcs10CertificateRequest
|
||||
* @returns {object} {commonName, altNames}
|
||||
*/
|
||||
|
||||
function parseDomains(params) {
|
||||
const commonName = parseCommonName(params.subject);
|
||||
const extensionArr = (params.ext || params.extreq || []);
|
||||
function parseDomains(input) {
|
||||
const commonName = input.subjectName.getField('CN').pop() || null;
|
||||
const altNamesRaw = input.getExtension(subjectAltNameOID);
|
||||
let altNames = [];
|
||||
|
||||
if (extensionArr && extensionArr.length) {
|
||||
const altNameExt = extensionArr.find((e) => (e.extname && (e.extname === 'subjectAltName')));
|
||||
const altNameArr = (altNameExt && altNameExt.array && altNameExt.array.length) ? altNameExt.array : [];
|
||||
altNames = altNameArr.map((a) => Object.values(a)[0] || null).filter((a) => a);
|
||||
if (altNamesRaw) {
|
||||
const altNamesExt = new x509.SubjectAlternativeNameExtension(altNamesRaw.rawData);
|
||||
altNames = altNames.concat(altNamesExt.names.items.map((i) => i.value));
|
||||
}
|
||||
|
||||
return {
|
||||
commonName,
|
||||
altNames
|
||||
altNames,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read domains from a Certificate Signing Request
|
||||
*
|
||||
@@ -297,12 +291,11 @@ exports.readCsrDomains = (csrPem) => {
|
||||
csrPem = csrPem.toString();
|
||||
}
|
||||
|
||||
/* Parse CSR */
|
||||
const params = jsrsasign.KJUR.asn1.csr.CSRUtil.getParam(csrPem);
|
||||
return parseDomains(params);
|
||||
const dec = x509.PemConverter.decodeFirst(csrPem);
|
||||
const csr = new x509.Pkcs10CertificateRequest(dec);
|
||||
return parseDomains(csr);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read information from a certificate
|
||||
* If multiple certificates are chained, the first will be read
|
||||
@@ -324,55 +317,50 @@ exports.readCsrDomains = (csrPem) => {
|
||||
*/
|
||||
|
||||
exports.readCertificateInfo = (certPem) => {
|
||||
const chain = splitPemChain(certPem);
|
||||
|
||||
if (!chain.length) {
|
||||
throw new Error('Unable to parse PEM body from string');
|
||||
if (Buffer.isBuffer(certPem)) {
|
||||
certPem = certPem.toString();
|
||||
}
|
||||
|
||||
/* Parse certificate */
|
||||
const obj = new jsrsasign.X509();
|
||||
obj.readCertPEM(chain[0]);
|
||||
const params = obj.getParam();
|
||||
const dec = x509.PemConverter.decodeFirst(certPem);
|
||||
const cert = new x509.X509Certificate(dec);
|
||||
|
||||
return {
|
||||
issuer: {
|
||||
commonName: parseCommonName(params.issuer)
|
||||
commonName: cert.issuerName.getField('CN').pop() || null,
|
||||
},
|
||||
domains: parseDomains(params),
|
||||
notBefore: jsrsasign.zulutodate(params.notbefore),
|
||||
notAfter: jsrsasign.zulutodate(params.notafter)
|
||||
domains: parseDomains(cert),
|
||||
notBefore: cert.notBefore,
|
||||
notAfter: cert.notAfter,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine ASN.1 character string type for CSR subject field
|
||||
* Determine ASN.1 character string type for CSR subject field name
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc5280
|
||||
* https://github.com/kjur/jsrsasign/blob/2613c64559768b91dde9793dfa318feacb7c3b8a/src/x509-1.1.js#L2404-L2412
|
||||
* https://github.com/kjur/jsrsasign/blob/2613c64559768b91dde9793dfa318feacb7c3b8a/src/asn1x509-1.0.js#L3526-L3535
|
||||
* https://datatracker.ietf.org/doc/html/rfc5280
|
||||
* https://github.com/PeculiarVentures/x509/blob/ecf78224fd594abbc2fa83c41565d79874f88e00/src/name.ts#L65-L71
|
||||
*
|
||||
* @private
|
||||
* @param {string} field CSR subject field
|
||||
* @returns {string} ASN.1 jsrsasign character string type
|
||||
* @param {string} field CSR subject field name
|
||||
* @returns {string} ASN.1 character string type
|
||||
*/
|
||||
|
||||
function getCsrAsn1CharStringType(field) {
|
||||
switch (field) {
|
||||
case 'C':
|
||||
return 'prn';
|
||||
return 'printableString';
|
||||
case 'E':
|
||||
return 'ia5';
|
||||
return 'ia5String';
|
||||
default:
|
||||
return 'utf8';
|
||||
return 'utf8String';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create array of subject fields for a Certificate Signing Request
|
||||
*
|
||||
* https://github.com/PeculiarVentures/x509/blob/ecf78224fd594abbc2fa83c41565d79874f88e00/src/name.ts#L65-L71
|
||||
*
|
||||
* @private
|
||||
* @param {object} input Key-value of subject fields
|
||||
* @returns {object[]} Certificate Signing Request subject array
|
||||
@@ -382,74 +370,73 @@ function createCsrSubject(input) {
|
||||
return Object.entries(input).reduce((result, [type, value]) => {
|
||||
if (value) {
|
||||
const ds = getCsrAsn1CharStringType(type);
|
||||
result.push([{ type, value, ds }]);
|
||||
result.push({ [type]: [{ [ds]: value }] });
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create array of alt names for Certificate Signing Requests
|
||||
* Create x509 subject alternate name extension
|
||||
*
|
||||
* https://github.com/kjur/jsrsasign/blob/3edc0070846922daea98d9588978e91d855577ec/src/x509-1.1.js#L1355-L1410
|
||||
* https://github.com/PeculiarVentures/x509/blob/ecf78224fd594abbc2fa83c41565d79874f88e00/src/extensions/subject_alt_name.ts
|
||||
*
|
||||
* @private
|
||||
* @param {string[]} altNames Array of alt names
|
||||
* @returns {object[]} Certificate Signing Request alt names array
|
||||
* @returns {x509.SubjectAlternativeNameExtension} Subject alternate name extension
|
||||
*/
|
||||
|
||||
function formatCsrAltNames(altNames) {
|
||||
return altNames.map((value) => {
|
||||
const key = net.isIP(value) ? 'ip' : 'dns';
|
||||
return { [key]: value };
|
||||
});
|
||||
function createSubjectAltNameExtension(altNames) {
|
||||
return new x509.SubjectAlternativeNameExtension(altNames.map((value) => {
|
||||
const type = net.isIP(value) ? 'ip' : 'dns';
|
||||
return { type, value };
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Certificate Signing Request
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {number} [data.keySize] Size of newly created RSA private key modulus in bits, default: `2048`
|
||||
* @param {string} [data.commonName] FQDN of your server
|
||||
* @param {array} [data.altNames] SAN (Subject Alternative Names), default: `[]`
|
||||
* @param {string[]} [data.altNames] SAN (Subject Alternative Names), default: `[]`
|
||||
* @param {string} [data.country] 2 letter country code
|
||||
* @param {string} [data.state] State or province
|
||||
* @param {string} [data.locality] City
|
||||
* @param {string} [data.organization] Organization name
|
||||
* @param {string} [data.organizationUnit] Organizational unit name
|
||||
* @param {string} [data.emailAddress] Email address
|
||||
* @param {string} [keyPem] PEM encoded CSR private key
|
||||
* @param {buffer|string} [keyPem] PEM encoded CSR private key
|
||||
* @returns {Promise<buffer[]>} [privateKey, certificateSigningRequest]
|
||||
*
|
||||
* @example Create a Certificate Signing Request
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example Certificate Signing Request with both common and alternative names
|
||||
* > *Warning*: Certificate subject common name has been [deprecated](https://letsencrypt.org/docs/glossary/#def-CN) and its use is [discouraged](https://cabforum.org/uploads/BRv1.2.3.pdf).
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
* keySize: 4096,
|
||||
* commonName: 'test.example.com',
|
||||
* altNames: ['foo.example.com', 'bar.example.com']
|
||||
* altNames: ['foo.example.com', 'bar.example.com'],
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example Certificate Signing Request with additional information
|
||||
* ```js
|
||||
* const [certificateKey, certificateRequest] = await acme.crypto.createCsr({
|
||||
* commonName: 'test.example.com',
|
||||
* altNames: ['test.example.com'],
|
||||
* country: 'US',
|
||||
* state: 'California',
|
||||
* locality: 'Los Angeles',
|
||||
* organization: 'The Company Inc.',
|
||||
* organizationUnit: 'IT Department',
|
||||
* emailAddress: 'contact@example.com'
|
||||
* emailAddress: 'contact@example.com',
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
@@ -458,8 +445,9 @@ function formatCsrAltNames(altNames) {
|
||||
* const certificateKey = await acme.crypto.createPrivateEcdsaKey();
|
||||
*
|
||||
* const [, certificateRequest] = await acme.crypto.createCsr({
|
||||
* commonName: 'test.example.com'
|
||||
* altNames: ['test.example.com'],
|
||||
* }, certificateKey);
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.createCsr = async (data, keyPem = null) => {
|
||||
@@ -474,53 +462,143 @@ exports.createCsr = async (data, keyPem = null) => {
|
||||
data.altNames = [];
|
||||
}
|
||||
|
||||
/* Get key info and JWK */
|
||||
const info = getKeyInfo(keyPem);
|
||||
const jwk = getJwk(keyPem);
|
||||
const extensionRequests = [];
|
||||
|
||||
/* Missing support for NIST curve names in jsrsasign - https://github.com/kjur/jsrsasign/blob/master/src/asn1x509-1.0.js#L4388-L4393 */
|
||||
if (jwk.crv && (jwk.kty === 'EC')) {
|
||||
jwk.crv = convertNistCurveNameToSecg(jwk.crv);
|
||||
}
|
||||
|
||||
/* Ensure subject common name is present in SAN - https://cabforum.org/wp-content/uploads/BRv1.2.3.pdf */
|
||||
if (data.commonName && !data.altNames.includes(data.commonName)) {
|
||||
data.altNames.unshift(data.commonName);
|
||||
}
|
||||
|
||||
/* Subject */
|
||||
const subject = createCsrSubject({
|
||||
CN: data.commonName,
|
||||
C: data.country,
|
||||
ST: data.state,
|
||||
L: data.locality,
|
||||
O: data.organization,
|
||||
OU: data.organizationUnit,
|
||||
E: data.emailAddress
|
||||
});
|
||||
/* CryptoKeyPair and signing algorithm from private key */
|
||||
const [keys, signingAlgorithm] = await getWebCryptoKeyPair(keyPem);
|
||||
|
||||
/* SAN extension */
|
||||
if (data.altNames.length) {
|
||||
extensionRequests.push({
|
||||
extname: 'subjectAltName',
|
||||
array: formatCsrAltNames(data.altNames)
|
||||
});
|
||||
}
|
||||
const extensions = [
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 */
|
||||
new x509.KeyUsagesExtension(x509.KeyUsageFlags.digitalSignature | x509.KeyUsageFlags.keyEncipherment), // eslint-disable-line no-bitwise
|
||||
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6 */
|
||||
createSubjectAltNameExtension(data.altNames),
|
||||
];
|
||||
|
||||
/* Create CSR */
|
||||
const csr = new jsrsasign.KJUR.asn1.csr.CertificationRequest({
|
||||
subject: { array: subject },
|
||||
sigalg: info.signatureAlgorithm,
|
||||
sbjprvkey: keyPem.toString(),
|
||||
sbjpubkey: jwk,
|
||||
extreq: extensionRequests
|
||||
const csr = await x509.Pkcs10CertificateRequestGenerator.create({
|
||||
keys,
|
||||
extensions,
|
||||
signingAlgorithm,
|
||||
name: createCsrSubject({
|
||||
CN: data.commonName,
|
||||
C: data.country,
|
||||
ST: data.state,
|
||||
L: data.locality,
|
||||
O: data.organization,
|
||||
OU: data.organizationUnit,
|
||||
E: data.emailAddress,
|
||||
}),
|
||||
});
|
||||
|
||||
/* Sign CSR, get PEM */
|
||||
csr.sign();
|
||||
const pem = csr.getPEM();
|
||||
|
||||
/* Done */
|
||||
const pem = csr.toString('pem');
|
||||
return [keyPem, Buffer.from(pem)];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a self-signed ALPN certificate for TLS-ALPN-01 challenges
|
||||
*
|
||||
* https://datatracker.ietf.org/doc/html/rfc8737
|
||||
*
|
||||
* @param {object} authz Identifier authorization
|
||||
* @param {string} keyAuthorization Challenge key authorization
|
||||
* @param {buffer|string} [keyPem] PEM encoded CSR private key
|
||||
* @returns {Promise<buffer[]>} [privateKey, certificate]
|
||||
*
|
||||
* @example Create a ALPN certificate
|
||||
* ```js
|
||||
* const [alpnKey, alpnCertificate] = await acme.crypto.createAlpnCertificate(authz, keyAuthorization);
|
||||
* ```
|
||||
*
|
||||
* @example Create a ALPN certificate with ECDSA private key
|
||||
* ```js
|
||||
* const alpnKey = await acme.crypto.createPrivateEcdsaKey();
|
||||
* const [, alpnCertificate] = await acme.crypto.createAlpnCertificate(authz, keyAuthorization, alpnKey);
|
||||
* ```
|
||||
*/
|
||||
|
||||
exports.createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) => {
|
||||
if (!keyPem) {
|
||||
keyPem = await createPrivateRsaKey();
|
||||
}
|
||||
else if (!Buffer.isBuffer(keyPem)) {
|
||||
keyPem = Buffer.from(keyPem);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const commonName = authz.identifier.value;
|
||||
|
||||
/* Pseudo-random serial - max 20 bytes, 11 for epoch (year 5138), 9 random */
|
||||
const random = await randomInt(1, 999999999);
|
||||
const serialNumber = `${Math.floor(now.getTime() / 1000)}${random}`;
|
||||
|
||||
/* CryptoKeyPair and signing algorithm from private key */
|
||||
const [keys, signingAlgorithm] = await getWebCryptoKeyPair(keyPem);
|
||||
|
||||
const extensions = [
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 */
|
||||
new x509.KeyUsagesExtension(x509.KeyUsageFlags.keyCertSign | x509.KeyUsageFlags.cRLSign, true), // eslint-disable-line no-bitwise
|
||||
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.9 */
|
||||
new x509.BasicConstraintsExtension(true, 2, true),
|
||||
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.2 */
|
||||
await x509.SubjectKeyIdentifierExtension.create(keys.publicKey),
|
||||
|
||||
/* https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6 */
|
||||
createSubjectAltNameExtension([commonName]),
|
||||
];
|
||||
|
||||
/* ALPN extension */
|
||||
const payload = crypto.createHash('sha256').update(keyAuthorization).digest('hex');
|
||||
const octstr = new asn1js.OctetString({ valueHex: Buffer.from(payload, 'hex') });
|
||||
extensions.push(new x509.Extension(alpnAcmeIdentifierOID, true, octstr.toBER()));
|
||||
|
||||
/* Self-signed ALPN certificate */
|
||||
const cert = await x509.X509CertificateGenerator.createSelfSigned({
|
||||
keys,
|
||||
signingAlgorithm,
|
||||
extensions,
|
||||
serialNumber,
|
||||
notBefore: now,
|
||||
notAfter: now,
|
||||
name: createCsrSubject({
|
||||
CN: commonName,
|
||||
}),
|
||||
});
|
||||
|
||||
/* Done */
|
||||
const pem = cert.toString('pem');
|
||||
return [keyPem, Buffer.from(pem)];
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate that a ALPN certificate contains the expected key authorization
|
||||
*
|
||||
* @param {buffer|string} certPem PEM encoded certificate
|
||||
* @param {string} keyAuthorization Expected challenge key authorization
|
||||
* @returns {boolean} True when valid
|
||||
*/
|
||||
|
||||
exports.isAlpnCertificateAuthorizationValid = (certPem, keyAuthorization) => {
|
||||
const expected = crypto.createHash('sha256').update(keyAuthorization).digest('hex');
|
||||
|
||||
/* Attempt to locate ALPN extension */
|
||||
const cert = new x509.X509Certificate(certPem);
|
||||
const ext = cert.getExtension(alpnAcmeIdentifierOID);
|
||||
|
||||
if (!ext) {
|
||||
throw new Error('Unable to locate ALPN extension within parsed certificate');
|
||||
}
|
||||
|
||||
/* Decode extension value */
|
||||
const parsed = asn1js.fromBER(ext.value);
|
||||
const result = Buffer.from(parsed.result.valueBlock.valueHexView).toString('hex');
|
||||
|
||||
/* Return true if match */
|
||||
return (result === expected);
|
||||
};
|
||||
|
||||
@@ -3,10 +3,20 @@
|
||||
*/
|
||||
|
||||
const { createHmac, createSign, constants: { RSA_PKCS1_PADDING } } = require('crypto');
|
||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
||||
const { getJwk } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
const axios = require('./axios');
|
||||
const axios1 = require('./axios');
|
||||
|
||||
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||
let httpsAgent = null;
|
||||
if (httpsProxy) {
|
||||
httpsAgent = new HttpsProxyAgent(httpsProxy);
|
||||
}
|
||||
const axios = axios1.create({
|
||||
proxy: false,
|
||||
httpsAgent
|
||||
});
|
||||
|
||||
/**
|
||||
* ACME HTTP client
|
||||
@@ -30,7 +40,6 @@ class HttpClient {
|
||||
this.jwk = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTTP request
|
||||
*
|
||||
@@ -60,11 +69,10 @@ class HttpClient {
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensure provider directory exists
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.1.1
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.1
|
||||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@@ -85,7 +93,6 @@ class HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get JSON Web Key
|
||||
*
|
||||
@@ -100,11 +107,10 @@ class HttpClient {
|
||||
return this.jwk;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get nonce from directory API endpoint
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-7.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-7.2
|
||||
*
|
||||
* @returns {Promise<string>} nonce
|
||||
*/
|
||||
@@ -120,7 +126,6 @@ class HttpClient {
|
||||
return resp.headers['replay-nonce'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get URL for a directory resource
|
||||
*
|
||||
@@ -138,7 +143,6 @@ class HttpClient {
|
||||
return this.directory[resource];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get directory meta field
|
||||
*
|
||||
@@ -156,7 +160,6 @@ class HttpClient {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare HTTP request body for signature
|
||||
*
|
||||
@@ -189,11 +192,10 @@ class HttpClient {
|
||||
/* Body */
|
||||
return {
|
||||
payload: payload ? Buffer.from(JSON.stringify(payload)).toString('base64url') : '',
|
||||
protected: Buffer.from(JSON.stringify(header)).toString('base64url')
|
||||
protected: Buffer.from(JSON.stringify(header)).toString('base64url'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create JWS HTTP request body using HMAC
|
||||
*
|
||||
@@ -216,7 +218,6 @@ class HttpClient {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create JWS HTTP request body using RSA or ECC
|
||||
*
|
||||
@@ -257,17 +258,16 @@ class HttpClient {
|
||||
result.signature = signer.sign({
|
||||
key: this.accountKey,
|
||||
padding: RSA_PKCS1_PADDING,
|
||||
dsaEncoding: 'ieee-p1363'
|
||||
dsaEncoding: 'ieee-p1363',
|
||||
}, 'base64url');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signed HTTP request
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-6.2
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-6.2
|
||||
*
|
||||
* @param {string} url Request URL
|
||||
* @param {object} payload Request payload
|
||||
@@ -299,7 +299,7 @@ class HttpClient {
|
||||
const data = this.createSignedBody(url, payload, { nonce, kid });
|
||||
const resp = await this.request(url, 'post', { data });
|
||||
|
||||
/* Retry on bad nonce - https://tools.ietf.org/html/draft-ietf-acme-acme-10#section-6.4 */
|
||||
/* Retry on bad nonce - https://datatracker.ietf.org/doc/html/rfc8555#section-6.5 */
|
||||
if (resp.data && resp.data.type && (resp.status === 400) && (resp.data.type === 'urn:ietf:params:acme:error:badNonce') && (attempts < this.maxBadNonceRetries)) {
|
||||
nonce = resp.headers['replay-nonce'] || null;
|
||||
attempts += 1;
|
||||
@@ -313,6 +313,5 @@ class HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Export client */
|
||||
module.exports = HttpClient;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
exports.Client = require('./client');
|
||||
|
||||
|
||||
/**
|
||||
* Directory URLs
|
||||
*/
|
||||
@@ -12,18 +11,17 @@ exports.Client = require('./client');
|
||||
exports.directory = {
|
||||
buypass: {
|
||||
staging: 'https://api.test4.buypass.no/acme/directory',
|
||||
production: 'https://api.buypass.com/acme/directory'
|
||||
production: 'https://api.buypass.com/acme/directory',
|
||||
},
|
||||
letsencrypt: {
|
||||
staging: 'https://acme-staging-v02.api.letsencrypt.org/directory',
|
||||
production: 'https://acme-v02.api.letsencrypt.org/directory'
|
||||
production: 'https://acme-v02.api.letsencrypt.org/directory',
|
||||
},
|
||||
zerossl: {
|
||||
production: 'https://acme.zerossl.com/v2/DV90'
|
||||
}
|
||||
production: 'https://acme.zerossl.com/v2/DV90',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Crypto
|
||||
*/
|
||||
@@ -31,14 +29,12 @@ exports.directory = {
|
||||
exports.crypto = require('./crypto');
|
||||
exports.forge = require('./crypto/forge');
|
||||
|
||||
|
||||
/**
|
||||
* Axios
|
||||
*/
|
||||
|
||||
exports.axios = require('./axios');
|
||||
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,6 @@ const debug = require('debug')('acme-client');
|
||||
|
||||
let logger = () => {};
|
||||
|
||||
|
||||
/**
|
||||
* Set logger function
|
||||
*
|
||||
@@ -17,11 +16,10 @@ exports.setLogger = (fn) => {
|
||||
logger = fn;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*
|
||||
* @param {string} Message
|
||||
* @param {string} msg Message
|
||||
*/
|
||||
|
||||
exports.log = (msg) => {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* Utility methods
|
||||
*/
|
||||
|
||||
const tls = require('tls');
|
||||
const dns = require('dns').promises;
|
||||
const { readCertificateInfo, splitPemChain } = require('./crypto');
|
||||
const { log } = require('./logger');
|
||||
|
||||
|
||||
/**
|
||||
* Exponential backoff
|
||||
*
|
||||
@@ -25,7 +25,6 @@ class Backoff {
|
||||
this.attempts = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get backoff duration
|
||||
*
|
||||
@@ -39,7 +38,6 @@ class Backoff {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retry promise
|
||||
*
|
||||
@@ -69,7 +67,6 @@ async function retryPromise(fn, attempts, backoff) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retry promise
|
||||
*
|
||||
@@ -86,13 +83,12 @@ function retry(fn, { attempts = 5, min = 5000, max = 30000 } = {}) {
|
||||
return retryPromise(fn, attempts, backoff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse URLs from link header
|
||||
*
|
||||
* @param {string} header Link header contents
|
||||
* @param {string} rel Link relation, default: `alternate`
|
||||
* @returns {array} Array of URLs
|
||||
* @returns {string[]} Array of URLs
|
||||
*/
|
||||
|
||||
function parseLinkHeader(header, rel = 'alternate') {
|
||||
@@ -106,13 +102,12 @@ function parseLinkHeader(header, rel = 'alternate') {
|
||||
return results.filter((r) => r);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find certificate chain with preferred issuer common name
|
||||
* - If issuer is found in multiple chains, the closest to root wins
|
||||
* - If issuer can not be located, the first chain will be returned
|
||||
*
|
||||
* @param {array} certificates Array of PEM encoded certificate chains
|
||||
* @param {string[]} certificates Array of PEM encoded certificate chains
|
||||
* @param {string} issuer Preferred certificate issuer
|
||||
* @returns {string} PEM encoded certificate chain
|
||||
*/
|
||||
@@ -156,7 +151,6 @@ function findCertificateChainForIssuer(chains, issuer) {
|
||||
return chains[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find and format error in response object
|
||||
*
|
||||
@@ -177,7 +171,6 @@ function formatResponseError(resp) {
|
||||
return result.replace(/\n/g, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve root domain name by looking for SOA record
|
||||
*
|
||||
@@ -203,7 +196,6 @@ async function resolveDomainBySoaRecord(recordName) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get DNS resolver using domains authoritative NS records
|
||||
*
|
||||
@@ -244,6 +236,58 @@ async function getAuthoritativeDnsResolver(recordName) {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to retrieve TLS ALPN certificate from peer
|
||||
*
|
||||
* https://nodejs.org/api/tls.html#tlsconnectoptions-callback
|
||||
*
|
||||
* @param {string} host Host the TLS client should connect to
|
||||
* @param {number} port Port the client should connect to
|
||||
* @param {string} servername Server name for the SNI (Server Name Indication)
|
||||
* @returns {Promise<string>} PEM encoded certificate
|
||||
*/
|
||||
|
||||
async function retrieveTlsAlpnCertificate(host, port, timeout = 30000) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let result;
|
||||
|
||||
/* TLS connection */
|
||||
const socket = tls.connect({
|
||||
host,
|
||||
port,
|
||||
servername: host,
|
||||
rejectUnauthorized: false,
|
||||
ALPNProtocols: ['acme-tls/1'],
|
||||
});
|
||||
|
||||
socket.setTimeout(timeout);
|
||||
socket.setEncoding('utf-8');
|
||||
|
||||
/* Grab certificate once connected and close */
|
||||
socket.on('secureConnect', () => {
|
||||
result = socket.getPeerX509Certificate();
|
||||
socket.end();
|
||||
});
|
||||
|
||||
/* Errors */
|
||||
socket.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
socket.on('timeout', () => {
|
||||
socket.destroy(new Error('TLS ALPN certificate lookup request timed out'));
|
||||
});
|
||||
|
||||
/* Done, return cert as PEM if found */
|
||||
socket.on('end', () => {
|
||||
if (result) {
|
||||
return resolve(result.toString());
|
||||
}
|
||||
|
||||
return reject(new Error('TLS ALPN lookup failed to retrieve certificate'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Export utils
|
||||
@@ -254,5 +298,6 @@ module.exports = {
|
||||
parseLinkHeader,
|
||||
findCertificateChainForIssuer,
|
||||
formatResponseError,
|
||||
getAuthoritativeDnsResolver
|
||||
getAuthoritativeDnsResolver,
|
||||
retrieveTlsAlpnCertificate,
|
||||
};
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
*/
|
||||
|
||||
const dns = require('dns').promises;
|
||||
const https = require('https');
|
||||
const { log } = require('./logger');
|
||||
const axios = require('./axios');
|
||||
const util = require('./util');
|
||||
|
||||
const { isAlpnCertificateAuthorizationValid } = require('./crypto');
|
||||
|
||||
/**
|
||||
* Verify ACME HTTP challenge
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-8.3
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-8.3
|
||||
*
|
||||
* @param {object} authz Identifier authorization
|
||||
* @param {object} challenge Authorization challenge
|
||||
@@ -24,8 +25,11 @@ async function verifyHttpChallenge(authz, challenge, keyAuthorization, suffix =
|
||||
const httpPort = axios.defaults.acmeSettings.httpChallengePort || 80;
|
||||
const challengeUrl = `http://${authz.identifier.value}:${httpPort}${suffix}`;
|
||||
|
||||
/* May redirect to HTTPS with invalid/self-signed cert - https://letsencrypt.org/docs/challenge-types/#http-01-challenge */
|
||||
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||
|
||||
log(`Sending HTTP query to ${authz.identifier.value}, suffix: ${suffix}, port: ${httpPort}`);
|
||||
const resp = await axios.get(challengeUrl);
|
||||
const resp = await axios.get(challengeUrl, { httpsAgent });
|
||||
const data = (resp.data || '').replace(/\s+$/, '');
|
||||
|
||||
log(`Query successful, HTTP status code: ${resp.status}`);
|
||||
@@ -38,7 +42,6 @@ async function verifyHttpChallenge(authz, challenge, keyAuthorization, suffix =
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Walk DNS until TXT records are found
|
||||
*/
|
||||
@@ -76,11 +79,10 @@ async function walkDnsChallengeRecord(recordName, resolver = dns) {
|
||||
throw new Error(`No TXT records found for name: ${recordName}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify ACME DNS challenge
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc8555#section-8.4
|
||||
* https://datatracker.ietf.org/doc/html/rfc8555#section-8.4
|
||||
*
|
||||
* @param {object} authz Identifier authorization
|
||||
* @param {object} challenge Authorization challenge
|
||||
@@ -116,6 +118,32 @@ async function verifyDnsChallenge(authz, challenge, keyAuthorization, prefix = '
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify ACME TLS ALPN challenge
|
||||
*
|
||||
* https://datatracker.ietf.org/doc/html/rfc8737
|
||||
*
|
||||
* @param {object} authz Identifier authorization
|
||||
* @param {object} challenge Authorization challenge
|
||||
* @param {string} keyAuthorization Challenge key authorization
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
|
||||
async function verifyTlsAlpnChallenge(authz, challenge, keyAuthorization) {
|
||||
const tlsAlpnPort = axios.defaults.acmeSettings.tlsAlpnChallengePort || 443;
|
||||
const host = authz.identifier.value;
|
||||
log(`Establishing TLS connection with host: ${host}:${tlsAlpnPort}`);
|
||||
|
||||
const certificate = await util.retrieveTlsAlpnCertificate(host, tlsAlpnPort);
|
||||
log('Certificate received from server successfully, matching key authorization in ALPN');
|
||||
|
||||
if (!isAlpnCertificateAuthorizationValid(certificate, keyAuthorization)) {
|
||||
throw new Error(`Authorization not found in certificate from ${authz.identifier.value}`);
|
||||
}
|
||||
|
||||
log(`Key authorization match for ${challenge.type}/${authz.identifier.value}, ACME challenge verified`);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export API
|
||||
@@ -123,5 +151,6 @@ async function verifyDnsChallenge(authz, challenge, keyAuthorization, prefix = '
|
||||
|
||||
module.exports = {
|
||||
'http-01': verifyHttpChallenge,
|
||||
'dns-01': verifyDnsChallenge
|
||||
'dns-01': verifyDnsChallenge,
|
||||
'tls-alpn-01': verifyTlsAlpnChallenge,
|
||||
};
|
||||
|
||||
9
packages/core/acme-client/src/wait.js
Normal file
@@ -0,0 +1,9 @@
|
||||
async function wait(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
wait
|
||||
};
|
||||
@@ -3,16 +3,22 @@
|
||||
*/
|
||||
|
||||
const dns = require('dns').promises;
|
||||
const { randomUUID: uuid } = require('crypto');
|
||||
const https = require('https');
|
||||
const { assert } = require('chai');
|
||||
const { v4: uuid } = require('uuid');
|
||||
const cts = require('./challtestsrv');
|
||||
const axios = require('./../src/axios');
|
||||
const { retrieveTlsAlpnCertificate } = require('./../src/util');
|
||||
const { isAlpnCertificateAuthorizationValid } = require('./../src/crypto');
|
||||
|
||||
const domainName = process.env.ACME_DOMAIN_NAME || 'example.com';
|
||||
const httpPort = axios.defaults.acmeSettings.httpChallengePort || 80;
|
||||
|
||||
const httpsPort = axios.defaults.acmeSettings.httpsChallengePort || 443;
|
||||
const tlsAlpnPort = axios.defaults.acmeSettings.tlsAlpnChallengePort || 443;
|
||||
|
||||
describe('pebble', () => {
|
||||
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||
|
||||
const testAHost = `${uuid()}.${domainName}`;
|
||||
const testARecords = ['1.1.1.1', '2.2.2.2'];
|
||||
const testCnameHost = `${uuid()}.${domainName}`;
|
||||
@@ -21,21 +27,27 @@ describe('pebble', () => {
|
||||
const testHttp01ChallengeHost = `${uuid()}.${domainName}`;
|
||||
const testHttp01ChallengeToken = uuid();
|
||||
const testHttp01ChallengeContent = uuid();
|
||||
|
||||
const testHttps01ChallengeHost = `${uuid()}.${domainName}`;
|
||||
const testHttps01ChallengeToken = uuid();
|
||||
const testHttps01ChallengeContent = uuid();
|
||||
|
||||
const testDns01ChallengeHost = `_acme-challenge.${uuid()}.${domainName}.`;
|
||||
const testDns01ChallengeValue = uuid();
|
||||
|
||||
const testTlsAlpn01ChallengeHost = `${uuid()}.${domainName}`;
|
||||
const testTlsAlpn01ChallengeValue = uuid();
|
||||
|
||||
/**
|
||||
* Pebble CTS required
|
||||
*/
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
if (!cts.isEnabled()) {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* DNS mocking
|
||||
*/
|
||||
@@ -77,45 +89,120 @@ describe('pebble', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Challenge response
|
||||
* HTTP-01 challenge response
|
||||
*/
|
||||
|
||||
describe('challenges', () => {
|
||||
it('should not locate http-01 challenge response', async () => {
|
||||
describe('http-01', () => {
|
||||
it('should not locate challenge response', async () => {
|
||||
const resp = await axios.get(`http://${testHttp01ChallengeHost}:${httpPort}/.well-known/acme-challenge/${testHttp01ChallengeToken}`);
|
||||
|
||||
assert.isString(resp.data);
|
||||
assert.notEqual(resp.data, testHttp01ChallengeContent);
|
||||
});
|
||||
|
||||
it('should add http-01 challenge response', async () => {
|
||||
it('should add challenge response', async () => {
|
||||
const resp = await cts.addHttp01ChallengeResponse(testHttp01ChallengeToken, testHttp01ChallengeContent);
|
||||
assert.isTrue(resp);
|
||||
});
|
||||
|
||||
it('should locate http-01 challenge response', async () => {
|
||||
it('should locate challenge response', async () => {
|
||||
const resp = await axios.get(`http://${testHttp01ChallengeHost}:${httpPort}/.well-known/acme-challenge/${testHttp01ChallengeToken}`);
|
||||
|
||||
assert.isString(resp.data);
|
||||
assert.strictEqual(resp.data, testHttp01ChallengeContent);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not locate dns-01 challenge response', async () => {
|
||||
/**
|
||||
* HTTPS-01 challenge response
|
||||
*/
|
||||
|
||||
describe('https-01', () => {
|
||||
it('should not locate challenge response', async () => {
|
||||
const r1 = await axios.get(`http://${testHttps01ChallengeHost}:${httpPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, { httpsAgent });
|
||||
const r2 = await axios.get(`https://${testHttps01ChallengeHost}:${httpsPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, { httpsAgent });
|
||||
|
||||
[r1, r2].forEach((resp) => {
|
||||
assert.isString(resp.data);
|
||||
assert.notEqual(resp.data, testHttps01ChallengeContent);
|
||||
});
|
||||
});
|
||||
|
||||
it('should add challenge response', async () => {
|
||||
const resp = await cts.addHttps01ChallengeResponse(testHttps01ChallengeToken, testHttps01ChallengeContent, testHttps01ChallengeHost);
|
||||
assert.isTrue(resp);
|
||||
});
|
||||
|
||||
it('should 302 with self-signed cert', async () => {
|
||||
/* Assert HTTP 302 */
|
||||
const resp = await axios.get(`http://${testHttps01ChallengeHost}:${httpPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, {
|
||||
maxRedirects: 0,
|
||||
validateStatus: null,
|
||||
});
|
||||
|
||||
assert.strictEqual(resp.status, 302);
|
||||
assert.strictEqual(resp.headers.location, `https://${testHttps01ChallengeHost}:${httpsPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`);
|
||||
|
||||
/* Self-signed cert test */
|
||||
await assert.isRejected(axios.get(`https://${testHttps01ChallengeHost}:${httpsPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`));
|
||||
await assert.isFulfilled(axios.get(`https://${testHttps01ChallengeHost}:${httpsPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, { httpsAgent }));
|
||||
});
|
||||
|
||||
it('should locate challenge response', async () => {
|
||||
const r1 = await axios.get(`http://${testHttps01ChallengeHost}:${httpPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, { httpsAgent });
|
||||
const r2 = await axios.get(`https://${testHttps01ChallengeHost}:${httpsPort}/.well-known/acme-challenge/${testHttps01ChallengeToken}`, { httpsAgent });
|
||||
|
||||
[r1, r2].forEach((resp) => {
|
||||
assert.isString(resp.data);
|
||||
assert.strictEqual(resp.data, testHttps01ChallengeContent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* DNS-01 challenge response
|
||||
*/
|
||||
|
||||
describe('dns-01', () => {
|
||||
it('should not locate challenge response', async () => {
|
||||
await assert.isRejected(dns.resolveTxt(testDns01ChallengeHost));
|
||||
});
|
||||
|
||||
it('should add dns-01 challenge response', async () => {
|
||||
it('should add challenge response', async () => {
|
||||
const resp = await cts.addDns01ChallengeResponse(testDns01ChallengeHost, testDns01ChallengeValue);
|
||||
assert.isTrue(resp);
|
||||
});
|
||||
|
||||
it('should locate dns-01 challenge response', async () => {
|
||||
it('should locate challenge response', async () => {
|
||||
const resp = await dns.resolveTxt(testDns01ChallengeHost);
|
||||
|
||||
assert.isArray(resp);
|
||||
assert.deepStrictEqual(resp, [[testDns01ChallengeValue]]);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* TLS-ALPN-01 challenge response
|
||||
*/
|
||||
|
||||
describe('tls-alpn-01', () => {
|
||||
it('should not locate challenge response', async () => {
|
||||
await assert.isRejected(retrieveTlsAlpnCertificate(testTlsAlpn01ChallengeHost, tlsAlpnPort), /(failed to retrieve)|(ssl3_read_bytes:tlsv1 alert internal error)/);
|
||||
});
|
||||
|
||||
it('should timeout challenge response', async () => {
|
||||
await assert.isRejected(retrieveTlsAlpnCertificate('example.org', tlsAlpnPort, 500));
|
||||
});
|
||||
|
||||
it('should add challenge response', async () => {
|
||||
const resp = await cts.addTlsAlpn01ChallengeResponse(testTlsAlpn01ChallengeHost, testTlsAlpn01ChallengeValue);
|
||||
assert.isTrue(resp);
|
||||
});
|
||||
|
||||
it('should locate challenge response', async () => {
|
||||
const resp = await retrieveTlsAlpnCertificate(testTlsAlpn01ChallengeHost, tlsAlpnPort);
|
||||
assert.isTrue(isAlpnCertificateAuthorizationValid(resp, testTlsAlpn01ChallengeValue));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
* HTTP client tests
|
||||
*/
|
||||
|
||||
const { randomUUID: uuid } = require('crypto');
|
||||
const { assert } = require('chai');
|
||||
const { v4: uuid } = require('uuid');
|
||||
const nock = require('nock');
|
||||
const axios = require('./../src/axios');
|
||||
const HttpClient = require('./../src/http');
|
||||
const pkg = require('./../package.json');
|
||||
|
||||
|
||||
describe('http', () => {
|
||||
let testClient;
|
||||
|
||||
@@ -20,14 +19,11 @@ describe('http', () => {
|
||||
const defaultUaEndpoint = `http://${uuid()}.example.com`;
|
||||
const customUaEndpoint = `http://${uuid()}.example.com`;
|
||||
|
||||
|
||||
/**
|
||||
* HTTP mocking
|
||||
*/
|
||||
|
||||
before(() => {
|
||||
axios.defaults.acmeSettings.bypassCustomDnsResolver = true;
|
||||
|
||||
const defaultUaOpts = { reqheaders: { 'User-Agent': defaultUserAgent } };
|
||||
const customUaOpts = { reqheaders: { 'User-Agent': customUserAgent } };
|
||||
|
||||
@@ -43,10 +39,8 @@ describe('http', () => {
|
||||
|
||||
after(() => {
|
||||
axios.defaults.headers.common['User-Agent'] = defaultUserAgent;
|
||||
axios.defaults.acmeSettings.bypassCustomDnsResolver = false;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
@@ -55,7 +49,6 @@ describe('http', () => {
|
||||
testClient = new HttpClient();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* HTTP verbs
|
||||
*/
|
||||
@@ -68,7 +61,6 @@ describe('http', () => {
|
||||
assert.strictEqual(resp.data, 'ok');
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* User-Agent
|
||||
*/
|
||||
|
||||