Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openpgp

Package Overview
Dependencies
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openpgp - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

3

package.json
{
"name": "openpgp",
"description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
"version": "0.3.2",
"version": "0.4.0",
"homepage": "http://openpgpjs.org/",

@@ -36,2 +36,3 @@ "engines": {

"chai": "~1.8.1",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-copy": "~0.4.1",

@@ -38,0 +39,0 @@ "grunt-browserify": "~1.2.11",

@@ -332,3 +332,3 @@ // GPG4Browsers - An OpenPGP implementation in javascript

break;
case enums.armor.mutlipart_last:
case enums.armor.multipart_last:
result += "-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n";

@@ -335,0 +335,0 @@ result += addheader();

@@ -330,5 +330,5 @@ // GPG4Browsers - An OpenPGP implementation in javascript

keyPacket.algorithm !== enums.read(enums.publicKey, enums.publicKey.rsa_sign) &&
((signature.keyFlags & enums.keyFlags.encrypt_communication) !== 0 ||
(signature.keyFlags & enums.keyFlags.encrypt_storage) !== 0 ||
!signature.keyFlags);
(!signature.keyFlags ||
(signature.keyFlags[0] & enums.keyFlags.encrypt_communication) !== 0 ||
(signature.keyFlags[0] & enums.keyFlags.encrypt_storage) !== 0);
}

@@ -340,4 +340,4 @@

keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_encrypt_sign)) &&
((signature.keyFlags & enums.keyFlags.sign_data) !== 0 ||
!signature.keyFlags);
(!signature.keyFlags ||
(signature.keyFlags[0] & enums.keyFlags.sign_data) !== 0);
}

@@ -445,3 +445,3 @@

if (this.primaryKey.version == 4 && primaryUser.selfCertificate.keyNeverExpires === false &&
Date.now() > (primaryUser.selfCertificate.created.getTime() + primaryUser.selfCertificate.keyExpirationTime*1000)) {
Date.now() > (this.primaryKey.created.getTime() + primaryUser.selfCertificate.keyExpirationTime*1000)) {
return enums.keyStatus.expired;

@@ -453,2 +453,32 @@ }

/**
* Returns the expiration time of the primary key or null if key does not expire
* @return {Date|null}
*/
Key.prototype.getExpirationTime = function() {
if (this.primaryKey.version == 3) {
return getExpirationTime(this.primaryKey);
}
if (this.primaryKey.version == 4) {
var primaryUser = this.getPrimaryUser();
if (!primaryUser) {
return null;
}
return getExpirationTime(this.primaryKey, primaryUser.selfCertificate);
}
};
function getExpirationTime(keyPacket, selfCertificate) {
// check V3 expiration time
if (keyPacket.version == 3 && keyPacket.expirationTimeV3 !== 0) {
return new Date(keyPacket.created.getTime() + keyPacket.expirationTimeV3*24*3600*1000);
}
// check V4 expiration time
if (keyPacket.version == 4 && selfCertificate.keyNeverExpires === false) {
return new Date(keyPacket.created.getTime() + selfCertificate.keyExpirationTime*1000);
}
return null;
};
/**
* Returns primary user and most significant (latest valid) self signature

@@ -647,3 +677,3 @@ * - if multiple users are marked as primary users returns the one with the latest self signature

(this.revocationSignature.verified ||
this.revocationSignature.verify(primaryKey, {key: this.subKey}))) {
this.revocationSignature.verify(primaryKey, {key:primaryKey, bind: this.subKey}))) {
return enums.keyStatus.revoked;

@@ -677,2 +707,10 @@ }

/**
* Returns the expiration time of the subkey or null if key does not expire
* @return {Date|null}
*/
SubKey.prototype.getExpirationTime = function() {
return getExpirationTime(this.subKey, this.bindingSignature);
};
/**
* Reads an OpenPGP armored text and returns one or multiple key objects

@@ -679,0 +717,0 @@ * @param {String} armoredText text to be parsed

@@ -20,7 +20,11 @@ // GPG4Browsers - An OpenPGP implementation in javascript

* The class that deals with storage of the keyring. Currently the only option is to use HTML5 local storage.
* @requires openpgp
* @requires enums
* @requires key
* @requires util
* @module keyring/keyring
*/
var openpgp = require('../');
var enums = require('../enums.js'),
keyModule = require('../key.js'),
util = require('../util.js');

@@ -71,3 +75,3 @@ /**

var keyEmails = key.getUserIds();
for (var i; i < keyEmails.length; i++) {
for (var i = 0; i < keyEmails.length; i++) {
//we need to get just the email from the userid key

@@ -92,3 +96,3 @@ keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();

for (var i = 0; i < keyids.length; i++) {
if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
if (util.hexstrdump(keyids[i].write()) == id) {
return true;

@@ -113,3 +117,3 @@ }

switch (keyType) {
case openpgp.enums.packet.publicKey:
case enums.packet.publicKey:
if (key.isPublic() && identityFunction(identityInput, key)) {

@@ -119,3 +123,3 @@ results.push(key);

break;
case openpgp.enums.packet.private_key:
case enums.packet.secretKey:
if (key.isPrivate() && identityFunction(identityInput, key)) {

@@ -136,3 +140,3 @@ results.push(key);

Keyring.prototype.getPublicKeyForAddress = function (email) {
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.publicKey);
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, enums.packet.publicKey);
};

@@ -146,3 +150,3 @@

Keyring.prototype.getPrivateKeyForAddress = function (email) {
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secretKey);
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, enums.packet.secretKey);
};

@@ -156,3 +160,3 @@

Keyring.prototype.getKeysForKeyId = function (keyId) {
return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.publicKey);
return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, enums.packet.publicKey);
};

@@ -165,3 +169,3 @@

Keyring.prototype.importKey = function (armored) {
this.keys = this.keys.concat(openpgp.key.readArmored(armored).keys);
this.keys = this.keys.concat(keyModule.readArmored(armored).keys);

@@ -168,0 +172,0 @@ return true;

@@ -22,2 +22,3 @@ // GPG4Browsers - An OpenPGP implementation in javascript

* @module keyring/localstore
* @param {String} item itemname in localstore
*/

@@ -28,3 +29,3 @@ module.exports = LocalStore;

function LocalStore() {
function LocalStore(item) {
if (typeof window != 'undefined' && window.localStorage) {

@@ -35,4 +36,12 @@ this.storage = window.localStorage;

}
if(typeof item == 'string') {
this.item = item;
}
}
/*
* Declare the localstore itemname
*/
LocalStore.prototype.item = 'armoredKeys';
/**

@@ -43,3 +52,3 @@ * Load the keyring from HTML5 local storage and initializes this instance.

LocalStore.prototype.load = function () {
var armoredKeys = JSON.parse(this.storage.getItem('armoredKeys'));
var armoredKeys = JSON.parse(this.storage.getItem(this.item));
var keys = [];

@@ -66,3 +75,3 @@ if (armoredKeys !== null && armoredKeys.length !== 0) {

}
this.storage.setItem('armoredKeys', JSON.stringify(armoredKeys));
this.storage.setItem(this.item, JSON.stringify(armoredKeys));
};

@@ -40,17 +40,36 @@ // GPG4Browsers - An OpenPGP implementation in javascript

cleartext = require('./cleartext.js'),
key = require('./key.js');
key = require('./key.js'),
AsyncProxy = require('./worker/async_proxy.js');
var asyncProxy; // instance of the asyncproxy
/**
* Set the path for the web worker script and create an instance of the async proxy
* @param {String} path relative path to the worker scripts
*/
function initWorker(path) {
asyncProxy = new AsyncProxy(path);
}
/**
* Encrypts message text with keys
* @param {Array<module:key~Key>} keys array of keys, used to encrypt the message
* @param {String} text message as native JavaScript string
* @param {function} callback (optional) callback(error, result) for async style
* @return {String} encrypted ASCII armored message
* @static
*/
function encryptMessage(keys, text) {
var msg = message.fromText(text);
msg = msg.encrypt(keys);
var armored = armor.encode(enums.armor.message, msg.packets.write());
return armored;
function encryptMessage(keys, text, callback) {
if (useWorker(callback)) {
asyncProxy.encryptMessage(keys, text, callback);
return;
}
return execute(function() {
var msg, armored;
msg = message.fromText(text);
msg = msg.encrypt(keys);
armored = armor.encode(enums.armor.message, msg.packets.write());
return armored;
}, callback);
}

@@ -63,11 +82,20 @@

* @param {String} text message as native JavaScript string
* @param {function} callback (optional) callback(error, result) for async style
* @return {String} encrypted ASCII armored message
* @static
*/
function signAndEncryptMessage(publicKeys, privateKey, text) {
var msg = message.fromText(text);
msg = msg.sign([privateKey]);
msg = msg.encrypt(publicKeys);
var armored = armor.encode(enums.armor.message, msg.packets.write());
return armored;
function signAndEncryptMessage(publicKeys, privateKey, text, callback) {
if (useWorker(callback)) {
asyncProxy.signAndEncryptMessage(publicKeys, privateKey, text, callback);
return;
}
return execute(function() {
var msg, armored;
msg = message.fromText(text);
msg = msg.sign([privateKey]);
msg = msg.encrypt(publicKeys);
armored = armor.encode(enums.armor.message, msg.packets.write());
return armored;
}, callback);
}

@@ -78,3 +106,4 @@

* @param {module:key~Key} privateKey private key with decrypted secret key data
* @param {module:message~Message} message the message object with the encrypted data
* @param {module:message~Message} msg the message object with the encrypted data
* @param {function} callback (optional) callback(error, result) for async style
* @return {(String|null)} decrypted message as as native JavaScript string

@@ -84,5 +113,12 @@ * or null if no literal data found

*/
function decryptMessage(privateKey, message) {
message = message.decrypt(privateKey);
return message.getText();
function decryptMessage(privateKey, msg, callback) {
if (useWorker(callback)) {
asyncProxy.decryptMessage(privateKey, msg, callback);
return;
}
return execute(function() {
msg = msg.decrypt(privateKey);
return msg.getText();
}, callback);
}

@@ -94,3 +130,4 @@

* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
* @param {module:message~Message} message the message object with signed and encrypted data
* @param {module:message~Message} msg the message object with signed and encrypted data
* @param {function} callback (optional) callback(error, result) for async style
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}

@@ -101,11 +138,18 @@ * decrypted message as as native JavaScript string

*/
function decryptAndVerifyMessage(privateKey, publicKeys, message) {
var result = {};
message = message.decrypt(privateKey);
result.text = message.getText();
if (result.text) {
result.signatures = message.verify(publicKeys);
return result;
function decryptAndVerifyMessage(privateKey, publicKeys, msg, callback) {
if (useWorker(callback)) {
asyncProxy.decryptAndVerifyMessage(privateKey, publicKeys, msg, callback);
return;
}
return null;
return execute(function() {
var result = {};
msg = msg.decrypt(privateKey);
result.text = msg.getText();
if (result.text) {
result.signatures = msg.verify(publicKeys);
return result;
}
return null;
}, callback);
}

@@ -117,9 +161,17 @@

* @param {String} text cleartext
* @param {function} callback (optional) callback(error, result) for async style
* @return {String} ASCII armored message
* @static
*/
function signClearMessage(privateKeys, text) {
var cleartextMessage = new cleartext.CleartextMessage(text);
cleartextMessage.sign(privateKeys);
return cleartextMessage.armor();
function signClearMessage(privateKeys, text, callback) {
if (useWorker(callback)) {
asyncProxy.signClearMessage(privateKeys, text, callback);
return;
}
return execute(function() {
var cleartextMessage = new cleartext.CleartextMessage(text);
cleartextMessage.sign(privateKeys);
return cleartextMessage.armor();
}, callback);
}

@@ -130,3 +182,4 @@

* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
* @param {module:cleartext~CleartextMessage} message cleartext message object with signatures
* @param {module:cleartext~CleartextMessage} msg cleartext message object with signatures
* @param {function} callback (optional) callback(error, result) for async style
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}

@@ -136,10 +189,17 @@ * cleartext with status of verified signatures

*/
function verifyClearSignedMessage(publicKeys, message) {
var result = {};
if (!(message instanceof cleartext.CleartextMessage)) {
throw new Error('Parameter [message] needs to be of type CleartextMessage.');
function verifyClearSignedMessage(publicKeys, msg, callback) {
if (useWorker(callback)) {
asyncProxy.verifyClearSignedMessage(publicKeys, msg, callback);
return;
}
result.text = message.getText();
result.signatures = message.verify(publicKeys);
return result;
return execute(function() {
var result = {};
if (!(msg instanceof cleartext.CleartextMessage)) {
throw new Error('Parameter [message] needs to be of type CleartextMessage.');
}
result.text = msg.getText();
result.signatures = msg.verify(publicKeys);
return result;
}, callback);
}

@@ -155,14 +215,67 @@

* @param {String} passphrase The passphrase used to encrypt the resulting private key
* @param {function} callback (optional) callback(error, result) for async style
* @return {Object} {key: Array<module:key~Key>, privateKeyArmored: Array<String>, publicKeyArmored: Array<String>}
* @static
*/
function generateKeyPair(keyType, numBits, userId, passphrase) {
var result = {};
var newKey = key.generate(keyType, numBits, userId, passphrase);
result.key = newKey;
result.privateKeyArmored = newKey.armor();
result.publicKeyArmored = newKey.toPublic().armor();
function generateKeyPair(keyType, numBits, userId, passphrase, callback) {
if (useWorker(callback)) {
asyncProxy.generateKeyPair(keyType, numBits, userId, passphrase, callback);
return;
}
return execute(function() {
var result = {};
var newKey = key.generate(keyType, numBits, userId, passphrase);
result.key = newKey;
result.privateKeyArmored = newKey.armor();
result.publicKeyArmored = newKey.toPublic().armor();
return result;
}, callback);
}
//
// helper functions
//
/**
* Are we in a browser and do we support worker?
*/
function useWorker(callback) {
if (typeof window === 'undefined' || !window.Worker || typeof callback !== 'function') {
return false;
}
if (!asyncProxy) {
throw new Error('You need to set the worker path!');
}
return true;
}
/**
* Command pattern that handles async calls gracefully
*/
function execute(cmd, callback) {
var result;
try {
result = cmd();
} catch (err) {
if (callback) {
callback(err);
return;
}
throw err;
}
if (callback) {
callback(null, result);
return;
}
return result;
}
exports.initWorker = initWorker;
exports.encryptMessage = encryptMessage;

@@ -169,0 +282,0 @@ exports.signAndEncryptMessage = signAndEncryptMessage;

@@ -554,2 +554,3 @@ // GPG4Browsers - An OpenPGP implementation in javascript

case t.subkey_binding:
case t.subkey_revocation:
case t.key_binding:

@@ -567,3 +568,2 @@ return this.toSign(t.key, data) + this.toSign(t.key, {

case t.key_revocation:
case t.subkey_revocation:
return this.toSign(t.key, data);

@@ -570,0 +570,0 @@ case t.timestamp:

@@ -20,3 +20,3 @@ // GPG4Browsers - An OpenPGP implementation in javascript

importScripts('openpgp.js');
importScripts('openpgp.min.js');

@@ -23,0 +23,0 @@ var MIN_SIZE_RANDOM_BUFFER = 40000;

@@ -281,3 +281,3 @@ 'use strict';

it.skip('Verify status of revoked subkey', function(done) {
it('Verify status of revoked subkey', function(done) {
var pubKeys = openpgp.key.readArmored(pub_sig_test);

@@ -297,3 +297,32 @@ expect(pubKeys).to.exist;

});
it('Evaluate key flags to find valid encryption key packet', function() {
var pubKeys = openpgp.key.readArmored(pub_sig_test);
expect(pubKeys).to.exist;
expect(pubKeys.err).to.not.exist;
expect(pubKeys.keys).to.have.length(1);
var pubKey = pubKeys.keys[0];
// remove subkeys
pubKey.subKeys = null;
// primary key has only key flags for signing
var keyPacket = pubKey.getEncryptionKeyPacket();
expect(keyPacket).to.not.exist;
});
it('Method getExpirationTime V4 Key', function() {
var pubKey = openpgp.key.readArmored(twoKeys).keys[1];
expect(pubKey).to.exist;
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
expect(pubKey.getExpirationTime().toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
});
it('Method getExpirationTime V4 SubKey', function() {
var pubKey = openpgp.key.readArmored(twoKeys).keys[1];
expect(pubKey).to.exist;
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
expect(pubKey.subKeys[0].getExpirationTime().toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
});
});

@@ -10,3 +10,3 @@ 'use strict';

describe("Keyring", function() {
var user = 'test@t-online.de',
var user = 'whiteout.test@t-online.de',
passphrase = 'asdf',

@@ -58,3 +58,3 @@ keySize = 512,

var key = keyring.getPublicKeyForAddress(user);
expect(key).to.exist;
expect(key).to.exist.and.have.length(1);
done();

@@ -69,3 +69,3 @@ });

var key = keyring.getPrivateKeyForAddress(user);
expect(key).to.exist;
expect(key).to.exist.and.have.length(1);
done();

@@ -93,3 +93,13 @@ });

});
it('customize localstorage itemname', function() {
var localstore1 = new openpgp.Keyring.localstore('my-custom-name');
var localstore2 = new openpgp.Keyring.localstore('my-custom-name');
var localstore3 = new openpgp.Keyring.localstore();
localstore3.store([]);
var key = openpgp.key.readArmored(pubkey).keys[0];
localstore1.store([key]);
expect(localstore2.load()[0].primaryKey.getKeyId().equals(key.primaryKey.getKeyId())).to.be.true;
expect(localstore3.load()).to.have.length(0);
});
});

@@ -548,6 +548,6 @@ 'use strict';

it.skip('Verify subkey revocation signature', function(done) {
it('Verify subkey revocation signature', function(done) {
var pubKey = openpgp.key.readArmored(pub_revoked).keys[0];
var verified = pubKey.subKeys[0].revocationSignature.verify(pubKey.primaryKey, {key: pubKey.subKeys[0].subKey});
var verified = pubKey.subKeys[0].revocationSignature.verify(pubKey.primaryKey, {key: pubKey.primaryKey, bind: pubKey.subKeys[0].subKey});

@@ -554,0 +554,0 @@ expect(verified).to.be.true;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc