Support GNU export-secret-subkeys extension
This commit is contained in:
parent
dff2dcd9a7
commit
10e10effb6
|
@ -257,6 +257,9 @@ SecretKey.prototype.decrypt = async function (passphrase) {
|
||||||
const s2k = new type_s2k();
|
const s2k = new type_s2k();
|
||||||
i += s2k.read(this.encrypted.subarray(i, this.encrypted.length));
|
i += s2k.read(this.encrypted.subarray(i, this.encrypted.length));
|
||||||
|
|
||||||
|
if (s2k.type === 'gnu-dummy') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
key = await produceEncryptionKey(s2k, passphrase, symmetric);
|
key = await produceEncryptionKey(s2k, passphrase, symmetric);
|
||||||
} else {
|
} else {
|
||||||
symmetric = s2k_usage;
|
symmetric = s2k_usage;
|
||||||
|
|
|
@ -67,7 +67,10 @@ S2K.prototype.get_count = function () {
|
||||||
S2K.prototype.read = function (bytes) {
|
S2K.prototype.read = function (bytes) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
this.type = enums.read(enums.s2k, bytes[i++]);
|
this.type = enums.read(enums.s2k, bytes[i++]);
|
||||||
this.algorithm = enums.read(enums.hash, bytes[i++]);
|
this.algorithm = bytes[i++];
|
||||||
|
if (this.type !== 'gnu') {
|
||||||
|
this.algorithm = enums.read(enums.hash, this.algorithm);
|
||||||
|
}
|
||||||
|
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case 'simple':
|
case 'simple':
|
||||||
|
@ -87,11 +90,11 @@ S2K.prototype.read = function (bytes) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'gnu':
|
case 'gnu':
|
||||||
if (util.Uint8Array_to_str(bytes.subarray(i, 3)) === "GNU") {
|
if (util.Uint8Array_to_str(bytes.subarray(i, i + 3)) === "GNU") {
|
||||||
i += 3; // GNU
|
i += 3; // GNU
|
||||||
const gnuExtType = 1000 + bytes[i++];
|
const gnuExtType = 1000 + bytes[i++];
|
||||||
if (gnuExtType === 1001) {
|
if (gnuExtType === 1001) {
|
||||||
this.type = gnuExtType;
|
this.type = 'gnu-dummy';
|
||||||
// GnuPG extension mode 1001 -- don't write secret key at all
|
// GnuPG extension mode 1001 -- don't write secret key at all
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown s2k gnu protection mode.");
|
throw new Error("Unknown s2k gnu protection mode.");
|
||||||
|
|
|
@ -340,15 +340,12 @@ describe("Signature", function() {
|
||||||
const pub_key = (await openpgp.key.readArmored(pub_key_arm1)).keys[0];
|
const pub_key = (await openpgp.key.readArmored(pub_key_arm1)).keys[0];
|
||||||
const msg = await openpgp.message.readArmored(msg_arm1);
|
const msg = await openpgp.message.readArmored(msg_arm1);
|
||||||
|
|
||||||
await priv_key_gnupg_ext.subKeys[0].keyPacket.decrypt("abcd");
|
await priv_key_gnupg_ext.decrypt("abcd");
|
||||||
return msg.decrypt([priv_key_gnupg_ext]).then(function(msg) {
|
return openpgp.decrypt({ message: msg, privateKeys: [priv_key_gnupg_ext], publicKeys: [pub_key] }).then(function(msg) {
|
||||||
return msg.verify([pub_key]).then(async verified => {
|
expect(msg.signatures).to.exist;
|
||||||
openpgp.stream.pipe(msg.getLiteralData(), new WritableStream());
|
expect(msg.signatures).to.have.length(1);
|
||||||
expect(verified).to.exist;
|
expect(msg.signatures[0].valid).to.be.true;
|
||||||
expect(verified).to.have.length(1);
|
expect(msg.signatures[0].signature.packets.length).to.equal(1);
|
||||||
expect(await verified[0].verified).to.be.true;
|
|
||||||
expect((await verified[0].signature).packets.length).to.equal(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user