From b94566a154d09bd63df963adb3bd515c729273e4 Mon Sep 17 00:00:00 2001 From: seancolyer Date: Wed, 9 Oct 2013 19:09:54 -0400 Subject: [PATCH] Rebuilding binaries. Fixing minor issue with PR#105 --- resources/openpgp.js | 64 ++++++++++++++------- resources/openpgp.min.js | 13 +++-- src/encoding/openpgp.encoding.asciiarmor.js | 4 +- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/resources/openpgp.js b/resources/openpgp.js index 061c3110..3d3a7f0b 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -1430,9 +1430,15 @@ function bnpMillerRabin(t) { t = (t+1)>>1; if(t > lowprimes.length) t = lowprimes.length; var a = nbi(); + var j, bases = []; for(var i = 0; i < t; ++i) { //Pick bases at random, instead of starting at 2 - a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]); + for (;;) { + j = lowprimes[Math.floor(Math.random() * lowprimes.length)]; + if (bases.indexOf(j) == -1) break; + } + bases.push(j); + a.fromInt(j); var y = a.modPow(r,this); if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { var j = 1; @@ -7418,7 +7424,7 @@ function openpgp_config() { keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371" }; - this.versionstring ="OpenPGP.js v.1.20130825"; + this.versionstring ="OpenPGP.js v.1.20131009"; this.commentstring ="http://openpgpjs.org"; /** * Reads the config out of the HTML5 local storage @@ -7506,7 +7512,8 @@ function s2r(t) { r += "\n"; r += '='; } - + if (r.charAt(r.length-1)==="\n") + r=r.slice(0,-1); return r; } @@ -7552,7 +7559,7 @@ function r2s(t) { * and an attribute "openpgp" containing the bytes. */ function openpgp_encoding_deArmor(text) { - text = text.replace(/\r/g, '') + text = text.replace(/\r/g, ''); // remove whitespace of blank line to allow later split at \n\n text = text.replace(/\n\s+\n/, '\n\n'); @@ -7560,29 +7567,42 @@ function openpgp_encoding_deArmor(text) { if (type != 2) { var splittedtext = text.split('-----'); + // splittedtext[0] - should be the empty string + // splittedtext[1] - should be BEGIN... + // splittedtext[2] - the message and checksum + // splittedtest[3] - should be END... + + // chunks separated by blank lines + var splittedChunks = splittedtext[2] + .split('\n\n'); + var messageAndChecksum = splittedtext[2] + .split('\n\n')[1] + .split('\n='); + + var message = messageAndChecksum[0] + .replace(/\n- /g,"\n"); + // sometimes, there's a blank line between message and checksum + var checksum; + if(messageAndChecksum.length == 1){ + // blank line + checksum = splittedtext[2] + .replace(/[\n=]/g, ""); + } else { + // no blank line + checksum = messageAndChecksum[1] + .split('\n')[0]; + } var data = { - openpgp: openpgp_encoding_base64_decode( - splittedtext[2] - .split('\n\n')[1] - .split("\n=")[0] - .replace(/\n- /g,"\n")), + openpgp: openpgp_encoding_base64_decode(message), type: type }; - if (verifyCheckSum(data.openpgp, - splittedtext[2] - .split('\n\n')[1] - .split("\n=")[1] - .split('\n')[0])) - + if (verifyCheckSum(data.openpgp, checksum)) { return data; - else { + } else { util.print_error("Ascii armor integrity check on message failed: '" - + splittedtext[2] - .split('\n\n')[1] - .split("\n=")[1] - .split('\n')[0] + + checksum + "' should be '" + getCheckSum(data)) + "'"; return false; @@ -8354,8 +8374,8 @@ function _openpgp () { * This can be directly used to OpenPGP armor the message */ function write_signed_message(privatekey, messagetext) { - var sig = new openpgp_packet_signature().write_message_signature(1, messagetext.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"), privatekey); - var result = {text: messagetext.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"), openpgp: sig.openpgp, hash: sig.hash}; + var sig = new openpgp_packet_signature().write_message_signature(1, messagetext.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"), privatekey); + var result = {text: messagetext.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"), openpgp: sig.openpgp, hash: sig.hash}; return openpgp_encoding_armor(2,result, null, null) } diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index 10d91339..45e8cc54 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -50,7 +50,7 @@ var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83, 733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=67108864/lowprimes[lowprimes.length-1]; function bnIsProbablePrime(b){var a,c=this.abs();if(1==c.t&&c[0]<=lowprimes[lowprimes.length-1]){for(a=0;a>>16))b=c,a+=16;if(0!=(c=b>>8))b=c,a+=8;if(0!=(c=b>>4))b=c,a+=4;if(0!=(c=b>>2))b=c,a+=2;0!=b>>1&&(a+=1);return a}function bnToMPI(){var b=this.toByteArray(),a=8*(b.length-1)+nbits(b[0]),c;c=""+String.fromCharCode((a&65280)>>8);c+=String.fromCharCode(a&255);return c+=util.bin2str(b)} -function bnpMillerRabin(b){var a=this.subtract(BigInteger.ONE),c=a.getLowestSetBit();if(0>=c)return!1;var d=a.shiftRight(c),b=b+1>>1;if(b>lowprimes.length)b=lowprimes.length;for(var e=nbi(),f=0;f=c)return!1;var d=a.shiftRight(c),b=b+1>>1;if(b>lowprimes.length)b=lowprimes.length;for(var e=nbi(),f,g=[],h=0;hd?(a.push(String.fromCharCode(d)),c++):191d?(e=b.charCodeAt(c+1),a.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=b.charCodeAt(c+1),f=b.charCodeAt(c+2),a.push(String.fromCharCode((d&15)<<12|(e&63)<<6|f&63)),c+=3);return a.join("")}; JXG.Util.genUUID=function(){for(var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),a=Array(36),c=0,d,e=0;36>e;e++)8==e||13==e||18==e||23==e?a[e]="-":14==e?a[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,a[e]=b[19==e?d&3|8:d]);return a.join("")}; -function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm:8,encryption_cipher:9,compression:1,show_version:!0,show_comment:!0,integrity_protect:!0,composition_behavior:0,keyserver:"keyserver.linux.it"};this.versionstring="OpenPGP.js v.1.20130825";this.commentstring="http://openpgpjs.org";this.debug=!1;this.read=function(){var b=JSON.parse(window.localStorage.getItem("config"));null==b?(this.config=this.default_config,this.write()):this.config=b};this.write=function(){window.localStorage.setItem("config", -JSON.stringify(this.config))}}var b64s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function s2r(b){var a,c,d,e="",f=0,g=0,h=b.length;for(d=0;d>2&63),a=(c&3)<<4):1==g?(e+=b64s.charAt(a|c>>4&15),a=(c&15)<<2):2==g&&(e+=b64s.charAt(a|c>>6&3),f+=1,0==f%60&&(e+="\n"),e+=b64s.charAt(c&63)),f+=1,0==f%60&&(e+="\n"),g+=1,3==g&&(g=0);0>2&63),a=(c&3)<<4):1==g?(e+=b64s.charAt(a|c>>4&15),a=(c&15)<<2):2==g&&(e+=b64s.charAt(a|c>>6&3),f+=1,0==f%60&&(e+="\n"),e+=b64s.charAt(c&63)),f+=1,0==f%60&&(e+="\n"),g+=1,3==g&&(g=0);0>6-e&255)),e=e+2&7,f=a<>8&255)+String.fromCharCode(g.length&255)+g+ String.fromCharCode(180)+String.fromCharCode(d.length>>24)+String.fromCharCode(d.length>>16&255)+String.fromCharCode(d.length>>8&255)+String.fromCharCode(d.length&255)+d;d=new openpgp_packet_signature;d=d.write_message_signature(16,g,e);b=openpgp_encoding_armor(4,b.publicKey.string+f+d.openpgp);f=openpgp_encoding_armor(5,a.string+f+d.openpgp);return{privateKey:e,privateKeyArmored:f,publicKeyArmored:b}};this.write_signed_message=function(a,b){var d=(new openpgp_packet_signature).write_message_signature(1, -b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),a),d={text:b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),openpgp:d.openpgp,hash:d.hash};return openpgp_encoding_armor(2,d,null,null)};this.write_signed_and_encrypted_message=function(a,b,d){var e="",f=(new openpgp_packet_literaldata).write_packet(d.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug_hexstr_dump("literal_packet: |"+f+"|\n",f);for(var g=0;g