forked from Azure/azure-iot-sdk-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_individual_tpm_enrollment.js
44 lines (39 loc) · 1.34 KB
/
create_individual_tpm_enrollment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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;
const path = require('path');
var argv = require('yargs')
.usage('Usage: $0 --endorsementkey <ENDORSMENT KEY> --connectionstring <DEVICE PROVISIONING CONNECTION STRING> ')
.option('endorsementKey', {
alias: 'e',
describe: 'Endorsment key for TPM',
type: 'string',
demandOption: true
})
.option('connectionstring', {
alias: 'c',
describe: 'The connection string for the Device Provisioning instance',
type: 'string',
demandOption: true
})
.argv;
var endorsementKey = argv.endorsementKey;
var connectionString = argv.connectionString;
var serviceClient = provisioningServiceClient.fromConnectionString(connectionString);
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);
} else {
console.log("enrollment record returned: " + JSON.stringify(enrollmentResponse, null, 2));
}
});