AWS IoT连接错误:无效的"caCert" aws-iot-device-sdk随附的选项 [英] AWS IoT Connection error : Invalid "caCert" option supplied with aws-iot-device-sdk

查看:274
本文介绍了AWS IoT连接错误:无效的"caCert" aws-iot-device-sdk随附的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在AWS中为设备配置了由我的CA签名的设备证书.另外,我之前已经在AWS上将我的CA和VerificationCert一起注册.

I've provisioned a device in AWS with device Certificate which is signed by my CA. Also, I've registered my CA along with verificationCert in AWS previously.

现在,当我发送数据时,在选项中,

Now when I send the data, In the options,

var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({
privateKey: '--BEGIN RSA PRIVATE KEY--', //private key of my device
clientCert: '--BEGIN CERTIFICATE --', //cat deviceCertificate and registered CA 
caCert: '--BEGIN CERTIFICATE--', //Amazon root CA
clientId: 'Thing01',
region: 'us-west-2',
host: xxxxxxxx.iot.us-west-2.amazonaws.com,
secretKey: 'dcvevv',
accessKeyId: 'ferferer'
});

device.on('connect',function(err){
device.publish('$aws/things/Thing01/shadow/update',JSON.stringify({
"state" :{
  "desired": {
 "color": "blue"
 }
}
})
);
})

我遇到了错误

抛出新的错误(exceptions.INVALID_CA_CERT_OPTION); ^错误:提供了无效的"caCert"选项.

throw new Error(exceptions.INVALID_CA_CERT_OPTION); ^ Error: Invalid "caCert" option supplied.

有人可以让我知道上面的代码片段在哪里做错了吗?

Can anyone let me know where I'm doing wrong in the above code snippet?

在选项中进行更正后,下面是代码:

After making corrections in the options, below is the code:

    var awsIot = require('aws-iot-device-sdk');
    var device = awsIot.device({
    host:'xxxxx.iot.us-west-2.amazonaws.com',
    keyPath : './certs/deviceTest/5e2570c0605418.key',  
    certPath : './certs/deviceTest/5e2570c0605418AndCA.crt',   //cat of device and Registered CA
    caPath : './certs/rootCA.pem', //public cert of AWS root CA1 
    clientId: 'ManualDevice_01', //ThingName
    region : 'us-west-2',
   secretKey: 'xxxxxxxxxxxx',
   accessKeyId: 'xxxxxxxxxxxxxxxx'
  }); 
   console.log("Invoking on connect");
   device.on('connect',function(error ){
    console.log("In on connect !!");
    if(error)
       console.log('could not connect');
  device.publish('$aws/things/ManualDevice_01/shadow/update',JSON.stringify({
  "state" : {
    "desired" : {
        "color" : "pink",
        "power" : "off",
        "val":"1"
     }
    }
   } ), function(err){
   if(err)
      console.log("Could not send : Error : "+err)
   else
   {
      console.log("Sent data")
   } 
   }
  );
 console.log('Message sent........')
 })
 device.on('message',function(topic,payload){
     console.log('message',topic,payload.toString());
  })

device.on('connect')内部的语句未执行. 我只能看到正在打印的在连接上调用"

The statements inside device.on('connect') are not getting executed. I could see only "Invoking on connect" being printed

问题已解决!!!

在创建设备时,我必须将Policy附加到该设备上. 然后,我就可以通过上述带有证书的MQTT以指定的方式发送数据.

While creating a device, I have to attach Policy to it. Then I'm able to send the data in above specified way through MQTT with certificates.

推荐答案

The doc implies you should be passing paths to the files for the TLS certificate's and key.

例如

var device = awsIot.device({
   keyPath: <YourPrivateKeyPath>,
  certPath: <YourCertificatePath>,
    caPath: <YourRootCACertificatePath>,
  clientId: <YourUniqueClientIdentifier>,
      host: <YourCustomEndpoint>
});

稍后在同一 doc 中说,caCert可以是缓冲区(不是字符串)

Later on in the same doc it says caCert can be a buffer (not a String)

  • caCert:与caPath相同,但也可以接受包含CA证书数据的缓冲区
  • caCert: same as caPath, but can also accept a buffer containing CA certificate data

这意味着您将需要首先对字符串值进行解码.

This means you will need to decode the string value first.

这篇关于AWS IoT连接错误:无效的"caCert" aws-iot-device-sdk随附的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆