adding openpgp_encoding_eme_pkcs1_decode() function replacing the PKCS1 decoding in the encryptedsessionkey packet
This commit is contained in:
parent
1c9aa9b781
commit
d80e04d3f0
|
@ -68,6 +68,19 @@ function openpgp_encoding_eme_pkcs1_encode(message, length) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes a EME-PKCS1-v1_5 padding (See RFC4880 13.1.2)
|
||||
* @param message [String] EME-PKCS1 padded message
|
||||
* @return [String] decoded message
|
||||
*/
|
||||
function openpgp_encoding_eme_pkcs1_decode(message) {
|
||||
if (message.length < 12 || message.charCodeAt(0) != 0 || message.charCodeAt(1) != 2)
|
||||
return -1;
|
||||
var i = 2;
|
||||
while (message.charCodeAt(i) != 0 && message.length < i)
|
||||
i++;
|
||||
return message.substring(i+1, message.length);
|
||||
}
|
||||
/**
|
||||
* ASN1 object identifiers for hashes (See RFC4880 5.2.2)
|
||||
*/
|
||||
|
|
|
@ -178,17 +178,9 @@ function openpgp_packet_encryptedsessionkey() {
|
|||
key.secMPIs, this.MPIs).toMPI();
|
||||
var checksum = ((result.charCodeAt(result.length - 2) << 8) + result
|
||||
.charCodeAt(result.length - 1));
|
||||
// search for zero
|
||||
// FIXME: this is a poor way to decode a padding
|
||||
var i = 0;
|
||||
while (result.charCodeAt(i) != 0 && i < result.length)
|
||||
i++;
|
||||
i++;
|
||||
if (i > result.length) {
|
||||
return null;
|
||||
}
|
||||
var algo = result.charCodeAt(i++);
|
||||
var sesskey = result.substring(i, result.length - 2);
|
||||
var decoded = openpgp_encoding_eme_pkcs1_decode(result.substring(2, result.length - 2));
|
||||
var sesskey = decoded.substring(1);
|
||||
var algo = decoded.charCodeAt(0);
|
||||
if (msg.encryptedData.tagType == 18)
|
||||
return msg.encryptedData.decrypt(algo, sesskey);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue
Block a user