node.js - 加载扩展部分 v3_req PEM 时出错
问题描述
尝试使用库“pem”生成带有 v3_req 扩展名的证书,但我总是遇到错误。API 文档说如果我指定配置,那么将使用 v3_req 部分。但是现在,它无法加载并显示此错误:
% openssl x509 -req -sha256 -days 1095 -in /tmp/dc4690e0574dfc1e6c1239c0215aed5326041d2e -signkey /tmp/01177dfb1c2748532d5f380144deb30ac61a1e66 -extensions v3_req -extfile /tmp/4e2988602eaded57582aea801ec912dd6ad9b4e1
2021-09-18 14:03:17.443706158 +0200 CEST [web-1] Error Loading extension section v3_req
2021-09-18 14:03:17.443702601 +0200 CEST [web-1] Error: Invalid openssl exit code: 1
2021-09-18 14:03:17.442257164 +0200 CEST [web-1] at Pipe._handle.close (net.js:607:12)
2021-09-18 14:03:17.442253496 +0200 CEST [web-1] at Socket.emit (events.js:198:13)
2021-09-18 14:03:17.442237483 +0200 CEST [web-1] at Socket.stream.socket.on (internal/child_process.js:389:11)
2021-09-18 14:03:17.442237047 +0200 CEST [web-1] at maybeClose (internal/child_process.js:982:16)
2021-09-18 14:03:17.442227991 +0200 CEST [web-1] at ChildProcess.emit (events.js:198:13)
2021-09-18 14:03:17.442227473 +0200 CEST [web-1] at ChildProcess. (/app/node_modules/pem/lib/openssl.js:175:7)
2021-09-18 14:03:17.442214690 +0200 CEST [web-1] at done (/app/node_modules/pem/lib/openssl.js:158:27)
2021-09-18 14:03:17.442212176 +0200 CEST [web-1]
2021-09-18 14:03:17.441976235 +0200 CEST [web-1] Error Loading extension section v3_req
我正在使用这个函数来生成证书:
const cert = await pem.createCertificate({ clientKey: clientPrivateKey, serviceKey: servicePrivateKey, selfSigned: true, extFile:${_dirname}/ext${keyName}.txt, config: {}, csr, days: 1095 });
并加载此文件:
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
[req_distinguished_name]
commonName = Common Name
commonName_max = 64
[v3_req]
basicConstraints = critical,CA:TRUE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
知道为什么我会收到此错误吗?
问候
解决方案
我终于找到了我的错误,我错误地使用了配置参数。正确的做法->
const cert = await pem.createCertificate({
clientKey: clientPrivateKey,
serviceKey: servicePrivateKey,
selfSigned: true,
config: [
'[req]',
'req_extensions = v3_req',
'distinguished_name = req_distinguished_name',
'[req_distinguished_name]',
'commonName = Common Name',
'commonName_max = 64',
'[v3_req]',
'basicConstraints = critical,CA:TRUE',
`keyUsage = ${keyUsage}`].join('\n'),
csr,
days: 1095
});
推荐阅读
- jquery - Laravel - 除非浏览器刷新或直接访问页面,否则脚本将无法运行
- react-native - 使用 react-native-fcm 正确设置
- python-3.x - 为什么尽管给出了完整的邮件范围,我仍然收到权限不足的错误?
- c# - WPF C# Ninject 与 mainViewModel 和多个 viewmodel 问题
- c# - 尝试从第三方 api 同步数据
- elasticsearch - 如何为多值属性添加动态范围过滤器?
- ssh - 通过 SSH 在两个远程节点之间复制文件而不通过控制器
- reactjs - React Native - FlatList 的应用程序性能问题?
- java - SimpleJdbc,请求的转换无效
- bash - 修改几个特定文件中的某些内容,例如 txt (bash)