How to use the azure-iot-security-x509.X509Security function in azure-iot-security-x509

To help you get started, we’ve selected a few azure-iot-security-x509 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / azure-iot-samples-node / provisioning / Samples / device / register_x509.js View on Github external
// REGISTRATION_ID is the device id which was used for certificate generation.
// This id will be shown at the device enrollment registration records
//
var registrationId = process.env.REGISTRATION_ID;
if (!registrationId) {
  console.error('please set the REGISTRATION_ID environment variable to the one you want to use.');
  process.exit(-1);
}

var deviceCert = {
  cert: fs.readFileSync('').toString(),
  key: fs.readFileSync('').toString()
};

var transport = new Transport();
var securityClient = new X509Security(registrationId, deviceCert);
var deviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);

// Register the device.  Do not force a re-registration.
deviceClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
    process.exit(-1);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    process.exit(0);
  }
});
github Azure / azure-iot-sdk-node / provisioning / device / samples / register_x509.js View on Github external
// var Transport = require('azure-iot-provisioning-device-mqtt').Mqtt;
// var Transport = require('azure-iot-provisioning-device-mqtt').MqttWs;

var X509Security = require('azure-iot-security-x509').X509Security;
var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;

var provisioningHost = '[provisioning host]';
var idScope = '[id scope]';
var registrationId = '[registration id]';
var deviceCert = {
  cert: fs.readFileSync('[cert filename]').toString(),
  key: fs.readFileSync('[key filename]').toString()
};

var transport = new Transport();
var securityClient = new X509Security(registrationId, deviceCert);
var deviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);

// Register the device.  Do not force a re-registration.
deviceClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
  }
});
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.register = function (Transport, callback) {
    var securityClient = new X509Security(self.registrationId, self._cert);
    var transport = new Transport();
    var provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);
    provisioningDeviceClient.register(function (err, result) {
      callback(err, result);
    });
  };
github Azure / azure-iot-sdk-node / provisioning / e2e / _server_validation.js View on Github external
it.skip ('Should fail to register a device', function(done) {
        this.timeout(30000);
        var transport = new DeviceTransport();
        var securityClient = new X509Security('abcd', deviceCert);
        var deviceClient = ProvisioningDeviceClient.create(dpsDeviceClientEndpoint, 'scope', transport, securityClient);
        deviceClient.register(function(err) {
          correctDisconnectMessage(err, done);
        });
      });
    });
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.register = function (Transport, callback) {
    var securityClient = new X509Security(self.registrationId, self._cert);
    var transport = new Transport();
    var provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);
    provisioningDeviceClient.register(function (err, result) {
      assert.isNotOk(err);
      assert.isOk(result.deviceId);
      self.deviceId = result.deviceId;
      callback(err, result);
    });
  };

azure-iot-security-x509

Azure IoT x509 security client

MIT
Latest version published 2 years ago

Package Health Score

60 / 100
Full package analysis

Popular azure-iot-security-x509 functions

Similar packages