Browse Source

Fixed RSA generation and added digest option to verify

Matt 5 years ago
parent
commit
e0f000b913

+ 9 - 0
src/core/lib/RSA.mjs

@@ -0,0 +1,9 @@
+import forge from "node-forge/dist/forge.min.js";
+
+export const MD_ALGORITHMS = {
+    "SHA-1": forge.md.sha1,
+    "MD5": forge.md.md5,
+    "SHA-256": forge.md.sha256,
+    "SHA-384": forge.md.sha384,
+    "SHA-512": forge.md.sha512,
+};

+ 2 - 1
src/core/operations/GenerateRSAKeyPair.mjs

@@ -1,4 +1,5 @@
 /**
+ * @author Matt C [me@mitt.dev]
  * @author gchq77703 []
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
@@ -55,7 +56,7 @@ class GenerateRSAKeyPair extends Operation {
         const [keyLength, outputFormat] = args;
 
         return new Promise((resolve, reject) => {
-            forge.pki.rsa.generateKeyPair({ bits: Number(keyLength), workers: -1}, (err, keypair) => {
+            forge.pki.rsa.generateKeyPair({ bits: Number(keyLength), workers: -1, workerScript: "./assets/forge/prime.worker.min.js"}, (err, keypair) => {
                 if (err) return reject(err);
 
                 let result;

+ 11 - 5
src/core/operations/RSASign.mjs

@@ -1,11 +1,13 @@
 /**
+ * @author Matt C [me@mitt.dev]
  * @author gchq77703 []
- * @copyright Crown Copyright 2018
+ * @copyright Crown Copyright 2020
  * @license Apache-2.0
  */
 
 import Operation from "../Operation";
 import forge from "node-forge/dist/forge.min.js";
+import { MD_ALGORITHMS } from "../lib/RSA.mjs";
 
 /**
  * RSA Sign operation
@@ -31,9 +33,14 @@ class RSASign extends Operation {
                 value: "-----BEGIN RSA PRIVATE KEY-----"
             },
             {
-                name: "Password",
+                name: "Key Password",
                 type: "text",
                 value: ""
+            },
+            {
+                name: "Message Digest Algorithm",
+                type: "option",
+                value: Object.keys(MD_ALGORITHMS)
             }
         ];
     }
@@ -44,11 +51,10 @@ class RSASign extends Operation {
      * @returns {string}
      */
     run(input, args) {
-        const [key, password] = args;
+        const [key, password, mdAlgo] = args;
 
         const privateKey = forge.pki.decryptRsaPrivateKey(key, password);
-
-        const md = forge.md.sha1.create();
+        const md = MD_ALGORITHMS[mdAlgo].create();
         md.update(input, "utf8");
         const signature = privateKey.sign(md);
 

+ 5 - 0
webpack.config.js

@@ -56,6 +56,11 @@ module.exports = {
                 context: "src/core/vendor/",
                 from: "tesseract/**/*",
                 to: "assets/"
+            },
+            {
+                context: "node_modules/node-forge/dist",
+                from: "prime.worker.min.js",
+                to: "assets/forge/"
             }
         ])
     ],