Skip to content

Add PGPSign operation #2090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"Generate PGP Key Pair",
"PGP Encrypt",
"PGP Decrypt",
"PGP Sign",
"PGP Verify",
"PGP Encrypt and Sign",
"PGP Decrypt and Verify",
Expand Down
85 changes: 85 additions & 0 deletions src/core/operations/PGPSign.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @author engrach
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import kbpgp from "kbpgp";
import { ASP, importPrivateKey } from "../lib/PGP.mjs";
import OperationError from "../errors/OperationError.mjs";
import * as es6promisify from "es6-promisify";
const promisify = es6promisify.default ? es6promisify.default.promisify : es6promisify.promisify;

/**
* PGP Encrypt and Sign operation
*/
class PGPSign extends Operation {

/**
* PGPSign constructor
*/
constructor() {
super();

this.name = "PGP Sign";
this.module = "PGP";
this.description = [
"Input: the cleartext you want to sign.",
"<br><br>",
"Arguments: the ASCII-armoured private key of the signer (plus the private key password if necessary).",
"<br><br>",
"This operation uses PGP to produce a PGP signed message.",
"<br><br>",
"Pretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.",
"<br><br>",
"This function uses the Keybase implementation of PGP.",
].join("\n");
this.infoURL = "https://wikipedia.org/wiki/Pretty_Good_Privacy";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Private key of signer",
"type": "text",
"value": ""
},
{
"name": "Private key passphrase",
"type": "string",
"value": ""
},
];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*
* @throws {OperationError} if failure to sign message
*/
async run(input, args) {
const message = input,
[privateKey, passphrase] = args;
let signedMessage;

if (!privateKey) throw new OperationError("Enter the private key of the signer.");
const privKey = await importPrivateKey(privateKey, passphrase);

try {
signedMessage = await promisify(kbpgp.box)({
"msg": message,
"sign_with": privKey,
"asp": ASP
});
} catch (err) {
throw new OperationError(`Couldn't sign message: ${err}`);
}

return signedMessage;
}

}

export default PGPSign;
Loading