Skip to content

Commit 7b0085f

Browse files
authored
Merge pull request #745 from particle-iot/feature/device-protection
Add Device Protection feature
2 parents 8f40833 + 105cb40 commit 7b0085f

23 files changed

+1568
-109
lines changed

npm-shrinkwrap.json

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
],
5454
"dependencies": {
5555
"@particle/device-constants": "^3.4.0",
56-
"binary-version-reader": "^2.3.1",
56+
"binary-version-reader": "^2.4.0",
5757
"chalk": "^2.4.2",
5858
"cli-progress": "^3.12.0",
5959
"cli-spinner": "^0.2.10",
@@ -67,10 +67,10 @@
6767
"lodash": "^4.17.15",
6868
"moment": "^2.24.0",
6969
"node-wifiscanner2": "^1.2.1",
70-
"particle-api-js": "^10.3.0",
70+
"particle-api-js": "^10.5.1",
7171
"particle-commands": "^1.0.1",
7272
"particle-library-manager": "^0.1.15",
73-
"particle-usb": "^3.1.0",
73+
"particle-usb": "^3.4.0",
7474
"request": "https://github.com/particle-iot/request/releases/download/v2.75.1-relativepath.1/request-2.75.1-relativepath.1.tgz",
7575
"safe-buffer": "^5.2.0",
7676
"semver": "^7.5.2",
@@ -143,6 +143,7 @@
143143
"test:e2e:ci": "npm run test:e2e:no-device -- --forbid-only",
144144
"test:e2e:no-device": "npm run test:e2e -- --grep @device --invert",
145145
"test:e2e:wifi": "npm run test:e2e -- --grep @device,@wifi",
146+
"test:e2e:device-protection": "npm run test:e2e -- --grep @device,@device-protection",
146147
"test:e2e:watch": "npm run test:e2e -- --watch --watch-extensions js,json",
147148
"test:e2e:inspect": "npm test:e2e -- --inspect-brk",
148149
"test:e2e:silent": "PARTICLE_NOOP=$(npm run test:e2e:ci)",

src/cli/binary.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,21 @@ module.exports = ({ commandProcessor, root }) => {
1212
}
1313
});
1414

15+
commandProcessor.createCommand(binary, 'enable-device-protection', 'Create a protected bootloader binary', {
16+
params: '<file>',
17+
options: {
18+
'saveTo': {
19+
description: 'Specify the filename for the protected binary'
20+
}
21+
},
22+
handler: (args) => {
23+
const BinaryCommand = require('../cmd/binary');
24+
return new BinaryCommand().createProtectedBinary({ saveTo: args.saveTo, file: args.params.file, verbose: true });
25+
},
26+
examples: {
27+
'$0 $command bootloader.bin': 'Provide bootloader binary to protect'
28+
}
29+
});
30+
1531
return binary;
1632
};

src/cli/device-protection.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = ({ commandProcessor, root }) => {
2+
const deviceProtection = commandProcessor.createCategory(root, 'device-protection', 'Manage device protection');
3+
4+
commandProcessor.createCommand(deviceProtection, 'status', 'Gets the current device protection status', {
5+
handler: () => {
6+
const DeviceProtectionCommands = require('../cmd/device-protection');
7+
return new DeviceProtectionCommands().getStatus();
8+
},
9+
examples: {
10+
'$0 $command': 'Gets the current device protection status'
11+
}
12+
});
13+
14+
commandProcessor.createCommand(deviceProtection, 'disable', 'Disables device protection', {
15+
16+
handler: () => {
17+
const DeviceProtectionCommands = require('../cmd/device-protection');
18+
return new DeviceProtectionCommands().disableProtection();
19+
},
20+
examples: {
21+
'$0 $command': 'Puts a Protected Device to Service Mode',
22+
},
23+
epilogue: 'A Protected Device in Service Mode allows any command to be performed on it that can be performed on an Open Device like flashing firmware or serial monitor.'
24+
});
25+
26+
commandProcessor.createCommand(deviceProtection, 'enable', 'Enables device protection', {
27+
options: {
28+
file: {
29+
description: 'File to use for device protection'
30+
}
31+
},
32+
handler: (args) => {
33+
const DeviceProtectionCommands = require('../cmd/device-protection');
34+
return new DeviceProtectionCommands().enableProtection(args);
35+
},
36+
examples: {
37+
'$0 $command': 'Turns an Open Device into a Protected Device'
38+
}
39+
});
40+
41+
return deviceProtection;
42+
};
43+

src/cli/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const bundle = require('./bundle');
55
const cloud = require('./cloud');
66
const config = require('./config');
77
const doctor = require('./doctor');
8+
const protection = require('./device-protection');
89
const flash = require('./flash');
910
const func = require('./function');
1011
const keys = require('./keys');
@@ -50,6 +51,7 @@ module.exports = function registerAllCommands(context) {
5051
cloud(context);
5152
config(context);
5253
doctor(context);
54+
protection(context);
5355
flash(context);
5456
func(context);
5557
keys(context);

src/cmd/api.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ module.exports = class ParticleApi {
274274
}));
275275
}
276276

277+
unprotectDevice({ deviceId, product, action, serverNonce, deviceNonce, deviceSignature, devicePublicKeyFingerprint, auth, headers, context }) {
278+
return this._wrap(this.api.unprotectDevice({
279+
deviceId,
280+
product,
281+
action,
282+
serverNonce,
283+
deviceNonce,
284+
deviceSignature,
285+
devicePublicKeyFingerprint,
286+
auth,
287+
headers,
288+
context
289+
}));
290+
}
291+
277292
createLogicFunction({ org, logicFunction }) {
278293
return this._wrap(this.api.createLogicFunction({
279294
auth: this.accessToken,
@@ -282,6 +297,15 @@ module.exports = class ParticleApi {
282297
}));
283298
}
284299

300+
getProduct({ product, auth, headers, context }) {
301+
return this._wrap(this.api.getProduct({
302+
product,
303+
auth,
304+
headers,
305+
context
306+
}));
307+
}
308+
285309
_wrap(promise){
286310
return Promise.resolve(promise)
287311
.then(result => result.body || result)

0 commit comments

Comments
 (0)