diff --git a/resources/openpgp.js b/resources/openpgp.js index f7f44d0c..1c07c6ea 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -3064,7 +3064,7 @@ function openpgp_packet_keymaterial() { str_sha1(cleartextMPIs.substring(0,cleartextMPIs.length - 20)) == cleartextMPIs.substring(cleartextMPIs.length - 20)) { cleartextMPIslength -= 20; - } else if (this.s2kUsageConcentions != 254 && util.calc_checksum(cleartextMPIs.substring(0,cleartextMPIs.length - 2)) == + } else if (this.s2kUsageConventions != 254 && util.calc_checksum(cleartextMPIs.substring(0,cleartextMPIs.length - 2)) == (cleartextMPIs.charCodeAt(cleartextMPIs.length -2) << 8 | cleartextMPIs.charCodeAt(cleartextMPIs.length -1))) { cleartextMPIslength -= 2; } else { @@ -11335,7 +11335,7 @@ function openpgp_type_s2k() { var isp = this.saltValue+passphrase; while (isp.length < this.count) isp += this.saltValue+passphrase; - if (isp.length < this.count) + if (isp.length > this.count) isp = isp.substr(0, this.count); return openpgp_crypto_hashData(this.hashAlgorithm,isp); } else return null; diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index f38a510b..28f946b2 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -91,7 +91,7 @@ d,c-2-(d-b)),d+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mp else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a,d,c-2-(d-b)),d+=this.secMPIs[0].packetLength;this.checksum=[];this.checksum[0]=a[d++].charCodeAt();this.checksum[1]=a[d++].charCodeAt()}else this.encryptedMPIData=a.substring(d,c);return this};this.decryptSecretMPIs=function(a){if(this.hasUnencryptedSecretKeyData)return this.secMPIs;var b=this.s2k.produce_key(a),a="";switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encryption algorithim: IDEA is not implemented"), !1;case 2:a=normal_cfb_decrypt(function(a,b){return des(b,a,1,null,0)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 3:a=normal_cfb_decrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(b.substring(0,16)),this.encryptedMPIData,this.IV);break;case 4:a=normal_cfb_decrypt(function(a,b){return(new Blowfish(b)).encrypt(a)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 7:case 8:case 9:a=normal_cfb_decrypt(AESencrypt, this.IVLength,keyExpansion(b),this.encryptedMPIData,this.IV);break;case 10:return util.print_error("openpgp.packet.keymaterial.js\nKey material is encrypted with twofish: not implemented"),!1;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm),!1}if(null==a)return util.print_error("openpgp.packet.keymaterial.js\ncleartextMPIs was null"),!1;b=a.length;if(254==this.s2kUsageConventions&&str_sha1(a.substring(0, -a.length-20))==a.substring(a.length-20))b-=20;else if(254!=this.s2kUsageConcentions&&util.calc_checksum(a.substring(0,a.length-2))==(a.charCodeAt(a.length-2)<<8|a.charCodeAt(a.length-1)))b-=2;else return!1;if(0this.publicKey.publicKeyAlgorithm){var c=0;this.secMPIs=[];this.secMPIs[0]=new openpgp_type_mpi;this.secMPIs[0].read(a,0,b);c+=this.secMPIs[0].packetLength;this.secMPIs[1]=new openpgp_type_mpi;this.secMPIs[1].read(a,c,b-c);c+=this.secMPIs[1].packetLength; +a.length-20))==a.substring(a.length-20))b-=20;else if(254!=this.s2kUsageConventions&&util.calc_checksum(a.substring(0,a.length-2))==(a.charCodeAt(a.length-2)<<8|a.charCodeAt(a.length-1)))b-=2;else return!1;if(0this.publicKey.publicKeyAlgorithm){var c=0;this.secMPIs=[];this.secMPIs[0]=new openpgp_type_mpi;this.secMPIs[0].read(a,0,b);c+=this.secMPIs[0].packetLength;this.secMPIs[1]=new openpgp_type_mpi;this.secMPIs[1].read(a,c,b-c);c+=this.secMPIs[1].packetLength; this.secMPIs[2]=new openpgp_type_mpi;this.secMPIs[2].read(a,c,b-c);c+=this.secMPIs[2].packetLength;this.secMPIs[3]=new openpgp_type_mpi;this.secMPIs[3].read(a,c,b-c);c+=this.secMPIs[3].packetLength}else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a,0,a);else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a,0,b);return!0};this.read_nodes=function(a,b,c,d){this.parentNode= a;if(14==this.tagType){for(var a=c,e=null;b.length!=a;)if(d=b.length-a,e=openpgp_packet.read_packet(b,a,d),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_pub]parsing ends here @:"+a+" l:"+d);break}else switch(e.tagType){case 2:if(24==e.signatureType){this.subKeySignature=e;a+=e.packetLength+e.headerLength;break}else if(40==e.signatureType){this.subKeyRevocationSignature=e;a+=e.packetLength+e.headerLength;break}else util.print_error("openpgp.packet.keymaterial.js\nunknown signature:"+ e.toString());default:return this.data=b,this.position=c-this.parentNode.packetLength,this.len=a-c}this.data=b;this.position=c-this.parentNode.packetLength;return this.len=a-c}if(7==this.tagType){for(a=c;b.length!=a;)if(e=openpgp_packet.read_packet(b,a,d-(a-c)),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_priv] parsing ends here @:"+a);break}else switch(e.tagType){case 2:24==e.signatureType?this.subKeySignature=e:40==e.signatureType&&(this.subKeyRevocationSignature[this.subKeyRevocationSignature]= @@ -419,7 +419,7 @@ function openpgp_type_mpi(){this.data=this.mpiByteLength=this.mpiBitLength=this. this.toString=function(){var a=" MPI("+this.mpiBitLength+"b/"+this.mpiByteLength+"B) : 0x",a=a+util.hexstrdump(this.MPI);return a+"\n"};this.create=function(a){this.MPI=a;var b=8*(a.length-1),c;a:for(var d=a.charCodeAt(0),e=0;9>e;e++)if(0==d>>e){c=e;break a}this.mpiBitLength=b+c;this.mpiByteLength=a.length;return this};this.toBin=function(){var a=String.fromCharCode(this.mpiBitLength>>8&255),a=a+String.fromCharCode(this.mpiBitLength&255);return a+=this.MPI};this.getByteLength=function(){return this.mpiByteLength}} function openpgp_type_keyid(){this.read_packet=function(a,b){this.bytes=a.substring(b,b+8);return this};this.toString=function(){return util.hexstrdump(this.bytes)}} function openpgp_type_s2k(){this.read=function(a,b){var c=b;this.type=a[c++].charCodeAt();switch(this.type){case 0:this.hashAlgorithm=a[c++].charCodeAt();this.s2kLength=1;break;case 1:this.hashAlgorithm=a[c++].charCodeAt();this.saltValue=a.substring(c,c+8);this.s2kLength=9;break;case 3:this.hashAlgorithm=a[c++].charCodeAt();this.saltValue=a.substring(c,c+8);c+=8;this.EXPBIAS=6;c=a[c++].charCodeAt();this.count=16+(c&15)<<(c>>4)+this.EXPBIAS;this.s2kLength=10;break;default:util.print_error("unknown s2k type! "+ -this.type)}return this};this.produce_key=function(a){if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,a);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+a);if(3==this.type){for(var b=this.saltValue+a;b.lengththis.count&&(b=b.substr(0,this.count));return openpgp_crypto_hashData(this.hashAlgorithm,b)}return null}} function openpgp_keyring(){this.init=function(){var a=JSON.parse(window.localStorage.getItem("privatekeys")),b=JSON.parse(window.localStorage.getItem("publickeys"));if(null==a||0==a.length)a=[];if(null==b||0==b.length)b=[];this.publicKeys=[];this.privateKeys=[];for(var c=0,d=0;d")[0]: a.trim(),a=0;a")[0]:a.trim(),a=0;a this.count) isp = isp.substr(0, this.count); return openpgp_crypto_hashData(this.hashAlgorithm,isp); } else return null;