diff --git a/package.json b/package.json index 8878ff97b..e423bdabc 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,9 @@ "type": "git", "url": "https://github.com/gchq/CyberChef/" }, + "scripts": { + "build": "webpack" + }, "devDependencies": { "grunt": "~1.0.1", "grunt-chmod": "~1.1.1", @@ -41,6 +44,25 @@ "grunt-inline-alt": "~0.3.10", "grunt-jsdoc": "^2.1.0", "ink-docstrap": "^1.1.4", - "phantomjs-prebuilt": "^2.1.14" + "phantomjs-prebuilt": "^2.1.14", + "webpack": "^2.2.1" + }, + "dependencies": { + "crypto-api": "^0.6.2", + "crypto-js": "^3.1.9-1", + "diff": "^3.2.0", + "escodegen": "^1.8.1", + "esmangle": "^1.0.1", + "esprima": "^3.1.3", + "google-code-prettify": "^1.0.5", + "jquery": "^3.1.1", + "jsbn": "^1.1.0", + "jsrsasign": "^7.1.0", + "moment": "^2.17.1", + "moment-timezone": "^0.5.11", + "sladex-blowfish": "^0.8.1", + "uas-parser": "^0.2.2", + "vkbeautify": "^0.99.1", + "zlibjs": "^0.2.0" } } diff --git a/src/js/.eslintrc.json b/src/js/.eslintrc.json index 7ea169f38..b2a8a24e3 100755 --- a/src/js/.eslintrc.json +++ b/src/js/.eslintrc.json @@ -9,7 +9,8 @@ "browser": true, "jquery": true, "es6": true, - "node": false + "commonjs": true, + "node": true }, "extends": "eslint:recommended", "rules": { diff --git a/src/js/config/Categories.js b/src/js/config/Categories.js index 3a84b0ef7..2eb93fd3f 100755 --- a/src/js/config/Categories.js +++ b/src/js/config/Categories.js @@ -17,7 +17,7 @@ * @constant * @type {CatConf[]} */ -var Categories = [ +var Categories = module.exports = [ { name: "Favourites", ops: [] diff --git a/src/js/config/OperationConfig.js b/src/js/config/OperationConfig.js index e8e3a881a..c32654ab4 100755 --- a/src/js/config/OperationConfig.js +++ b/src/js/config/OperationConfig.js @@ -1,8 +1,41 @@ -/* - * Tell eslint to ignore "'Object' is not defined" errors in this file, as it references every - * single operation object by definition. - */ -/* eslint no-undef: "off" */ +var FlowControl = require("../core/FlowControl.js"), + Base = require("../operations/Base.js"), + Base58 = require("../operations/Base58.js"), + Base64 = require("../operations/Base64.js"), + BitwiseOp = require("../operations/BitwiseOp.js"), + ByteRepr = require("../operations/ByteRepr.js"), + CharEnc = require("../operations/CharEnc.js"), + Checksum = require("../operations/Checksum.js"), + Cipher = require("../operations/Cipher.js"), + Code = require("../operations/Code.js"), + Compress = require("../operations/Compress.js"), + Convert = require("../operations/Convert.js"), + DateTime = require("../operations/DateTime.js"), + Endian = require("../operations/Endian.js"), + Entropy = require("../operations/Entropy.js"), + Extract = require("../operations/Extract.js"), + FileType = require("../operations/FileType.js"), + Hash = require("../operations/Hash.js"), + Hexdump = require("../operations/Hexdump.js"), + HTML = require("../operations/HTML.js"), + HTTP = require("../operations/HTTP.js"), + IP = require("../operations/IP.js"), + JS = require("../operations/JS.js"), + MAC = require("../operations/MAC.js"), + MorseCode = require("../operations/MorseCode.js"), + NetBIOS = require("../operations/NetBIOS.js"), + Numberwang = require("../operations/Numberwang.js"), + OS = require("../operations/OS.js"), + PublicKey = require("../operations/PublicKey.js"), + Punycode = require("../operations/Punycode.js"), + QuotedPrintable = require("../operations/QuotedPrintable.js"), + Rotate = require("../operations/Rotate.js"), + SeqUtils = require("../operations/SeqUtils.js"), + StrUtils = require("../operations/StrUtils.js"), + Tidy = require("../operations/Tidy.js"), + Unicode = require("../operations/Unicode.js"), + URL_ = require("../operations/URL.js"), + UUID = require("../operations/UUID.js"); /** @@ -45,7 +78,7 @@ * @constant * @type {Object.} */ -var OperationConfig = { +var OperationConfig = module.exports = { "Fork": { description: "Split the input data up based on the specified delimiter and run all subsequent operations on each branch separately.

For example, to decode multiple Base64 strings, enter them all on separate lines then add the 'Fork' and 'From Base64' operations to the recipe. Each string will be decoded separately.", run: FlowControl.runFork, diff --git a/src/js/core/Chef.js b/src/js/core/Chef.js index e6bac71dc..1e33496ed 100755 --- a/src/js/core/Chef.js +++ b/src/js/core/Chef.js @@ -1,3 +1,7 @@ +var Dish = require("./Dish.js"), + Recipe = require("./Recipe.js"); + + /** * The main controller for CyberChef. * @@ -7,7 +11,7 @@ * * @class */ -var Chef = function() { +var Chef = module.exports = function() { this.dish = new Dish(); }; diff --git a/src/js/core/Dish.js b/src/js/core/Dish.js index 27fcdc06c..db2c8e72b 100755 --- a/src/js/core/Dish.js +++ b/src/js/core/Dish.js @@ -1,3 +1,6 @@ +var Utils = require("./Utils.js"); + + /** * The data being operated on by each operation. * @@ -9,7 +12,7 @@ * @param {byteArray|string|number} value - The value of the input data. * @param {number} type - The data type of value, see Dish enums. */ -var Dish = function(value, type) { +var Dish = module.exports = function(value, type) { this.value = value || typeof value == "string" ? value : null; this.type = type || Dish.BYTE_ARRAY; }; diff --git a/src/js/core/FlowControl.js b/src/js/core/FlowControl.js index dc2db7d5d..72edcda43 100755 --- a/src/js/core/FlowControl.js +++ b/src/js/core/FlowControl.js @@ -7,7 +7,7 @@ * * @namespace */ -var FlowControl = { +var FlowControl = module.exports = { /** * @constant diff --git a/src/js/core/Ingredient.js b/src/js/core/Ingredient.js index b79088b8e..eacd56b93 100755 --- a/src/js/core/Ingredient.js +++ b/src/js/core/Ingredient.js @@ -1,3 +1,6 @@ +var Utils = require("./Utils.js"); + + /** * The arguments to operations. * @@ -8,7 +11,7 @@ * @class * @param {Object} ingredientConfig */ -var Ingredient = function(ingredientConfig) { +var Ingredient = module.exports = function(ingredientConfig) { this.name = ""; this.type = ""; this.value = null; diff --git a/src/js/core/Operation.js b/src/js/core/Operation.js index aaa2e45bb..a92dd1b82 100755 --- a/src/js/core/Operation.js +++ b/src/js/core/Operation.js @@ -1,3 +1,7 @@ +var Dish = require("./Dish.js"), + Ingredient = require("./Ingredient.js"); + + /** * The Operation specified by the user to be run. * @@ -9,7 +13,7 @@ * @param {string} operationName * @param {Object} operationConfig */ -var Operation = function(operationName, operationConfig) { +var Operation = module.exports = function(operationName, operationConfig) { this.name = operationName; this.description = ""; this.inputType = -1; diff --git a/src/js/core/Recipe.js b/src/js/core/Recipe.js index d5f383fce..0f6afd592 100755 --- a/src/js/core/Recipe.js +++ b/src/js/core/Recipe.js @@ -1,3 +1,7 @@ +var OperationConfig = require("../config/OperationConfig.js"), + Operation = require("./Operation.js"); + + /** * The Recipe controls a list of Operations and the Dish they operate on. * @@ -8,7 +12,7 @@ * @class * @param {Object} recipeConfig */ -var Recipe = function(recipeConfig) { +var Recipe = module.exports = function(recipeConfig) { this.opList = []; if (recipeConfig) { diff --git a/src/js/core/Utils.js b/src/js/core/Utils.js index 9ef0b2b1c..5948dc274 100755 --- a/src/js/core/Utils.js +++ b/src/js/core/Utils.js @@ -1,4 +1,7 @@ -/* globals CryptoJS, moment */ +var CryptoJS = require("crypto-js"), + moment = require("moment"), + $ = require("jquery"); + /** * Utility functions for use in operations, the core framework and the stage. @@ -9,7 +12,7 @@ * * @namespace */ -var Utils = { +var Utils = module.exports = { /** * Translates an ordinal into a character. @@ -1182,21 +1185,21 @@ var Utils = { * // Places the cursor at the beginning of the element #input-text. * $("#input-text").selectRange(0); */ -$.fn.selectRange = function(start, end) { - if (!end) end = start; - return this.each(function() { - if (this.setSelectionRange) { - this.focus(); - this.setSelectionRange(start, end); - } else if (this.createTextRange) { - var range = this.createTextRange(); - range.collapse(true); - range.moveEnd("character", end); - range.moveStart("character", start); - range.select(); - } - }); -}; +// $.fn.selectRange = function(start, end) { +// if (!end) end = start; +// return this.each(function() { +// if (this.setSelectionRange) { +// this.focus(); +// this.setSelectionRange(start, end); +// } else if (this.createTextRange) { +// var range = this.createTextRange(); +// range.collapse(true); +// range.moveEnd("character", end); +// range.moveStart("character", start); +// range.select(); +// } +// }); +// }; /** diff --git a/src/js/operations/Base.js b/src/js/operations/Base.js index 314970936..c25c0eebb 100755 --- a/src/js/operations/Base.js +++ b/src/js/operations/Base.js @@ -7,7 +7,7 @@ * * @namespace */ -var Base = { +var Base = module.exports = { /** * @constant diff --git a/src/js/operations/Base58.js b/src/js/operations/Base58.js index 8f6e0967d..74a5bd58c 100755 --- a/src/js/operations/Base58.js +++ b/src/js/operations/Base58.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Base58 operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Base58 = { +var Base58 = module.exports = { /** * @constant diff --git a/src/js/operations/Base64.js b/src/js/operations/Base64.js index 905296820..433bb7ac4 100755 --- a/src/js/operations/Base64.js +++ b/src/js/operations/Base64.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Base64 operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Base64 = { +var Base64 = module.exports = { /** * @constant diff --git a/src/js/operations/BitwiseOp.js b/src/js/operations/BitwiseOp.js index 27fc33855..b6bfac92e 100755 --- a/src/js/operations/BitwiseOp.js +++ b/src/js/operations/BitwiseOp.js @@ -1,4 +1,6 @@ -/* globals CryptoJS */ +var Utils = require("../core/Utils.js"), + CryptoJS = require("crypto-js"); + /** * Bitwise operations. @@ -9,7 +11,7 @@ * * @namespace */ -var BitwiseOp = { +var BitwiseOp = module.exports = { /** * Runs bitwise operations across the input data. diff --git a/src/js/operations/ByteRepr.js b/src/js/operations/ByteRepr.js index 2130409d6..f485ad832 100755 --- a/src/js/operations/ByteRepr.js +++ b/src/js/operations/ByteRepr.js @@ -1,4 +1,6 @@ /* globals app */ +var Utils = require("../core/Utils.js"); + /** * Byte representation operations. @@ -9,7 +11,7 @@ * * @namespace */ -var ByteRepr = { +var ByteRepr = module.exports = { /** * @constant diff --git a/src/js/operations/CharEnc.js b/src/js/operations/CharEnc.js index 55cef46af..00b54dc52 100755 --- a/src/js/operations/CharEnc.js +++ b/src/js/operations/CharEnc.js @@ -1,4 +1,6 @@ -/* globals CryptoJS */ +var Utils = require("../core/Utils.js"), + CryptoJS = require("crypto-js"); + /** * Character encoding operations. @@ -9,7 +11,7 @@ * * @namespace */ -var CharEnc = { +var CharEnc = module.exports = { /** * @constant diff --git a/src/js/operations/Checksum.js b/src/js/operations/Checksum.js index 644694e13..88c8c3436 100755 --- a/src/js/operations/Checksum.js +++ b/src/js/operations/Checksum.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Checksum operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Checksum = { +var Checksum = module.exports = { /** * Fletcher-8 Checksum operation. diff --git a/src/js/operations/Cipher.js b/src/js/operations/Cipher.js index 672c4731f..f452d75ff 100755 --- a/src/js/operations/Cipher.js +++ b/src/js/operations/Cipher.js @@ -1,4 +1,7 @@ -/* globals CryptoJS, blowfish */ +var Utils = require("../core/Utils.js"), + CryptoJS = require("crypto-js"), + Blowfish = require("sladex-blowfish"); + /** * Cipher operations. @@ -9,7 +12,7 @@ * * @namespace */ -var Cipher = { +var Cipher = module.exports = { /** * @constant @@ -263,7 +266,7 @@ var Cipher = { if (key.length === 0) return "Enter a key"; - var encHex = blowfish.encrypt(input, key, { + var encHex = Blowfish.encrypt(input, key, { outputType: 1, cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode) }), @@ -289,7 +292,7 @@ var Cipher = { input = Utils.format[inputFormat].parse(input); - return blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, { + return Blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, { outputType: 0, // This actually means inputType. The library is weird. cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode) }); diff --git a/src/js/operations/Code.js b/src/js/operations/Code.js index a65bacb91..71dd242ca 100755 --- a/src/js/operations/Code.js +++ b/src/js/operations/Code.js @@ -1,4 +1,8 @@ -/* globals prettyPrintOne, vkbeautify, xpath */ +/* globals xpath */ +var Utils = require("../core/Utils.js"), + VKbeautify = require("vkbeautify"); + //Prettify = require("google-code-prettify"); + /** * Code operations. @@ -9,7 +13,7 @@ * * @namespace */ -var Code = { +var Code = module.exports = { /** * @constant @@ -32,7 +36,7 @@ var Code = { runSyntaxHighlight: function(input, args) { var language = args[0], lineNums = args[1]; - return "" + prettyPrintOne(Utils.escapeHtml(input), language, lineNums) + ""; + return "" + Prettify.prettyPrintOne(Utils.escapeHtml(input), language, lineNums) + ""; }, @@ -51,7 +55,7 @@ var Code = { */ runXmlBeautify: function(input, args) { var indentStr = args[0]; - return vkbeautify.xml(input, indentStr); + return VKbeautify.xml(input, indentStr); }, @@ -65,7 +69,7 @@ var Code = { runJsonBeautify: function(input, args) { var indentStr = args[0]; if (!input) return ""; - return vkbeautify.json(input, indentStr); + return VKbeautify.json(input, indentStr); }, @@ -78,7 +82,7 @@ var Code = { */ runCssBeautify: function(input, args) { var indentStr = args[0]; - return vkbeautify.css(input, indentStr); + return VKbeautify.css(input, indentStr); }, @@ -91,7 +95,7 @@ var Code = { */ runSqlBeautify: function(input, args) { var indentStr = args[0]; - return vkbeautify.sql(input, indentStr); + return VKbeautify.sql(input, indentStr); }, @@ -110,7 +114,7 @@ var Code = { */ runXmlMinify: function(input, args) { var preserveComments = args[0]; - return vkbeautify.xmlmin(input, preserveComments); + return VKbeautify.xmlmin(input, preserveComments); }, @@ -123,7 +127,7 @@ var Code = { */ runJsonMinify: function(input, args) { if (!input) return ""; - return vkbeautify.jsonmin(input); + return VKbeautify.jsonmin(input); }, @@ -136,7 +140,7 @@ var Code = { */ runCssMinify: function(input, args) { var preserveComments = args[0]; - return vkbeautify.cssmin(input, preserveComments); + return VKbeautify.cssmin(input, preserveComments); }, @@ -148,7 +152,7 @@ var Code = { * @returns {string} */ runSqlMinify: function(input, args) { - return vkbeautify.sqlmin(input); + return VKbeautify.sqlmin(input); }, diff --git a/src/js/operations/Compress.js b/src/js/operations/Compress.js index 6e7562642..b3d450598 100755 --- a/src/js/operations/Compress.js +++ b/src/js/operations/Compress.js @@ -1,4 +1,21 @@ -/* globals Zlib, bzip2 */ +/* globals bzip2 */ +var rawdeflate = require("zlibjs/bin/rawdeflate.min"), + rawinflate = require("zlibjs/bin/rawinflate.min"), + zlibAndGzip = require("zlibjs/bin/zlib_and_gzip.min"), + zip = require("zlibjs/bin/zip.min"), + unzip = require("zlibjs/bin/unzip.min"); + +var Zlib = { + RawDeflate: rawdeflate.Zlib.RawDeflate, + RawInflate: rawinflate.Zlib.RawInflate, + Deflate: zlibAndGzip.Zlib.Deflate, + Inflate: zlibAndGzip.Zlib.Inflate, + Gzip: zlibAndGzip.Zlib.Gzip, + Gunzip: zlibAndGzip.Zlib.Gunzip, + Zip: zip.Zlib.Zip, + Unzip: unzip.Zlib.Unzip, +}; + /** * Compression operations. @@ -9,7 +26,7 @@ * * @namespace */ -var Compress = { +var Compress = module.exports = { /** * @constant diff --git a/src/js/operations/Convert.js b/src/js/operations/Convert.js index e10360bad..9586f522c 100755 --- a/src/js/operations/Convert.js +++ b/src/js/operations/Convert.js @@ -7,7 +7,7 @@ * * @namespace */ -var Convert = { +var Convert = module.exports = { /** * @constant diff --git a/src/js/operations/DateTime.js b/src/js/operations/DateTime.js index e4145c3fd..e35c874a7 100755 --- a/src/js/operations/DateTime.js +++ b/src/js/operations/DateTime.js @@ -1,4 +1,5 @@ -/* globals moment */ +var moment = require("moment-timezone"); + /** * Date and time operations. @@ -9,7 +10,7 @@ * * @namespace */ -var DateTime = { +var DateTime = module.exports = { /** * @constant diff --git a/src/js/operations/Endian.js b/src/js/operations/Endian.js index 0ce1dc8cb..e241c97a6 100755 --- a/src/js/operations/Endian.js +++ b/src/js/operations/Endian.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Endian operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Endian = { +var Endian = module.exports = { /** * @constant diff --git a/src/js/operations/Entropy.js b/src/js/operations/Entropy.js index 4d99bac0a..82c8cc1f8 100755 --- a/src/js/operations/Entropy.js +++ b/src/js/operations/Entropy.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Entropy operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Entropy = { +var Entropy = module.exports = { /** * @constant diff --git a/src/js/operations/Extract.js b/src/js/operations/Extract.js index ac0899bf6..799eb5311 100755 --- a/src/js/operations/Extract.js +++ b/src/js/operations/Extract.js @@ -7,7 +7,7 @@ * * @namespace */ -var Extract = { +var Extract = module.exports = { /** * Runs search operations across the input data using regular expressions. diff --git a/src/js/operations/FileType.js b/src/js/operations/FileType.js index c265e4180..4196fbbaa 100755 --- a/src/js/operations/FileType.js +++ b/src/js/operations/FileType.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * File type operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var FileType = { +var FileType = module.exports = { /** * Detect File Type operation. diff --git a/src/js/operations/HTML.js b/src/js/operations/HTML.js index 6a82933de..e9cfe1e21 100755 --- a/src/js/operations/HTML.js +++ b/src/js/operations/HTML.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * HTML operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var HTML = { +var HTML = module.exports = { /** * @constant diff --git a/src/js/operations/HTTP.js b/src/js/operations/HTTP.js index eab2abf82..c1695b18e 100755 --- a/src/js/operations/HTTP.js +++ b/src/js/operations/HTTP.js @@ -1,4 +1,5 @@ -/* globals UAS_parser */ +var UAParser = require("uas-parser"); + /** * HTTP operations. @@ -9,7 +10,7 @@ * * @namespace */ -var HTTP = { +var HTTP = module.exports = { /** * Strip HTTP headers operation. @@ -34,7 +35,7 @@ var HTTP = { * @returns {string} */ runParseUserAgent: function(input, args) { - var ua = UAS_parser.parse(input); // eslint-disable-line camelcase + var ua = UAParser.parse(input); return "Type: " + ua.type + "\n" + "Family: " + ua.uaFamily + "\n" + diff --git a/src/js/operations/Hash.js b/src/js/operations/Hash.js index ed30c1c1f..285de4673 100755 --- a/src/js/operations/Hash.js +++ b/src/js/operations/Hash.js @@ -1,4 +1,8 @@ -/* globals CryptoApi, CryptoJS, Checksum */ +var Utils = require("../core/Utils.js"), + CryptoJS = require("crypto-js"), + CryptoApi = require("crypto-api"), + Checksum = require("./Checksum.js"); + /** * Hashing operations. @@ -9,7 +13,7 @@ * * @namespace */ -var Hash = { +var Hash = module.exports = { /** * MD2 operation. diff --git a/src/js/operations/Hexdump.js b/src/js/operations/Hexdump.js index bca7c6676..92c147d6c 100755 --- a/src/js/operations/Hexdump.js +++ b/src/js/operations/Hexdump.js @@ -1,4 +1,6 @@ /* globals app */ +var Utils = require("../core/Utils.js"); + /** * Hexdump operations. @@ -9,7 +11,7 @@ * * @namespace */ -var Hexdump = { +var Hexdump = module.exports = { /** * @constant diff --git a/src/js/operations/IP.js b/src/js/operations/IP.js index 54302eb80..d9ad9d36e 100755 --- a/src/js/operations/IP.js +++ b/src/js/operations/IP.js @@ -1,4 +1,7 @@ -/* globals BigInteger, Checksum */ +var Utils = require("../core/Utils.js"), + Checksum = require("./Checksum.js"), + BigInteger = require("jsbn").BigInteger; + /** * Internet Protocol address operations. @@ -9,7 +12,7 @@ * * @namespace */ -var IP = { +var IP = module.exports = { /** * @constant diff --git a/src/js/operations/JS.js b/src/js/operations/JS.js index a2f94dcf2..906717e3a 100755 --- a/src/js/operations/JS.js +++ b/src/js/operations/JS.js @@ -1,4 +1,7 @@ -/* globals esprima, escodegen, esmangle */ +var esprima = require("esprima"), + escodegen = require("escodegen"), + esmangle = require("esmangle"); + /** * JavaScript operations. @@ -9,7 +12,7 @@ * * @namespace */ -var JS = { +var JS = module.exports = { /** * @constant diff --git a/src/js/operations/MAC.js b/src/js/operations/MAC.js index 93457e369..a890b1c03 100755 --- a/src/js/operations/MAC.js +++ b/src/js/operations/MAC.js @@ -7,7 +7,7 @@ * * @namespace */ -var MAC = { +var MAC = module.exports = { /** * @constant diff --git a/src/js/operations/MorseCode.js b/src/js/operations/MorseCode.js index 5a048df5a..4759fde29 100644 --- a/src/js/operations/MorseCode.js +++ b/src/js/operations/MorseCode.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Morse Code translation operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var MorseCode = { +var MorseCode = module.exports = { /** * @constant diff --git a/src/js/operations/NetBIOS.js b/src/js/operations/NetBIOS.js index 58d69cb6e..b71704aec 100644 --- a/src/js/operations/NetBIOS.js +++ b/src/js/operations/NetBIOS.js @@ -7,7 +7,7 @@ * * @namespace */ -var NetBIOS = { +var NetBIOS = module.exports = { /** * @constant diff --git a/src/js/operations/Numberwang.js b/src/js/operations/Numberwang.js index d19a590d9..f5d06d111 100755 --- a/src/js/operations/Numberwang.js +++ b/src/js/operations/Numberwang.js @@ -4,7 +4,7 @@ * @author Unknown Male 282 * @namespace */ -var Numberwang = { +var Numberwang = module.exports = { /** * Numberwang operation. Remain indoors. diff --git a/src/js/operations/OS.js b/src/js/operations/OS.js index 6b89627af..e517152cd 100755 --- a/src/js/operations/OS.js +++ b/src/js/operations/OS.js @@ -7,7 +7,7 @@ * * @namespace */ -var OS = { +var OS = module.exports = { /** * Parse UNIX file permissions operation. diff --git a/src/js/operations/PublicKey.js b/src/js/operations/PublicKey.js index cb43026a0..758c331a8 100755 --- a/src/js/operations/PublicKey.js +++ b/src/js/operations/PublicKey.js @@ -1,4 +1,6 @@ -/* globals X509, KJUR, ASN1HEX, KEYUTIL, BigInteger */ +var Utils = require("../core/Utils.js"), + r = require("jsrsasign"); + /** * Public Key operations. @@ -9,7 +11,7 @@ * * @namespace */ -var PublicKey = { +var PublicKey = module.exports = { /** * @constant @@ -25,7 +27,7 @@ var PublicKey = { * @returns {string} */ runParseX509: function (input, args) { - var cert = new X509(), + var cert = new r.X509(), inputFormat = args[0]; if (!input.length) { @@ -36,39 +38,39 @@ var PublicKey = { case "DER Hex": input = input.replace(/\s/g, ""); cert.hex = input; - cert.pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(input, "CERTIFICATE"); + cert.pem = r.KJUR.asn1.ASN1Util.getPEMStringFromHex(input, "CERTIFICATE"); break; case "PEM": - cert.hex = X509.pemToHex(input); + cert.hex = r.X509.pemToHex(input); cert.pem = input; break; case "Base64": cert.hex = Utils.toHex(Utils.fromBase64(input, null, "byteArray"), ""); - cert.pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE"); + cert.pem = r.KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE"); break; case "Raw": cert.hex = Utils.toHex(Utils.strToByteArray(input), ""); - cert.pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE"); + cert.pem = r.KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE"); break; default: throw "Undefined input format"; } - var version = ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 0, 0]), + var version = r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 0, 0]), sn = cert.getSerialNumberHex(), - algorithm = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 2, 0]))), + algorithm = r.KJUR.asn1.x509.OID.oid2name(r.KJUR.asn1.ASN1Util.oidHexToInt(r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 2, 0]))), issuer = cert.getIssuerString(), notBefore = cert.getNotBefore(), notAfter = cert.getNotAfter(), subject = cert.getSubjectString(), - pkAlgorithm = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 6, 0, 0]))), - pk = X509.getPublicKeyFromCertPEM(cert.pem), + pkAlgorithm = r.KJUR.asn1.x509.OID.oid2name(r.KJUR.asn1.ASN1Util.oidHexToInt(r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 6, 0, 0]))), + pk = r.X509.getPublicKeyFromCertPEM(cert.pem), pkFields = [], pkStr = "", - certSigAlg = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [1, 0]))), - certSig = ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [2]).substr(2), + certSigAlg = r.KJUR.asn1.x509.OID.oid2name(r.KJUR.asn1.ASN1Util.oidHexToInt(r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [1, 0]))), + certSig = r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [2]).substr(2), sigStr = "", - extensions = ASN1HEX.dump(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 7])); + extensions = r.ASN1HEX.dump(r.ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 7])); // Public Key fields if (pk.type === "EC") { // ECDSA @@ -78,7 +80,7 @@ var PublicKey = { }); pkFields.push({ key: "Length", - value: (((new BigInteger(pk.pubKeyHex, 16)).bitLength()-3) /2) + " bits" + value: (((new r.BigInteger(pk.pubKeyHex, 16)).bitLength()-3) /2) + " bits" }); pkFields.push({ key: "pub", @@ -122,9 +124,9 @@ var PublicKey = { } // Signature fields - if (ASN1HEX.dump(certSig).indexOf("SEQUENCE") === 0) { // DSA or ECDSA - sigStr = " r: " + PublicKey._formatByteStr(ASN1HEX.getDecendantHexVByNthList(certSig, 0, [0]), 16, 18) + "\n" + - " s: " + PublicKey._formatByteStr(ASN1HEX.getDecendantHexVByNthList(certSig, 0, [1]), 16, 18) + "\n"; + if (r.ASN1HEX.dump(certSig).indexOf("SEQUENCE") === 0) { // DSA or ECDSA + sigStr = " r: " + PublicKey._formatByteStr(r.ASN1HEX.getDecendantHexVByNthList(certSig, 0, [0]), 16, 18) + "\n" + + " s: " + PublicKey._formatByteStr(r.ASN1HEX.getDecendantHexVByNthList(certSig, 0, [1]), 16, 18) + "\n"; } else { // RSA sigStr = " Signature: " + PublicKey._formatByteStr(certSig, 16, 18) + "\n"; } @@ -145,7 +147,7 @@ var PublicKey = { subjectStr = PublicKey._formatDnStr(subject, 2); var output = "Version: " + (parseInt(version, 16) + 1) + " (0x" + version + ")\n" + - "Serial number: " + new BigInteger(sn, 16).toString() + " (0x" + sn + ")\n" + + "Serial number: " + new r.BigInteger(sn, 16).toString() + " (0x" + sn + ")\n" + "Algorithm ID: " + algorithm + "\n" + "Validity\n" + " Not Before: " + nbDate + " (dd-mm-yy hh:mm:ss) (" + notBefore + ")\n" + @@ -183,7 +185,7 @@ var PublicKey = { // Add footer so that the KEYUTIL function works input = input + "-----END CERTIFICATE-----"; } - return KEYUTIL.getHexFromPEM(input); + return r.KEYUTIL.getHexFromPEM(input); }, @@ -201,7 +203,7 @@ var PublicKey = { * @returns {string} */ runHexToPem: function(input, args) { - return KJUR.asn1.ASN1Util.getPEMStringFromHex(input.replace(/\s/g, ""), args[0]); + return r.KJUR.asn1.ASN1Util.getPEMStringFromHex(input.replace(/\s/g, ""), args[0]); }, @@ -213,7 +215,7 @@ var PublicKey = { * @returns {string} */ runHexToObjectIdentifier: function(input, args) { - return KJUR.asn1.ASN1Util.oidHexToInt(input.replace(/\s/g, "")); + return r.KJUR.asn1.ASN1Util.oidHexToInt(input.replace(/\s/g, "")); }, @@ -225,7 +227,7 @@ var PublicKey = { * @returns {string} */ runObjectIdentifierToHex: function(input, args) { - return KJUR.asn1.ASN1Util.oidIntToHex(input); + return r.KJUR.asn1.ASN1Util.oidIntToHex(input); }, @@ -245,7 +247,7 @@ var PublicKey = { runParseAsn1HexString: function(input, args) { var truncateLen = args[1], index = args[0]; - return ASN1HEX.dump(input.replace(/\s/g, ""), { + return r.ASN1HEX.dump(input.replace(/\s/g, ""), { "ommitLongOctet": truncateLen }, index); }, @@ -342,12 +344,12 @@ var PublicKey = { * @param {string} hDN - Hex DN string * @returns {string} */ -X509.hex2dn = function(hDN) { +r.X509.hex2dn = function(hDN) { var s = ""; - var a = ASN1HEX.getPosArrayOfChildren_AtObj(hDN, 0); + var a = r.ASN1HEX.getPosArrayOfChildren_AtObj(hDN, 0); for (var i = 0; i < a.length; i++) { - var hRDN = ASN1HEX.getHexOfTLV_AtObj(hDN, a[i]); - s = s + ",/|" + X509.hex2rdn(hRDN); + var hRDN = r.ASN1HEX.getHexOfTLV_AtObj(hDN, a[i]); + s = s + ",/|" + r.X509.hex2rdn(hRDN); } return s; }; @@ -361,7 +363,7 @@ X509.hex2dn = function(hDN) { * * @constant */ -X509.DN_ATTRHEX = { +r.X509.DN_ATTRHEX = { "0603550403" : "commonName", "0603550404" : "surname", "0603550406" : "countryName", diff --git a/src/js/operations/Punycode.js b/src/js/operations/Punycode.js index 8fb80579a..a53f176fd 100755 --- a/src/js/operations/Punycode.js +++ b/src/js/operations/Punycode.js @@ -1,4 +1,5 @@ -/* globals punycode */ +var punycode = require("punycode"); + /** * Punycode operations. @@ -9,7 +10,7 @@ * * @namespace */ -var Punycode = { +var Punycode = module.exports = { /** * @constant @@ -28,7 +29,7 @@ var Punycode = { var idn = args[0]; if (idn) { - return punycode.ToASCII(input); + return punycode.toASCII(input); } else { return punycode.encode(input); } @@ -46,7 +47,7 @@ var Punycode = { var idn = args[0]; if (idn) { - return punycode.ToUnicode(input); + return punycode.toUnicode(input); } else { return punycode.decode(input); } diff --git a/src/js/operations/QuotedPrintable.js b/src/js/operations/QuotedPrintable.js index c19a11b46..a07135be4 100755 --- a/src/js/operations/QuotedPrintable.js +++ b/src/js/operations/QuotedPrintable.js @@ -30,7 +30,7 @@ * * @namespace */ -var QuotedPrintable = { +var QuotedPrintable = module.exports = { /** * To Quoted Printable operation. diff --git a/src/js/operations/Rotate.js b/src/js/operations/Rotate.js index accb93d11..b38560994 100755 --- a/src/js/operations/Rotate.js +++ b/src/js/operations/Rotate.js @@ -9,7 +9,7 @@ * * @todo Support for UTF16 */ -var Rotate = { +var Rotate = module.exports = { /** * @constant diff --git a/src/js/operations/SeqUtils.js b/src/js/operations/SeqUtils.js index cd6ac99b4..3153b3963 100755 --- a/src/js/operations/SeqUtils.js +++ b/src/js/operations/SeqUtils.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Sequence utility operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var SeqUtils = { +var SeqUtils = module.exports = { /** * @constant diff --git a/src/js/operations/StrUtils.js b/src/js/operations/StrUtils.js index ee2e38aae..0770de3e1 100755 --- a/src/js/operations/StrUtils.js +++ b/src/js/operations/StrUtils.js @@ -1,4 +1,6 @@ -/* globals JsDiff */ +var Utils = require("../core/Utils.js"), + JsDiff = require("diff"); + /** * String utility operations. @@ -9,7 +11,7 @@ * * @namespace */ -var StrUtils = { +var StrUtils = module.exports = { /** * @constant diff --git a/src/js/operations/Tidy.js b/src/js/operations/Tidy.js index 1fe0a3ed0..4493e48b5 100755 --- a/src/js/operations/Tidy.js +++ b/src/js/operations/Tidy.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Tidy operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Tidy = { +var Tidy = module.exports = { /** * @constant diff --git a/src/js/operations/URL.js b/src/js/operations/URL.js index a42f47a1b..88814d2d6 100755 --- a/src/js/operations/URL.js +++ b/src/js/operations/URL.js @@ -1,5 +1,8 @@ /* globals unescape */ +var Utils = require("../core/Utils.js"); + + /** * URL operations. * Namespace is appended with an underscore to prevent overwriting the global URL object. @@ -10,7 +13,7 @@ * * @namespace */ -var URL_ = { +var URL_ = module.exports = { /** * @constant diff --git a/src/js/operations/UUID.js b/src/js/operations/UUID.js index 2248eb63d..1e0dc22c4 100755 --- a/src/js/operations/UUID.js +++ b/src/js/operations/UUID.js @@ -7,7 +7,7 @@ * * @namespace */ -var UUID = { +var UUID = module.exports = { /** * Generate UUID operation. diff --git a/src/js/operations/Unicode.js b/src/js/operations/Unicode.js index 2ab39c861..354271b64 100755 --- a/src/js/operations/Unicode.js +++ b/src/js/operations/Unicode.js @@ -1,3 +1,6 @@ +var Utils = require("../core/Utils.js"); + + /** * Unicode operations. * @@ -7,7 +10,7 @@ * * @namespace */ -var Unicode = { +var Unicode = module.exports = { /** * @constant diff --git a/src/js/views/node/index.js b/src/js/views/node/index.js new file mode 100644 index 000000000..ebab8bf7e --- /dev/null +++ b/src/js/views/node/index.js @@ -0,0 +1,12 @@ +var Chef = require("../../core/Chef.js"); + + +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ + +var chef = new Chef(); + +console.log(chef.bake("test", [{"op":"To Hex","args":["Space"]}], {}, 0, false)); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..7fd92fb82 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,11 @@ +/* eslint-env node */ + +var path = require("path"); + +module.exports = { + entry: "./src/js/views/html/index.js", + output: { + filename: "bundle.js", + path: path.resolve(__dirname, "build/dev") + } +};