Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var argv = require('yargs')
.usage('Usage: $0 --connectionString ')
.option('connectionString', {
alias: 'c',
describe: 'The connection string for the Device Provisioning instance',
type: 'string',
demandOption: true
})
.argv;
var connectionString = argv.connectionString;
var serviceClient = provisioningServiceClient.fromConnectionString(connectionString);
var queryForEnrollments = serviceClient.createIndividualEnrollmentQuery({
"query": "*"
}, 10);
var queryForEnrollmentGroups = serviceClient.createEnrollmentGroupQuery({
"query": "*"
}, 10);
var onEnrollmentResults = function (err, results) {
if (err) {
console.error('Failed to fetch the results: ' + err.message);
} else {
// Do something with the results
results.forEach(function (enrollment) {
console.log(JSON.stringify(enrollment, null, 2));
});
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var serviceClient = provisioningServiceClient.fromConnectionString(process.argv[2]);
var endorsementKey = process.argv[3];
var enrollment = {
registrationId: 'first',
attestation: {
type: 'tpm',
tpm: {
endorsementKey: endorsementKey
}
}
};
serviceClient.createOrUpdateIndividualEnrollment(enrollment, function(err, enrollmentResponse) {
if (err) {
console.log('error creating the individual enrollment: ' + err);
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var assert = require('chai').assert;
var uuid = require('uuid');
var debug = require('debug')('azure-iot-provisioning-device-e2e');
var certHelper = require('./cert_helper');
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var serviceClient = provisioningServiceClient.fromConnectionString(process.env.IOT_PROVISIONING_SERVICE_CONNECTION_STRING);
var enrollment = {
registrationId: 'e2e-node-deleteme-psc-' + uuid.v4(),
attestation: {
type: 'tpm',
tpm: {
endorsementKey: "AToAAQALAAMAsgAgg3GXZ0SEs/gakMyNRqXXJP1S124GUgtk8qHaGzMUaaoABgCAAEMAEAgAAAAAAAEAtKEADl/sNRgmYAjP6gXmbccRaJoTnVixisUaek0OwAzFGN70xt9ZOYp6fhIwfcft3fdVKOrKpXYcTe72CGNkGJGlQz5ti9n2pQ0uJhcX8aefh4Onm7lVlUCQAVp1K0r6zI8vkEXWsBIvwvxk0eMJbFaq146kbTkJHIGczb89RkFH2TX+CgXeZOG9oXQzUNwktmTUacspamune5Wywc/ce8HsDFYchyUHogFhrZ/LPnzyTDXO8sSC5z5dvsUBtUME3iRYDyKgZOfBtmRMqQewD+4iH+ZEJjtsyJiWR8hFhyKROnOuqXfNFwjd5IcNU4wtlKO0cLyXmTOfQK6Da1pr5Q=="
}
},
provisioningStatus: "enabled",
capabilities: {
iotEdge: true
},
reprovisionPolicy: {
updateHubAssignment: true,
migrateDeviceData: true
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var serviceClient = provisioningServiceClient.fromConnectionString(process.argv[2]);
var enrollment1 = {
registrationId: 'first',
provisioningStatus: 'disabled',
attestation: {
type: 'tpm',
tpm: {
endorsementKey: 'a'
}
}
};
var enrollment2 = {
registrationId: 'second',
provisioningStatus: 'disabled',
attestation: {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var fs = require('fs');
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var serviceClient = provisioningServiceClient.fromConnectionString(process.argv[2]);
var enrollment = {
enrollmentGroupId: 'first',
attestation: {
type: 'x509',
x509: {
signingCertificates: {
primary: {
certificate: fs.readFileSync(process.argv[3], 'utf-8').toString()
}
}
}
},
provisioningStatus: 'disabled'
};
var MqttWs = require('azure-iot-provisioning-device-mqtt').MqttWs;
var ProvisioningDeviceClient = require('azure-iot-provisioning-device').ProvisioningDeviceClient;
var ProvisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var X509Security = require('azure-iot-security-x509').X509Security;
var Registry = require('azure-iothub').Registry;
var certHelper = require('./cert_helper');
var TpmSecurityClient = require('azure-iot-security-tpm').TpmSecurityClient;
var SymmetricKeySecurityClient = require('azure-iot-security-symmetric-key').SymmetricKeySecurityClient;
var TssJs = require("tss.js");
var idScope = process.env.IOT_PROVISIONING_DEVICE_IDSCOPE;
var provisioningConnectionString = process.env.IOT_PROVISIONING_SERVICE_CONNECTION_STRING;
var registryConnectionString = process.env.IOTHUB_CONNECTION_STRING;
var provisioningHost = process.env.IOT_PROVISIONING_DEVICE_ENDPOINT;
var provisioningServiceClient = ProvisioningServiceClient.fromConnectionString(provisioningConnectionString);
var registry = Registry.fromConnectionString(registryConnectionString);
var X509IndividualTransports = [ Http, Amqp, AmqpWs, Mqtt, MqttWs ];
var X509GroupTransports = [ Http, Amqp, Mqtt, MqttWs ]; // AmqpWs is disabled because of an occasional ECONNRESET error when closing the socket. See Task 2233264.
var TpmIndividualTransports = [ Http, Amqp, AmqpWs ];
var SymmetricKeyIndividualTransports = [ Http, Amqp, AmqpWs, Mqtt, MqttWs ];
var SymmetricKeyGroupTransports = [ Http, Amqp, AmqpWs, Mqtt, MqttWs ];
var rootCert = {
cert: Buffer.from(process.env.IOT_PROVISIONING_ROOT_CERT,"base64").toString('ascii'),
key: Buffer.from(process.env.IOT_PROVISIONING_ROOT_CERT_KEY,"base64").toString('ascii'),
};
var selfSignedCert;
var certWithoutChain;
var intermediateCert1;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var serviceClient = provisioningServiceClient.fromConnectionString(process.argv[2]);
var enrollment1 = {
registrationId: 'first',
attestation: {
type: 'tpm',
tpm: {
endorsementKey: 'a'
}
}
};
var enrollment2 = {
registrationId: 'second',
attestation: {
type: 'tpm',
tpm: {
describe: 'Unique identifier for the device that shall be created',
type: 'string',
demandOption: true
})
.option('connectionstring', {
alias: 'c',
describe: 'The connection string for the Device Provisioning instance',
type: 'string',
demandOption: true
})
.argv;
var deviceID = argv.deviceid;
var connectionString = argv.connectionstring;
var serviceClient = provisioningServiceClient.fromConnectionString(connectionString);
var certFile = path.join(__dirname, "cert", deviceID + "-cert.pem");
if (!fs.existsSync(certFile)) {
console.log('Certificate File not found:' + certFile);
process.exit();
} else {
var certificate = fs.readFileSync(certFile, 'utf-8').toString();
};
var enrollment = {
registrationId: deviceID,
deviceID: deviceID,
attestation: {
type: 'x509',
x509: {
it('Should fail to create enrollment', function(done) {
var dpsServiceClient = provisioningServiceClient.fromConnectionString(process.env.DPS_CONN_STRING_INVALID_CERT);
dpsServiceClient.createOrUpdateIndividualEnrollment(enrollment1, function(err) {
correctDisconnectMessage(err, done);
});
});
});