Changed up the interface. Instead of a dedicated list,
all packets are directly on the packetlist object.
This commit is contained in:
parent
38330ea4a6
commit
43c5d1b30d
|
@ -9311,7 +9311,7 @@ function openpgp_msg_publickey() {
|
||||||
*/
|
*/
|
||||||
function openpgp_packet_compressed() {
|
function openpgp_packet_compressed() {
|
||||||
this.tag = 8;
|
this.tag = 8;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
this.algorithm = openpgp.compression.uncompressed;
|
this.algorithm = openpgp.compression.uncompressed;
|
||||||
this.compressed = null;
|
this.compressed = null;
|
||||||
|
|
||||||
|
@ -9402,7 +9402,7 @@ function openpgp_packet_compressed() {
|
||||||
|
|
||||||
util.print_debug("decompressed:"+util.hexstrdump(decompressed));
|
util.print_debug("decompressed:"+util.hexstrdump(decompressed));
|
||||||
|
|
||||||
this.data.read(decompressed);
|
this.packets.read(decompressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9415,7 +9415,7 @@ function openpgp_packet_compressed() {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
|
|
||||||
case openpgp.compression.uncompressed: // - Uncompressed
|
case openpgp.compression.uncompressed: // - Uncompressed
|
||||||
this.compressed = this.data.write();
|
this.compressed = this.packets.write();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case openpgp.compression.zip: // - ZIP [RFC1951]
|
case openpgp.compression.zip: // - ZIP [RFC1951]
|
||||||
|
@ -12387,11 +12387,11 @@ var openpgp_packet = new _openpgp_packet();
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
* @classdesc This class represents a list of openpgp packets.
|
* @classdesc This class represents a list of openpgp packets.
|
||||||
|
* Take care when iterating over it - the packets themselves
|
||||||
|
* are stored as numerical indices.
|
||||||
*/
|
*/
|
||||||
function openpgp_packetlist() {
|
function openpgp_packetlist() {
|
||||||
|
this.length = 0;
|
||||||
/** @type {openpgp_packet_[]} A list of packets */
|
|
||||||
this.packets = []
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12419,9 +12419,9 @@ function openpgp_packetlist() {
|
||||||
this.write = function() {
|
this.write = function() {
|
||||||
var bytes = '';
|
var bytes = '';
|
||||||
|
|
||||||
for(var i in this.packets) {
|
for(var i = 0; i < this.length; i++) {
|
||||||
var packetbytes = this.packets[i].write();
|
var packetbytes = this[i].write();
|
||||||
bytes += openpgp_packet.write_packet_header(this.packets[i].tag, packetbytes.length);
|
bytes += openpgp_packet.write_packet_header(this[i].tag, packetbytes.length);
|
||||||
bytes += packetbytes;
|
bytes += packetbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12429,7 +12429,8 @@ function openpgp_packetlist() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push = function(packet) {
|
this.push = function(packet) {
|
||||||
this.packets.push(packet);
|
this[this.length] = packet;
|
||||||
|
this.length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12473,7 +12474,7 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
* should be discarded.
|
* should be discarded.
|
||||||
*/
|
*/
|
||||||
this.modification = false;
|
this.modification = false;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
/** @type {openpgp.symmetric} */
|
/** @type {openpgp.symmetric} */
|
||||||
this.algorithm = openpgp.symmetric.plaintext;
|
this.algorithm = openpgp.symmetric.plaintext;
|
||||||
|
|
||||||
|
@ -12502,7 +12503,7 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.encrypt = function(symmetric_algorithm, key) {
|
this.encrypt = function(symmetric_algorithm, key) {
|
||||||
var bytes = this.data.write()
|
var bytes = this.packets.write()
|
||||||
|
|
||||||
var prefixrandom = openpgp_crypto_getPrefixRandom(symmetric_algorithm);
|
var prefixrandom = openpgp_crypto_getPrefixRandom(symmetric_algorithm);
|
||||||
var prefix = prefixrandom
|
var prefix = prefixrandom
|
||||||
|
@ -12553,12 +12554,12 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
util.print_debug_hexstr_dump("calc hash = ", this.hash);
|
util.print_debug_hexstr_dump("calc hash = ", this.hash);
|
||||||
|
|
||||||
|
|
||||||
this.data.read(decrypted.substr(0, decrypted.length - 22));
|
this.packets.read(decrypted.substr(0, decrypted.length - 22));
|
||||||
|
|
||||||
var mdc = decrypted.substr(decrypted.length - 20, 20);
|
var mdc = decrypted.substr(decrypted.length - 20, 20);
|
||||||
|
|
||||||
if(this.hash != mdc) {
|
if(this.hash != mdc) {
|
||||||
this.data = null;
|
this.packets = null;
|
||||||
util.print_error("Decryption stopped: discovered a " +
|
util.print_error("Decryption stopped: discovered a " +
|
||||||
"modification of encrypted data.");
|
"modification of encrypted data.");
|
||||||
return;
|
return;
|
||||||
|
@ -12720,7 +12721,7 @@ function openpgp_packet_sym_encrypted_session_key() {
|
||||||
function openpgp_packet_symmetrically_encrypted() {
|
function openpgp_packet_symmetrically_encrypted() {
|
||||||
this.tag = 9;
|
this.tag = 9;
|
||||||
this.encrypted = null;
|
this.encrypted = null;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12746,11 +12747,11 @@ function openpgp_packet_symmetrically_encrypted() {
|
||||||
var decrypted = openpgp_crypto_symmetricDecrypt(
|
var decrypted = openpgp_crypto_symmetricDecrypt(
|
||||||
symmetric_algorithm_type, key, this.encrypted, true);
|
symmetric_algorithm_type, key, this.encrypted, true);
|
||||||
|
|
||||||
this.data.read(decrypted);
|
this.packets.read(decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.encrypt = function(algo, key) {
|
this.encrypt = function(algo, key) {
|
||||||
var data = this.data.write();
|
var data = this.packets.write();
|
||||||
|
|
||||||
this.encrypted = openpgp_crypto_symmetricEncrypt(
|
this.encrypted = openpgp_crypto_symmetricEncrypt(
|
||||||
openpgp_crypto_getPrefixRandom(algo), algo, key, data, true);
|
openpgp_crypto_getPrefixRandom(algo), algo, key, data, true);
|
||||||
|
|
14
resources/openpgp.min.js
vendored
14
resources/openpgp.min.js
vendored
|
@ -352,9 +352,9 @@ function(){for(var b=" OPENPGP Public Key\n length: "+this.len+"\n",b=b+"
|
||||||
return b};this.validate=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=!1;for(b=0;b<this.userIds.length;b++)if(0==this.userIds[b].verify(this.publicKeyPacket)){a=!0;break}return!a?!1:!0};this.getFingerprint=function(){return this.publicKeyPacket.getFingerprint()};
|
return b};this.validate=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=!1;for(b=0;b<this.userIds.length;b++)if(0==this.userIds[b].verify(this.publicKeyPacket)){a=!0;break}return!a?!1:!0};this.getFingerprint=function(){return this.publicKeyPacket.getFingerprint()};
|
||||||
this.getKeyId=function(){return this.publicKeyPacket.getKeyId()};this.verifyBasicSignatures=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(null!=this.subKeys[b]&&3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=this.getKeyId();for(b=0;b<this.userIds.length;b++)for(var c=0;c<this.userIds[b].certificationRevocationSignatures.length;c++)if(this.userIds[b].certificationSignatures[c].getIssuer==
|
this.getKeyId=function(){return this.publicKeyPacket.getKeyId()};this.verifyBasicSignatures=function(){for(var b=0;b<this.revocationSignatures.length;b++)if(this.revocationSignatures[b].verify(this.publicKeyPacket.header+this.publicKeyPacket.data,this.publicKeyPacket))return!1;if(0!=this.subKeys.length){for(var a=!1,b=0;b<this.subKeys.length;b++)if(null!=this.subKeys[b]&&3==this.subKeys[b].verifyKey()){a=!0;break}if(!a)return!1}a=this.getKeyId();for(b=0;b<this.userIds.length;b++)for(var c=0;c<this.userIds[b].certificationRevocationSignatures.length;c++)if(this.userIds[b].certificationSignatures[c].getIssuer==
|
||||||
a&&4!=this.userIds[b].certificationSignatures[c].verifyBasic(this.publicKeyPacket))return!1;return!0};this.getSubKeyAsKey=function(b){var a=new openpgp_msg_publickey;a.userIds=this.userIds;a.userAttributes=this.userAttributes;a.publicKeyPacket=this.subKeys[b];return a}}
|
a&&4!=this.userIds[b].certificationSignatures[c].verifyBasic(this.publicKeyPacket))return!1;return!0};this.getSubKeyAsKey=function(b){var a=new openpgp_msg_publickey;a.userIds=this.userIds;a.userAttributes=this.userAttributes;a.publicKeyPacket=this.subKeys[b];return a}}
|
||||||
function openpgp_packet_compressed(){this.tag=8;this.data=new openpgp_packetlist;this.algorithm=openpgp.compression.uncompressed;this.compressed=null;this.read=function(b){this.algorithm=b.charCodeAt(0);this.compressed=b.substr(1);this.decompress()};this.write=function(){null==this.compressed&&this.compress();return String.fromCharCode(this.type)+this.compressed};this.decompress=function(){var b;switch(this.algorithm){case openpgp.compression.uncompressed:b=this.compressed;break;case openpgp.compression.zip:util.print_info("Decompressed packet [Type 1-ZIP]: "+
|
function openpgp_packet_compressed(){this.tag=8;this.packets=new openpgp_packetlist;this.algorithm=openpgp.compression.uncompressed;this.compressed=null;this.read=function(b){this.algorithm=b.charCodeAt(0);this.compressed=b.substr(1);this.decompress()};this.write=function(){null==this.compressed&&this.compress();return String.fromCharCode(this.type)+this.compressed};this.decompress=function(){var b;switch(this.algorithm){case openpgp.compression.uncompressed:b=this.compressed;break;case openpgp.compression.zip:util.print_info("Decompressed packet [Type 1-ZIP]: "+
|
||||||
this.toString());b=this.compressed;b=s2r(b).replace(/\n/g,"");b=new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(b));b=unescape(b.deflate()[0][0]);break;case openpgp.compression.zlib:util.print_info("Decompressed packet [Type 2-ZLIB]: "+this.toString());if(8==this.compressed.charCodeAt(0)%16){b=this.compressed.substring(0,this.compressed.length-4);b=s2r(b).replace(/\n/g,"");b=JXG.decompress(b);break}else util.print_error("Compression algorithm ZLIB only supports DEFLATE compression method.");break;
|
this.toString());b=this.compressed;b=s2r(b).replace(/\n/g,"");b=new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(b));b=unescape(b.deflate()[0][0]);break;case openpgp.compression.zlib:util.print_info("Decompressed packet [Type 2-ZLIB]: "+this.toString());if(8==this.compressed.charCodeAt(0)%16){b=this.compressed.substring(0,this.compressed.length-4);b=s2r(b).replace(/\n/g,"");b=JXG.decompress(b);break}else util.print_error("Compression algorithm ZLIB only supports DEFLATE compression method.");break;
|
||||||
case openpgp.compression.bzip2:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}util.print_debug("decompressed:"+util.hexstrdump(b));this.data.read(b)};this.compress=function(){switch(this.type){case openpgp.compression.uncompressed:this.compressed=this.data.write();break;case openpgp.compression.zip:util.print_error("Compression algorithm ZIP [RFC1951] is not implemented.");break;case openpgp.compression.zlib:util.print_error("Compression algorithm ZLIB [RFC1950] is not implemented.");
|
case openpgp.compression.bzip2:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}util.print_debug("decompressed:"+util.hexstrdump(b));this.packets.read(b)};this.compress=function(){switch(this.type){case openpgp.compression.uncompressed:this.compressed=this.packets.write();break;case openpgp.compression.zip:util.print_error("Compression algorithm ZIP [RFC1951] is not implemented.");break;case openpgp.compression.zlib:util.print_error("Compression algorithm ZLIB [RFC1950] is not implemented.");
|
||||||
break;case openpgp.compression.bzip2:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}};this.toString=function(){return"5.6. Compressed Data Packet (Tag 8)\n Compression Algorithm = "+this.algorithm+"\n Compressed Data: Byte ["+util.hexstrdump(this.compressed)+"]\n"}}
|
break;case openpgp.compression.bzip2:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}};this.toString=function(){return"5.6. Compressed Data Packet (Tag 8)\n Compression Algorithm = "+this.algorithm+"\n Compressed Data: Byte ["+util.hexstrdump(this.compressed)+"]\n"}}
|
||||||
function openpgp_packet_literal(){this.tag=11;this.format=openpgp_packet_literal.format.utf8;this.data="";this.date=new Date;this.set_data=function(b,a){this.format=a;this.data=b};this.set_data_bytes=function(b,a){this.format=a;a==openpgp_packet_literal.format.utf8&&(b=util.decode_utf8(b));this.data=b};this.get_data_bytes=function(){return this.format==openpgp_packet_literal.format.utf8?util.encode_utf8(this.data):this.data};this.read=function(b){var a=b[0];this.filename=util.decode_utf8(b.substr(2,
|
function openpgp_packet_literal(){this.tag=11;this.format=openpgp_packet_literal.format.utf8;this.data="";this.date=new Date;this.set_data=function(b,a){this.format=a;this.data=b};this.set_data_bytes=function(b,a){this.format=a;a==openpgp_packet_literal.format.utf8&&(b=util.decode_utf8(b));this.data=b};this.get_data_bytes=function(){return this.format==openpgp_packet_literal.format.utf8?util.encode_utf8(this.data):this.data};this.read=function(b){var a=b[0];this.filename=util.decode_utf8(b.substr(2,
|
||||||
b.charCodeAt(1)));this.date=new Date(1E3*parseInt(b.substr(2+b.charCodeAt(1),4)));this.set_data_bytes(b.substring(6+b.charCodeAt(1)),a)};this.write=function(){var b=util.encode_utf8("msg.txt"),a=this.get_data_bytes(),c;c=""+this.format;c+=String.fromCharCode(b.length);c=c+b+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255);c+=String.fromCharCode(Math.round(this.date.getTime()/1E3)>>16&255);c+=String.fromCharCode(Math.round(this.date.getTime()/1E3)>>8&255);c+=String.fromCharCode(Math.round(this.date.getTime()/
|
b.charCodeAt(1)));this.date=new Date(1E3*parseInt(b.substr(2+b.charCodeAt(1),4)));this.set_data_bytes(b.substring(6+b.charCodeAt(1)),a)};this.write=function(){var b=util.encode_utf8("msg.txt"),a=this.get_data_bytes(),c;c=""+this.format;c+=String.fromCharCode(b.length);c=c+b+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255);c+=String.fromCharCode(Math.round(this.date.getTime()/1E3)>>16&255);c+=String.fromCharCode(Math.round(this.date.getTime()/1E3)>>8&255);c+=String.fromCharCode(Math.round(this.date.getTime()/
|
||||||
|
@ -442,14 +442,14 @@ null;var e=-1,f=-1,f=0;0!=(a[b].charCodeAt()&64)&&(f=1);var g;f?e=a[b].charCodeA
|
||||||
d);g=b+d;for(h=a.substring(b,b+d);;)if(192>a[g].charCodeAt()){j=a[g++].charCodeAt();d+=j;h+=a.substring(g,g+j);g+=j;break}else if(192<=a[g].charCodeAt()&&224>a[g].charCodeAt()){j=(a[g++].charCodeAt()-192<<8)+a[g++].charCodeAt()+192;d+=j;h+=a.substring(g,g+j);g+=j;break}else if(223<a[g].charCodeAt()&&255>a[g].charCodeAt())j=1<<(a[g++].charCodeAt()&31),d+=j,h+=a.substring(g,g+j),g+=j;else{g++;j=a[g++].charCodeAt()<<24|a[g++].charCodeAt()<<16|a[g++].charCodeAt()<<8|a[g++].charCodeAt();h+=a.substring(g,
|
d);g=b+d;for(h=a.substring(b,b+d);;)if(192>a[g].charCodeAt()){j=a[g++].charCodeAt();d+=j;h+=a.substring(g,g+j);g+=j;break}else if(192<=a[g].charCodeAt()&&224>a[g].charCodeAt()){j=(a[g++].charCodeAt()-192<<8)+a[g++].charCodeAt()+192;d+=j;h+=a.substring(g,g+j);g+=j;break}else if(223<a[g].charCodeAt()&&255>a[g].charCodeAt())j=1<<(a[g++].charCodeAt()&31),d+=j,h+=a.substring(g,g+j),g+=j;else{g++;j=a[g++].charCodeAt()<<24|a[g++].charCodeAt()<<16|a[g++].charCodeAt()<<8|a[g++].charCodeAt();h+=a.substring(g,
|
||||||
g+j);d+=j;g+=j;break}j=g}else b++,d=a[b++].charCodeAt()<<24|a[b++].charCodeAt()<<16|a[b++].charCodeAt()<<8|a[b++].charCodeAt();else switch(g){case 0:d=a[b++].charCodeAt();break;case 1:d=a[b++].charCodeAt()<<8|a[b++].charCodeAt();break;case 2:d=a[b++].charCodeAt()<<24|a[b++].charCodeAt()<<16|a[b++].charCodeAt()<<8|a[b++].charCodeAt();break}-1==j&&(j=d);null==h&&(h=a.substring(b,b+j));var a={},k;for(k in this.type)a[this.type[k]]=k;k="openpgp_packet_"+a[e];a=window[k];if(void 0==a)throw k;k=new a;k.read(h);
|
g+j);d+=j;g+=j;break}j=g}else b++,d=a[b++].charCodeAt()<<24|a[b++].charCodeAt()<<16|a[b++].charCodeAt()<<8|a[b++].charCodeAt();else switch(g){case 0:d=a[b++].charCodeAt();break;case 1:d=a[b++].charCodeAt()<<8|a[b++].charCodeAt();break;case 2:d=a[b++].charCodeAt()<<24|a[b++].charCodeAt()<<16|a[b++].charCodeAt()<<8|a[b++].charCodeAt();break}-1==j&&(j=d);null==h&&(h=a.substring(b,b+j));var a={},k;for(k in this.type)a[this.type[k]]=k;k="openpgp_packet_"+a[e];a=window[k];if(void 0==a)throw k;k=new a;k.read(h);
|
||||||
return{packet:k,offset:b+d}};this.type={reserved:0,public_key_encrypted_session_key:1,signature:2,sym_encrypted_session_key:3,one_pass_signature:4,secret_key:5,public_key:6,secret_subkey:7,compressed:8,symmetrically_encrypted:9,marker:10,literal:11,trust:12,userid:13,public_subkey:14,user_attribute:17,sym_encrypted_integrity_protected:18,modification_detection_code:19}}var openpgp_packet=new _openpgp_packet;
|
return{packet:k,offset:b+d}};this.type={reserved:0,public_key_encrypted_session_key:1,signature:2,sym_encrypted_session_key:3,one_pass_signature:4,secret_key:5,public_key:6,secret_subkey:7,compressed:8,symmetrically_encrypted:9,marker:10,literal:11,trust:12,userid:13,public_subkey:14,user_attribute:17,sym_encrypted_integrity_protected:18,modification_detection_code:19}}var openpgp_packet=new _openpgp_packet;
|
||||||
function openpgp_packetlist(){this.packets=[];this.read=function(b){this.packets=[];for(var a=0;a<b.length;){var c=openpgp_packet.read_packet(b,a,b.length-a),a=c.offset;this.push(c.packet)}};this.write=function(){var b="",a;for(a in this.packets)var c=this.packets[a].write(),b=b+openpgp_packet.write_packet_header(this.packets[a].tag,c.length),b=b+c;return b};this.push=function(b){this.packets.push(b)}}
|
function openpgp_packetlist(){this.length=0;this.read=function(b){this.packets=[];for(var a=0;a<b.length;){var c=openpgp_packet.read_packet(b,a,b.length-a),a=c.offset;this.push(c.packet)}};this.write=function(){for(var b="",a=0;a<this.length;a++)var c=this[a].write(),b=b+openpgp_packet.write_packet_header(this[a].tag,c.length),b=b+c;return b};this.push=function(b){this[this.length]=b;this.length++}}
|
||||||
function openpgp_packet_sym_encrypted_integrity_protected(){this.tag=18;this.version=1;this.encrypted=null;this.modification=!1;this.data=new openpgp_packetlist;this.algorithm=openpgp.symmetric.plaintext;this.read=function(b){this.version=b[0].charCodeAt();if(1!=this.version)return util.print_error("openpgp.packet.encryptedintegrityprotecteddata.js\nunknown encrypted integrity protected data packet version: "+this.version+"hex:"+util.hexstrdump(b)),null;this.encrypted=b.substr(1)};this.write=function(){return String.fromCharCode(this.version)+
|
function openpgp_packet_sym_encrypted_integrity_protected(){this.tag=18;this.version=1;this.encrypted=null;this.modification=!1;this.packets=new openpgp_packetlist;this.algorithm=openpgp.symmetric.plaintext;this.read=function(b){this.version=b[0].charCodeAt();if(1!=this.version)return util.print_error("openpgp.packet.encryptedintegrityprotecteddata.js\nunknown encrypted integrity protected data packet version: "+this.version+"hex:"+util.hexstrdump(b)),null;this.encrypted=b.substr(1)};this.write=function(){return String.fromCharCode(this.version)+
|
||||||
this.encrypted};this.encrypt=function(b,a){var c=this.data.write(),d=openpgp_crypto_getPrefixRandom(b),e=d+d.charAt(d.length-2)+d.charAt(d.length-1),c=c+String.fromCharCode(211),c=c+String.fromCharCode(20);util.print_debug_hexstr_dump("data to be hashed:",e+c);c+=str_sha1(e+c);util.print_debug_hexstr_dump("hash:",c.substring(c.length-20,c.length));this.encrypted=openpgp_crypto_symmetricEncrypt(d,b,a,c,!1).substring(0,e.length+c.length)};this.decrypt=function(b,a){var c=openpgp_crypto_symmetricDecrypt(b,
|
this.encrypted};this.encrypt=function(b,a){var c=this.packets.write(),d=openpgp_crypto_getPrefixRandom(b),e=d+d.charAt(d.length-2)+d.charAt(d.length-1),c=c+String.fromCharCode(211),c=c+String.fromCharCode(20);util.print_debug_hexstr_dump("data to be hashed:",e+c);c+=str_sha1(e+c);util.print_debug_hexstr_dump("hash:",c.substring(c.length-20,c.length));this.encrypted=openpgp_crypto_symmetricEncrypt(d,b,a,c,!1).substring(0,e.length+c.length)};this.decrypt=function(b,a){var c=openpgp_crypto_symmetricDecrypt(b,
|
||||||
a,this.encrypted,!1);this.hash=str_sha1(openpgp_crypto_MDCSystemBytes(b,a,this.encrypted)+c.substring(0,c.length-20));util.print_debug_hexstr_dump("calc hash = ",this.hash);this.data.read(c.substr(0,c.length-22));if(this.hash!=c.substr(c.length-20,20))this.data=null,util.print_error("Decryption stopped: discovered a modification of encrypted data.")};this.toString=function(){var b="";openpgp.config.debug&&(b=" data: Bytes ["+util.hexstrdump(this.encrypted)+"]");return"5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18)\n\n version: "+
|
a,this.encrypted,!1);this.hash=str_sha1(openpgp_crypto_MDCSystemBytes(b,a,this.encrypted)+c.substring(0,c.length-20));util.print_debug_hexstr_dump("calc hash = ",this.hash);this.packets.read(c.substr(0,c.length-22));if(this.hash!=c.substr(c.length-20,20))this.packets=null,util.print_error("Decryption stopped: discovered a modification of encrypted data.")};this.toString=function(){var b="";openpgp.config.debug&&(b=" data: Bytes ["+util.hexstrdump(this.encrypted)+"]");return"5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18)\n\n version: "+
|
||||||
this.version+"\n"+b}}
|
this.version+"\n"+b}}
|
||||||
function openpgp_packet_sym_encrypted_session_key(){this.tag=3;this.algorithm=this.private_algorithm=openpgp.symmetric.plaintext;this.encrypted=null;this.s2k=new openpgp_type_s2k;this.read=function(b){this.version=b[0].charCodeAt();this.private_algorithm=b[1].charCodeAt();this.s2k.read(b,2);var a=this.s2k.length+2;if(a<b.length)this.encrypted=b.substr(a)};this.decrypt=function(b){var a=openpgp_crypto_getKeyLength(this.private_algorithm),b=this.s2k.produce_key(b,a);null==this.encrypted?(this.key=b,
|
function openpgp_packet_sym_encrypted_session_key(){this.tag=3;this.algorithm=this.private_algorithm=openpgp.symmetric.plaintext;this.encrypted=null;this.s2k=new openpgp_type_s2k;this.read=function(b){this.version=b[0].charCodeAt();this.private_algorithm=b[1].charCodeAt();this.s2k.read(b,2);var a=this.s2k.length+2;if(a<b.length)this.encrypted=b.substr(a)};this.decrypt=function(b){var a=openpgp_crypto_getKeyLength(this.private_algorithm),b=this.s2k.produce_key(b,a);null==this.encrypted?(this.key=b,
|
||||||
this.algorithm=this.private_algorithm):(b=openpgp_crypto_symmetricDecrypt(this.private_algorithm,b,this.encrypted,!0),this.algorithm=b[0].keyCodeAt(),this.key=b.substr(1))};this.toString=function(){return"5.3 Symmetric-Key Encrypted Session Key Packets (Tag 3)\n KeyId: "+this.keyId.toString()+"\n length: "+this.packetLength+"\n version:"+this.version+"\n symKeyA:"+this.symmetricKeyAlgorithmUsed+"\n s2k: "+this.s2k+"\n"}}
|
this.algorithm=this.private_algorithm):(b=openpgp_crypto_symmetricDecrypt(this.private_algorithm,b,this.encrypted,!0),this.algorithm=b[0].keyCodeAt(),this.key=b.substr(1))};this.toString=function(){return"5.3 Symmetric-Key Encrypted Session Key Packets (Tag 3)\n KeyId: "+this.keyId.toString()+"\n length: "+this.packetLength+"\n version:"+this.version+"\n symKeyA:"+this.symmetricKeyAlgorithmUsed+"\n s2k: "+this.s2k+"\n"}}
|
||||||
function openpgp_packet_symmetrically_encrypted(){this.tag=9;this.encrypted=null;this.data=new openpgp_packetlist;this.read=function(b){this.encrypted=b};this.write=function(){return this.encrypted};this.decrypt=function(b,a){this.data.read(openpgp_crypto_symmetricDecrypt(b,a,this.encrypted,!0))};this.encrypt=function(b,a){var c=this.data.write();this.encrypted=openpgp_crypto_symmetricEncrypt(openpgp_crypto_getPrefixRandom(b),b,a,c,!0)};this.toString=function(){return"5.7. Symmetrically Encrypted Data Packet (Tag 9)\n Used symmetric algorithm: "+
|
function openpgp_packet_symmetrically_encrypted(){this.tag=9;this.encrypted=null;this.packets=new openpgp_packetlist;this.read=function(b){this.encrypted=b};this.write=function(){return this.encrypted};this.decrypt=function(b,a){this.packets.read(openpgp_crypto_symmetricDecrypt(b,a,this.encrypted,!0))};this.encrypt=function(b,a){var c=this.packets.write();this.encrypted=openpgp_crypto_symmetricEncrypt(openpgp_crypto_getPrefixRandom(b),b,a,c,!0)};this.toString=function(){return"5.7. Symmetrically Encrypted Data Packet (Tag 9)\n Used symmetric algorithm: "+
|
||||||
this.algorithmType+"\n encrypted data: Bytes ["+util.hexstrdump(this.encryptedData)+"]\n"}}function openpgp_type_keyid(){this.read_packet=function(b,a){this.bytes=b.substring(a,a+8);return this};this.toString=function(){return util.hexstrdump(this.bytes)}}
|
this.algorithmType+"\n encrypted data: Bytes ["+util.hexstrdump(this.encryptedData)+"]\n"}}function openpgp_type_keyid(){this.read_packet=function(b,a){this.bytes=b.substring(a,a+8);return this};this.toString=function(){return util.hexstrdump(this.bytes)}}
|
||||||
function openpgp_type_mpi(){this.data=this.mpiByteLength=this.mpiBitLength=this.MPI=null;this.read=function(b,a){var c=a;this.mpiBitLength=b[c++].charCodeAt()<<8|b[c++].charCodeAt();this.mpiByteLength=(this.mpiBitLength-this.mpiBitLength%8)/8;0!=this.mpiBitLength%8&&this.mpiByteLength++;this.MPI=b.substring(c,c+this.mpiByteLength);this.data=b.substring(a,a+2+this.mpiByteLength);this.packetLength=this.mpiByteLength+2;return this};this.toBigInteger=function(){return new BigInteger(util.hexstrdump(this.MPI),
|
function openpgp_type_mpi(){this.data=this.mpiByteLength=this.mpiBitLength=this.MPI=null;this.read=function(b,a){var c=a;this.mpiBitLength=b[c++].charCodeAt()<<8|b[c++].charCodeAt();this.mpiByteLength=(this.mpiBitLength-this.mpiBitLength%8)/8;0!=this.mpiBitLength%8&&this.mpiByteLength++;this.MPI=b.substring(c,c+this.mpiByteLength);this.data=b.substring(a,a+2+this.mpiByteLength);this.packetLength=this.mpiByteLength+2;return this};this.toBigInteger=function(){return new BigInteger(util.hexstrdump(this.MPI),
|
||||||
16)};this.toString=function(){var b=" MPI("+this.mpiBitLength+"b/"+this.mpiByteLength+"B) : 0x",b=b+util.hexstrdump(this.MPI);return b+"\n"};this.create=function(b){this.MPI=b;var a=8*(b.length-1),c;a:for(var d=b.charCodeAt(0),e=0;9>e;e++)if(0==d>>e){c=e;break a}this.mpiBitLength=a+c;this.mpiByteLength=b.length;return this};this.toBin=function(){var b=String.fromCharCode(this.mpiBitLength>>8&255),b=b+String.fromCharCode(this.mpiBitLength&255);return b+=this.MPI};this.getByteLength=function(){return this.mpiByteLength}}
|
16)};this.toString=function(){var b=" MPI("+this.mpiBitLength+"b/"+this.mpiByteLength+"B) : 0x",b=b+util.hexstrdump(this.MPI);return b+"\n"};this.create=function(b){this.MPI=b;var a=8*(b.length-1),c;a:for(var d=b.charCodeAt(0),e=0;9>e;e++)if(0==d>>e){c=e;break a}this.mpiBitLength=a+c;this.mpiByteLength=b.length;return this};this.toBin=function(){var b=String.fromCharCode(this.mpiBitLength>>8&255),b=b+String.fromCharCode(this.mpiBitLength&255);return b+=this.MPI};this.getByteLength=function(){return this.mpiByteLength}}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
function openpgp_packet_compressed() {
|
function openpgp_packet_compressed() {
|
||||||
this.tag = 8;
|
this.tag = 8;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
this.algorithm = openpgp.compression.uncompressed;
|
this.algorithm = openpgp.compression.uncompressed;
|
||||||
this.compressed = null;
|
this.compressed = null;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function openpgp_packet_compressed() {
|
||||||
|
|
||||||
util.print_debug("decompressed:"+util.hexstrdump(decompressed));
|
util.print_debug("decompressed:"+util.hexstrdump(decompressed));
|
||||||
|
|
||||||
this.data.read(decompressed);
|
this.packets.read(decompressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,7 +131,7 @@ function openpgp_packet_compressed() {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
|
|
||||||
case openpgp.compression.uncompressed: // - Uncompressed
|
case openpgp.compression.uncompressed: // - Uncompressed
|
||||||
this.compressed = this.data.write();
|
this.compressed = this.packets.write();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case openpgp.compression.zip: // - ZIP [RFC1951]
|
case openpgp.compression.zip: // - ZIP [RFC1951]
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
* @classdesc This class represents a list of openpgp packets.
|
* @classdesc This class represents a list of openpgp packets.
|
||||||
|
* Take care when iterating over it - the packets themselves
|
||||||
|
* are stored as numerical indices.
|
||||||
*/
|
*/
|
||||||
function openpgp_packetlist() {
|
function openpgp_packetlist() {
|
||||||
|
this.length = 0;
|
||||||
/** @type {openpgp_packet_[]} A list of packets */
|
|
||||||
this.packets = []
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ function openpgp_packetlist() {
|
||||||
this.write = function() {
|
this.write = function() {
|
||||||
var bytes = '';
|
var bytes = '';
|
||||||
|
|
||||||
for(var i in this.packets) {
|
for(var i = 0; i < this.length; i++) {
|
||||||
var packetbytes = this.packets[i].write();
|
var packetbytes = this[i].write();
|
||||||
bytes += openpgp_packet.write_packet_header(this.packets[i].tag, packetbytes.length);
|
bytes += openpgp_packet.write_packet_header(this[i].tag, packetbytes.length);
|
||||||
bytes += packetbytes;
|
bytes += packetbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,8 @@ function openpgp_packetlist() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push = function(packet) {
|
this.push = function(packet) {
|
||||||
this.packets.push(packet);
|
this[this.length] = packet;
|
||||||
|
this.length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
* should be discarded.
|
* should be discarded.
|
||||||
*/
|
*/
|
||||||
this.modification = false;
|
this.modification = false;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
/** @type {openpgp.symmetric} */
|
/** @type {openpgp.symmetric} */
|
||||||
this.algorithm = openpgp.symmetric.plaintext;
|
this.algorithm = openpgp.symmetric.plaintext;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.encrypt = function(symmetric_algorithm, key) {
|
this.encrypt = function(symmetric_algorithm, key) {
|
||||||
var bytes = this.data.write()
|
var bytes = this.packets.write()
|
||||||
|
|
||||||
var prefixrandom = openpgp_crypto_getPrefixRandom(symmetric_algorithm);
|
var prefixrandom = openpgp_crypto_getPrefixRandom(symmetric_algorithm);
|
||||||
var prefix = prefixrandom
|
var prefix = prefixrandom
|
||||||
|
@ -118,12 +118,12 @@ function openpgp_packet_sym_encrypted_integrity_protected() {
|
||||||
util.print_debug_hexstr_dump("calc hash = ", this.hash);
|
util.print_debug_hexstr_dump("calc hash = ", this.hash);
|
||||||
|
|
||||||
|
|
||||||
this.data.read(decrypted.substr(0, decrypted.length - 22));
|
this.packets.read(decrypted.substr(0, decrypted.length - 22));
|
||||||
|
|
||||||
var mdc = decrypted.substr(decrypted.length - 20, 20);
|
var mdc = decrypted.substr(decrypted.length - 20, 20);
|
||||||
|
|
||||||
if(this.hash != mdc) {
|
if(this.hash != mdc) {
|
||||||
this.data = null;
|
this.packets = null;
|
||||||
util.print_error("Decryption stopped: discovered a " +
|
util.print_error("Decryption stopped: discovered a " +
|
||||||
"modification of encrypted data.");
|
"modification of encrypted data.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
function openpgp_packet_symmetrically_encrypted() {
|
function openpgp_packet_symmetrically_encrypted() {
|
||||||
this.tag = 9;
|
this.tag = 9;
|
||||||
this.encrypted = null;
|
this.encrypted = null;
|
||||||
this.data = new openpgp_packetlist();
|
this.packets = new openpgp_packetlist();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,11 +55,11 @@ function openpgp_packet_symmetrically_encrypted() {
|
||||||
var decrypted = openpgp_crypto_symmetricDecrypt(
|
var decrypted = openpgp_crypto_symmetricDecrypt(
|
||||||
symmetric_algorithm_type, key, this.encrypted, true);
|
symmetric_algorithm_type, key, this.encrypted, true);
|
||||||
|
|
||||||
this.data.read(decrypted);
|
this.packets.read(decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.encrypt = function(algo, key) {
|
this.encrypt = function(algo, key) {
|
||||||
var data = this.data.write();
|
var data = this.packets.write();
|
||||||
|
|
||||||
this.encrypted = openpgp_crypto_symmetricEncrypt(
|
this.encrypted = openpgp_crypto_symmetricEncrypt(
|
||||||
openpgp_crypto_getPrefixRandom(algo), algo, key, data, true);
|
openpgp_crypto_getPrefixRandom(algo), algo, key, data, true);
|
||||||
|
|
|
@ -7,7 +7,7 @@ unittests.register("Packet testing", function() {
|
||||||
literal.set_data('Hello world', openpgp_packet_literal.format.utf8);
|
literal.set_data('Hello world', openpgp_packet_literal.format.utf8);
|
||||||
|
|
||||||
var enc = new openpgp_packet_symmetrically_encrypted();
|
var enc = new openpgp_packet_symmetrically_encrypted();
|
||||||
enc.data.push(literal);
|
enc.packets.push(literal);
|
||||||
|
|
||||||
var key = '12345678901234567890123456789012',
|
var key = '12345678901234567890123456789012',
|
||||||
algo = openpgp.symmetric.aes256;
|
algo = openpgp.symmetric.aes256;
|
||||||
|
@ -21,10 +21,11 @@ unittests.register("Packet testing", function() {
|
||||||
var msg2 = new openpgp_packetlist();
|
var msg2 = new openpgp_packetlist();
|
||||||
msg2.read(message.write());
|
msg2.read(message.write());
|
||||||
|
|
||||||
msg2.packets[0].decrypt(algo, key);
|
msg2[0].decrypt(algo, key);
|
||||||
|
|
||||||
|
return new test_result('Symmetrically encrypted packet',
|
||||||
|
msg2[0].packets[0].data == literal.data);
|
||||||
|
|
||||||
return new test_result('Symmetrically encrypted data packet',
|
|
||||||
msg2.packets[0].data.packets[0].data == literal.data);
|
|
||||||
}, function() {
|
}, function() {
|
||||||
var key = '12345678901234567890123456789012',
|
var key = '12345678901234567890123456789012',
|
||||||
algo = openpgp.symmetric.aes256;
|
algo = openpgp.symmetric.aes256;
|
||||||
|
@ -34,17 +35,17 @@ unittests.register("Packet testing", function() {
|
||||||
msg = new openpgp_packetlist();
|
msg = new openpgp_packetlist();
|
||||||
|
|
||||||
literal.set_data('Hello world!', openpgp_packet_literal.format.utf8);
|
literal.set_data('Hello world!', openpgp_packet_literal.format.utf8);
|
||||||
enc.data.push(literal);
|
enc.packets.push(literal);
|
||||||
enc.encrypt(algo, key);
|
enc.encrypt(algo, key);
|
||||||
msg.push(enc);
|
msg.push(enc);
|
||||||
|
|
||||||
var msg2 = new openpgp_packetlist();
|
var msg2 = new openpgp_packetlist();
|
||||||
msg2.read(msg.write());
|
msg2.read(msg.write());
|
||||||
|
|
||||||
msg2.packets[0].decrypt(algo, key);
|
msg2[0].decrypt(algo, key);
|
||||||
|
|
||||||
return new test_result('Sym. encrypted integrity protected data packet',
|
return new test_result('Sym. encrypted integrity protected packet',
|
||||||
msg2.packets[0].data.packets[0].data == literal.data);
|
msg2[0].packets[0].data == literal.data);
|
||||||
|
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
||||||
|
@ -64,14 +65,13 @@ unittests.register("Packet testing", function() {
|
||||||
var parsed = new openpgp_packetlist();
|
var parsed = new openpgp_packetlist();
|
||||||
parsed.read(msgbytes);
|
parsed.read(msgbytes);
|
||||||
|
|
||||||
parsed.packets[0].decrypt('test');
|
parsed[0].decrypt('test');
|
||||||
|
|
||||||
var key = parsed.packets[0].key;
|
var key = parsed[0].key;
|
||||||
parsed.packets[1].decrypt(parsed.packets[0].algorithm, key);
|
parsed[1].decrypt(parsed[0].algorithm, key);
|
||||||
var compressed = parsed.packets[1].data.packets[0];
|
var compressed = parsed[1].packets[0];
|
||||||
compressed.decompress();
|
|
||||||
|
|
||||||
var result = compressed.data.packets[0].data;
|
var result = compressed.packets[0].data;
|
||||||
|
|
||||||
return new test_result('Sym encrypted session key with a compressed packet',
|
return new test_result('Sym encrypted session key with a compressed packet',
|
||||||
result == 'Hello world!\n');
|
result == 'Hello world!\n');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user