diff --git a/src/key.js b/src/key.js index afbe435a..ad119318 100644 --- a/src/key.js +++ b/src/key.js @@ -507,7 +507,7 @@ function getExpirationTime(keyPacket, selfCertificate) { Key.prototype.getPrimaryUser = function() { var primUser = []; for (var i = 0; i < this.users.length; i++) { - if ((!this.users[i].userId && !this.users[i].userAttribute) || !this.users[i].selfCertifications) { + if (!this.users[i].userId || !this.users[i].selfCertifications) { continue; } for (var j = 0; j < this.users[i].selfCertifications.length; j++) { diff --git a/src/openpgp.js b/src/openpgp.js index fd0d5b68..b027991e 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -34,7 +34,7 @@ import * as messageLib from './message.js'; import * as cleartext from './cleartext.js'; -import * as keyLib from './key.js'; +import * as key from './key.js'; import config from './config/config.js'; import util from './util'; import AsyncProxy from './worker/async_proxy.js'; @@ -104,7 +104,7 @@ export function generateKey({ userIds=[], passphrase, numBits=2048, unlocked=fal return asyncProxy.delegate('generateKey', options); } - return keyLib.generate(options).then(newKey => ({ + return key.generate(options).then(newKey => ({ key: newKey, privateKeyArmored: newKey.armor(), @@ -361,65 +361,6 @@ export function decryptSessionKey({ message, privateKey, password }) { } -///////////////////////////////////////////// -// // -// Public key signing and verification // -// // -///////////////////////////////////////////// - - -/** - * Signs a paublic key. - * @param {Key} publicKey public key to be signed - * @param {Key|Array} privateKeys array of keys or single key with decrypted secret key data to sign public key - * @return {Promise} Public key object in form: - * { publicKey:Key, publicKeyArmored:String } - * @static - */ -export function signPublicKey({ publicKey, privateKeys }) { - checkKey(publicKey, 'publicKey'); - privateKeys = toArray(privateKeys); - - if (asyncProxy) { // use web worker if available - return asyncProxy.delegate('signPublicKey', { publicKey, privateKeys }); - } - - return execute(() => { - - const signedPublicKey = publicKey.sign(privateKeys); - - return { - publicKey: signedPublicKey, - publicKeyArmored: signedPublicKey.armor() - }; - - }, 'Error signing public key'); -} - -/** - * Verifies public key - * @param {Key} publicKey public key object with signatures - * @param {Key|Array} publicKeys array of publicKeys or single key, to verify signatures - * @return {Promise} cleartext with status of verified signatures in the form of: - * { signatures: [{ keyid:String, valid:Boolean|null }] } - * @static - */ -export function verifyPublicKey({ publicKey, publicKeys }) { - checkKey(publicKey, 'publicKey'); - publicKeys = toArray(publicKeys); - - if (asyncProxy) { // use web worker if available - return asyncProxy.delegate('verifyPublicKey', { publicKey, publicKeys }); - } - - return execute(() => ({ - - signatures: publicKey.verify(publicKeys) - - }), 'Error verifying signed public key'); -} - - ////////////////////////// // // // Helper functions // @@ -455,11 +396,6 @@ function checkCleartextMessage(message) { throw new Error('Parameter [message] needs to be of type CleartextMessage'); } } -function checkKey(key, name) { - if (!keyLib.Key.prototype.isPrototypeOf(key)) { - throw new Error('Parameter [' + (name || 'key') + '] needs to be of type Key'); - } -} /** * Format user ids for internal use. diff --git a/test/general/openpgp.js b/test/general/openpgp.js index ebab63e7..9cde0211 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -158,20 +158,6 @@ var priv_key_de = '=kyeP', '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); - -var wrong_pubkey = [ - '-----BEGIN PGP PUBLIC KEY BLOCK-----', - 'Version: OpenPGP.js v0.9.0', - 'Comment: Hoodiecrow - https://hoodiecrow.com', - '', - 'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5', - 'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg', - 'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM', - 'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq', - 'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1', - '=6XMW', - '-----END PGP PUBLIC KEY BLOCK-----'].join('\n'); - var passphrase = 'hello world'; var plaintext = 'short message\nnext line\n한국어/조선말'; var password1 = 'I am a password'; @@ -621,6 +607,18 @@ describe('OpenPGP.js public api tests', function() { }); describe('AES / RSA encrypt, decrypt, sign, verify', function() { + var wrong_pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' + + 'Version: OpenPGP.js v0.9.0\r\n' + + 'Comment: Hoodiecrow - https://hoodiecrow.com\r\n' + + '\r\n' + + 'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' + + 'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\r\n' + + 'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\r\n' + + 'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\r\n' + + 'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\r\n' + + '=6XMW\r\n' + + '-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n'; + beforeEach(function() { expect(privateKey.keys[0].decrypt(passphrase)).to.be.true; }); @@ -911,48 +909,6 @@ describe('OpenPGP.js public api tests', function() { }); }); }); - - describe('signPublicKey, verifyPublicKey', function() { - beforeEach(function() { - expect(privateKey.keys[0].decrypt(passphrase)).to.be.true; - }); - - it('should sign and verify public key', function(done) { - var signOpt = { - publicKey: openpgp.key.readArmored(pub_key_de).keys[0], - privateKeys: privateKey.keys - }; - var verifyOpt = { - publicKeys: publicKey.keys - }; - openpgp.signPublicKey(signOpt).then(function(signed) { - verifyOpt.publicKey = signed.publicKey; - return openpgp.verifyPublicKey(verifyOpt); - }).then(function(verified) { - expect(verified.signatures[0].valid).to.be.true; - expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex()); - done(); - }); - }); - - it('should sign and fail to verify public key with wrong public key', function(done) { - var signOpt = { - publicKey: openpgp.key.readArmored(pub_key_de).keys[0], - privateKeys: privateKey.keys - }; - var verifyOpt = { - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys - }; - openpgp.signPublicKey(signOpt).then(function(signed) { - verifyOpt.publicKey = signed.publicKey; - return openpgp.verifyPublicKey(verifyOpt); - }).then(function(verified) { - expect(verified.signatures[0].valid).to.be.null; - expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex()); - done(); - }); - }); - }); } });