fix case with binary signatures on text data
This commit is contained in:
parent
5111a2ba43
commit
bcfb9c037a
|
@ -86,15 +86,17 @@ Literal.prototype.setBytes = function(bytes, format) {
|
||||||
* Get the byte sequence representing the literal packet data
|
* Get the byte sequence representing the literal packet data
|
||||||
* @returns {Uint8Array} A sequence of bytes
|
* @returns {Uint8Array} A sequence of bytes
|
||||||
*/
|
*/
|
||||||
Literal.prototype.getBytes = function() {
|
Literal.prototype.getBytes = function(textMode=false) {
|
||||||
if (this.data !== null) {
|
if (this.data !== null) {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize EOL to \r\n
|
if (textMode) {
|
||||||
const text = util.canonicalizeEOL(this.text);
|
// normalize EOL to \r\n and UTF-8 encode
|
||||||
// encode UTF8
|
this.data = util.str_to_Uint8Array(util.encode_utf8(util.canonicalizeEOL(this.text)));
|
||||||
this.data = util.str_to_Uint8Array(util.encode_utf8(text));
|
} else {
|
||||||
|
this.data = util.str_to_Uint8Array(this.text);
|
||||||
|
}
|
||||||
return this.data;
|
return this.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,7 +150,7 @@ Literal.prototype.write = function() {
|
||||||
|
|
||||||
const format = new Uint8Array([enums.write(enums.literal, this.format)]);
|
const format = new Uint8Array([enums.write(enums.literal, this.format)]);
|
||||||
const date = util.writeDate(this.date);
|
const date = util.writeDate(this.date);
|
||||||
const data = this.getBytes();
|
const data = this.getBytes(format !== 'binary');
|
||||||
|
|
||||||
return util.concatUint8Array([format, filename_length, filename, date, data]);
|
return util.concatUint8Array([format, filename_length, filename, date, data]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -765,6 +765,24 @@ yYDnCgA=
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should verify cleartext message correctly when using a detached binary signature and text literal data', async function () {
|
||||||
|
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
|
const plaintextArray = openpgp.util.str_to_Uint8Array(plaintext);
|
||||||
|
const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||||
|
const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0];
|
||||||
|
await privKey.decrypt('hello world');
|
||||||
|
return openpgp.sign({ privateKeys:[privKey], data:plaintextArray, detached: true}).then(function(signed) {
|
||||||
|
console.log(signed);
|
||||||
|
const signature = openpgp.signature.readArmored(signed.signature);
|
||||||
|
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromText(plaintext), signature: signature });
|
||||||
|
}).then(function(cleartextSig) {
|
||||||
|
expect(cleartextSig).to.exist;
|
||||||
|
expect(cleartextSig.signatures).to.have.length(1);
|
||||||
|
expect(cleartextSig.signatures[0].valid).to.be.true;
|
||||||
|
expect(cleartextSig.signatures[0].signature.packets.length).to.equal(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Should verify encrypted cleartext message correctly when encrypting binary literal data with a canonical text signature', async function () {
|
it('Should verify encrypted cleartext message correctly when encrypting binary literal data with a canonical text signature', async function () {
|
||||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||||
const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user