ssl Node.js Apple Pay -在服务器上验证商家时出现“unsupported”错误

uidvcgyl  于 2023-08-06  发布在  Node.js
关注(0)|答案(1)|浏览(186)

我有一个Node.js应用程序,它通过验证商家来启动Apple Pay会话。在本地运行此应用程序时,一切正常。然而,当我将其部署到Railway.app平台时,我遇到了一个“不支持”的错误,似乎与TLS/SSL配置有关。
下面是我的代码的关键部分:

async function validateMerchant() {
  let response = {}

  const certFilePath = './merchent_certificate/Certificates.p12'

  const cert = fs.readFileSync(certFilePath)

  try {
    const options = {
      url: 'https://apple-pay-gateway.apple.com/paymentservices/startSession',
      agentOptions: {
        pfx: cert,
        passphrase: '********',
      },
      method: 'post',
      body: {
        merchantIdentifier: 'merchant.com.zeebuz.pay',
        displayName: 'Your Store Name',
        initiative: 'web',
        initiativeContext: 'dev-app.zeebuz.com',
      },
      json: true,
    }
    response = await promisifyRequest(options)
  } catch (error) {
    console.error(error)
  }
  return response
}

字符串
(Note:出于安全原因,实际的密码短语被替换为“*”。)
确切的错误消息是:

Error: unsupported
at configSecureContext (node:internal/tls/secure-context:277:15)
at Object.createSecureContext (node:_tls_common:121:3)
at Object.connect (node:_tls_wrap:1630:48)
at Agent.createConnection (node:https:147:22)
at Agent.createSocket (node:_http_agent:347:26)
at Agent.addRequest (node:_http_agent:294:10)
at new ClientRequest (node:_http_client:335:16)
at Object.request (node:https:357:10)
at Request.start (/app/node_modules/request/request.js:751:32)
at Request.write (/app/node_modules/request/request.js:1491:10)


证书和私钥是根据Apple Pay指南在我的本地机器上生成的,PKCS 12证书存储在文件“Certificates.p12”中。
我想知道证书创建位置是否可能导致此问题,尽管这似乎不太可能。
任何见解将不胜感激。谢谢你,谢谢

iyr7buue

iyr7buue1#

如果其他任何人遇到此问题,解决方案是将p12转换为单个pem(包括证书和密钥),并修改agentOptions

agentOptions: {
  cert: pemFile
  key: pemFile
}

字符串

相关问题