Error: unable to verify the first certificate in nodejs azure queue storage createMessage

Error: unable to verify the first certificate in nodejs azure queue storage createMessage

我正在尝试在本地环境中的 MacOS 上的 Azurite 模拟器上测试我的 Azure 队列存储。我写了一段代码来发送消息,要在 Azure Storage Explorer 上查看。我正在使用 Azure 存储资源管理器中 Azurite documentation and have set up self-signed rootCA.pem certificate 中所述的 https 连接字符串。但是,当我将代码放入文件 file.js 和 运行 node file.js 时。它仍然给我以下错误消息。有谁知道我做错了什么?如果需要更多信息,请告诉我。

file.js

'use strict';


const storage = require('azure-storage');
const queueService = storage.createQueueService("DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:11000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:11001/devstoreaccount1;");

queueService.messageEncoder = new storage.QueueMessageEncoder.TextBase64QueueMessageEncoder();



function testing() {

  queueService.createMessage('emailv2', "Hello world", (error) => {
    if (error) {
      console.log('Error encountered when enqueueing welcome message', error);
      console.log()
    }
  });
}



console.log(testing())

错误信息

Error encountered when enqueueing welcome message Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1497:34)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket._finishInit (_tls_wrap.js:932:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}

关于错误,您的节点的 CA 包中似乎缺少根证书,然后链验证失败。我建议您在节点运行时添加根证书。

例如

  1. 为 Azurite 模拟器配置 Https

    一个。生成 PEM 文件和密钥文件

     mkcert -install
     mkcert 127.0.0.1
    

    b。带 HTTPS 的 Strat Azurite 模拟器

    azurite --cert 127.0.0.1.pem --key 127.0.0.1-key.pem -s -l c:\azurite -d c:\azurite\debug.log --oauth basic
    
  2. 代码

//add the root certificate in your HTTP angent 
const rootCas = require("ssl-root-cas").create();
rootCas.addFile("<the path of rootCA.pem>");
require("https").globalAgent.options.ca = rootCas;

const storage = require("azure-storage");
const queue = storage.createQueueService(
  "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;"
);
// use our own HTTP anagent 
queue.enableGlobalHttpAgent = true;
// the message encoding I use base64
queue.messageEncoder = new storage.QueueMessageEncoder.TextBase64QueueMessageEncoder();
queue.createMessage("test", "hello", (error) => {
  if (error) throw error;
  console.log("send sucessfully");
});

queue.getMessages("test", (error, serverMessages) => {
  if (error) throw error;
  console.log(serverMessages[0].messageText);
  queue.deleteMessage(
    "test",
    serverMessages[0].messageId,
    serverMessages[0].popReceipt,
    (error) => {
      if (error) throw error;
      console.log("complete the message successfully");
    }
  );
});

详情请参考here and here