Add key/subKey.getKeyId, getFingerprint, getAlgorithmInfo, getCreationTime, isDecrypted

This commit is contained in:
Daniel Huigens 2018-07-19 14:25:32 +02:00
parent 8cfe817b18
commit 91b7165b78
12 changed files with 209 additions and 180 deletions

View File

@ -75,7 +75,7 @@ Key.prototype.packetlist2structure = function(packetlist) {
case enums.packet.publicKey:
case enums.packet.secretKey:
this.keyPacket = packetlist[i];
primaryKeyId = this.keyPacket.getKeyId();
primaryKeyId = this.getKeyId();
break;
case enums.packet.userid:
case enums.packet.userAttribute:
@ -160,7 +160,7 @@ Key.prototype.toPacketlist = function() {
Key.prototype.getSubkeyPackets = function(keyId=null) {
const packets = new packet.List();
this.subKeys.forEach(subKey => {
if (!keyId || subKey.keyPacket.getKeyId().equals(keyId, true)) {
if (!keyId || subKey.getKeyId().equals(keyId, true)) {
packets.push(subKey.keyPacket);
}
});
@ -175,7 +175,7 @@ Key.prototype.getSubkeyPackets = function(keyId=null) {
*/
Key.prototype.getKeyPackets = function(keyId=null) {
const packets = new packet.List();
if (!keyId || this.keyPacket.getKeyId().equals(keyId, true)) {
if (!keyId || this.getKeyId().equals(keyId, true)) {
packets.push(this.keyPacket);
}
packets.concat(this.getSubkeyPackets(keyId));
@ -296,7 +296,7 @@ Key.prototype.getSigningKey = async function (keyId=null, date=new Date(), userI
if (await this.verifyPrimaryKey(date, userId) === enums.keyStatus.valid) {
const subKeys = this.subKeys.slice().sort((a, b) => b.created - a.created);
for (let i = 0; i < subKeys.length; i++) {
if (!keyId || subKeys[i].keyPacket.getKeyId().equals(keyId)) {
if (!keyId || subKeys[i].getKeyId().equals(keyId)) {
// eslint-disable-next-line no-await-in-loop
if (await subKeys[i].verify(primaryKey, date) === enums.keyStatus.valid) {
const bindingSignature = getLatestSignature(subKeys[i].bindingSignatures, date);
@ -342,7 +342,7 @@ Key.prototype.getEncryptionKey = async function(keyId, date=new Date(), userId={
// V3: keys MUST NOT have subkeys
const subKeys = this.subKeys.slice().sort((a, b) => b.created - a.created);
for (let i = 0; i < subKeys.length; i++) {
if (!keyId || subKeys[i].keyPacket.getKeyId().equals(keyId)) {
if (!keyId || subKeys[i].getKeyId().equals(keyId)) {
// eslint-disable-next-line no-await-in-loop
if (await subKeys[i].verify(primaryKey, date) === enums.keyStatus.valid) {
const bindingSignature = getLatestSignature(subKeys[i].bindingSignatures, date);
@ -382,7 +382,7 @@ Key.prototype.encrypt = async function(passphrases, keyId=null) {
return Promise.all(keyPackets.map(async function(keyPacket, i) {
await keyPacket.encrypt(passphrases[i]);
await keyPacket.clearPrivateParams();
keyPacket.clearPrivateParams();
return keyPacket;
}));
};
@ -565,7 +565,7 @@ Key.prototype.update = async function(key) {
if (await key.verifyPrimaryKey() === enums.keyStatus.invalid) {
return;
}
if (this.keyPacket.getFingerprint() !== key.keyPacket.getFingerprint()) {
if (this.getFingerprint() !== key.getFingerprint()) {
throw new Error('Key update method: fingerprints of keys not equal');
}
if (this.isPublic() && key.isPrivate()) {
@ -573,7 +573,7 @@ Key.prototype.update = async function(key) {
const equal = (this.subKeys.length === key.subKeys.length) &&
(this.subKeys.every(destSubKey => {
return key.subKeys.some(srcSubKey => {
return destSubKey.keyPacket.getFingerprint() === srcSubKey.keyPacket.getFingerprint();
return destSubKey.getFingerprint() === srcSubKey.getFingerprint();
});
}));
if (!equal) {
@ -608,7 +608,7 @@ Key.prototype.update = async function(key) {
await Promise.all(key.subKeys.map(async srcSubKey => {
let found = false;
await Promise.all(this.subKeys.map(async dstSubKey => {
if (srcSubKey.keyPacket.getFingerprint() === dstSubKey.keyPacket.getFingerprint()) {
if (srcSubKey.getFingerprint() === dstSubKey.getFingerprint()) {
await dstSubKey.update(srcSubKey, this.keyPacket);
found = true;
}
@ -698,7 +698,7 @@ Key.prototype.applyRevocationCertificate = async function(revocationCertificate)
if (!revocationSignature || revocationSignature.signatureType !== enums.signature.key_revocation) {
throw new Error('Could not find revocation signature packet');
}
if (!revocationSignature.issuerKeyId.equals(this.keyPacket.getKeyId())) {
if (!revocationSignature.issuerKeyId.equals(this.getKeyId())) {
throw new Error('Revocation signature does not match key');
}
if (revocationSignature.isExpired()) {
@ -834,16 +834,13 @@ User.prototype.sign = async function(primaryKey, privateKeys) {
if (privateKey.isPublic()) {
throw new Error('Need private key for signing');
}
if (privateKey.keyPacket.getFingerprint() === primaryKey.getFingerprint()) {
if (privateKey.getFingerprint() === primaryKey.getFingerprint()) {
throw new Error('Not implemented for self signing');
}
const signingKey = await privateKey.getSigningKey();
if (!signingKey) {
throw new Error('Could not find valid signing key packet in key ' +
privateKey.keyPacket.getKeyId().toHex());
}
if (!signingKey.keyPacket.isDecrypted) {
throw new Error('Private key is not decrypted.');
privateKey.getKeyId().toHex());
}
return createSignaturePacket(dataToSign, privateKey, signingKey.keyPacket, {
// Most OpenPGP implementations use generic certification (0x10)
@ -888,7 +885,7 @@ User.prototype.isRevoked = async function(primaryKey, certificate, key, date=new
* @return {module:packet/signature} signature packet
*/
export async function createSignaturePacket(dataToSign, privateKey, signingKeyPacket, signatureProperties, date, userId) {
if (!signingKeyPacket.isDecrypted) {
if (!signingKeyPacket.isDecrypted()) {
throw new Error('Private key is not decrypted.');
}
const signaturePacket = new packet.Signature(date);
@ -1105,7 +1102,7 @@ SubKey.prototype.update = async function(subKey, primaryKey) {
if (await subKey.verify(primaryKey) === enums.keyStatus.invalid) {
return;
}
if (this.keyPacket.getFingerprint() !== subKey.keyPacket.getFingerprint()) {
if (this.getFingerprint() !== subKey.getFingerprint()) {
throw new Error('SubKey update method: fingerprints of subkeys not equal');
}
// key packet
@ -1160,6 +1157,14 @@ SubKey.prototype.revoke = async function(primaryKey, {
return subKey;
};
['getKeyId', 'getFingerprint', 'getAlgorithmInfo', 'getCreationTime', 'isDecrypted'].forEach(name => {
Key.prototype[name] =
SubKey.prototype[name] =
function() {
return this.keyPacket[name]();
};
});
/**
* Reads an unarmored OpenPGP key list and returns one or multiple key objects
* @param {Uint8Array} data to be parsed
@ -1321,7 +1326,7 @@ export async function reformat(options) {
options = sanitizeKeyOptions(options);
try {
const isDecrypted = options.privateKey.getKeyPackets().every(keyPacket => keyPacket.isDecrypted);
const isDecrypted = options.privateKey.getKeyPackets().every(keyPacket => keyPacket.isDecrypted());
if (!isDecrypted) {
await options.privateKey.decrypt();
}

View File

@ -138,14 +138,14 @@ function emailCheck(email, key) {
* @private
* @param {String} keyId provided as string of lowercase hex number
* withouth 0x prefix (can be 16-character key ID or fingerprint)
* @param {module:packet.SecretKey|public_key|public_subkey|secret_subkey} keypacket The keypacket to be checked
* @returns {Boolean} True if keypacket has the specified keyid
* @param {module:key.Key|module:key.SubKey} key The key to be checked
* @returns {Boolean} True if key has the specified keyid
*/
function keyIdCheck(keyId, keypacket) {
function keyIdCheck(keyId, key) {
if (keyId.length === 16) {
return keyId === keypacket.getKeyId().toHex();
return keyId === key.getKeyId().toHex();
}
return keyId === keypacket.getFingerprint();
return keyId === key.getFingerprint();
}
/**
@ -157,12 +157,12 @@ function keyIdCheck(keyId, keypacket) {
*/
KeyArray.prototype.getForId = function (keyId, deep) {
for (let i = 0; i < this.keys.length; i++) {
if (keyIdCheck(keyId, this.keys[i].keyPacket)) {
if (keyIdCheck(keyId, this.keys[i])) {
return this.keys[i];
}
if (deep && this.keys[i].subKeys.length) {
for (let j = 0; j < this.keys[i].subKeys.length; j++) {
if (keyIdCheck(keyId, this.keys[i].subKeys[j].keyPacket)) {
if (keyIdCheck(keyId, this.keys[i].subKeys[j])) {
return this.keys[i];
}
}
@ -182,7 +182,7 @@ KeyArray.prototype.importKey = async function (armored) {
for (let i = 0; i < imported.keys.length; i++) {
const key = imported.keys[i];
// check if key already in key array
const keyidHex = key.keyPacket.getKeyId().toHex();
const keyidHex = key.getKeyId().toHex();
const keyFound = this.getForId(keyidHex);
if (keyFound) {
// eslint-disable-next-line no-await-in-loop
@ -211,7 +211,7 @@ KeyArray.prototype.push = function (key) {
*/
KeyArray.prototype.removeForId = function (keyId) {
for (let i = 0; i < this.keys.length; i++) {
if (keyIdCheck(keyId, this.keys[i].keyPacket)) {
if (keyIdCheck(keyId, this.keys[i])) {
return this.keys.splice(i, 1)[0];
}
}

View File

@ -176,7 +176,7 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) {
if (!privateKeyPacket) {
return;
}
if (!privateKeyPacket.isDecrypted) {
if (!privateKeyPacket.isDecrypted()) {
throw new Error('Private key is not decrypted.');
}
try {
@ -326,10 +326,10 @@ export async function encryptSessionKey(sessionKey, symAlgo, aeadAlgo, publicKey
const encryptionKey = await publicKey.getEncryptionKey(undefined, date, userId);
if (!encryptionKey) {
throw new Error('Could not find valid key packet for encryption in key ' +
publicKey.keyPacket.getKeyId().toHex());
publicKey.getKeyId().toHex());
}
const pkESKeyPacket = new packet.PublicKeyEncryptedSessionKey();
pkESKeyPacket.publicKeyId = wildcard ? type_keyid.wildcard() : encryptionKey.keyPacket.getKeyId();
pkESKeyPacket.publicKeyId = wildcard ? type_keyid.wildcard() : encryptionKey.getKeyId();
pkESKeyPacket.publicKeyAlgorithm = encryptionKey.keyPacket.algorithm;
pkESKeyPacket.sessionKey = sessionKey;
pkESKeyPacket.sessionKeyAlgorithm = symAlgo;
@ -424,13 +424,13 @@ Message.prototype.sign = async function(privateKeys=[], signature=null, date=new
const signingKey = await privateKey.getSigningKey(undefined, date, userId);
if (!signingKey) {
throw new Error('Could not find valid key packet for signing in key ' +
privateKey.keyPacket.getKeyId().toHex());
privateKey.getKeyId().toHex());
}
const onePassSig = new packet.OnePassSignature();
onePassSig.type = signatureType;
onePassSig.hashAlgorithm = await getPreferredHashAlgo(privateKey, signingKey.keyPacket, date, userId);
onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
onePassSig.signingKeyId = signingKey.keyPacket.getKeyId();
onePassSig.signingKeyId = signingKey.getKeyId();
if (i === privateKeys.length - 1) {
onePassSig.flags = 1;
}
@ -506,7 +506,7 @@ export async function createSignaturePackets(literalDataPacket, privateKeys, sig
const signingKey = await privateKey.getSigningKey(undefined, date, userId);
if (!signingKey) {
throw new Error(`Could not find valid signing key packet in key ${
privateKey.keyPacket.getKeyId().toHex()}`);
privateKey.getKeyId().toHex()}`);
}
return createSignaturePacket(literalDataPacket, privateKey, signingKey.keyPacket, {signatureType}, date, userId);
})).then(signatureList => {

View File

@ -180,6 +180,22 @@ PublicKey.prototype.writeOld = function () {
return util.concatUint8Array([new Uint8Array([0x99]), util.writeNumber(bytes.length, 2), bytes]);
};
/**
* Check whether secret-key data is available in decrypted form. Returns null for public keys.
* @returns {Boolean|null}
*/
PublicKey.prototype.isDecrypted = function() {
return null;
};
/**
* Returns the creation time of the key
* @returns {Date}
*/
PublicKey.prototype.getCreationTime = function() {
return this.created;
};
/**
* Calculates the key id of the key
* @returns {String} A 8 byte key id

View File

@ -51,9 +51,9 @@ function SecretKey(date=new Date()) {
*/
this.encrypted = null;
/**
* Indicator if secret-key data is available in decrypted form
* Indicator if secret-key data is encrypted. `this.isEncrypted === false` means data is available in decrypted form.
*/
this.isDecrypted = false;
this.isEncrypted = null;
}
SecretKey.prototype = new publicKey();
@ -149,13 +149,14 @@ SecretKey.prototype.read = function (bytes) {
if (isEncrypted) {
this.encrypted = bytes;
this.isEncrypted = true;
} else {
// - Plain or encrypted multiprecision integers comprising the secret
// key data. These algorithm-specific fields are as described
// below.
const privParams = parse_cleartext_params('mod', bytes.subarray(1, bytes.length), this.algorithm);
this.params = this.params.concat(privParams);
this.isDecrypted = true;
this.isEncrypted = false;
}
};
@ -176,10 +177,17 @@ SecretKey.prototype.write = function () {
return util.concatUint8Array(arr);
};
/**
* Check whether secret-key data is available in decrypted form. Returns null for public keys.
* @returns {Boolean|null}
*/
SecretKey.prototype.isDecrypted = function() {
return this.isEncrypted === false;
};
/**
* Encrypt the payload. By default, we use aes256 and iterated, salted string
* to key specifier. If the key is in a decrypted state (isDecrypted === true)
* to key specifier. If the key is in a decrypted state (isEncrypted === false)
* and the passphrase is empty or undefined, the key will be set as not encrypted.
* This can be used to remove passphrase protection after calling decrypt().
* @param {String} passphrase
@ -187,7 +195,7 @@ SecretKey.prototype.write = function () {
* @async
*/
SecretKey.prototype.encrypt = async function (passphrase) {
if (this.isDecrypted && !passphrase) {
if (this.isDecrypted() && !passphrase) {
this.encrypted = null;
return false;
} else if (!passphrase) {
@ -242,7 +250,7 @@ function produceEncryptionKey(s2k, passphrase, algorithm) {
* @async
*/
SecretKey.prototype.decrypt = async function (passphrase) {
if (this.isDecrypted) {
if (this.isDecrypted()) {
throw new Error('Key packet is already decrypted.');
}
@ -323,7 +331,7 @@ SecretKey.prototype.decrypt = async function (passphrase) {
const privParams = parse_cleartext_params(hash, cleartext, this.algorithm);
this.params = this.params.concat(privParams);
this.isDecrypted = true;
this.isEncrypted = false;
this.encrypted = null;
return true;
@ -332,7 +340,7 @@ SecretKey.prototype.decrypt = async function (passphrase) {
SecretKey.prototype.generate = async function (bits, curve) {
const algo = enums.write(enums.publicKey, this.algorithm);
this.params = await crypto.generateParams(algo, bits, curve);
this.isDecrypted = true;
this.isEncrypted = false;
};
/**
@ -344,7 +352,7 @@ SecretKey.prototype.clearPrivateParams = function () {
}
const algo = enums.write(enums.publicKey, this.algorithm);
this.params = this.params.slice(0, crypto.getPubKeyParamTypes(algo).length);
this.isDecrypted = false;
this.isEncrypted = true;
};
/**

View File

@ -134,7 +134,7 @@ describe('Brainpool Cryptography', function () {
expect(pub).to.exist;
expect(pub.err).to.not.exist;
expect(pub.keys).to.have.length(1);
expect(pub.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pub.keys[0].getKeyId().toHex()).to.equal(data[name].id);
data[name].pub_key = pub.keys[0];
return data[name].pub_key;
}
@ -146,7 +146,7 @@ describe('Brainpool Cryptography', function () {
expect(pk).to.exist;
expect(pk.err).to.not.exist;
expect(pk.keys).to.have.length(1);
expect(pk.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pk.keys[0].getKeyId().toHex()).to.equal(data[name].id);
expect(await pk.keys[0].decrypt(data[name].pass)).to.be.true;
data[name].priv_key = pk.keys[0];
return data[name].priv_key;

View File

@ -139,7 +139,7 @@ describe('Elliptic Curve Cryptography', function () {
expect(pub).to.exist;
expect(pub.err).to.not.exist;
expect(pub.keys).to.have.length(1);
expect(pub.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pub.keys[0].getKeyId().toHex()).to.equal(data[name].id);
data[name].pub_key = pub.keys[0];
return data[name].pub_key;
}
@ -151,7 +151,7 @@ describe('Elliptic Curve Cryptography', function () {
expect(pk).to.exist;
expect(pk.err).to.not.exist;
expect(pk.keys).to.have.length(1);
expect(pk.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pk.keys[0].getKeyId().toHex()).to.equal(data[name].id);
expect(await pk.keys[0].decrypt(data[name].pass)).to.be.true;
data[name].priv_key = pk.keys[0];
return data[name].priv_key;

View File

@ -866,7 +866,7 @@ zoGJ6s48HcP591pN93uAitCcYcinY2ZslmdiCXw+zbeoX4spNrV4T4CYxBjNQdIa
expect(pubKeys).to.exist;
expect(pubKeys.err).to.not.exist;
expect(pubKeys.keys).to.have.length(1);
expect(pubKeys.keys[0].primaryKey.getKeyId().toHex()).to.equal('b8e4105cc9dedc77');
expect(pubKeys.keys[0].getKeyId().toHex()).to.equal('b8e4105cc9dedc77');
done();
});
@ -1310,8 +1310,8 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU=
expect(pubKeys).to.exist;
expect(pubKeys.err).to.not.exist;
expect(pubKeys.keys).to.have.length(2);
expect(pubKeys.keys[0].primaryKey.getKeyId().toHex()).to.equal('4a63613a4d6e4094');
expect(pubKeys.keys[1].primaryKey.getKeyId().toHex()).to.equal('dbf223e870534df4');
expect(pubKeys.keys[0].getKeyId().toHex()).to.equal('4a63613a4d6e4094');
expect(pubKeys.keys[1].getKeyId().toHex()).to.equal('dbf223e870534df4');
done();
});
@ -1348,16 +1348,16 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU=
const pubKeyV3 = pubKeysV3.keys[0];
expect(pubKeyV3).to.exist;
expect(pubKeyV4.primaryKey.getKeyId().toHex()).to.equal('4a63613a4d6e4094');
expect(pubKeyV4.primaryKey.getFingerprint()).to.equal('f470e50dcb1ad5f1e64e08644a63613a4d6e4094');
expect(pubKeyV3.primaryKey.getKeyId().toHex()).to.equal('e5b7a014a237ba9d');
expect(pubKeyV3.primaryKey.getFingerprint()).to.equal('a44fcee620436a443bc4913640ab3e49');
expect(pubKeyV4.getKeyId().toHex()).to.equal('4a63613a4d6e4094');
expect(pubKeyV4.getFingerprint()).to.equal('f470e50dcb1ad5f1e64e08644a63613a4d6e4094');
expect(pubKeyV3.getKeyId().toHex()).to.equal('e5b7a014a237ba9d');
expect(pubKeyV3.getFingerprint()).to.equal('a44fcee620436a443bc4913640ab3e49');
done();
});
it('Create new key ID with fromId()', function() {
const pubKeyV4 = openpgp.key.readArmored(twoKeys).keys[0];
const keyId = pubKeyV4.primaryKey.getKeyId();
const keyId = pubKeyV4.getKeyId();
const newKeyId = keyId.constructor.fromId(keyId.toHex());
expect(newKeyId.toHex()).to.equal(keyId.toHex());
});
@ -1506,8 +1506,8 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU=
dest.update(source).then(() => {
expect(dest.subKeys[1]).to.exist;
expect(
dest.subKeys[1].keyPacket.getKeyId().toHex()
).to.equal(source.subKeys[1].keyPacket.getKeyId().toHex());
dest.subKeys[1].getKeyId().toHex()
).to.equal(source.subKeys[1].getKeyId().toHex());
done();
});
});
@ -1817,8 +1817,8 @@ VYGdb3eNlV8CfoEC
return openpgp.generateKey(opt).then(function(newKey) {
expect(newKey.key).to.exist;
expect(+newKey.key.primaryKey.created).to.equal(+past);
expect(+newKey.key.subKeys[0].keyPacket.created).to.equal(+past);
expect(+newKey.key.getCreationTime()).to.equal(+past);
expect(+newKey.key.subKeys[0].getCreationTime()).to.equal(+past);
expect(+newKey.key.subKeys[0].bindingSignatures[0].created).to.equal(+past);
});
})
@ -1847,8 +1847,8 @@ VYGdb3eNlV8CfoEC
expect(key.users[0].userId.userid).to.equal(userId);
expect(key.users[0].selfCertifications[0].isPrimaryUserID).to.be.true;
expect(key.subKeys).to.have.lengthOf(2);
expect(key.subKeys[0].keyPacket.algorithm).to.equal('ecdh');
expect(key.subKeys[1].keyPacket.algorithm).to.equal('ecdh');
expect(key.subKeys[0].getAlgorithmInfo().algorithm).to.equal('ecdh');
expect(key.subKeys[1].getAlgorithmInfo().algorithm).to.equal('ecdh');
});
});
@ -1861,8 +1861,8 @@ VYGdb3eNlV8CfoEC
expect(key.users[0].userId.userid).to.equal(userId);
expect(key.users[0].selfCertifications[0].isPrimaryUserID).to.be.true;
expect(key.subKeys).to.have.lengthOf(2);
expect(key.subKeys[0].keyPacket.algorithm).to.equal('ecdh');
expect(key.subKeys[1].keyPacket.algorithm).to.equal('eddsa');
expect(key.subKeys[0].getAlgorithmInfo().algorithm).to.equal('ecdh');
expect(key.subKeys[1].getAlgorithmInfo().algorithm).to.equal('eddsa');
});
});
@ -1874,8 +1874,8 @@ VYGdb3eNlV8CfoEC
expect(key.users.length).to.equal(1);
expect(key.users[0].userId.userid).to.equal(userId);
expect(key.users[0].selfCertifications[0].isPrimaryUserID).to.be.true;
expect(key.primaryKey.algorithm).to.equal('rsa_encrypt_sign');
expect(key.subKeys[0].keyPacket.algorithm).to.equal('ecdh');
expect(key.getAlgorithmInfo().algorithm).to.equal('rsa_encrypt_sign');
expect(key.subKeys[0].getAlgorithmInfo().algorithm).to.equal('ecdh');
});
});
@ -1888,13 +1888,13 @@ VYGdb3eNlV8CfoEC
const armor2 = key.armor();
expect(armor1).to.equal(armor2);
expect(await key.decrypt('passphrase')).to.be.true;
expect(key.primaryKey.isDecrypted).to.be.true;
expect(key.isDecrypted()).to.be.true;
await key.encrypt('new_passphrase');
expect(key.primaryKey.isDecrypted).to.be.false;
expect(key.isDecrypted()).to.be.false;
await expect(key.decrypt('passphrase')).to.eventually.be.rejectedWith('Incorrect key passphrase');
expect(key.primaryKey.isDecrypted).to.be.false;
expect(key.isDecrypted()).to.be.false;
expect(await key.decrypt('new_passphrase')).to.be.true;
expect(key.primaryKey.isDecrypted).to.be.true;
expect(key.isDecrypted()).to.be.true;
const armor3 = key.armor();
expect(armor3).to.not.equal(armor1);
});
@ -1927,12 +1927,12 @@ VYGdb3eNlV8CfoEC
await privateKey.decrypt('hello world');
publicKey = await publicKey.signPrimaryUser([privateKey]);
const signatures = await publicKey.verifyPrimaryUser([privateKey]);
const publicKeyPacket = (await publicKey.getSigningKey()).keyPacket;
const privateKeyPacket = (await privateKey.getSigningKey()).keyPacket;
const publicSigningKey = await publicKey.getSigningKey();
const privateSigningKey = await privateKey.getSigningKey();
expect(signatures.length).to.equal(2);
expect(signatures[0].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[0].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[0].valid).to.be.null;
expect(signatures[1].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[1].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[1].valid).to.be.true;
});
@ -1943,12 +1943,12 @@ VYGdb3eNlV8CfoEC
await privateKey.decrypt('hello world');
publicKey = await publicKey.signPrimaryUser([privateKey]);
const signatures = await publicKey.verifyPrimaryUser([wrongKey]);
const publicKeyPacket = (await publicKey.getSigningKey()).keyPacket;
const privateKeyPacket = (await privateKey.getSigningKey()).keyPacket;
const publicSigningKey = await publicKey.getSigningKey();
const privateSigningKey = await privateKey.getSigningKey();
expect(signatures.length).to.equal(2);
expect(signatures[0].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[0].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[0].valid).to.be.null;
expect(signatures[1].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[1].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[1].valid).to.be.null;
});
@ -1958,20 +1958,20 @@ VYGdb3eNlV8CfoEC
await privateKey.decrypt('hello world');
publicKey = await publicKey.signAllUsers([privateKey]);
const signatures = await publicKey.verifyAllUsers([privateKey]);
const publicKeyPacket = (await publicKey.getSigningKey()).keyPacket;
const privateKeyPacket = (await privateKey.getSigningKey()).keyPacket;
const publicSigningKey = await publicKey.getSigningKey();
const privateSigningKey = await privateKey.getSigningKey();
expect(signatures.length).to.equal(4);
expect(signatures[0].userid).to.equal(publicKey.users[0].userId.userid);
expect(signatures[0].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[0].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[0].valid).to.be.null;
expect(signatures[1].userid).to.equal(publicKey.users[0].userId.userid);
expect(signatures[1].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[1].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[1].valid).to.be.true;
expect(signatures[2].userid).to.equal(publicKey.users[1].userId.userid);
expect(signatures[2].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[2].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[2].valid).to.be.null;
expect(signatures[3].userid).to.equal(publicKey.users[1].userId.userid);
expect(signatures[3].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[3].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[3].valid).to.be.true;
});
@ -1982,20 +1982,20 @@ VYGdb3eNlV8CfoEC
await privateKey.decrypt('hello world');
publicKey = await publicKey.signAllUsers([privateKey]);
const signatures = await publicKey.verifyAllUsers([wrongKey]);
const publicKeyPacket = (await publicKey.getSigningKey()).keyPacket;
const privateKeyPacket = (await privateKey.getSigningKey()).keyPacket;
const publicSigningKey = await publicKey.getSigningKey();
const privateSigningKey = await privateKey.getSigningKey();
expect(signatures.length).to.equal(4);
expect(signatures[0].userid).to.equal(publicKey.users[0].userId.userid);
expect(signatures[0].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[0].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[0].valid).to.be.null;
expect(signatures[1].userid).to.equal(publicKey.users[0].userId.userid);
expect(signatures[1].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[1].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[1].valid).to.be.null;
expect(signatures[2].userid).to.equal(publicKey.users[1].userId.userid);
expect(signatures[2].keyid.toHex()).to.equal(publicKeyPacket.getKeyId().toHex());
expect(signatures[2].keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
expect(signatures[2].valid).to.be.null;
expect(signatures[3].userid).to.equal(publicKey.users[1].userId.userid);
expect(signatures[3].keyid.toHex()).to.equal(privateKeyPacket.getKeyId().toHex());
expect(signatures[3].keyid.toHex()).to.equal(privateSigningKey.getKeyId().toHex());
expect(signatures[3].valid).to.be.null;
});
@ -2063,14 +2063,14 @@ VYGdb3eNlV8CfoEC
key = key.key;
expect(key.users.length).to.equal(1);
expect(key.users[0].userId.userid).to.equal(userId1);
expect(key.primaryKey.isDecrypted).to.be.true;
expect(key.isDecrypted()).to.be.true;
opt.privateKey = key;
opt.userIds = userId2;
return openpgp.reformatKey(opt).then(function(newKey) {
newKey = newKey.key;
expect(newKey.users.length).to.equal(1);
expect(newKey.users[0].userId.userid).to.equal(userId2);
expect(newKey.primaryKey.isDecrypted).to.be.true;
expect(newKey.isDecrypted()).to.be.true;
});
});
});
@ -2083,7 +2083,7 @@ VYGdb3eNlV8CfoEC
newKey = newKey.key;
expect(newKey.users.length).to.equal(1);
expect(newKey.users[0].userId.userid).to.equal(userId);
expect(newKey.primaryKey.isDecrypted).to.be.false;
expect(newKey.isDecrypted()).to.be.false;
});
});
@ -2096,8 +2096,8 @@ VYGdb3eNlV8CfoEC
return openpgp.generateKey(opt1).then(function(newKey) {
newKey = newKey.key;
expect(newKey.users[0].userId.userid).to.equal(userId1);
expect(+newKey.primaryKey.created).to.equal(+now);
expect(+newKey.subKeys[0].keyPacket.created).to.equal(+now);
expect(+newKey.getCreationTime()).to.equal(+now);
expect(+newKey.subKeys[0].getCreationTime()).to.equal(+now);
expect(+newKey.subKeys[0].bindingSignatures[0].created).to.equal(+now);
const opt2 = {privateKey: newKey, userIds: [userId2], date: before};
return openpgp.reformatKey(opt2).then(function(refKey) {
@ -2117,14 +2117,14 @@ VYGdb3eNlV8CfoEC
newKey = newKey.key;
expect(newKey.users.length).to.equal(1);
expect(newKey.users[0].userId.userid).to.equal(userId);
expect(newKey.primaryKey.isDecrypted).to.be.true;
expect(newKey.isDecrypted()).to.be.true;
return openpgp.sign({data: 'hello', privateKeys: newKey, armor: true}).then(function(signed) {
return openpgp.verify(
{message: openpgp.cleartext.readArmored(signed.data), publicKeys: newKey.toPublic()}
).then(async function(verified) {
expect(verified.signatures[0].valid).to.be.true;
const newKeyPacket = (await newKey.getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(newKeyPacket.getKeyId().toHex());
const newSigningKey = await newKey.getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(newSigningKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -2146,9 +2146,9 @@ VYGdb3eNlV8CfoEC
newKey = newKey.key;
expect(newKey.users.length).to.equal(2);
expect(newKey.users[0].userId.userid).to.equal(userId2);
expect(newKey.primaryKey.isDecrypted).to.be.false;
expect(newKey.isDecrypted()).to.be.false;
await newKey.decrypt('123');
expect(newKey.primaryKey.isDecrypted).to.be.true;
expect(newKey.isDecrypted()).to.be.true;
});
});
});
@ -2201,7 +2201,7 @@ VYGdb3eNlV8CfoEC
return openpgp.encrypt({publicKeys: [key], data: 'random data'}).then(() => {
throw new Error('encryptSessionKey should not encrypt with revoked public key');
}).catch(function(error) {
expect(error.message).to.equal('Error encrypting message: Could not find valid key packet for encryption in key ' + key.primaryKey.getKeyId().toHex());
expect(error.message).to.equal('Error encrypting message: Could not find valid key packet for encryption in key ' + key.getKeyId().toHex());
});
});
@ -2210,7 +2210,7 @@ VYGdb3eNlV8CfoEC
return openpgp.encrypt({publicKeys: [key], data: 'random data'}).then(() => {
throw new Error('encryptSessionKey should not encrypt with revoked public key');
}).catch(function(error) {
expect(error.message).to.equal('Error encrypting message: Could not find valid key packet for encryption in key ' + key.primaryKey.getKeyId().toHex());
expect(error.message).to.equal('Error encrypting message: Could not find valid key packet for encryption in key ' + key.getKeyId().toHex());
});
});
@ -2252,8 +2252,8 @@ VYGdb3eNlV8CfoEC
expect(updateKey).to.exist;
expect(key.users).to.have.length(1);
key.update(updateKey).then(() => {
expect(key.primaryKey.getFingerprint()).to.equal(
updateKey.primaryKey.getFingerprint());
expect(key.getFingerprint()).to.equal(
updateKey.getFingerprint());
expect(key.users).to.have.length(2);
expect(key.users[1].userId).to.be.null;
done();

View File

@ -123,7 +123,7 @@ describe("Keyring", function() {
const keys = keyring.getKeysForId(keyId);
// we get public and private key
expect(keys).to.exist.and.have.length(2);
expect(keys[0].primaryKey.getKeyId().toHex()).equals(keyId);
expect(keys[0].getKeyId().toHex()).equals(keyId);
});
it('publicKeys.getForId() - unknown id', function() {
@ -134,7 +134,7 @@ describe("Keyring", function() {
it('publicKeys.getForId() - valid id', function() {
const key = keyring.publicKeys.getForId(keyId);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId);
expect(key.getKeyId().toHex()).equals(keyId);
});
it('privateKeys.getForId() - unknown id', function() {
@ -145,7 +145,7 @@ describe("Keyring", function() {
it('privateKeys.getForId() - valid id', function() {
const key = keyring.privateKeys.getForId(keyId);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId);
expect(key.getKeyId().toHex()).equals(keyId);
});
it('publicKeys.getForId() - subkey id', function() {
@ -156,7 +156,7 @@ describe("Keyring", function() {
it('publicKeys.getForId() - deep, including subkeys - subkey id', function() {
const key = keyring.publicKeys.getForId(subkeyId2, true);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId2);
expect(key.getKeyId().toHex()).equals(keyId2);
});
it('getKeysForId() - unknown fingerprint', function() {
@ -167,7 +167,7 @@ describe("Keyring", function() {
it('getKeysForId() - valid fingerprint', function() {
const keys = keyring.getKeysForId(keyFingerP2);
expect(keys).to.exist.and.have.length(1);
expect(keys[0].primaryKey.getKeyId().toHex()).equals(keyId2);
expect(keys[0].getKeyId().toHex()).equals(keyId2);
});
it('publicKeys.getForId() - unknown fingerprint', function() {
@ -178,7 +178,7 @@ describe("Keyring", function() {
it('publicKeys.getForId() - valid fingerprint', function() {
const key = keyring.publicKeys.getForId(keyFingerP2);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId2);
expect(key.getKeyId().toHex()).equals(keyId2);
});
it('publicKeys.getForId() - subkey fingerprint', function() {
@ -189,7 +189,7 @@ describe("Keyring", function() {
it('publicKeys.getForId() - deep, including subkeys - subkey fingerprint', function() {
const key = keyring.publicKeys.getForId(subkeyFingerP2, true);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId2);
expect(key.getKeyId().toHex()).equals(keyId2);
});
it('publicKeys.getForAddress() - unknown address', function() {
@ -248,7 +248,7 @@ describe("Keyring", function() {
it('publicKeys.removeForId() - valid id', function() {
const key = keyring.publicKeys.removeForId(keyId);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId);
expect(key.getKeyId().toHex()).equals(keyId);
expect(keyring.publicKeys.keys).to.exist.and.have.length(1);
});
@ -261,7 +261,7 @@ describe("Keyring", function() {
it('publicKeys.removeForId() - valid fingerprint', function() {
const key = keyring.publicKeys.removeForId(keyFingerP2);
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
expect(key.primaryKey.getKeyId().toHex()).equals(keyId2);
expect(key.getKeyId().toHex()).equals(keyId2);
expect(keyring.publicKeys.keys).to.be.empty;
});
@ -272,7 +272,7 @@ describe("Keyring", function() {
localstore3.storePublic([]);
const key = openpgp.key.readArmored(pubkey).keys[0];
localstore1.storePublic([key]);
expect(localstore2.loadPublic()[0].primaryKey.getKeyId().equals(key.primaryKey.getKeyId())).to.be.true;
expect(localstore2.loadPublic()[0].getKeyId().equals(key.getKeyId())).to.be.true;
expect(localstore3.loadPublic()).to.have.length(0);
});

View File

@ -766,8 +766,8 @@ describe('OpenPGP.js public api tests', function() {
privateKey: privateKey.keys[0],
passphrase: passphrase
}).then(function(unlocked){
expect(unlocked.key.primaryKey.getKeyId().toHex()).to.equal(privateKey.keys[0].primaryKey.getKeyId().toHex());
expect(unlocked.key.primaryKey.isDecrypted).to.be.true;
expect(unlocked.key.getKeyId().toHex()).to.equal(privateKey.keys[0].getKeyId().toHex());
expect(unlocked.key.isDecrypted()).to.be.true;
});
});
@ -1121,8 +1121,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1144,8 +1144,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1177,8 +1177,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await newPrivateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await newPrivateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1200,8 +1200,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal('');
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1224,8 +1224,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1258,8 +1258,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1294,15 +1294,15 @@ describe('OpenPGP.js public api tests', function() {
decOpt.message = openpgp.message.readArmored(encrypted.data);
return openpgp.decrypt(decOpt);
}).then(async function (decrypted) {
let keyPacket;
let signingKey;
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
expect(decrypted.signatures[1].valid).to.be.true;
keyPacket = (await privKeyDE.getSigningKey()).keyPacket;
expect(decrypted.signatures[1].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privKeyDE.getSigningKey();
expect(decrypted.signatures[1].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[1].signature.packets.length).to.equal(1);
});
});
@ -1335,8 +1335,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1367,8 +1367,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1389,8 +1389,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1411,8 +1411,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal('');
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1432,8 +1432,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1456,8 +1456,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1483,15 +1483,15 @@ describe('OpenPGP.js public api tests', function() {
decOpt.message = openpgp.message.readArmored(encrypted.data);
return openpgp.decrypt(decOpt);
}).then(async function (decrypted) {
let keyPacket;
let signingKey;
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privateKey.keys[0].getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
expect(decrypted.signatures[1].valid).to.be.true;
keyPacket = (await privKeyDE.getSigningKey()).keyPacket;
expect(decrypted.signatures[1].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privKeyDE.getSigningKey();
expect(decrypted.signatures[1].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[1].signature.packets.length).to.equal(1);
});
});
@ -1511,8 +1511,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (verified) {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1533,15 +1533,15 @@ describe('OpenPGP.js public api tests', function() {
verifyOpt.message = openpgp.cleartext.readArmored(signed.data);
return openpgp.verify(verifyOpt);
}).then(async function (verified) {
let keyPacket;
let signingKey;
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
expect(verified.signatures[1].valid).to.be.true;
keyPacket = (await privKeyDE.getSigningKey()).keyPacket;
expect(verified.signatures[1].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
signingKey = await privKeyDE.getSigningKey();
expect(verified.signatures[1].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[1].signature.packets.length).to.equal(1);
});
});
@ -1562,8 +1562,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (verified) {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1582,8 +1582,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (verified) {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1604,8 +1604,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (verified) {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.null;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1625,8 +1625,8 @@ describe('OpenPGP.js public api tests', function() {
}).then(async function (verified) {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1651,8 +1651,8 @@ describe('OpenPGP.js public api tests', function() {
expect(+verified.signatures[0].signature.packets[0].created).to.be.lte(+openpgp.util.normalizeDate());
expect(+verified.signatures[0].signature.packets[0].created).to.be.gte(+start);
expect(verified.signatures[0].valid).to.be.true;
const keyPacket = (await privateKey.keys[0].getSigningKey()).keyPacket;
expect(verified.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privateKey.keys[0].getSigningKey();
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
});
});
@ -1911,8 +1911,8 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.exist;
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
const keyPacket = (await privKeyDE.getSigningKey()).keyPacket;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(keyPacket.getKeyId().toHex());
const signingKey = await privKeyDE.getSigningKey();
expect(decrypted.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
});
});

View File

@ -1009,9 +1009,9 @@ yYDnCgA=
const signerKey = openpgp.key.readArmored(priv_key_arm1).keys[0];
return signedKey.verifyPrimaryUser([signerKey]).then(signatures => {
expect(signatures[0].valid).to.be.null;
expect(signatures[0].keyid.toHex()).to.equal(signedKey.primaryKey.getKeyId().toHex());
expect(signatures[0].keyid.toHex()).to.equal(signedKey.getKeyId().toHex());
expect(signatures[1].valid).to.be.true;
expect(signatures[1].keyid.toHex()).to.equal(signerKey.primaryKey.getKeyId().toHex());
expect(signatures[1].keyid.toHex()).to.equal(signerKey.getKeyId().toHex());
});
});

View File

@ -123,7 +123,7 @@ describe('X25519 Cryptography', function () {
expect(pub).to.exist;
expect(pub.err).to.not.exist;
expect(pub.keys).to.have.length(1);
expect(pub.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pub.keys[0].getKeyId().toHex()).to.equal(data[name].id);
data[name].pub_key = pub.keys[0];
return data[name].pub_key;
}
@ -136,7 +136,7 @@ describe('X25519 Cryptography', function () {
expect(pk).to.exist;
expect(pk.err).to.not.exist;
expect(pk.keys).to.have.length(1);
expect(pk.keys[0].primaryKey.getKeyId().toHex()).to.equal(data[name].id);
expect(pk.keys[0].getKeyId().toHex()).to.equal(data[name].id);
expect(await pk.keys[0].decrypt(data[name].pass)).to.be.true;
data[name].priv_key = pk.keys[0];
return data[name].priv_key;
@ -231,11 +231,11 @@ describe('X25519 Cryptography', function () {
const hi = firstKey.key;
const primaryKey = hi.primaryKey;
const subKey = hi.subKeys[0].keyPacket;
expect(primaryKey.params[0].getName()).to.equal("ed25519");
expect(primaryKey.algorithm).to.equal('eddsa');
expect(subKey.params[0].getName()).to.equal('curve25519');
expect(subKey.algorithm).to.equal('ecdh');
const subKey = hi.subKeys[0];
expect(hi.getAlgorithmInfo().curve).to.equal('ed25519');
expect(hi.getAlgorithmInfo().algorithm).to.equal('eddsa');
expect(subKey.getAlgorithmInfo().curve).to.equal('curve25519');
expect(subKey.getAlgorithmInfo().algorithm).to.equal('ecdh');
// Self Certificate is valid
const user = hi.users[0];
@ -252,10 +252,10 @@ describe('X25519 Cryptography', function () {
};
return openpgp.generateKey(options).then(async function (secondKey) {
const bye = secondKey.key;
expect(bye.primaryKey.params[0].getName()).to.equal('ed25519');
expect(bye.primaryKey.algorithm).to.equal('eddsa');
expect(bye.subKeys[0].keyPacket.params[0].getName()).to.equal('curve25519');
expect(bye.subKeys[0].keyPacket.algorithm).to.equal('ecdh');
expect(bye.getAlgorithmInfo().curve).to.equal('ed25519');
expect(bye.getAlgorithmInfo().algorithm).to.equal('eddsa');
expect(bye.subKeys[0].getAlgorithmInfo().curve).to.equal('curve25519');
expect(bye.subKeys[0].getAlgorithmInfo().algorithm).to.equal('ecdh');
// Self Certificate is valid
const user = bye.users[0];