加载扩展部分时出错 v3_req PEM

Error Loading extension section 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
  });