mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-03-30 15:08:32 +00:00
missed a reference to untranslated EOL
This commit is contained in:
parent
c555dbfba9
commit
d2613e27b4
@ -7422,7 +7422,7 @@ function openpgp_config() {
|
||||
keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371"
|
||||
};
|
||||
|
||||
this.versionstring ="OpenPGP.js v.1.20131204";
|
||||
this.versionstring ="OpenPGP.js v.1.20131205";
|
||||
this.commentstring ="http://openpgpjs.org";
|
||||
/**
|
||||
* Reads the config out of the HTML5 local storage
|
||||
@ -7592,7 +7592,7 @@ function openpgp_encoding_deArmor(text) {
|
||||
// splittedtext[indexBase] - the message
|
||||
// splittedtext[indexBase + 1] - the signature and checksum
|
||||
|
||||
var msg = openpgp_encoding_split_headers(splittedtext[indexBase].replace(/^- /mg, ''));
|
||||
var msg = openpgp_encoding_split_headers(splittedtext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
|
||||
var sig = openpgp_encoding_split_headers(splittedtext[indexBase + 1].replace(/^- /mg, ''));
|
||||
var sig_sum = openpgp_encoding_split_checksum(sig.body);
|
||||
|
||||
@ -8059,7 +8059,7 @@ function _openpgp () {
|
||||
var mypos = 0;
|
||||
var publicKeys = new Array();
|
||||
var publicKeyCount = 0;
|
||||
var input = openpgp_encoding_deArmor(armoredText.replace(/\r/g,'')).openpgp;
|
||||
var input = openpgp_encoding_deArmor(armoredText).openpgp;
|
||||
var l = input.length;
|
||||
while (mypos != input.length) {
|
||||
var first_packet = openpgp_packet.read_packet(input, mypos, l);
|
||||
@ -8105,7 +8105,7 @@ function _openpgp () {
|
||||
var privateKeys = new Array();
|
||||
var privateKeyCount = 0;
|
||||
var mypos = 0;
|
||||
var input = openpgp_encoding_deArmor(armoredText.replace(/\r/g,'')).openpgp;
|
||||
var input = openpgp_encoding_deArmor(armoredText).openpgp;
|
||||
var l = input.length;
|
||||
while (mypos != input.length) {
|
||||
var first_packet = openpgp_packet.read_packet(input, mypos, l);
|
||||
@ -8304,7 +8304,7 @@ function _openpgp () {
|
||||
*/
|
||||
function write_signed_and_encrypted_message(privatekey, publickeys, messagetext) {
|
||||
var result = "";
|
||||
var literal = new openpgp_packet_literaldata().write_packet(messagetext.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));
|
||||
var literal = new openpgp_packet_literaldata().write_packet(messagetext);
|
||||
util.print_debug_hexstr_dump("literal_packet: |"+literal+"|\n",literal);
|
||||
for (var i = 0; i < publickeys.length; i++) {
|
||||
var onepasssignature = new openpgp_packet_onepasssignature();
|
||||
@ -8314,7 +8314,7 @@ function _openpgp () {
|
||||
else
|
||||
onepasssigstr = onepasssignature.write_packet(1, openpgp.config.config.prefer_hash_algorithm, privatekey, false);
|
||||
util.print_debug_hexstr_dump("onepasssigstr: |"+onepasssigstr+"|\n",onepasssigstr);
|
||||
var datasignature = new openpgp_packet_signature().write_message_signature(1, messagetext.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"), privatekey);
|
||||
var datasignature = new openpgp_packet_signature().write_message_signature(1, messagetext, privatekey);
|
||||
util.print_debug_hexstr_dump("datasignature: |"+datasignature.openpgp+"|\n",datasignature.openpgp);
|
||||
if (i == 0) {
|
||||
result = onepasssigstr+literal+datasignature.openpgp;
|
||||
@ -8361,7 +8361,7 @@ function _openpgp () {
|
||||
*/
|
||||
function write_encrypted_message(publickeys, messagetext) {
|
||||
var result = "";
|
||||
var literal = new openpgp_packet_literaldata().write_packet(messagetext.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));
|
||||
var literal = new openpgp_packet_literaldata().write_packet(messagetext);
|
||||
util.print_debug_hexstr_dump("literal_packet: |"+literal+"|\n",literal);
|
||||
result = literal;
|
||||
|
||||
@ -8404,9 +8404,10 @@ 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/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)
|
||||
var canonicalMsgText = messagetext.replace(/\r/g,'').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n");
|
||||
var sig = new openpgp_packet_signature().write_message_signature(1, canonicalMsgText, privatekey);
|
||||
var result = {text: canonicalMsgText, openpgp: sig.openpgp, hash: sig.hash};
|
||||
return openpgp_encoding_armor(2, result, null, null)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -11853,16 +11854,14 @@ function openpgp_packet_signature() {
|
||||
trailer += String.fromCharCode(((result.length) >> 16) & 0xFF);
|
||||
trailer += String.fromCharCode(((result.length) >> 8) & 0xFF);
|
||||
trailer += String.fromCharCode((result.length) & 0xFF);
|
||||
var result2 = String.fromCharCode(0);
|
||||
result2 += String.fromCharCode(0);
|
||||
var hash = openpgp_crypto_hashData(hash_algo, data+result+trailer);
|
||||
util.print_debug("DSA Signature is calculated with:|"+data+result+trailer+"|\n"+util.hexstrdump(data+result+trailer)+"\n hash:"+util.hexstrdump(hash));
|
||||
result2 += hash.charAt(0);
|
||||
result2 += hash.charAt(1);
|
||||
var hashData = signature_type == 1 ? data.replace(/\r/g, '').replace(/\n/g, "\r\n") : data;
|
||||
var hash = openpgp_crypto_hashData(hash_algo, hashData+result+trailer);
|
||||
util.print_debug("Signature is calculated with:|"+hashData+result+trailer+"|\n"+util.hexstrdump(hashData+result+trailer)+"\n hash:"+util.hexstrdump(hash));
|
||||
var result2 = String.fromCharCode(0) + String.fromCharCode(0) + hash.charAt(0) + hash.charAt(1);
|
||||
result2 += openpgp_crypto_signData(hash_algo,privatekey.privateKeyPacket.publicKey.publicKeyAlgorithm,
|
||||
publickey.MPIs,
|
||||
privatekey.privateKeyPacket.secMPIs,
|
||||
data+result+trailer);
|
||||
hashData+result+trailer);
|
||||
return {openpgp: (openpgp_packet.write_packet_header(2, (result+result2).length)+result + result2),
|
||||
hash: util.get_hashAlgorithmString(hash_algo)};
|
||||
}
|
||||
@ -12118,21 +12117,18 @@ function openpgp_packet_signature() {
|
||||
break;
|
||||
|
||||
case 1: // 0x01: Signature of a canonical text document.
|
||||
var tohash = data
|
||||
.replace(/\r\n/g,"\n")
|
||||
.replace(/[\t ]+\n/g, "\n")
|
||||
.replace(/\n/g,"\r\n");
|
||||
var canonicalMsgText = data.replace(/\r/g,'').replace(/\n/g,"\r\n");
|
||||
if (openpgp.config.debug) {
|
||||
util.print_debug('tohash: '+util.hexdump(tohash));
|
||||
util.print_debug('canonicalMsgText: '+util.hexdump(canonicalMsgText));
|
||||
util.print_debug('signatureData: '+util.hexdump(this.signatureData));
|
||||
util.print_debug('trailer: '+util.hexdump(trailer));
|
||||
}
|
||||
if (this.version == 4) {
|
||||
this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm,
|
||||
this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData+trailer);
|
||||
this.MPIs, key.obj.publicKeyPacket.MPIs, canonicalMsgText+this.signatureData+trailer);
|
||||
} else if (this.version == 3) {
|
||||
this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm,
|
||||
this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData);
|
||||
this.MPIs, key.obj.publicKeyPacket.MPIs, canonicalMsgText+this.signatureData);
|
||||
} else {
|
||||
this.verified = false;
|
||||
}
|
||||
@ -13464,7 +13460,10 @@ var Util = function() {
|
||||
}
|
||||
html = "<p style=\"font-size: 80%; background-color: #"+color+"; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;\"><span style=\"color: #888;\"><b>"+heading+":</b></span>"+str+"</p>";
|
||||
}
|
||||
showMessages(html);
|
||||
if (typeof showMessages === "function") {
|
||||
// only call function if defined
|
||||
showMessages(html);
|
||||
}
|
||||
}
|
||||
|
||||
this.getLeftNBits = function (string, bitcount) {
|
||||
|
38
resources/openpgp.min.js
vendored
38
resources/openpgp.min.js
vendored
@ -286,12 +286,12 @@ JXG.Util.asciiCharCodeAt=function(b,a){var c=b.charCodeAt(a);if(255<c)switch(c){
|
||||
151;break;case 732:c=152;break;case 8482:c=153;break;case 353:c=154;break;case 8250:c=155;break;case 339:c=156;break;case 382:c=158;break;case 376:c=159}return c};
|
||||
JXG.Util.utf8Decode=function(b){var a=[],c=0,d=0,e=0,f;if(!JXG.exists(b))return"";for(;c<b.length;)d=b.charCodeAt(c),128>d?(a.push(String.fromCharCode(d)),c++):191<d&&224>d?(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.20131204";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",
|
||||
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.20131205";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<h;d++)c=b.charCodeAt(d),0==g?(e+=b64s.charAt(c>>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<g&&(e+=b64s.charAt(a),f+=1,0==f%60&&(e+="\n"),e+="=",f+=1);1==g&&(0==f%60&&(e+="\n"),e+="=");"\n"===e.charAt(e.length-1)&&(e=e.slice(0,-1));return e}
|
||||
function r2s(b){var a,c,d="",e=0,f=0,g=b.length;for(c=0;c<g;c++)a=b64s.indexOf(b.charAt(c)),0<=a&&(e&&(d+=String.fromCharCode(f|a>>6-e&255)),e=e+2&7,f=a<<e&255);return d}
|
||||
function openpgp_encoding_deArmor(b){var a=/^-----[^-]+-----$\n/m,b=b.replace(/\r/g,""),c=openpgp_encoding_get_type(b),d=b.split(a),e=1;b.search(a)!=d[0].length&&(e=0);2!=c?(b=openpgp_encoding_split_headers(d[e].replace(/^- /mg,"")),d=openpgp_encoding_split_checksum(b.body),c={openpgp:openpgp_encoding_base64_decode(d.body),type:c}):(b=openpgp_encoding_split_headers(d[e].replace(/^- /mg,"")),d=openpgp_encoding_split_headers(d[e+1].replace(/^- /mg,"")),d=openpgp_encoding_split_checksum(d.body),c={text:b.body.replace(/\n$/,
|
||||
"").replace(/\n/g,"\r\n"),openpgp:openpgp_encoding_base64_decode(d.body),type:c});d=d.checksum;if(verifyCheckSum(c.openpgp,d))return c;util.print_error("Ascii armor integrity check on message failed: '"+d+"' should be '"+getCheckSum(c)+"'");return!1}function openpgp_encoding_split_headers(b){var a="",c=b,d=/^[\t ]*\n/m.exec(b);null!=d&&(a=b.slice(0,d.index),c=b.slice(d.index+d[0].length));return{headers:a,body:c}}
|
||||
function openpgp_encoding_deArmor(b){var a=/^-----[^-]+-----$\n/m,b=b.replace(/\r/g,""),c=openpgp_encoding_get_type(b),d=b.split(a),e=1;b.search(a)!=d[0].length&&(e=0);2!=c?(b=openpgp_encoding_split_headers(d[e].replace(/^- /mg,"")),d=openpgp_encoding_split_checksum(b.body),c={openpgp:openpgp_encoding_base64_decode(d.body),type:c}):(b=openpgp_encoding_split_headers(d[e].replace(/^- /mg,"").replace(/[\t ]+\n/g,"\n")),d=openpgp_encoding_split_headers(d[e+1].replace(/^- /mg,"")),d=openpgp_encoding_split_checksum(d.body),
|
||||
c={text:b.body.replace(/\n$/,"").replace(/\n/g,"\r\n"),openpgp:openpgp_encoding_base64_decode(d.body),type:c});d=d.checksum;if(verifyCheckSum(c.openpgp,d))return c;util.print_error("Ascii armor integrity check on message failed: '"+d+"' should be '"+getCheckSum(c)+"'");return!1}function openpgp_encoding_split_headers(b){var a="",c=b,d=/^[\t ]*\n/m.exec(b);null!=d&&(a=b.slice(0,d.index),c=b.slice(d.index+d[0].length));return{headers:a,body:c}}
|
||||
function openpgp_encoding_split_checksum(b){var a=b,c="",d=/^=/m.exec(b);null!=d&&(a=b.slice(0,d.index),c=b.slice(d.index+1));return{body:a,checksum:c}}
|
||||
function openpgp_encoding_get_type(b){b=b.match(/^-----([^-]+)-----$\n/m);if(b[1].match(/BEGIN PGP MESSAGE, PART \d+\/\d+/))return 0;if(b[1].match(/BEGIN PGP MESSAGE, PART \d+/))return 1;if(b[1].match(/BEGIN PGP SIGNED MESSAGE/))return 2;if(b[1].match(/BEGIN PGP MESSAGE/))return 3;if(b[1].match(/BEGIN PGP PUBLIC KEY BLOCK/))return 4;if(b[1].match(/BEGIN PGP PRIVATE KEY BLOCK/))return 5}
|
||||
function openpgp_encoding_armor_addheader(){var b="";openpgp.config.config.show_version&&(b+="Version: "+openpgp.config.versionstring+"\r\n");openpgp.config.config.show_comment&&(b+="Comment: "+openpgp.config.commentstring+"\r\n");return b+"\r\n"}
|
||||
@ -317,15 +317,15 @@ break}else if(1==j.tagType){util.print_debug("session key found:\n "+j.toString(
|
||||
j.tagType)}else{if(18==j.tagType){util.print_debug("symmetric encrypted data");break}}else 2==j.tagType&&3>j.signatureType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,e[f].text=d,e[f].signature=j,f++):4==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength):8==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,j=j.decompress(),e=e.concat(openpgp.read_messages_dearmored({text:j,openpgp:j}))):10==j.tagType?(e.length=0,g+=j.packetLength+
|
||||
j.headerLength,h-=j.packetLength+j.headerLength):11==j.tagType?(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength,d=j.data,e[f].data=j.data,f++):19==j.tagType&&(g+=j.packetLength+j.headerLength,h-=j.packetLength+j.headerLength);else return util.print_error("no message found!"),null}return e}this.tostring="";this.generate_key_pair=function(a,b,d,e){var f=(new openpgp_packet_userid).write_packet(d),b=openpgp_crypto_generateKeyPair(a,b,e,openpgp.config.config.prefer_hash_algorithm,3),
|
||||
a=b.privateKey,g=(new openpgp_packet_keymaterial).read_priv_key(a.string,3,a.string.length);g.decryptSecretMPIs(e)||util.print_error("Issue creating key. Unable to read resulting private key");e=new openpgp_msg_privatekey;e.privateKeyPacket=g;e.getPreferredSignatureHashAlgorithm=function(){return openpgp.config.config.prefer_hash_algorithm};g=e.privateKeyPacket.publicKey.data;d=util.encode_utf8(d);g=String.fromCharCode(153)+String.fromCharCode(g.length>>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/g,"\r\n"),a),d={text:b.replace(/\r\n/g,"\n").replace(/\n/g,"\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<b.length;g++){var h="",h=(new openpgp_packet_onepasssignature).write_packet(1,openpgp.config.config.prefer_hash_algorithm,
|
||||
a,!1);util.print_debug_hexstr_dump("onepasssigstr: |"+h+"|\n",h);var j=(new openpgp_packet_signature).write_message_signature(1,d.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),a);util.print_debug_hexstr_dump("datasignature: |"+j.openpgp+"|\n",j.openpgp);e=0==g?h+f+j.openpgp:h+e+j.openpgp}util.print_debug_hexstr_dump("signed packet: |"+e+"|\n",e);a=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher);d="";for(g=0;g<b.length;g++){f=b[g].getEncryptionKey();if(null==f)return util.print_error("no encryption key found! Key is for signing only."),
|
||||
null;d+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(f.getKeyId(),f.MPIs,f.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,a)}d=openpgp.config.config.integrity_protect?d+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,a,e):d+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,a,e);return openpgp_encoding_armor(3,d,null,null)};this.write_encrypted_message=function(a,b){var d="",
|
||||
d=(new openpgp_packet_literaldata).write_packet(b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug_hexstr_dump("literal_packet: |"+d+"|\n",d);for(var e=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher),f="",g=0;g<a.length;g++){var h=a[g].getEncryptionKey();if(null==h)return util.print_error("no encryption key found! Key is for signing only."),null;f+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(h.getKeyId(),h.MPIs,h.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,
|
||||
e)}f=openpgp.config.config.integrity_protect?f+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,e,d):f+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,e,d);return openpgp_encoding_armor(3,f,null,null)};this.read_message=function(a){var c;try{c=openpgp_encoding_deArmor(a)}catch(d){return util.print_error("no message found!"),null}return b(c)};this.read_messages_dearmored=b;this.read_publicKey=function(a){for(var b=
|
||||
0,d=[],e=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,f=a.length;b!=a.length;){var g=openpgp_packet.read_packet(a,b,f);if(153==a.charCodeAt(b)||6==g.tagType)d[e]=new openpgp_msg_publickey,d[e].header=a.substring(b,b+3),153==a.charCodeAt(b)?(b++,f=a.charCodeAt(b++)<<8|a.charCodeAt(b++),d[e].publicKeyPacket=new openpgp_packet_keymaterial,d[e].publicKeyPacket.header=d[e].header,d[e].publicKeyPacket.read_tag6(a,b,f),b+=d[e].publicKeyPacket.packetLength,b+=d[e].read_nodes(d[e].publicKeyPacket,
|
||||
a,b,a.length-b)):(d[e]=new openpgp_msg_publickey,d[e].publicKeyPacket=g,b+=g.headerLength+g.packetLength,b+=d[e].read_nodes(g,a,b,a.length-b));else return util.print_error("no public key found!"),null;d[e].data=a.substring(0,b);e++}return d};this.read_privateKey=function(a){for(var b=[],d=0,e=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,f=a.length;e!=a.length;){var g=openpgp_packet.read_packet(a,e,f);if(5==g.tagType)b[b.length]=new openpgp_msg_privatekey,e+=g.headerLength+g.packetLength,
|
||||
e+=b[d].read_nodes(g,a,e,f);else return util.print_error("no block packet found!"),null;b[d].data=a.substring(0,e);d++}return b};this.init=function(){this.config=new openpgp_config;this.config.read();this.keyring=new openpgp_keyring;this.keyring.init()}}var openpgp=new _openpgp;
|
||||
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=b.replace(/\r/g,"").replace(/[\t ]+\n/g,"\n").replace(/\n/g,
|
||||
"\r\n"),e=(new openpgp_packet_signature).write_message_signature(1,d,a);return openpgp_encoding_armor(2,{text:d,openpgp:e.openpgp,hash:e.hash},null,null)};this.write_signed_and_encrypted_message=function(a,b,d){var e="",f=(new openpgp_packet_literaldata).write_packet(d);util.print_debug_hexstr_dump("literal_packet: |"+f+"|\n",f);for(var g=0;g<b.length;g++){var h="",h=(new openpgp_packet_onepasssignature).write_packet(1,openpgp.config.config.prefer_hash_algorithm,a,!1);util.print_debug_hexstr_dump("onepasssigstr: |"+
|
||||
h+"|\n",h);var j=(new openpgp_packet_signature).write_message_signature(1,d,a);util.print_debug_hexstr_dump("datasignature: |"+j.openpgp+"|\n",j.openpgp);e=0==g?h+f+j.openpgp:h+e+j.openpgp}util.print_debug_hexstr_dump("signed packet: |"+e+"|\n",e);a=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher);d="";for(g=0;g<b.length;g++){f=b[g].getEncryptionKey();if(null==f)return util.print_error("no encryption key found! Key is for signing only."),null;d+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(f.getKeyId(),
|
||||
f.MPIs,f.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,a)}d=openpgp.config.config.integrity_protect?d+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,a,e):d+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,a,e);return openpgp_encoding_armor(3,d,null,null)};this.write_encrypted_message=function(a,b){var d="",d=(new openpgp_packet_literaldata).write_packet(b);util.print_debug_hexstr_dump("literal_packet: |"+
|
||||
d+"|\n",d);for(var e=openpgp_crypto_generateSessionKey(openpgp.config.config.encryption_cipher),f="",g=0;g<a.length;g++){var h=a[g].getEncryptionKey();if(null==h)return util.print_error("no encryption key found! Key is for signing only."),null;f+=(new openpgp_packet_encryptedsessionkey).write_pub_key_packet(h.getKeyId(),h.MPIs,h.publicKeyAlgorithm,openpgp.config.config.encryption_cipher,e)}f=openpgp.config.config.integrity_protect?f+(new openpgp_packet_encryptedintegrityprotecteddata).write_packet(openpgp.config.config.encryption_cipher,
|
||||
e,d):f+(new openpgp_packet_encrypteddata).write_packet(openpgp.config.config.encryption_cipher,e,d);return openpgp_encoding_armor(3,f,null,null)};this.read_message=function(a){var c;try{c=openpgp_encoding_deArmor(a)}catch(d){return util.print_error("no message found!"),null}return b(c)};this.read_messages_dearmored=b;this.read_publicKey=function(a){for(var b=0,d=[],e=0,a=openpgp_encoding_deArmor(a).openpgp,f=a.length;b!=a.length;){var g=openpgp_packet.read_packet(a,b,f);if(153==a.charCodeAt(b)||6==
|
||||
g.tagType)d[e]=new openpgp_msg_publickey,d[e].header=a.substring(b,b+3),153==a.charCodeAt(b)?(b++,f=a.charCodeAt(b++)<<8|a.charCodeAt(b++),d[e].publicKeyPacket=new openpgp_packet_keymaterial,d[e].publicKeyPacket.header=d[e].header,d[e].publicKeyPacket.read_tag6(a,b,f),b+=d[e].publicKeyPacket.packetLength,b+=d[e].read_nodes(d[e].publicKeyPacket,a,b,a.length-b)):(d[e]=new openpgp_msg_publickey,d[e].publicKeyPacket=g,b+=g.headerLength+g.packetLength,b+=d[e].read_nodes(g,a,b,a.length-b));else return util.print_error("no public key found!"),
|
||||
null;d[e].data=a.substring(0,b);e++}return d};this.read_privateKey=function(a){for(var b=[],d=0,e=0,a=openpgp_encoding_deArmor(a).openpgp,f=a.length;e!=a.length;){var g=openpgp_packet.read_packet(a,e,f);if(5==g.tagType)b[b.length]=new openpgp_msg_privatekey,e+=g.headerLength+g.packetLength,e+=b[d].read_nodes(g,a,e,f);else return util.print_error("no block packet found!"),null;b[d].data=a.substring(0,e);d++}return b};this.init=function(){this.config=new openpgp_config;this.config.read();this.keyring=
|
||||
new openpgp_keyring;this.keyring.init()}}var openpgp=new _openpgp;
|
||||
function openpgp_keyring(){this.init=function(){var b=JSON.parse(window.localStorage.getItem("privatekeys")),a=JSON.parse(window.localStorage.getItem("publickeys"));if(null==b||0==b.length)b=[];if(null==a||0==a.length)a=[];this.publicKeys=[];this.privateKeys=[];for(var c=0,d=0;d<b.length;d++){var e=openpgp.read_privateKey(b[d]);this.privateKeys[c]={armored:b[d],obj:e[0],keyId:e[0].getKeyId()};c++}for(d=c=0;d<a.length;d++)e=openpgp.read_publicKey(a[d]),null!=e[0]&&(this.publicKeys[c]={armored:a[d],
|
||||
obj:e[0],keyId:e[0].getKeyId()},c++)};this.hasPrivateKey=function(){return 0<this.privateKeys.length};this.store=function(){for(var b=[],a=0;a<this.privateKeys.length;a++)b[a]=this.privateKeys[a].armored;for(var c=[],a=0;a<this.publicKeys.length;a++)c[a]=this.publicKeys[a].armored;window.localStorage.setItem("privatekeys",JSON.stringify(b));window.localStorage.setItem("publickeys",JSON.stringify(c))};this.getPublicKeyForAddress=function(b){var a=[],c=b.split("<"),d="",d=1<c.length?c[1].split(">")[0]:
|
||||
b.trim(),d=d.toLowerCase();if(!util.emailRegEx.test(d))return a;for(b=0;b<this.publicKeys.length;b++)for(c=0;c<this.publicKeys[b].obj.userIds.length;c++)0<=this.publicKeys[b].obj.userIds[c].text.toLowerCase().indexOf(d)&&(a[a.length]=this.publicKeys[b]);return a};this.getPrivateKeyForAddress=function(b){var a=[],c=b.split("<"),d="",d=1<c.length?c[1].split(">")[0]:b.trim(),d=d.toLowerCase();if(!util.emailRegEx.test(d))return a;for(b=0;b<this.privateKeys.length;b++)for(c=0;c<this.privateKeys[b].obj.userIds.length;c++)0<=
|
||||
@ -427,11 +427,11 @@ new String;for(g=0;g<f-1;g++)this.regular_expression+=a[e++];break;case 7:this.r
|
||||
a[e++];break;case 27:this.keyFlags=[];for(g=0;g<f-1;g++)this.keyFlags=a.charCodeAt(e++);break;case 28:this.signersUserId=new String;for(g=0;g<f-1;g++)this.signersUserId+=a[e++];break;case 29:this.reasonForRevocationFlag=a.charCodeAt(e++);this.reasonForRevocationString=new String;for(g=0;g<f-2;g++)this.reasonForRevocationString+=a[e++];break;case 30:return f+1;case 31:this.signatureTargetPublicKeyAlgorithm=a.charCodeAt(e++);this.signatureTargetHashAlgorithm=a.charCodeAt(e++);f=0;switch(this.signatureTargetHashAlgorithm){case 1:case 2:f=
|
||||
20;break;case 3:case 8:case 9:case 10:case 11:break;default:return util.print_error("openpgp.packet.signature.js\nunknown signature target hash algorithm:"+this.signatureTargetHashAlgorithm),null}this.signatureTargetHash=[];for(g=0;g<f;g++)this.signatureTargetHash[g]=a[e++];case 32:return this.embeddedSignature=new openpgp_packet_signature,this.embeddedSignature.read_packet(a,e,d-(e-b)),e+this.embeddedSignature.packetLength-b;case 100:case 101:case 102:case 103:case 104:case 105:case 106:case 107:case 108:case 109:case 110:return util.print_error("openpgp.packet.signature.js\nprivate or experimental signature subpacket type "+
|
||||
g+" @:"+e+" subplen:"+f+" len:"+d),f+1;default:return util.print_error("openpgp.packet.signature.js\nunknown signature subpacket type "+g+" @:"+e+" subplen:"+f+" len:"+d),f+1}return e-b};this.getIssuerKey=function(){var a=null;if(4==this.version)a=openpgp.keyring.getPublicKeysForKeyId(this.issuerKeyId);else if(3==this.version)a=openpgp.keyring.getPublicKeysForKeyId(this.keyId);else return null;return 0==a.length?null:a[0]};this.getIssuer=function(){return 4==this.version?this.issuerKeyId:3==this.version?
|
||||
this.keyId:null};this.write_message_signature=function(a,c,d){var e=d.privateKeyPacket.publicKey,f=d.getPreferredSignatureHashAlgorithm(),g=String.fromCharCode(4),g=g+String.fromCharCode(a),g=g+String.fromCharCode(e.publicKeyAlgorithm),g=g+String.fromCharCode(f),a=Math.round((new Date).getTime()/1E3),a=b(2,""+String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255)),h=b(16,d.getKeyId()),g=g+String.fromCharCode(a.length+h.length>>8&255),
|
||||
g=g+String.fromCharCode(a.length+h.length&255),g=g+a+h,a=""+String.fromCharCode(4),a=a+String.fromCharCode(255),a=a+String.fromCharCode(g.length>>24),a=a+String.fromCharCode(g.length>>16&255),a=a+String.fromCharCode(g.length>>8&255),a=a+String.fromCharCode(g.length&255),h=String.fromCharCode(0),h=h+String.fromCharCode(0),j=openpgp_crypto_hashData(f,c+g+a);util.print_debug("DSA Signature is calculated with:|"+c+g+a+"|\n"+util.hexstrdump(c+g+a)+"\n hash:"+util.hexstrdump(j));h+=j.charAt(0);h+=j.charAt(1);
|
||||
h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+a);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,b){var d;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&
|
||||
255);switch(this.signatureType){case 0:this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d):3==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData):!1;break;case 1:var e=a.replace(/\r\n/g,"\n").replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");openpgp.config.debug&&(util.print_debug("tohash: "+util.hexdump(e)),
|
||||
util.print_debug("signatureData: "+util.hexdump(this.signatureData)),util.print_debug("trailer: "+util.hexdump(d)));this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,e+this.signatureData+d):3==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,e+this.signatureData):!1;break;case 2:this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,
|
||||
this.keyId:null};this.write_message_signature=function(a,c,d){var e=d.privateKeyPacket.publicKey,f=d.getPreferredSignatureHashAlgorithm(),g=String.fromCharCode(4),g=g+String.fromCharCode(a),g=g+String.fromCharCode(e.publicKeyAlgorithm),g=g+String.fromCharCode(f),h=Math.round((new Date).getTime()/1E3),h=b(2,""+String.fromCharCode(h>>24&255)+String.fromCharCode(h>>16&255)+String.fromCharCode(h>>8&255)+String.fromCharCode(h&255)),j=b(16,d.getKeyId()),g=g+String.fromCharCode(h.length+j.length>>8&255),
|
||||
g=g+String.fromCharCode(h.length+j.length&255),g=g+h+j,h=""+String.fromCharCode(4),h=h+String.fromCharCode(255),h=h+String.fromCharCode(g.length>>24),h=h+String.fromCharCode(g.length>>16&255),h=h+String.fromCharCode(g.length>>8&255),h=h+String.fromCharCode(g.length&255),a=1==a?c.replace(/\r/g,"").replace(/\n/g,"\r\n"):c,c=openpgp_crypto_hashData(f,a+g+h);util.print_debug("Signature is calculated with:|"+a+g+h+"|\n"+util.hexstrdump(a+g+h)+"\n hash:"+util.hexstrdump(c));c=String.fromCharCode(0)+String.fromCharCode(0)+
|
||||
c.charAt(0)+c.charAt(1);c+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,a+g+h);return{openpgp:openpgp_packet.write_packet_header(2,(g+c).length)+g+c,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,b){var d;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>
|
||||
8&255);d+=String.fromCharCode(this.signatureData.length&255);switch(this.signatureType){case 0:this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d):3==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData):!1;break;case 1:var e=a.replace(/\r/g,"").replace(/\n/g,"\r\n");openpgp.config.debug&&(util.print_debug("canonicalMsgText: "+
|
||||
util.hexdump(e)),util.print_debug("signatureData: "+util.hexdump(this.signatureData)),util.print_debug("trailer: "+util.hexdump(d)));this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,e+this.signatureData+d):3==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,e+this.signatureData):!1;break;case 2:this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,
|
||||
this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,this.signatureData+d):!1;break;case 16:case 17:case 18:case 19:case 48:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 24:if(3==this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 25:case 31:case 32:case 40:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,
|
||||
this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented"),this.verified=!1}return this.verified};this.read_packet=function(a,b,d){this.data=a.substring(b,b+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+b),null;var e=b;this.packetLength=d;this.version=a.charCodeAt(e++);switch(this.version){case 3:5!=
|
||||
a.charCodeAt(e++)&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));d=e;this.signatureType=a.charCodeAt(e++);this.creationTime=new Date(1E3*(a.charCodeAt(e++)<<24|a.charCodeAt(e++)<<16|a.charCodeAt(e++)<<8|a.charCodeAt(e++)));this.signatureData=a.substring(d,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a.charCodeAt(e++);this.hashAlgorithm=a.charCodeAt(e++);this.signedHashValue=a.charCodeAt(e++)<<8|a.charCodeAt(e++);
|
||||
@ -470,5 +470,5 @@ g;b.push(""+g)}return b.join("")};this.hex2bin=function(a){for(var b="",e=0;e<a.
|
||||
a.charCodeAt(e);return b},a=function(a){for(var b=[],e=0;e<a.length;e++)b.push(String.fromCharCode(a[e]));return b.join("")};this.str2bin=function(a){return b(a,Array(a.length))};this.bin2str=a;this.str2Uint8Array=function(a){return b(a,new Uint8Array(new ArrayBuffer(a.length)))};this.Uint8Array2str=a;this.calc_checksum=function(a){for(var b={s:0,add:function(a){this.s=(this.s+a)%65536}},e=0;e<a.length;e++)b.add(a.charCodeAt(e));return b.s};this.printLevel={error:1,warning:2,info:3,debug:4};this.print_debug=
|
||||
function(a){openpgp.config.debug&&this.print_output(this.printLevel.debug,a)};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),this.print_output(this.printLevel.debug,a))};this.print_error=function(a){this.print_output(this.printLevel.error,a)};this.print_info=function(a){this.print_output(this.printLevel.info,a)};this.print_warning=function(a){this.print_output(this.printLevel.warning,a)};this.print_output=function(a,b){var e,b=openpgp_encoding_html_encode(b).replace(/\n/g,
|
||||
"<br>");if(a==this.printLevel.debug)e='<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+b+"</p></tt>";else{var f;switch(a){case this.printLevel.error:e="FF8888";f="ERROR";break;case this.printLevel.warning:e="FFAA88";f="WARNING";break;case this.printLevel.info:e="88FF88",f="INFO"}e='<p style="font-size: 80%; background-color: #'+e+'; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>'+
|
||||
f+":</b></span>"+b+"</p>"}showMessages(e)};this.getLeftNBits=function(a,b){var e=b%8;return 0==e?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-e)/8+1),8-e)};this.shiftRight=function(a,b){var e=util.str2bin(a);if(0!=b%8)for(var f=e.length-1;0<=f;f--)e[f]>>=b%8,0<f&&(e[f]|=e[f-1]<<8-b%8&255);else return a;return util.bin2str(e)};this.get_hashAlgorithmString=function(a){switch(a){case 1:return"MD5";case 2:return"SHA1";case 3:return"RIPEMD160";case 8:return"SHA256";case 9:return"SHA384";case 10:return"SHA512";
|
||||
case 11:return"SHA224"}return"unknown"}},util=new Util;
|
||||
f+":</b></span>"+b+"</p>"}"function"===typeof showMessages&&showMessages(e)};this.getLeftNBits=function(a,b){var e=b%8;return 0==e?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-e)/8+1),8-e)};this.shiftRight=function(a,b){var e=util.str2bin(a);if(0!=b%8)for(var f=e.length-1;0<=f;f--)e[f]>>=b%8,0<f&&(e[f]|=e[f-1]<<8-b%8&255);else return a;return util.bin2str(e)};this.get_hashAlgorithmString=function(a){switch(a){case 1:return"MD5";case 2:return"SHA1";case 3:return"RIPEMD160";case 8:return"SHA256";
|
||||
case 9:return"SHA384";case 10:return"SHA512";case 11:return"SHA224"}return"unknown"}},util=new Util;
|
||||
|
@ -248,7 +248,7 @@ function openpgp_packet_signature() {
|
||||
result2 += openpgp_crypto_signData(hash_algo,privatekey.privateKeyPacket.publicKey.publicKeyAlgorithm,
|
||||
publickey.MPIs,
|
||||
privatekey.privateKeyPacket.secMPIs,
|
||||
data+result+trailer);
|
||||
hashData+result+trailer);
|
||||
return {openpgp: (openpgp_packet.write_packet_header(2, (result+result2).length)+result + result2),
|
||||
hash: util.get_hashAlgorithmString(hash_algo)};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user