Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,3 +59,9 @@ typings/

# next.js build output
.next

# coverage:report output
coverage.lcov

# test unwanted data output
tests/out_file_export.pfx
3 changes: 3 additions & 0 deletions .gitmodules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
[submodule "tests/sample-data"]
path = tests/sample-data
url = https://github.com/mdmulti/sample-data
82 changes: 82 additions & 0 deletions .npmignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
# from gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# end gitignore
# -------------------

# standard

node_modules/

coverage.lcov

# tests & that one submodule

tests/

.gitmodules

# travis config

.travis.yml
15 changes: 15 additions & 0 deletions .travis.yml
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
language: node_js

node_js:
- "10"

# Deploy on tags

deploy:
provider: npm
email: $NPME
api_key: $NPMP
on:
tags: true

# Run tests

install:
- npm install
jobs:
include:
- stage: Coverage
script: npm run coverage:all
1 change: 1 addition & 0 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
[![npm version](https://img.shields.io/npm/v/mdmcli)](https://www.npmjs.com/package/mdmcli)
[![npm license](https://img.shields.io/npm/l/mdmcli)](https://www.npmjs.com/package/mdmcli)
![Repo Size](https://shields-endpoints.prouser123.me/badge/reposize/mdmulti/cli)
![Code Coverage](https://img.shields.io/codecov/c/gh/mdmulti/cli)

A set of CLI tools for testing the MDMulti platform.

Expand Down
7 changes: 5 additions & 2 deletions cli_cmds/constants-update.js
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
const request = require("request");
const fs = require("fs");

require("colors");

const { install_path } = require("../cli");
const CONSTANTS_URL =
"https://raw.githubusercontent.com/mdmulti/constants/master/constants.json";
Expand All@@ -18,9 +20,10 @@ exports.handler = argv => {
install_path + "/constants.json",
JSON.stringify(JSON.parse(res.body), null, 4)
);
console.log("Done!");
console.log("Done!".green);
} catch (ex) {
console.error("Error saving file.");
console.error("Error saving file.".red);
process.exit(1);
}
});
};
36 changes: 36 additions & 0 deletions cli_cmds/file/common.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
const constants = require("../../constants.json");

function validateJSON(body) {
try {
var data = JSON.parse(body);
// if came to here, then valid
return data;
} catch (e) {
// failed to parse
return null;
}
}

function isHex(h) {
return /[0-9A-Fa-f]{6}/g.test(h);
}

function isValidId(id) {
return id.length == constants.cert_serial_len_bytes * 2 && isHex(id);
}

function allDatapointsAvailable(data) {
return (
data.version != null &&
data.id != null &&
data.serverId != null &&
data.keypairs != null &&
data.displayName != null
);
}

module.exports = {
validateJSON,
isValidId,
allDatapointsAvailable
};
35 changes: 35 additions & 0 deletions cli_cmds/file/exit_codes.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
Exit Code(s)
------------


originally from
https://github.com/mdmulti/cli/issues/14


- 0 | no failures

- 1 | invalid JSON

- 2 | missing data

- 3 | unsupported version

- 4 | invalid keypair (INFO ONLY)

- 5 | invalid [user] ID

- 6 | invalid ServerID

- 7 | invalid file extension

- 8 | file not available

- 9 | save location not available (EXPORT ONLY)

-------------------------------

- 10 | tamper : ID (INFO ONLY)

- 11 | tamper : serverID (INFO ONLY)

- 12 | tamper : both (INFO ONLY)
47 changes: 32 additions & 15 deletions cli_cmds/file/export.js
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
// For exit code information please see exit_codes.txt

const fs = require("fs");

require("colors");

const { validateJSON, allDatapointsAvailable, isValidId } = require("./common");

exports.command = "export <file> <exportPath>";
exports.desc = "export the certificate from a mdmc file";

Expand All@@ -21,13 +26,13 @@ exports.handler = argv => {
// Check to make sure the file has a .mdmc extension
if (!argv.file.endsWith(".mdmc")) {
console.error("Invalid file extension, must be *.mdmc!");
return;
process.exit(7);
}

// Check to make sure the file exists
if (!fs.existsSync(argv.file)) {
console.error("File doesn't exist!");
return;
process.exit(8);
}

const fileData = fs.readFileSync(argv.file, "utf8");
Expand All@@ -37,8 +42,30 @@ exports.handler = argv => {

if (data) {
// The data is valid JSON

if (!allDatapointsAvailable(data)) {
console.error("Missing data!");
process.exit(2);
}

if (data.version >= 3) {
// The file is probably a valid *.mdmc file

// Check if the *POSSIBLE* server / user IDs are valid
// I know we could check against both and have a 3rd exit code but
// we can't compare if they are invalid anyways.

// Therefore we will just put a process.exit on each ID check.
if (!isValidId(data.id)) {
console.error("Invalid ID!".red);
process.exit(5);
}

if (!isValidId(data.serverId)) {
console.error("Invalid Server ID!".red);
process.exit(6);
}

try {
// Add the pfx extension to the export path if it was not already present
if (!argv.exportPath.endsWith(".pfx")) argv.exportPath += ".pfx";
Expand All@@ -47,26 +74,16 @@ exports.handler = argv => {
console.log("Exported! The password is blank.".green);
} catch {
console.error("Could not save the certificate.");
process.exit(9);
}

// End of command function
} else {
console.error("Unsupported file format, must be mdmc v3 or later.");
return;
process.exit(3);
}
} else {
console.error("File is not valid JSON!");
return;
process.exit(1);
}
};

function validateJSON(body) {
try {
var data = JSON.parse(body);
// if came to here, then valid
return data;
} catch (e) {
// failed to parse
return null;
}
}
Loading