From f8fdfbf7a7c1e554a2ea07271e15aadb09cfcc1d Mon Sep 17 00:00:00 2001 From: Bert Kleewein Date: Mon, 13 Nov 2017 18:12:08 -0800 Subject: [PATCH 1/2] security stubs --- .gitignore | 3 ++ build/build_parallel/config.json | 6 ++++ security/tpm/.npmignore | 6 ++++ security/tpm/index.d.ts | 4 +++ security/tpm/index.js | 8 ++++++ security/tpm/package.json | 45 ++++++++++++++++++++++++++++++ security/tpm/readme.md | 13 +++++++++ security/tpm/src/tpm.ts | 24 ++++++++++++++++ security/tpm/test/_tpm_test.js | 47 ++++++++++++++++++++++++++++++++ security/tpm/tsconfig.json | 11 ++++++++ security/x509/.npmignore | 6 ++++ security/x509/index.d.ts | 4 +++ security/x509/index.js | 8 ++++++ security/x509/package.json | 45 ++++++++++++++++++++++++++++++ security/x509/readme.md | 13 +++++++++ security/x509/src/x509.ts | 16 +++++++++++ security/x509/test/_x509_test.js | 31 +++++++++++++++++++++ security/x509/tsconfig.json | 11 ++++++++ 18 files changed, 301 insertions(+) create mode 100644 security/tpm/.npmignore create mode 100644 security/tpm/index.d.ts create mode 100644 security/tpm/index.js create mode 100644 security/tpm/package.json create mode 100644 security/tpm/readme.md create mode 100644 security/tpm/src/tpm.ts create mode 100644 security/tpm/test/_tpm_test.js create mode 100644 security/tpm/tsconfig.json create mode 100644 security/x509/.npmignore create mode 100644 security/x509/index.d.ts create mode 100644 security/x509/index.js create mode 100644 security/x509/package.json create mode 100644 security/x509/readme.md create mode 100644 security/x509/src/x509.ts create mode 100644 security/x509/test/_x509_test.js create mode 100644 security/x509/tsconfig.json diff --git a/.gitignore b/.gitignore index 61dbfc1f9..e6e17e1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -221,6 +221,9 @@ provisioning/transport/http/lib/ provisioning/transport/mqtt/lib/ provisioning/device/lib/ +security/x509/lib +security/tpm/lib + service/lib ts-e2e/lib diff --git a/build/build_parallel/config.json b/build/build_parallel/config.json index 513990380..781d0783b 100644 --- a/build/build_parallel/config.json +++ b/build/build_parallel/config.json @@ -79,6 +79,12 @@ "skip_build": true, "skip_test": true, "skip_ci": true + }, + { + "directory": "security/x509" + }, + { + "directory": "security/tpm" } ] } \ No newline at end of file diff --git a/security/tpm/.npmignore b/security/tpm/.npmignore new file mode 100644 index 000000000..ceee25702 --- /dev/null +++ b/security/tpm/.npmignore @@ -0,0 +1,6 @@ +coverage/ +devdoc/ +test/ +samples/ +src/ +lib/**/*.map \ No newline at end of file diff --git a/security/tpm/index.d.ts b/security/tpm/index.d.ts new file mode 100644 index 000000000..f823e749a --- /dev/null +++ b/security/tpm/index.d.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +export { TMPSecurityObject } from './lib/tpm'; diff --git a/security/tpm/index.js b/security/tpm/index.js new file mode 100644 index 000000000..4e38e0ae2 --- /dev/null +++ b/security/tpm/index.js @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +'use strict'; + +module.exports = { + TMPSecurityObject: require('lib/tpm').TMPSecurityObject +}; \ No newline at end of file diff --git a/security/tpm/package.json b/security/tpm/package.json new file mode 100644 index 000000000..3750ced1b --- /dev/null +++ b/security/tpm/package.json @@ -0,0 +1,45 @@ +{ + "name": "azure-iot-security-tpm", + "version": "0.0.1", + "description": "Azure IoT TPM security client", + "author": "Microsoft Corporation", + "license": "MIT", + "main": "index.js", + "typings": "index.d.ts", + "dependencies": { + "azure-iot-common": "1.2.2", + "debug": "^3.0.1" + }, + "devDependencies": { + "chai": "^3.5.0", + "istanbul": "^0.4.4", + "jshint": "^2.9.2", + "mocha": "^3.0.1", + "sinon": "^1.17.5", + "tslint": "^5.1.0", + "typescript": "2.2.2", + "@types/node": "^7.0.5" + }, + "scripts": { + "lint": "tslint --project . -c ../../tslint.json", + "build": "tsc", + "unittest-min": "istanbul cover --report none node_modules/mocha/bin/_mocha -- --reporter dot test/_*_test.js", + "alltest-min": "istanbul cover --report none node_modules/mocha/bin/_mocha -- --reporter dot test/_*_test*.js", + "unittest": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/_*_test.js", + "alltest": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/_*_test*.js", + "ci": "npm -s run lint && npm -s run build && npm -s run alltest-min && npm -s run check-cover", + "test": "npm -s run lint && npm -s run build && npm -s run unittest", + "check-cover": "istanbul check-coverage --statements 50 --branches 50 --lines 50 --functions 50" + }, + "engines": { + "node": ">= 0.10" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-iot-sdk-node.git" + }, + "bugs": { + "url": "https://github.com/Azure/azure-iot-sdk-node/issues" + }, + "homepage": "https://github.com/Azure/azure-iot-sdk-node#readme" +} \ No newline at end of file diff --git a/security/tpm/readme.md b/security/tpm/readme.md new file mode 100644 index 000000000..0aac28cae --- /dev/null +++ b/security/tpm/readme.md @@ -0,0 +1,13 @@ +#azure-iot-security-tpm +Security module for Azure IoT TPM security + +[![npm version](https://badge.fury.io/js/azure-iot-security-x509.svg)](https://badge.fury.io/js/azure-iot-security-x509) + +## Install + +`npm install -g azure-iot-security-x509@latest` to get the latest (pre-release) version. + +## Getting Started + + + diff --git a/security/tpm/src/tpm.ts b/security/tpm/src/tpm.ts new file mode 100644 index 000000000..3b901de9d --- /dev/null +++ b/security/tpm/src/tpm.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +'use strict'; +import { errors } from 'azure-iot-common'; + +export class TMPSecurityObject { + getEndoresementKey(callback: (err?: Error) => void): void { + throw new errors.NotImplementedError(); + } + + getStorageKey(callback: (err?: Error) => void): void { + throw new errors.NotImplementedError(); + } + + signData(callback: (err?: Error) => void): void { + throw new errors.NotImplementedError(); + } + + activateSymetricIdentity(callback: (err?: Error) => void): void { + throw new errors.NotImplementedError(); + } +} + diff --git a/security/tpm/test/_tpm_test.js b/security/tpm/test/_tpm_test.js new file mode 100644 index 000000000..e87c0f73b --- /dev/null +++ b/security/tpm/test/_tpm_test.js @@ -0,0 +1,47 @@ +// 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 TMPSecurityObject = require('../lib/tpm').TMPSecurityObject; +var assert = require('chai').assert; + +describe('tpm', function () { + this.timeout(1000); + + var obj = new TMPSecurityObject(); + + describe('getEndoresementKey', function() { + it ('throws', function() { + assert.throws(function() { + obj.getEndoresementKey(); + }); + }); + }); + + describe('getStorageKey', function() { + it ('throws', function() { + assert.throws(function() { + obj.getStorageKey(); + }); + }); + }); + + describe('signData', function() { + it ('throws', function() { + assert.throws(function() { + obj.signData(); + }); + }); + }); + + describe('activateSymetricIdentity', function() { + it ('throws', function() { + assert.throws(function() { + obj.activateSymetricIdentity(); + }); + }); + }); + +}); + diff --git a/security/tpm/tsconfig.json b/security/tpm/tsconfig.json new file mode 100644 index 000000000..e08f5320f --- /dev/null +++ b/security/tpm/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "outDir": "./lib", + "target":"es5", + "sourceMap": true, + "declaration": true + }, + "include": [ + "./src/**/*.ts" + ] +} \ No newline at end of file diff --git a/security/x509/.npmignore b/security/x509/.npmignore new file mode 100644 index 000000000..ceee25702 --- /dev/null +++ b/security/x509/.npmignore @@ -0,0 +1,6 @@ +coverage/ +devdoc/ +test/ +samples/ +src/ +lib/**/*.map \ No newline at end of file diff --git a/security/x509/index.d.ts b/security/x509/index.d.ts new file mode 100644 index 000000000..5b32bbd3b --- /dev/null +++ b/security/x509/index.d.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +export { X509SecurityObject } from './lib/x509'; diff --git a/security/x509/index.js b/security/x509/index.js new file mode 100644 index 000000000..93f370fff --- /dev/null +++ b/security/x509/index.js @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +'use strict'; + +module.exports = { + X509SecurityObject: require('lib/x509').X509SecurityObject +}; \ No newline at end of file diff --git a/security/x509/package.json b/security/x509/package.json new file mode 100644 index 000000000..ea866487b --- /dev/null +++ b/security/x509/package.json @@ -0,0 +1,45 @@ +{ + "name": "azure-iot-security-x509", + "version": "0.0.1", + "description": "Azure IoT x509 security client", + "author": "Microsoft Corporation", + "license": "MIT", + "main": "index.js", + "typings": "index.d.ts", + "dependencies": { + "azure-iot-common": "1.2.2", + "debug": "^3.0.1" + }, + "devDependencies": { + "chai": "^3.5.0", + "istanbul": "^0.4.4", + "jshint": "^2.9.2", + "mocha": "^3.0.1", + "sinon": "^1.17.5", + "tslint": "^5.1.0", + "typescript": "2.2.2", + "@types/node": "^7.0.5" + }, + "scripts": { + "lint": "tslint --project . -c ../../tslint.json", + "build": "tsc", + "unittest-min": "istanbul cover --report none node_modules/mocha/bin/_mocha -- --reporter dot test/_*_test.js", + "alltest-min": "istanbul cover --report none node_modules/mocha/bin/_mocha -- --reporter dot test/_*_test*.js", + "unittest": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/_*_test.js", + "alltest": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/_*_test*.js", + "ci": "npm -s run lint && npm -s run build && npm -s run alltest-min && npm -s run check-cover", + "test": "npm -s run lint && npm -s run build && npm -s run unittest", + "check-cover": "istanbul check-coverage --statements 50 --branches 50 --lines 50 --functions 50" + }, + "engines": { + "node": ">= 0.10" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-iot-sdk-node.git" + }, + "bugs": { + "url": "https://github.com/Azure/azure-iot-sdk-node/issues" + }, + "homepage": "https://github.com/Azure/azure-iot-sdk-node#readme" +} \ No newline at end of file diff --git a/security/x509/readme.md b/security/x509/readme.md new file mode 100644 index 000000000..410cba868 --- /dev/null +++ b/security/x509/readme.md @@ -0,0 +1,13 @@ +#azure-iot-security-x509 +Security module for Azure IoT x509 security + +[![npm version](https://badge.fury.io/js/azure-iot-security-x509.svg)](https://badge.fury.io/js/azure-iot-security-x509) + +## Install + +`npm install -g azure-iot-security-x509@latest` to get the latest (pre-release) version. + +## Getting Started + + + diff --git a/security/x509/src/x509.ts b/security/x509/src/x509.ts new file mode 100644 index 000000000..c68903855 --- /dev/null +++ b/security/x509/src/x509.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +'use strict'; +import { errors } from 'azure-iot-common'; + +export class X509SecurityObject { + getCertificate(callback: (err?: Error, cert?: string) => void): void { + throw new errors.NotImplementedError(); + } + + getCertificateChain(callback: (err?: Error, cert?: string) => void): void { + throw new errors.NotImplementedError(); + } +} + diff --git a/security/x509/test/_x509_test.js b/security/x509/test/_x509_test.js new file mode 100644 index 000000000..c628b4d17 --- /dev/null +++ b/security/x509/test/_x509_test.js @@ -0,0 +1,31 @@ +// 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 X509SecurityObject = require('../lib/x509').X509SecurityObject; +var assert = require('chai').assert; + +describe('x509', function () { + this.timeout(1000); + + var obj = new X509SecurityObject(); + + describe('GetCertificate', function() { + it ('throws', function() { + assert.throws(function() { + obj.getCertificate(); + }); + }); + }); + + describe('GetCertificateChain', function() { + it ('throws', function() { + assert.throws(function() { + obj.getCertificateChain(); + }); + }); + }); + +}); + diff --git a/security/x509/tsconfig.json b/security/x509/tsconfig.json new file mode 100644 index 000000000..e08f5320f --- /dev/null +++ b/security/x509/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "outDir": "./lib", + "target":"es5", + "sourceMap": true, + "declaration": true + }, + "include": [ + "./src/**/*.ts" + ] +} \ No newline at end of file From dfe1f9181c37607191f394c67b922fde7a5531dd Mon Sep 17 00:00:00 2001 From: Bert Kleewein Date: Tue, 14 Nov 2017 10:29:19 -0800 Subject: [PATCH 2/2] Code review feedback --- security/tpm/index.d.ts | 2 +- security/tpm/index.js | 2 +- security/tpm/readme.md | 4 ++-- security/tpm/src/tpm.ts | 10 +++++----- security/tpm/test/_tpm_test.js | 20 ++++++++++---------- security/x509/index.d.ts | 2 +- security/x509/index.js | 2 +- security/x509/src/x509.ts | 2 +- security/x509/test/_x509_test.js | 8 ++++---- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/security/tpm/index.d.ts b/security/tpm/index.d.ts index f823e749a..74426fc92 100644 --- a/security/tpm/index.d.ts +++ b/security/tpm/index.d.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -export { TMPSecurityObject } from './lib/tpm'; +export { TpmSecurityClient } from './lib/tpm'; diff --git a/security/tpm/index.js b/security/tpm/index.js index 4e38e0ae2..d48d413cf 100644 --- a/security/tpm/index.js +++ b/security/tpm/index.js @@ -4,5 +4,5 @@ 'use strict'; module.exports = { - TMPSecurityObject: require('lib/tpm').TMPSecurityObject + TpmSecurityClient : require('lib/tpm').TpmSecurityClient }; \ No newline at end of file diff --git a/security/tpm/readme.md b/security/tpm/readme.md index 0aac28cae..5c70ed6e5 100644 --- a/security/tpm/readme.md +++ b/security/tpm/readme.md @@ -1,11 +1,11 @@ #azure-iot-security-tpm Security module for Azure IoT TPM security -[![npm version](https://badge.fury.io/js/azure-iot-security-x509.svg)](https://badge.fury.io/js/azure-iot-security-x509) +[![npm version](https://badge.fury.io/js/azure-iot-security-tpm.svg)](https://badge.fury.io/js/azure-iot-security-tpm) ## Install -`npm install -g azure-iot-security-x509@latest` to get the latest (pre-release) version. +`npm install -g azure-iot-security-tpm@latest` to get the latest (pre-release) version. ## Getting Started diff --git a/security/tpm/src/tpm.ts b/security/tpm/src/tpm.ts index 3b901de9d..87c46047c 100644 --- a/security/tpm/src/tpm.ts +++ b/security/tpm/src/tpm.ts @@ -4,20 +4,20 @@ 'use strict'; import { errors } from 'azure-iot-common'; -export class TMPSecurityObject { - getEndoresementKey(callback: (err?: Error) => void): void { +export class TpmSecurityClient { + getEndorsementKey(callback: (err?: Error) => void): void { throw new errors.NotImplementedError(); } - getStorageKey(callback: (err?: Error) => void): void { + getStorageRootKey(callback: (err?: Error) => void): void { throw new errors.NotImplementedError(); } - signData(callback: (err?: Error) => void): void { + signWithIdentity(callback: (err?: Error) => void): void { throw new errors.NotImplementedError(); } - activateSymetricIdentity(callback: (err?: Error) => void): void { + activateSymmetricIdentity(callback: (err?: Error) => void): void { throw new errors.NotImplementedError(); } } diff --git a/security/tpm/test/_tpm_test.js b/security/tpm/test/_tpm_test.js index e87c0f73b..46f5b9943 100644 --- a/security/tpm/test/_tpm_test.js +++ b/security/tpm/test/_tpm_test.js @@ -3,42 +3,42 @@ 'use strict'; -var TMPSecurityObject = require('../lib/tpm').TMPSecurityObject; +var TpmSecurityClient = require('../lib/tpm').TpmSecurityClient ; var assert = require('chai').assert; describe('tpm', function () { this.timeout(1000); - var obj = new TMPSecurityObject(); + var obj = new TpmSecurityClient (); - describe('getEndoresementKey', function() { + describe('getEndorsementKey', function() { it ('throws', function() { assert.throws(function() { - obj.getEndoresementKey(); + obj.getEndorsementKey(); }); }); }); - describe('getStorageKey', function() { + describe('getStorageRootKey', function() { it ('throws', function() { assert.throws(function() { - obj.getStorageKey(); + obj.getStorageRootKey(); }); }); }); - describe('signData', function() { + describe('signWithIdentity', function() { it ('throws', function() { assert.throws(function() { - obj.signData(); + obj.signWithIdentity(); }); }); }); - describe('activateSymetricIdentity', function() { + describe('activateSymmetricIdentity', function() { it ('throws', function() { assert.throws(function() { - obj.activateSymetricIdentity(); + obj.activateSymmetricIdentity(); }); }); }); diff --git a/security/x509/index.d.ts b/security/x509/index.d.ts index 5b32bbd3b..dec4f8c84 100644 --- a/security/x509/index.d.ts +++ b/security/x509/index.d.ts @@ -1,4 +1,4 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -export { X509SecurityObject } from './lib/x509'; +export { X509SecurityClient } from './lib/x509'; diff --git a/security/x509/index.js b/security/x509/index.js index 93f370fff..4dd484dee 100644 --- a/security/x509/index.js +++ b/security/x509/index.js @@ -4,5 +4,5 @@ 'use strict'; module.exports = { - X509SecurityObject: require('lib/x509').X509SecurityObject + X509SecurityClient: require('lib/x509').X509SecurityClient }; \ No newline at end of file diff --git a/security/x509/src/x509.ts b/security/x509/src/x509.ts index c68903855..8e4494f0d 100644 --- a/security/x509/src/x509.ts +++ b/security/x509/src/x509.ts @@ -4,7 +4,7 @@ 'use strict'; import { errors } from 'azure-iot-common'; -export class X509SecurityObject { +export class X509SecurityClient { getCertificate(callback: (err?: Error, cert?: string) => void): void { throw new errors.NotImplementedError(); } diff --git a/security/x509/test/_x509_test.js b/security/x509/test/_x509_test.js index c628b4d17..382c2ace3 100644 --- a/security/x509/test/_x509_test.js +++ b/security/x509/test/_x509_test.js @@ -3,15 +3,15 @@ 'use strict'; -var X509SecurityObject = require('../lib/x509').X509SecurityObject; +var X509SecurityClient = require('../lib/x509').X509SecurityClient; var assert = require('chai').assert; describe('x509', function () { this.timeout(1000); - var obj = new X509SecurityObject(); + var obj = new X509SecurityClient(); - describe('GetCertificate', function() { + describe('getCertificate', function() { it ('throws', function() { assert.throws(function() { obj.getCertificate(); @@ -19,7 +19,7 @@ describe('x509', function () { }); }); - describe('GetCertificateChain', function() { + describe('getCertificateChain', function() { it ('throws', function() { assert.throws(function() { obj.getCertificateChain();