Merge pull request #73 from dreamingofelectricsheep/utf8-clean
Utf8 support for the encrypted messages (cleanup)
This commit is contained in:
commit
419af151c1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
686
doc/global.html
686
doc/global.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -7383,7 +7383,7 @@ function openpgp_config() {
|
||||||
keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371"
|
keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371"
|
||||||
};
|
};
|
||||||
|
|
||||||
this.versionstring ="OpenPGP.js v.1.20130412";
|
this.versionstring ="OpenPGP.js v.1.20130416";
|
||||||
this.commentstring ="http://openpgpjs.org";
|
this.commentstring ="http://openpgpjs.org";
|
||||||
/**
|
/**
|
||||||
* Reads the config out of the HTML5 local storage
|
* Reads the config out of the HTML5 local storage
|
||||||
|
@ -8294,6 +8294,7 @@ function _openpgp () {
|
||||||
* be 1024+, generally)
|
* be 1024+, generally)
|
||||||
* @param {String} userId assumes already in form of "User Name
|
* @param {String} userId assumes already in form of "User Name
|
||||||
* <username@email.com>"
|
* <username@email.com>"
|
||||||
|
* @param {String} passphrase The passphrase used to encrypt the resulting private key
|
||||||
* @return {Object} {privateKey: [openpgp_msg_privatekey],
|
* @return {Object} {privateKey: [openpgp_msg_privatekey],
|
||||||
* privateKeyArmored: [string], publicKeyArmored: [string]}
|
* privateKeyArmored: [string], publicKeyArmored: [string]}
|
||||||
*/
|
*/
|
||||||
|
@ -11094,6 +11095,47 @@ function openpgp_packet_keymaterial() {
|
||||||
function openpgp_packet_literaldata() {
|
function openpgp_packet_literaldata() {
|
||||||
this.tagType = 11;
|
this.tagType = 11;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet data to a javascript native string or a squence of
|
||||||
|
* bytes. Conversion to a proper utf8 encoding takes place when the
|
||||||
|
* packet is written.
|
||||||
|
* @param {String} str Any native javascript string
|
||||||
|
* @param {String} format
|
||||||
|
*/
|
||||||
|
this.set_data = function(str, format) {
|
||||||
|
this.format = format;
|
||||||
|
this.data = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet data to value represented by the provided string
|
||||||
|
* of bytes together with the appropriate conversion format.
|
||||||
|
* @param {String} bytes The string of bytes
|
||||||
|
* @param {String} format
|
||||||
|
*/
|
||||||
|
this.set_data_bytes = function(bytes, format) {
|
||||||
|
this.format = format;
|
||||||
|
|
||||||
|
if(format == this.formats.utf8)
|
||||||
|
bytes = util.decode_utf8(bytes);
|
||||||
|
|
||||||
|
this.data = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the byte sequence representing the literal packet data
|
||||||
|
* @returns {String} A sequence of bytes
|
||||||
|
*/
|
||||||
|
this.get_data_bytes = function() {
|
||||||
|
if(this.format == 'u')
|
||||||
|
return util.encode_utf8(this.data);
|
||||||
|
else
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parsing function for a literal data packet (tag 11).
|
* Parsing function for a literal data packet (tag 11).
|
||||||
*
|
*
|
||||||
|
@ -11105,17 +11147,22 @@ function openpgp_packet_literaldata() {
|
||||||
* input at position
|
* input at position
|
||||||
* @return {openpgp_packet_encrypteddata} object representation
|
* @return {openpgp_packet_encrypteddata} object representation
|
||||||
*/
|
*/
|
||||||
function read_packet(input, position, len) {
|
this.read_packet = function(input, position, len) {
|
||||||
this.packetLength = len;
|
this.packetLength = len;
|
||||||
// - A one-octet field that describes how the data is formatted.
|
// - A one-octet field that describes how the data is formatted.
|
||||||
|
|
||||||
this.format = input[position];
|
var format = input[position];
|
||||||
this.filename = input.substr(position + 2, input
|
|
||||||
.charCodeAt(position + 1));
|
this.filename = util.decode_utf8(input.substr(position + 2, input
|
||||||
|
.charCodeAt(position + 1)));
|
||||||
|
|
||||||
this.date = new Date(parseInt(input.substr(position + 2
|
this.date = new Date(parseInt(input.substr(position + 2
|
||||||
+ input.charCodeAt(position + 1), 4)) * 1000);
|
+ input.charCodeAt(position + 1), 4)) * 1000);
|
||||||
this.data = input.substring(position + 6
|
|
||||||
|
var bytes = input.substring(position + 6
|
||||||
+ input.charCodeAt(position + 1));
|
+ input.charCodeAt(position + 1));
|
||||||
|
|
||||||
|
this.set_data_bytes(bytes, format);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11125,11 +11172,13 @@ function openpgp_packet_literaldata() {
|
||||||
* @param {String} data The data to be inserted as body
|
* @param {String} data The data to be inserted as body
|
||||||
* @return {String} string-representation of the packet
|
* @return {String} string-representation of the packet
|
||||||
*/
|
*/
|
||||||
function write_packet(data) {
|
this.write_packet = function(data) {
|
||||||
data = data.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n");
|
this.set_data(data, this.formats.utf8);
|
||||||
this.filename = "msg.txt";
|
this.filename = util.encode_utf8("msg.txt");
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.format = 't';
|
|
||||||
|
data = this.get_data_bytes();
|
||||||
|
|
||||||
var result = openpgp_packet.write_packet_header(11, data.length + 6
|
var result = openpgp_packet.write_packet_header(11, data.length + 6
|
||||||
+ this.filename.length);
|
+ this.filename.length);
|
||||||
result += this.format;
|
result += this.format;
|
||||||
|
@ -11144,7 +11193,6 @@ function openpgp_packet_literaldata() {
|
||||||
result += String
|
result += String
|
||||||
.fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF);
|
.fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF);
|
||||||
result += data;
|
result += data;
|
||||||
this.data = data;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11153,18 +11201,28 @@ function openpgp_packet_literaldata() {
|
||||||
*
|
*
|
||||||
* @return {String} String which gives some information about the keymaterial
|
* @return {String} String which gives some information about the keymaterial
|
||||||
*/
|
*/
|
||||||
function toString() {
|
this.toString = function() {
|
||||||
return '5.9. Literal Data Packet (Tag 11)\n' + ' length: '
|
return '5.9. Literal Data Packet (Tag 11)\n' + ' length: '
|
||||||
+ this.packetLength + '\n' + ' format: ' + this.format
|
+ this.packetLength + '\n' + ' format: ' + this.format
|
||||||
+ '\n' + ' filename:' + this.filename + '\n'
|
+ '\n' + ' filename:' + this.filename + '\n'
|
||||||
+ ' date: ' + this.date + '\n' + ' data: |'
|
+ ' date: ' + this.date + '\n' + ' data: |'
|
||||||
+ this.data + '|\n' + ' rdata: |' + this.real_data + '|\n';
|
+ this.data + '|\n' + ' rdata: |' + this.real_data + '|\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.read_packet = read_packet;
|
|
||||||
this.toString = toString;
|
|
||||||
this.write_packet = write_packet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data types in the literal packet
|
||||||
|
* @readonly
|
||||||
|
* @enum {String}
|
||||||
|
*/
|
||||||
|
openpgp_packet_literaldata.prototype.formats = {
|
||||||
|
/** Binary data */
|
||||||
|
binary: 'b',
|
||||||
|
/** Text data */
|
||||||
|
text: 't',
|
||||||
|
/** Utf8 data */
|
||||||
|
utf8: 'u'
|
||||||
|
};
|
||||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||||
// Copyright (C) 2011 Recurity Labs GmbH
|
// Copyright (C) 2011 Recurity Labs GmbH
|
||||||
//
|
//
|
||||||
|
@ -12340,38 +12398,71 @@ function openpgp_packet_userattribute() {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function openpgp_packet_userid() {
|
function openpgp_packet_userid() {
|
||||||
|
this.text = ''
|
||||||
this.tagType = 13;
|
this.tagType = 13;
|
||||||
this.certificationSignatures = new Array();
|
this.certificationSignatures = new Array();
|
||||||
this.certificationRevocationSignatures = new Array();
|
this.certificationRevocationSignatures = new Array();
|
||||||
this.revocationSignatures = new Array();
|
this.revocationSignatures = new Array();
|
||||||
this.parentNode = null;
|
this.parentNode = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet text field to a native javascript string
|
||||||
|
* Conversion to a proper utf8 encoding takes place when the
|
||||||
|
* packet is written.
|
||||||
|
* @param {String} str Any native javascript string
|
||||||
|
*/
|
||||||
|
this.set_text = function(str) {
|
||||||
|
this.text = str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parsing function for a user id packet (tag 13).
|
* Set the packet text to value represented by the provided string
|
||||||
|
* of bytes.
|
||||||
|
* @param {String} bytes A string of bytes
|
||||||
|
*/
|
||||||
|
this.set_text_bytes = function(bytes) {
|
||||||
|
this.text = util.decode_utf8(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the byte sequence representing the text of this packet.
|
||||||
|
* @returns {String} A sequence of bytes
|
||||||
|
*/
|
||||||
|
this.get_text_bytes = function() {
|
||||||
|
return util.encode_utf8(this.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parsing function for a user id packet (tag 13).
|
||||||
* @param {String} input payload of a tag 13 packet
|
* @param {String} input payload of a tag 13 packet
|
||||||
* @param {Integer} position position to start reading from the input string
|
* @param {Integer} position position to start reading from the input string
|
||||||
* @param {Integer} len length of the packet or the remaining length of input at position
|
* @param {Integer} len length of the packet or the remaining length of input at position
|
||||||
* @return {openpgp_packet_encrypteddata} object representation
|
* @return {openpgp_packet_encrypteddata} object representation
|
||||||
*/
|
*/
|
||||||
function read_packet(input, position, len) {
|
this.read_packet = function(input, position, len) {
|
||||||
this.text = '';
|
|
||||||
this.packetLength = len;
|
this.packetLength = len;
|
||||||
|
|
||||||
|
var bytes = '';
|
||||||
for ( var i = 0; i < len; i++) {
|
for ( var i = 0; i < len; i++) {
|
||||||
this.text += input[position + i];
|
bytes += input[position + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set_text_bytes(bytes);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a string representation of the user id packet
|
* Creates a string representation of the user id packet
|
||||||
* @param {String} user_id the user id as string ("John Doe <john.doe@mail.us")
|
* @param {String} user_id the user id as string ("John Doe <john.doe@mail.us")
|
||||||
* @return {String} string representation
|
* @return {String} string representation
|
||||||
*/
|
*/
|
||||||
function write_packet(user_id) {
|
this.write_packet = function(user_id) {
|
||||||
this.text = user_id;
|
this.set_text(user_id);
|
||||||
var result = openpgp_packet.write_packet_header(13,this.text.length);
|
var bytes = this.get_text_bytes();
|
||||||
result += this.text;
|
|
||||||
|
var result = openpgp_packet.write_packet_header(13, bytes.length);
|
||||||
|
result += bytes;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12383,7 +12474,7 @@ function openpgp_packet_userid() {
|
||||||
* @param {Integer} len length of the packet(s) or remaining length of input
|
* @param {Integer} len length of the packet(s) or remaining length of input
|
||||||
* @return {Integer} length of nodes read
|
* @return {Integer} length of nodes read
|
||||||
*/
|
*/
|
||||||
function read_nodes(parent_node, input, position, len) {
|
this.read_nodes = function(parent_node, input, position, len) {
|
||||||
if (parent_node.tagType == 6) { // public key
|
if (parent_node.tagType == 6) { // public key
|
||||||
this.parentNode = parent_node;
|
this.parentNode = parent_node;
|
||||||
var pos = position;
|
var pos = position;
|
||||||
|
@ -12463,7 +12554,7 @@ function openpgp_packet_userid() {
|
||||||
* generates debug output (pretty print)
|
* generates debug output (pretty print)
|
||||||
* @return {String} String which gives some information about the user id packet
|
* @return {String} String which gives some information about the user id packet
|
||||||
*/
|
*/
|
||||||
function toString() {
|
this.toString = function() {
|
||||||
var result = ' 5.11. User ID Packet (Tag 13)\n' + ' text ('
|
var result = ' 5.11. User ID Packet (Tag 13)\n' + ' text ('
|
||||||
+ this.text.length + '): "' + this.text.replace("<", "<")
|
+ this.text.length + '): "' + this.text.replace("<", "<")
|
||||||
+ '"\n';
|
+ '"\n';
|
||||||
|
@ -12483,7 +12574,7 @@ function openpgp_packet_userid() {
|
||||||
* @param {String} keyId string containing the key id of the issuer of this signature
|
* @param {String} keyId string containing the key id of the issuer of this signature
|
||||||
* @return a CertificationRevocationSignature if found; otherwise null
|
* @return a CertificationRevocationSignature if found; otherwise null
|
||||||
*/
|
*/
|
||||||
function hasCertificationRevocationSignature(keyId) {
|
this.hasCertificationRevocationSignature = function(keyId) {
|
||||||
for (var i = 0; i < this.certificationRevocationSignatures.length; i++) {
|
for (var i = 0; i < this.certificationRevocationSignatures.length; i++) {
|
||||||
if ((this.certificationRevocationSignatures[i].version == 3 &&
|
if ((this.certificationRevocationSignatures[i].version == 3 &&
|
||||||
this.certificationRevocationSignatures[i].keyId == keyId) ||
|
this.certificationRevocationSignatures[i].keyId == keyId) ||
|
||||||
|
@ -12506,7 +12597,8 @@ function openpgp_packet_userid() {
|
||||||
* 5 = signature by key owner expired
|
* 5 = signature by key owner expired
|
||||||
* 6 = signature by key owner revoked
|
* 6 = signature by key owner revoked
|
||||||
*/
|
*/
|
||||||
function verifyCertificationSignatures(publicKeyPacket) {
|
this.verifyCertificationSignatures = function(publicKeyPacket) {
|
||||||
|
var bytes = this.get_text_bytes();
|
||||||
result = new Array();
|
result = new Array();
|
||||||
for (var i = 0 ; i < this.certificationSignatures.length; i++) {
|
for (var i = 0 ; i < this.certificationSignatures.length; i++) {
|
||||||
// A certification signature (type 0x10 through 0x13) hashes the User
|
// A certification signature (type 0x10 through 0x13) hashes the User
|
||||||
|
@ -12549,13 +12641,14 @@ function openpgp_packet_userid() {
|
||||||
var revocation = this.hasCertificationRevocationSignature(this.certificationSignatures[i].issuerKeyId);
|
var revocation = this.hasCertificationRevocationSignature(this.certificationSignatures[i].issuerKeyId);
|
||||||
if (revocation != null && revocation.creationTime >
|
if (revocation != null && revocation.creationTime >
|
||||||
this.certificationSignatures[i].creationTime) {
|
this.certificationSignatures[i].creationTime) {
|
||||||
|
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
||||||
String.fromCharCode((this.text.length >> 24) & 0xFF)+
|
String.fromCharCode((bytes.length >> 24) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 16) & 0xFF)+
|
String.fromCharCode((bytes.length >> 16) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 8) & 0xFF)+
|
String.fromCharCode((bytes.length >> 8) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length) & 0xFF)+
|
String.fromCharCode((bytes.length) & 0xFF)+
|
||||||
this.text;
|
bytes;
|
||||||
if (revocation.verify(signaturedata, signingKey)) {
|
if (revocation.verify(signaturedata, signingKey)) {
|
||||||
if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId())
|
if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId())
|
||||||
result[i] = 6;
|
result[i] = 6;
|
||||||
|
@ -12564,13 +12657,14 @@ function openpgp_packet_userid() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
||||||
String.fromCharCode((this.text.length >> 24) & 0xFF)+
|
String.fromCharCode((bytes.length >> 24) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 16) & 0xFF)+
|
String.fromCharCode((bytes.length >> 16) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 8) & 0xFF)+
|
String.fromCharCode((bytes.length >> 8) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length) & 0xFF)+
|
String.fromCharCode((bytes.length) & 0xFF)+
|
||||||
this.text;
|
bytes;
|
||||||
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
||||||
result[i] = 4;
|
result[i] = 4;
|
||||||
} else
|
} else
|
||||||
|
@ -12595,7 +12689,7 @@ function openpgp_packet_userid() {
|
||||||
if (revocation != null && revocation.creationTime >
|
if (revocation != null && revocation.creationTime >
|
||||||
this.certificationSignatures[i].creationTime) {
|
this.certificationSignatures[i].creationTime) {
|
||||||
var signaturedata = String.fromCharCode(0x99)+ this.publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ this.publicKeyPacket.header.substring(1)+
|
||||||
this.publicKeyPacket.data+this.text;
|
this.publicKeyPacket.data+bytes;
|
||||||
if (revocation.verify(signaturedata, signingKey)) {
|
if (revocation.verify(signaturedata, signingKey)) {
|
||||||
if (revocation.keyId == publicKeyPacket.getKeyId())
|
if (revocation.keyId == publicKeyPacket.getKeyId())
|
||||||
result[i] = 6;
|
result[i] = 6;
|
||||||
|
@ -12605,7 +12699,7 @@ function openpgp_packet_userid() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+this.text;
|
publicKeyPacket.data + bytes;
|
||||||
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
||||||
result[i] = 4;
|
result[i] = 4;
|
||||||
} else
|
} else
|
||||||
|
@ -12621,7 +12715,7 @@ function openpgp_packet_userid() {
|
||||||
* verifies the signatures of the user id
|
* verifies the signatures of the user id
|
||||||
* @return 0 if the userid is valid; 1 = userid expired; 2 = userid revoked
|
* @return 0 if the userid is valid; 1 = userid expired; 2 = userid revoked
|
||||||
*/
|
*/
|
||||||
function verify(publicKeyPacket) {
|
this.verify = function(publicKeyPacket) {
|
||||||
var result = this.verifyCertificationSignatures(publicKeyPacket);
|
var result = this.verifyCertificationSignatures(publicKeyPacket);
|
||||||
if (result.indexOf(6) != -1)
|
if (result.indexOf(6) != -1)
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -12631,22 +12725,14 @@ function openpgp_packet_userid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implementation missing
|
// TODO: implementation missing
|
||||||
function addCertification(publicKeyPacket, privateKeyPacket) {
|
this.addCertification = function(publicKeyPacket, privateKeyPacket) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implementation missing
|
// TODO: implementation missing
|
||||||
function revokeCertification(publicKeyPacket, privateKeyPacket) {
|
this.revokeCertification = function(publicKeyPacket, privateKeyPacket) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasCertificationRevocationSignature = hasCertificationRevocationSignature;
|
|
||||||
this.verifyCertificationSignatures = verifyCertificationSignatures;
|
|
||||||
this.verify = verify;
|
|
||||||
this.read_packet = read_packet;
|
|
||||||
this.write_packet = write_packet;
|
|
||||||
this.toString = toString;
|
|
||||||
this.read_nodes = read_nodes;
|
|
||||||
}
|
}
|
||||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||||
// Copyright (C) 2011 Recurity Labs GmbH
|
// Copyright (C) 2011 Recurity Labs GmbH
|
||||||
|
@ -12948,6 +13034,7 @@ function openpgp_type_s2k() {
|
||||||
* hashAlgorithm hash length
|
* hashAlgorithm hash length
|
||||||
*/
|
*/
|
||||||
function produce_key(passphrase, numBytes) {
|
function produce_key(passphrase, numBytes) {
|
||||||
|
passphrase = util.encode_utf8(passphrase);
|
||||||
if (this.type == 0) {
|
if (this.type == 0) {
|
||||||
return openpgp_crypto_hashData(this.hashAlgorithm,passphrase);
|
return openpgp_crypto_hashData(this.hashAlgorithm,passphrase);
|
||||||
} else if (this.type == 1) {
|
} else if (this.type == 1) {
|
||||||
|
@ -13059,45 +13146,68 @@ var Util = function() {
|
||||||
}
|
}
|
||||||
return r.join('');
|
return r.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a native javascript string to a string of utf8 bytes
|
||||||
|
* @param {String} str The string to convert
|
||||||
|
* @return {String} A valid squence of utf8 bytes
|
||||||
|
*/
|
||||||
|
this.encode_utf8 = function(str) {
|
||||||
|
return unescape(encodeURIComponent(str));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a string of utf8 bytes to a native javascript string
|
||||||
|
* @param {String} utf8 A valid squence of utf8 bytes
|
||||||
|
* @return {String} A native javascript string
|
||||||
|
*/
|
||||||
|
this.decode_utf8 = function(utf8) {
|
||||||
|
return decodeURIComponent(escape(utf8));
|
||||||
|
};
|
||||||
|
|
||||||
|
var str2bin = function(str, result) {
|
||||||
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
result[i] = str.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
var bin2str = function(bin) {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < bin.length; i++) {
|
||||||
|
result.push(String.fromCharCode(bin[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join('');
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string to an array of integers(0.255)
|
* Convert a string to an array of integers(0.255)
|
||||||
* @param {String} str String to convert
|
* @param {String} str String to convert
|
||||||
* @return {Integer[]} An array of (binary) integers
|
* @return {Integer[]} An array of (binary) integers
|
||||||
*/
|
*/
|
||||||
this.str2bin = function(str) {
|
this.str2bin = function(str) {
|
||||||
var result = new Array();
|
return str2bin(str, new Array(str.length));
|
||||||
for (var i = 0; i < str.length; i++) {
|
|
||||||
result[i] = str.charCodeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of integers(0.255) to a string
|
* Convert an array of integers(0.255) to a string
|
||||||
* @param {Integer[]} bin An array of (binary) integers to convert
|
* @param {Integer[]} bin An array of (binary) integers to convert
|
||||||
* @return {String} The string representation of the array
|
* @return {String} The string representation of the array
|
||||||
*/
|
*/
|
||||||
this.bin2str = function(bin) {
|
this.bin2str = bin2str;
|
||||||
var result = [];
|
|
||||||
for (var i = 0; i < bin.length; i++) {
|
|
||||||
result.push(String.fromCharCode(bin[i]));
|
|
||||||
}
|
|
||||||
return result.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string to a Uint8Array
|
* Convert a string to a Uint8Array
|
||||||
* @param {String} str String to convert
|
* @param {String} str String to convert
|
||||||
* @return {Uint8Array} The array of (binary) integers
|
* @return {Uint8Array} The array of (binary) integers
|
||||||
*/
|
*/
|
||||||
this.str2Uint8Array = function(str){
|
this.str2Uint8Array = function(str) {
|
||||||
var uintArray = new Uint8Array(new ArrayBuffer(str.length));
|
return str2bin(str, new Uint8Array(new ArrayBuffer(str.length)));
|
||||||
for(var n = 0; n < str.length; n++){
|
|
||||||
uintArray[n] = str.charCodeAt(n);
|
|
||||||
}
|
|
||||||
return uintArray;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13106,13 +13216,7 @@ var Util = function() {
|
||||||
* @param {Uint8Array} bin An array of (binary) integers to convert
|
* @param {Uint8Array} bin An array of (binary) integers to convert
|
||||||
* @return {String} String representation of the array
|
* @return {String} String representation of the array
|
||||||
*/
|
*/
|
||||||
this.Uint8Array2str = function(bin) {
|
this.Uint8Array2str = bin2str;
|
||||||
var result = [];
|
|
||||||
for(n = 0; n< bin.length; n++){
|
|
||||||
result[n] = String.fromCharCode(bin[n]);
|
|
||||||
}
|
|
||||||
return result.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates a 16bit sum of a string by adding each character
|
* Calculates a 16bit sum of a string by adding each character
|
||||||
|
|
50
resources/openpgp.min.js
vendored
50
resources/openpgp.min.js
vendored
|
@ -285,7 +285,7 @@ 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};
|
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.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("")};
|
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:2,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.20130412";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:2,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.20130416";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+="=");return e}
|
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+="=");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 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=getPGPMessageType(b);if(2!=a){b=b.split("-----");data={openpgp:openpgp_encoding_base64_decode(b[2].split("\n\n")[1].split("\n=")[0].replace(/\n- /g,"\n")),type:a};if(verifyCheckSum(data.openpgp,b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]))return data;util.print_error("Ascii armor integrity check on message failed: '"+b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]+"' should be '"+getCheckSum(data))}else{b=b.split("-----");a={text:b[2].replace(/\n- /g,
|
function openpgp_encoding_deArmor(b){var a=getPGPMessageType(b);if(2!=a){b=b.split("-----");data={openpgp:openpgp_encoding_base64_decode(b[2].split("\n\n")[1].split("\n=")[0].replace(/\n- /g,"\n")),type:a};if(verifyCheckSum(data.openpgp,b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]))return data;util.print_error("Ascii armor integrity check on message failed: '"+b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]+"' should be '"+getCheckSum(data))}else{b=b.split("-----");a={text:b[2].replace(/\n- /g,
|
||||||
|
@ -407,9 +407,10 @@ a),f=openpgp_crypto_getRandomBytes(8),util.print_debug_hexstr_dump("write_privat
|
||||||
this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength),ciphertextMPIs=normal_cfb_encrypt(AESencrypt,this.IVLength,c,b+a,this.IV),e+=this.IV+ciphertextMPIs}else e+=String.fromCharCode(0),e+=a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),c=util.calc_checksum(a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI()),e+=String.fromCharCode(c/256)+String.fromCharCode(c%256),util.print_debug_hexstr_dump("write_private_key basic checksum: "+
|
this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength),ciphertextMPIs=normal_cfb_encrypt(AESencrypt,this.IVLength,c,b+a,this.IV),e+=this.IV+ciphertextMPIs}else e+=String.fromCharCode(0),e+=a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI(),c=util.calc_checksum(a.d.toMPI()+a.p.toMPI()+a.q.toMPI()+a.u.toMPI()),e+=String.fromCharCode(c/256)+String.fromCharCode(c%256),util.print_debug_hexstr_dump("write_private_key basic checksum: "+
|
||||||
c);break;default:e="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}c=openpgp_packet.write_packet_header(5,e.length);return{string:c+e,header:c,body:e}};this.write_public_key=function(b,a,c){var d=String.fromCharCode(4),d=d+c;switch(b){case 1:d+=String.fromCharCode(1);d+=a.n.toMPI();d+=a.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}b=openpgp_packet.write_packet_header(6,d.length);
|
c);break;default:e="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}c=openpgp_packet.write_packet_header(5,e.length);return{string:c+e,header:c,body:e}};this.write_public_key=function(b,a,c){var d=String.fromCharCode(4),d=d+c;switch(b){case 1:d+=String.fromCharCode(1);d+=a.n.toMPI();d+=a.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+b)}b=openpgp_packet.write_packet_header(6,d.length);
|
||||||
return{string:b+d,header:b,body:d}}}
|
return{string:b+d,header:b,body:d}}}
|
||||||
function openpgp_packet_literaldata(){this.tagType=11;this.read_packet=function(b,a,c){this.packetLength=c;this.format=b[a];this.filename=b.substr(a+2,b.charCodeAt(a+1));this.date=new Date(1E3*parseInt(b.substr(a+2+b.charCodeAt(a+1),4)));this.data=b.substring(a+6+b.charCodeAt(a+1));return this};this.toString=function(){return"5.9. Literal Data Packet (Tag 11)\n length: "+this.packetLength+"\n format: "+this.format+"\n filename:"+this.filename+"\n date: "+this.date+"\n data: |"+
|
function openpgp_packet_literaldata(){this.tagType=11;this.set_data=function(b,a){this.format=a;this.data=b};this.set_data_bytes=function(b,a){this.format=a;a==this.formats.utf8&&(b=util.decode_utf8(b));this.data=b};this.get_data_bytes=function(){return"u"==this.format?util.encode_utf8(this.data):this.data};this.read_packet=function(b,a,c){this.packetLength=c;c=b[a];this.filename=util.decode_utf8(b.substr(a+2,b.charCodeAt(a+1)));this.date=new Date(1E3*parseInt(b.substr(a+2+b.charCodeAt(a+1),4)));
|
||||||
this.data+"|\n rdata: |"+this.real_data+"|\n"};this.write_packet=function(b){b=b.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");this.filename="msg.txt";this.date=new Date;this.format="t";var a=openpgp_packet.write_packet_header(11,b.length+6+this.filename.length),a=a+this.format,a=a+String.fromCharCode(this.filename.length),a=a+this.filename,a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>16&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/
|
this.set_data_bytes(b.substring(a+6+b.charCodeAt(a+1)),c);return this};this.write_packet=function(b){this.set_data(b,this.formats.utf8);this.filename=util.encode_utf8("msg.txt");this.date=new Date;var b=this.get_data_bytes(),a=openpgp_packet.write_packet_header(11,b.length+6+this.filename.length),a=a+this.format,a=a+String.fromCharCode(this.filename.length),a=a+this.filename,a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/
|
||||||
1E3)>>8&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)&255);this.data=b;return a+b}}function openpgp_packet_marker(){this.tagType=10;this.read_packet=function(b,a){this.packetLength=3;return 80==b[a].charCodeAt()&&71==b[a+1].charCodeAt()&&80==b[a+2].charCodeAt()?this:null};this.toString=function(){return'5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)\n packet reads: "PGP"\n'}}
|
1E3)>>16&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>8&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/1E3)&255);return a+b};this.toString=function(){return"5.9. Literal Data Packet (Tag 11)\n length: "+this.packetLength+"\n format: "+this.format+"\n filename:"+this.filename+"\n date: "+this.date+"\n data: |"+this.data+"|\n rdata: |"+this.real_data+"|\n"}}openpgp_packet_literaldata.prototype.formats={binary:"b",text:"t",utf8:"u"};
|
||||||
|
function openpgp_packet_marker(){this.tagType=10;this.read_packet=function(b,a){this.packetLength=3;return 80==b[a].charCodeAt()&&71==b[a+1].charCodeAt()&&80==b[a+2].charCodeAt()?this:null};this.toString=function(){return'5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)\n packet reads: "PGP"\n'}}
|
||||||
function openpgp_packet_modificationdetectioncode(){this.tagType=19;this.hash=null;this.read_packet=function(b,a,c){this.packetLength=c;if(20!=c)return util.print_error("openpgp.packet.modificationdetectioncode.js\ninvalid length for a modification detection code packet!"+c),null;this.hash=b.substring(a,a+20);return this};this.toString=function(){return"5.14 Modification detection code packet\n bytes ("+this.hash.length+"): ["+util.hexstrdump(this.hash)+"]"}}
|
function openpgp_packet_modificationdetectioncode(){this.tagType=19;this.hash=null;this.read_packet=function(b,a,c){this.packetLength=c;if(20!=c)return util.print_error("openpgp.packet.modificationdetectioncode.js\ninvalid length for a modification detection code packet!"+c),null;this.hash=b.substring(a,a+20);return this};this.toString=function(){return"5.14 Modification detection code packet\n bytes ("+this.hash.length+"): ["+util.hexstrdump(this.hash)+"]"}}
|
||||||
function openpgp_packet_onepasssignature(){this.tagType=4;this.flags=this.signingKeyId=this.publicKeyAlgorithm=this.hashAlgorithm=this.type=this.version=null;this.read_packet=function(b,a,c){this.packetLength=c;this.version=b.charCodeAt(a++);this.type=b.charCodeAt(a++);this.hashAlgorithm=b.charCodeAt(a++);this.publicKeyAlgorithm=b.charCodeAt(a++);this.signingKeyId=new openpgp_type_keyid;this.signingKeyId.read_packet(b,a);a+=8;this.flags=b.charCodeAt(a++);return this};this.toString=function(){return"5.4. One-Pass Signature Packets (Tag 4)\n length: "+
|
function openpgp_packet_onepasssignature(){this.tagType=4;this.flags=this.signingKeyId=this.publicKeyAlgorithm=this.hashAlgorithm=this.type=this.version=null;this.read_packet=function(b,a,c){this.packetLength=c;this.version=b.charCodeAt(a++);this.type=b.charCodeAt(a++);this.hashAlgorithm=b.charCodeAt(a++);this.publicKeyAlgorithm=b.charCodeAt(a++);this.signingKeyId=new openpgp_type_keyid;this.signingKeyId.read_packet(b,a);a+=8;this.flags=b.charCodeAt(a++);return this};this.toString=function(){return"5.4. One-Pass Signature Packets (Tag 4)\n length: "+
|
||||||
this.packetLength+"\n type: "+this.type+"\n keyID: "+this.signingKeyId.toString()+"\n hashA: "+this.hashAlgorithm+"\n pubKeyA:"+this.publicKeyAlgorithm+"\n flags: "+this.flags+"\n version:"+this.version+"\n"};this.write_packet=function(b,a,c,d,e){d=""+openpgp_packet.write_packet_header(4,13);d+=String.fromCharCode(3);d+=String.fromCharCode(b);d+=String.fromCharCode(a);d+=String.fromCharCode(c.privateKeyPacket.publicKey.publicKeyAlgorithm);d+=c.getKeyId();return d=e?d+String.fromCharCode(0):
|
this.packetLength+"\n type: "+this.type+"\n keyID: "+this.signingKeyId.toString()+"\n hashA: "+this.hashAlgorithm+"\n pubKeyA:"+this.publicKeyAlgorithm+"\n flags: "+this.flags+"\n version:"+this.version+"\n"};this.write_packet=function(b,a,c,d,e){d=""+openpgp_packet.write_packet_header(4,13);d+=String.fromCharCode(3);d+=String.fromCharCode(b);d+=String.fromCharCode(a);d+=String.fromCharCode(c.privateKeyPacket.publicKey.publicKeyAlgorithm);d+=c.getKeyId();return d=e?d+String.fromCharCode(0):
|
||||||
|
@ -444,27 +445,28 @@ function openpgp_packet_userattribute(){this.tagType=17;this.certificationSignat
|
||||||
(packet_length=1<<(b[e++].charCodeAt()&31),f=1):(f=5,e++,packet_length=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt());b[e++].charCodeAt();packet_length--;f++;this.userattributes[0]=[];this.userattributes[0]=b.substring(e,e+packet_length);e+=packet_length;d+=f+packet_length}this.packetLength=e-a;return this};this.read_nodes=function(b,a,c,d){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f);if(null==g){util.print_error("openpgp.packet.userattribute.js\n[user_attr] parsing ends here @:"+
|
(packet_length=1<<(b[e++].charCodeAt()&31),f=1):(f=5,e++,packet_length=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt());b[e++].charCodeAt();packet_length--;f++;this.userattributes[0]=[];this.userattributes[0]=b.substring(e,e+packet_length);e+=packet_length;d+=f+packet_length}this.packetLength=e-a;return this};this.read_nodes=function(b,a,c,d){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f);if(null==g){util.print_error("openpgp.packet.userattribute.js\n[user_attr] parsing ends here @:"+
|
||||||
e+" l:"+f);break}else switch(g.tagType){case 2:15<g.signatureType&&20>g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=g:32==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);e+=g.packetLength+g.headerLength;f=d-(e-c);break;default:return this.data=a,this.position=c-b.packetLength,this.len=e-c}}this.data=a;this.position=c-b.packetLength;return this.len=e-c};this.toString=function(){for(var b="5.12. User Attribute Packet (Tag 17)\n AttributePackets: (count = "+
|
e+" l:"+f);break}else switch(g.tagType){case 2:15<g.signatureType&&20>g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=g:32==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);e+=g.packetLength+g.headerLength;f=d-(e-c);break;default:return this.data=a,this.position=c-b.packetLength,this.len=e-c}}this.data=a;this.position=c-b.packetLength;return this.len=e-c};this.toString=function(){for(var b="5.12. User Attribute Packet (Tag 17)\n AttributePackets: (count = "+
|
||||||
this.userattributes.length+")\n",a=0;a<this.userattributes.length;a++)b+=" ("+this.userattributes[a].length+") bytes: ["+util.hexidump(this.userattributes[a])+"]\n";return b}}
|
this.userattributes.length+")\n",a=0;a<this.userattributes.length;a++)b+=" ("+this.userattributes[a].length+") bytes: ["+util.hexidump(this.userattributes[a])+"]\n";return b}}
|
||||||
function openpgp_packet_userid(){this.tagType=13;this.certificationSignatures=[];this.certificationRevocationSignatures=[];this.revocationSignatures=[];this.parentNode=null;this.hasCertificationRevocationSignature=function(b){for(var a=0;a<this.certificationRevocationSignatures.length;a++)if(3==this.certificationRevocationSignatures[a].version&&this.certificationRevocationSignatures[a].keyId==b||4==this.certificationRevocationSignatures[a].version&&this.certificationRevocationSignatures[a].issuerKeyId==
|
function openpgp_packet_userid(){this.text="";this.tagType=13;this.certificationSignatures=[];this.certificationRevocationSignatures=[];this.revocationSignatures=[];this.parentNode=null;this.set_text=function(b){this.text=b};this.set_text_bytes=function(b){this.text=util.decode_utf8(b)};this.get_text_bytes=function(){return util.encode_utf8(this.text)};this.read_packet=function(b,a,c){this.packetLength=c;for(var d="",e=0;e<c;e++)d+=b[a+e];this.set_text_bytes(d);return this};this.write_packet=function(b){this.set_text(b);
|
||||||
b)return this.certificationRevocationSignatures[a];return null};this.verifyCertificationSignatures=function(b){result=[];for(var a=0;a<this.certificationSignatures.length;a++)if(4==this.certificationSignatures[a].version)if(null!=this.certificationSignatures[a].signatureExpirationTime&&null!=this.certificationSignatures[a].signatureExpirationTime&&0!=this.certificationSignatures[a].signatureExpirationTime&&!this.certificationSignatures[a].signatureNeverExpires&&new Date(this.certificationSignatures[a].creationTime.getTime()+
|
var b=this.get_text_bytes(),a=openpgp_packet.write_packet_header(13,b.length);return a+b};this.read_nodes=function(b,a,c,d){if(6==b.tagType){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f-(e-c));if(null==g){util.print_error("[user_id] parsing ends here @:"+e+" l:"+f);break}else switch(e+=g.packetLength+g.headerLength,f=a.length-e,g.tagType){case 2:if(15<g.signatureType&&20>g.signatureType){this.certificationSignatures[this.certificationSignatures.length]=g;
|
||||||
1E3*this.certificationSignatures[a].signatureExpirationTime)<new Date)result[a]=this.certificationSignatures[a].issuerKeyId==b.getKeyId()?5:1;else if(null==this.certificationSignatures[a].issuerKeyId)result[a]=0;else{var c=openpgp.keyring.getPublicKeysForKeyId(this.certificationSignatures[a].issuerKeyId);if(null==c||0==c.length)result[a]=2;else if(c=c[0],c=c.obj.getSigningKey(),null==c)result[a]=0;else{var d=this.hasCertificationRevocationSignature(this.certificationSignatures[a].issuerKeyId);if(null!=
|
break}else if(48==g.signatureType){this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g;break}else if(24==g.signatureType){this.certificationSignatures[this.certificationSignatures.length]=g;break}else util.print_debug("unknown sig t: "+g.signatureType+"@"+(e-(g.packetLength+g.headerLength)));default:return this.data=a,this.position=c-b.packetLength,this.len=e-c-(g.headerLength+g.packetLength)}}this.data=a;this.position=c-b.packetLength;return this.len=e-c-(g.headerLength+
|
||||||
d&&d.creationTime>this.certificationSignatures[a].creationTime){var e=String.fromCharCode(153)+b.header.substring(1)+b.data+String.fromCharCode(180)+String.fromCharCode(this.text.length>>24&255)+String.fromCharCode(this.text.length>>16&255)+String.fromCharCode(this.text.length>>8&255)+String.fromCharCode(this.text.length&255)+this.text;if(d.verify(e,c)){result[a]=this.certificationSignatures[a].issuerKeyId==b.getKeyId()?6:3;continue}}e=String.fromCharCode(153)+b.header.substring(1)+b.data+String.fromCharCode(180)+
|
g.packetLength)}if(5==b.tagType){this.parentNode=b;for(e=c;a.length!=e;)if(g=openpgp_packet.read_packet(a,e,f-(e-c)),null==g){util.print_error("parsing ends here @:"+e+" l:"+f);break}else switch(e+=g.packetLength+g.headerLength,g.tagType){case 2:15<g.signatureType&&20>g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=g:48==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);default:return this.data=a,this.position=
|
||||||
String.fromCharCode(this.text.length>>24&255)+String.fromCharCode(this.text.length>>16&255)+String.fromCharCode(this.text.length>>8&255)+String.fromCharCode(this.text.length&255)+this.text;result[a]=this.certificationSignatures[a].verify(e,c)?4:0}}else if(3==this.certificationSignatures[a].version)if(null==this.certificationSignatures[a].keyId)result[a]=0;else if(c=openpgp.keyring.getPublicKeysForKeyId(this.certificationSignatures[a].keyId),null==c||0==c.length)result[a]=2;else if(c=publicKey.obj.getSigningKey(),
|
c-b.packetLength,this.len=e-c-(g.headerLength+g.packetLength)}}else util.print_error("unknown parent node for a userId packet "+b.tagType)};this.toString=function(){for(var b=" 5.11. User ID Packet (Tag 13)\n text ("+this.text.length+'): "'+this.text.replace("<","<")+'"\n',b=b+"certification signatures:\n",a=0;a<this.certificationSignatures.length;a++)b+=" "+this.certificationSignatures[a].toString();b+="certification revocation signatures:\n";for(a=0;a<this.certificationRevocationSignatures.length;a++)b+=
|
||||||
null==c)result[a]=0;else{d=this.hasCertificationRevocationSignature(this.certificationSignatures[a].keyId);if(null!=d&&d.creationTime>this.certificationSignatures[a].creationTime&&(e=String.fromCharCode(153)+this.publicKeyPacket.header.substring(1)+this.publicKeyPacket.data+this.text,d.verify(e,c))){result[a]=d.keyId==b.getKeyId()?6:3;continue}e=String.fromCharCode(153)+b.header.substring(1)+b.data+this.text;result[a]=this.certificationSignatures[a].verify(e,c)?4:0}else result[a]=0;return result};
|
" "+this.certificationRevocationSignatures[a].toString();return b};this.hasCertificationRevocationSignature=function(b){for(var a=0;a<this.certificationRevocationSignatures.length;a++)if(3==this.certificationRevocationSignatures[a].version&&this.certificationRevocationSignatures[a].keyId==b||4==this.certificationRevocationSignatures[a].version&&this.certificationRevocationSignatures[a].issuerKeyId==b)return this.certificationRevocationSignatures[a];return null};this.verifyCertificationSignatures=
|
||||||
this.verify=function(b){b=this.verifyCertificationSignatures(b);return-1!=b.indexOf(6)?2:-1!=b.indexOf(5)?1:0};this.read_packet=function(b,a,c){this.text="";this.packetLength=c;for(var d=0;d<c;d++)this.text+=b[a+d];return this};this.write_packet=function(b){this.text=b;b=openpgp_packet.write_packet_header(13,this.text.length);return b+=this.text};this.toString=function(){for(var b=" 5.11. User ID Packet (Tag 13)\n text ("+this.text.length+'): "'+this.text.replace("<","<")+'"\n',b=b+"certification signatures:\n",
|
function(b){var a=this.get_text_bytes();result=[];for(var c=0;c<this.certificationSignatures.length;c++)if(4==this.certificationSignatures[c].version)if(null!=this.certificationSignatures[c].signatureExpirationTime&&null!=this.certificationSignatures[c].signatureExpirationTime&&0!=this.certificationSignatures[c].signatureExpirationTime&&!this.certificationSignatures[c].signatureNeverExpires&&new Date(this.certificationSignatures[c].creationTime.getTime()+1E3*this.certificationSignatures[c].signatureExpirationTime)<
|
||||||
a=0;a<this.certificationSignatures.length;a++)b+=" "+this.certificationSignatures[a].toString();b+="certification revocation signatures:\n";for(a=0;a<this.certificationRevocationSignatures.length;a++)b+=" "+this.certificationRevocationSignatures[a].toString();return b};this.read_nodes=function(b,a,c,d){if(6==b.tagType){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f-(e-c));if(null==g){util.print_error("[user_id] parsing ends here @:"+e+" l:"+f);
|
new Date)result[c]=this.certificationSignatures[c].issuerKeyId==b.getKeyId()?5:1;else if(null==this.certificationSignatures[c].issuerKeyId)result[c]=0;else{var d=openpgp.keyring.getPublicKeysForKeyId(this.certificationSignatures[c].issuerKeyId);if(null==d||0==d.length)result[c]=2;else if(d=d[0],d=d.obj.getSigningKey(),null==d)result[c]=0;else{var e=this.hasCertificationRevocationSignature(this.certificationSignatures[c].issuerKeyId);if(null!=e&&e.creationTime>this.certificationSignatures[c].creationTime){var f=
|
||||||
break}else switch(e+=g.packetLength+g.headerLength,f=a.length-e,g.tagType){case 2:if(15<g.signatureType&&20>g.signatureType){this.certificationSignatures[this.certificationSignatures.length]=g;break}else if(48==g.signatureType){this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g;break}else if(24==g.signatureType){this.certificationSignatures[this.certificationSignatures.length]=g;break}else util.print_debug("unknown sig t: "+g.signatureType+"@"+(e-(g.packetLength+
|
String.fromCharCode(153)+b.header.substring(1)+b.data+String.fromCharCode(180)+String.fromCharCode(a.length>>24&255)+String.fromCharCode(a.length>>16&255)+String.fromCharCode(a.length>>8&255)+String.fromCharCode(a.length&255)+a;if(e.verify(f,d)){result[c]=this.certificationSignatures[c].issuerKeyId==b.getKeyId()?6:3;continue}}f=String.fromCharCode(153)+b.header.substring(1)+b.data+String.fromCharCode(180)+String.fromCharCode(a.length>>24&255)+String.fromCharCode(a.length>>16&255)+String.fromCharCode(a.length>>
|
||||||
g.headerLength)));default:return this.data=a,this.position=c-b.packetLength,this.len=e-c-(g.headerLength+g.packetLength)}}this.data=a;this.position=c-b.packetLength;return this.len=e-c-(g.headerLength+g.packetLength)}if(5==b.tagType){this.parentNode=b;for(e=c;a.length!=e;)if(g=openpgp_packet.read_packet(a,e,f-(e-c)),null==g){util.print_error("parsing ends here @:"+e+" l:"+f);break}else switch(e+=g.packetLength+g.headerLength,g.tagType){case 2:15<g.signatureType&&20>g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=
|
8&255)+String.fromCharCode(a.length&255)+a;result[c]=this.certificationSignatures[c].verify(f,d)?4:0}}else if(3==this.certificationSignatures[c].version)if(null==this.certificationSignatures[c].keyId)result[c]=0;else if(d=openpgp.keyring.getPublicKeysForKeyId(this.certificationSignatures[c].keyId),null==d||0==d.length)result[c]=2;else if(d=publicKey.obj.getSigningKey(),null==d)result[c]=0;else{e=this.hasCertificationRevocationSignature(this.certificationSignatures[c].keyId);if(null!=e&&e.creationTime>
|
||||||
g:48==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);default:return this.data=a,this.position=c-b.packetLength,this.len=e-c-(g.headerLength+g.packetLength)}}else util.print_error("unknown parent node for a userId packet "+b.tagType)}}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.certificationSignatures[c].creationTime&&(f=String.fromCharCode(153)+this.publicKeyPacket.header.substring(1)+this.publicKeyPacket.data+a,e.verify(f,d))){result[c]=e.keyId==b.getKeyId()?6:3;continue}f=String.fromCharCode(153)+b.header.substring(1)+b.data+a;result[c]=this.certificationSignatures[c].verify(f,d)?4:0}else result[c]=0;return result};this.verify=function(b){b=this.verifyCertificationSignatures(b);return-1!=b.indexOf(6)?2:-1!=b.indexOf(5)?1:0};this.addCertification=function(){};this.revokeCertification=
|
||||||
|
function(){}}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}}
|
||||||
function openpgp_type_s2k(){this.read=function(b,a){var c=a;this.type=b[c++].charCodeAt();switch(this.type){case 0:this.hashAlgorithm=b[c++].charCodeAt();this.s2kLength=1;break;case 1:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);this.s2kLength=9;break;case 3:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);c+=8;this.EXPBIAS=6;c=b[c++].charCodeAt();this.count=16+(c&15)<<(c>>4)+this.EXPBIAS;this.s2kLength=10;break;case 101:"GNU"==b.substring(c+1,c+
|
function openpgp_type_s2k(){this.read=function(b,a){var c=a;this.type=b[c++].charCodeAt();switch(this.type){case 0:this.hashAlgorithm=b[c++].charCodeAt();this.s2kLength=1;break;case 1:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);this.s2kLength=9;break;case 3:this.hashAlgorithm=b[c++].charCodeAt();this.saltValue=b.substring(c,c+8);c+=8;this.EXPBIAS=6;c=b[c++].charCodeAt();this.count=16+(c&15)<<(c>>4)+this.EXPBIAS;this.s2kLength=10;break;case 101:"GNU"==b.substring(c+1,c+
|
||||||
4)?(this.hashAlgorithm=b[c++].charCodeAt(),c+=3,c=1E3+b[c++].charCodeAt(),1001==c?(this.type=c,this.s2kLength=5):util.print_error("unknown s2k gnu protection mode! "+this.type)):util.print_error("unknown s2k type! "+this.type);break;default:util.print_error("unknown s2k type! "+this.type)}return this};this.write=function(b,a,c,d,e){this.type=b;if(3==this.type)this.saltValue=d,this.hashAlgorithm=a,this.count=16+(e&15)<<(e>>4)+6,this.s2kLength=10;return this.produce_key(c)};this.produce_key=function(b,
|
4)?(this.hashAlgorithm=b[c++].charCodeAt(),c+=3,c=1E3+b[c++].charCodeAt(),1001==c?(this.type=c,this.s2kLength=5):util.print_error("unknown s2k gnu protection mode! "+this.type)):util.print_error("unknown s2k type! "+this.type);break;default:util.print_error("unknown s2k type! "+this.type)}return this};this.write=function(b,a,c,d,e){this.type=b;if(3==this.type)this.saltValue=d,this.hashAlgorithm=a,this.count=16+(e&15)<<(e>>4)+6,this.s2kLength=10;return this.produce_key(c)};this.produce_key=function(b,
|
||||||
a){if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,b);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+b);if(3==this.type){var c=[];for(c[0]=this.saltValue+b;c.length*(this.saltValue+b).length<this.count;)c.push(this.saltValue+b);c=c.join("");c.length>this.count&&(c=c.substr(0,this.count));return a&&(24==a||32==a)?openpgp_crypto_hashData(this.hashAlgorithm,c)+openpgp_crypto_hashData(this.hashAlgorithm,String.fromCharCode(0)+c):openpgp_crypto_hashData(this.hashAlgorithm,
|
a){b=util.encode_utf8(b);if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,b);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+b);if(3==this.type){var c=[];for(c[0]=this.saltValue+b;c.length*(this.saltValue+b).length<this.count;)c.push(this.saltValue+b);c=c.join("");c.length>this.count&&(c=c.substr(0,this.count));return a&&(24==a||32==a)?openpgp_crypto_hashData(this.hashAlgorithm,c)+openpgp_crypto_hashData(this.hashAlgorithm,String.fromCharCode(0)+c):
|
||||||
c)}return null}}
|
openpgp_crypto_hashData(this.hashAlgorithm,c)}return null}}
|
||||||
var Util=function(){this.emailRegEx=/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;this.hexdump=function(b){for(var a=[],c=b.length,d=0,e,f=0;d<c;){for(e=b.charCodeAt(d++).toString(16);2>e.length;)e="0"+e;a.push(" "+e);f++;0==f%32&&a.push("\n ")}return a.join("")};this.hexstrdump=function(b){if(null==b)return"";for(var a=[],c=b.length,d=0,e;d<c;){for(e=b[d++].charCodeAt().toString(16);2>e.length;)e=
|
var Util=function(){this.emailRegEx=/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;this.hexdump=function(a){for(var b=[],e=a.length,f=0,g,h=0;f<e;){for(g=a.charCodeAt(f++).toString(16);2>g.length;)g="0"+g;b.push(" "+g);h++;0==h%32&&b.push("\n ")}return b.join("")};this.hexstrdump=function(a){if(null==a)return"";for(var b=[],e=a.length,f=0,g;f<e;){for(g=a[f++].charCodeAt().toString(16);2>g.length;)g=
|
||||||
"0"+e;a.push(""+e)}return a.join("")};this.hex2bin=function(b){for(var a="",c=0;c<b.length;c+=2)a+=String.fromCharCode(parseInt(b.substr(c,2),16));return a};this.hexidump=function(b){for(var a=[],c=b.length,d=0,e;d<c;){for(e=b[d++].toString(16);2>e.length;)e="0"+e;a.push(""+e)}return a.join("")};this.str2bin=function(b){for(var a=[],c=0;c<b.length;c++)a[c]=b.charCodeAt(c);return a};this.bin2str=function(b){for(var a=[],c=0;c<b.length;c++)a.push(String.fromCharCode(b[c]));return a.join("")};this.str2Uint8Array=
|
"0"+g;b.push(""+g)}return b.join("")};this.hex2bin=function(a){for(var b="",e=0;e<a.length;e+=2)b+=String.fromCharCode(parseInt(a.substr(e,2),16));return b};this.hexidump=function(a){for(var b=[],e=a.length,f=0,g;f<e;){for(g=a[f++].toString(16);2>g.length;)g="0"+g;b.push(""+g)}return b.join("")};this.encode_utf8=function(a){return unescape(encodeURIComponent(a))};this.decode_utf8=function(a){return decodeURIComponent(escape(a))};var b=function(a,b){for(var e=0;e<a.length;e++)b[e]=a.charCodeAt(e);
|
||||||
function(b){for(var a=new Uint8Array(new ArrayBuffer(b.length)),c=0;c<b.length;c++)a[c]=b.charCodeAt(c);return a};this.Uint8Array2str=function(b){var a=[];for(n=0;n<b.length;n++)a[n]=String.fromCharCode(b[n]);return a.join("")};this.calc_checksum=function(b){for(var a={s:0,add:function(a){this.s=(this.s+a)%65536}},c=0;c<b.length;c++)a.add(b.charCodeAt(c));return a.s};this.print_debug=function(b){openpgp.config.debug&&(b=openpgp_encoding_html_encode(b),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+
|
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.print_debug=function(a){openpgp.config.debug&&(a=openpgp_encoding_html_encode(a),
|
||||||
b.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_debug_hexstr_dump=function(b,a){openpgp.config.debug&&(b+=this.hexstrdump(a),b=openpgp_encoding_html_encode(b),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+b.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_error=function(b){b=openpgp_encoding_html_encode(b);showMessages('<p style="font-size: 80%; background-color: #FF8888; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>ERROR:</b></span>\t'+
|
showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_error=
|
||||||
b.replace(/\n/g,"<br>")+"</p>")};this.print_info=function(b){b=openpgp_encoding_html_encode(b);showMessages('<p style="font-size: 80%; background-color: #88FF88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>INFO:</b></span>\t'+b.replace(/\n/g,"<br>")+"</p>")};this.print_warning=function(b){b=openpgp_encoding_html_encode(b);showMessages('<p style="font-size: 80%; background-color: #FFAA88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>WARNING:</b></span>\t'+
|
function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #FF8888; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>ERROR:</b></span>\t'+a.replace(/\n/g,"<br>")+"</p>")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #88FF88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>INFO:</b></span>\t'+
|
||||||
b.replace(/\n/g,"<br>")+"</p>")};this.getLeftNBits=function(b,a){var c=a%8;return 0==c?b.substring(0,a/8):this.shiftRight(b.substring(0,(a-c)/8+1),8-c)};this.shiftRight=function(b,a){var c=util.str2bin(b);if(0!=a%8)for(var d=c.length-1;0<=d;d--)c[d]>>=a%8,0<d&&(c[d]|=c[d-1]<<8-a%8&255);else return b;return util.bin2str(c)};this.get_hashAlgorithmString=function(b){switch(b){case 1:return"MD5";case 2:return"SHA1";case 3:return"RIPEMD160";case 8:return"SHA256";case 9:return"SHA384";case 10:return"SHA512";
|
a.replace(/\n/g,"<br>")+"</p>")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #FFAA88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>WARNING:</b></span>\t'+a.replace(/\n/g,"<br>")+"</p>")};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=
|
||||||
case 11:return"SHA224"}return"unknown"}},util=new Util;
|
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;
|
||||||
|
|
|
@ -414,6 +414,7 @@ function _openpgp () {
|
||||||
* be 1024+, generally)
|
* be 1024+, generally)
|
||||||
* @param {String} userId assumes already in form of "User Name
|
* @param {String} userId assumes already in form of "User Name
|
||||||
* <username@email.com>"
|
* <username@email.com>"
|
||||||
|
* @param {String} passphrase The passphrase used to encrypt the resulting private key
|
||||||
* @return {Object} {privateKey: [openpgp_msg_privatekey],
|
* @return {Object} {privateKey: [openpgp_msg_privatekey],
|
||||||
* privateKeyArmored: [string], publicKeyArmored: [string]}
|
* privateKeyArmored: [string], publicKeyArmored: [string]}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,47 @@
|
||||||
function openpgp_packet_literaldata() {
|
function openpgp_packet_literaldata() {
|
||||||
this.tagType = 11;
|
this.tagType = 11;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet data to a javascript native string or a squence of
|
||||||
|
* bytes. Conversion to a proper utf8 encoding takes place when the
|
||||||
|
* packet is written.
|
||||||
|
* @param {String} str Any native javascript string
|
||||||
|
* @param {openpgp_packet_literaldata.formats} format
|
||||||
|
*/
|
||||||
|
this.set_data = function(str, format) {
|
||||||
|
this.format = format;
|
||||||
|
this.data = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet data to value represented by the provided string
|
||||||
|
* of bytes together with the appropriate conversion format.
|
||||||
|
* @param {String} bytes The string of bytes
|
||||||
|
* @param {openpgp_packet_literaldata.formats} format
|
||||||
|
*/
|
||||||
|
this.set_data_bytes = function(bytes, format) {
|
||||||
|
this.format = format;
|
||||||
|
|
||||||
|
if(format == openpgp_packet_literaldata.formats.utf8)
|
||||||
|
bytes = util.decode_utf8(bytes);
|
||||||
|
|
||||||
|
this.data = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the byte sequence representing the literal packet data
|
||||||
|
* @returns {String} A sequence of bytes
|
||||||
|
*/
|
||||||
|
this.get_data_bytes = function() {
|
||||||
|
if(this.format == openpgp_packet_literaldata.formats.utf8)
|
||||||
|
return util.encode_utf8(this.data);
|
||||||
|
else
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parsing function for a literal data packet (tag 11).
|
* Parsing function for a literal data packet (tag 11).
|
||||||
*
|
*
|
||||||
|
@ -36,17 +77,22 @@ function openpgp_packet_literaldata() {
|
||||||
* input at position
|
* input at position
|
||||||
* @return {openpgp_packet_encrypteddata} object representation
|
* @return {openpgp_packet_encrypteddata} object representation
|
||||||
*/
|
*/
|
||||||
function read_packet(input, position, len) {
|
this.read_packet = function(input, position, len) {
|
||||||
this.packetLength = len;
|
this.packetLength = len;
|
||||||
// - A one-octet field that describes how the data is formatted.
|
// - A one-octet field that describes how the data is formatted.
|
||||||
|
|
||||||
this.format = input[position];
|
var format = input[position];
|
||||||
this.filename = input.substr(position + 2, input
|
|
||||||
.charCodeAt(position + 1));
|
this.filename = util.decode_utf8(input.substr(position + 2, input
|
||||||
|
.charCodeAt(position + 1)));
|
||||||
|
|
||||||
this.date = new Date(parseInt(input.substr(position + 2
|
this.date = new Date(parseInt(input.substr(position + 2
|
||||||
+ input.charCodeAt(position + 1), 4)) * 1000);
|
+ input.charCodeAt(position + 1), 4)) * 1000);
|
||||||
this.data = input.substring(position + 6
|
|
||||||
|
var bytes = input.substring(position + 6
|
||||||
+ input.charCodeAt(position + 1));
|
+ input.charCodeAt(position + 1));
|
||||||
|
|
||||||
|
this.set_data_bytes(bytes, format);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +102,13 @@ function openpgp_packet_literaldata() {
|
||||||
* @param {String} data The data to be inserted as body
|
* @param {String} data The data to be inserted as body
|
||||||
* @return {String} string-representation of the packet
|
* @return {String} string-representation of the packet
|
||||||
*/
|
*/
|
||||||
function write_packet(data) {
|
this.write_packet = function(data) {
|
||||||
data = data.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n");
|
this.set_data(data, openpgp_packet_literaldata.formats.utf8);
|
||||||
this.filename = "msg.txt";
|
this.filename = util.encode_utf8("msg.txt");
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.format = 't';
|
|
||||||
|
data = this.get_data_bytes();
|
||||||
|
|
||||||
var result = openpgp_packet.write_packet_header(11, data.length + 6
|
var result = openpgp_packet.write_packet_header(11, data.length + 6
|
||||||
+ this.filename.length);
|
+ this.filename.length);
|
||||||
result += this.format;
|
result += this.format;
|
||||||
|
@ -75,7 +123,6 @@ function openpgp_packet_literaldata() {
|
||||||
result += String
|
result += String
|
||||||
.fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF);
|
.fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF);
|
||||||
result += data;
|
result += data;
|
||||||
this.data = data;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,15 +131,25 @@ function openpgp_packet_literaldata() {
|
||||||
*
|
*
|
||||||
* @return {String} String which gives some information about the keymaterial
|
* @return {String} String which gives some information about the keymaterial
|
||||||
*/
|
*/
|
||||||
function toString() {
|
this.toString = function() {
|
||||||
return '5.9. Literal Data Packet (Tag 11)\n' + ' length: '
|
return '5.9. Literal Data Packet (Tag 11)\n' + ' length: '
|
||||||
+ this.packetLength + '\n' + ' format: ' + this.format
|
+ this.packetLength + '\n' + ' format: ' + this.format
|
||||||
+ '\n' + ' filename:' + this.filename + '\n'
|
+ '\n' + ' filename:' + this.filename + '\n'
|
||||||
+ ' date: ' + this.date + '\n' + ' data: |'
|
+ ' date: ' + this.date + '\n' + ' data: |'
|
||||||
+ this.data + '|\n' + ' rdata: |' + this.real_data + '|\n';
|
+ this.data + '|\n' + ' rdata: |' + this.real_data + '|\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.read_packet = read_packet;
|
|
||||||
this.toString = toString;
|
|
||||||
this.write_packet = write_packet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data types in the literal packet
|
||||||
|
* @readonly
|
||||||
|
* @enum {String}
|
||||||
|
*/
|
||||||
|
openpgp_packet_literaldata.formats = {
|
||||||
|
/** Binary data */
|
||||||
|
binary: 'b',
|
||||||
|
/** Text data */
|
||||||
|
text: 't',
|
||||||
|
/** Utf8 data */
|
||||||
|
utf8: 'u'
|
||||||
|
};
|
||||||
|
|
|
@ -26,38 +26,71 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function openpgp_packet_userid() {
|
function openpgp_packet_userid() {
|
||||||
|
this.text = ''
|
||||||
this.tagType = 13;
|
this.tagType = 13;
|
||||||
this.certificationSignatures = new Array();
|
this.certificationSignatures = new Array();
|
||||||
this.certificationRevocationSignatures = new Array();
|
this.certificationRevocationSignatures = new Array();
|
||||||
this.revocationSignatures = new Array();
|
this.revocationSignatures = new Array();
|
||||||
this.parentNode = null;
|
this.parentNode = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the packet text field to a native javascript string
|
||||||
|
* Conversion to a proper utf8 encoding takes place when the
|
||||||
|
* packet is written.
|
||||||
|
* @param {String} str Any native javascript string
|
||||||
|
*/
|
||||||
|
this.set_text = function(str) {
|
||||||
|
this.text = str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parsing function for a user id packet (tag 13).
|
* Set the packet text to value represented by the provided string
|
||||||
|
* of bytes.
|
||||||
|
* @param {String} bytes A string of bytes
|
||||||
|
*/
|
||||||
|
this.set_text_bytes = function(bytes) {
|
||||||
|
this.text = util.decode_utf8(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the byte sequence representing the text of this packet.
|
||||||
|
* @returns {String} A sequence of bytes
|
||||||
|
*/
|
||||||
|
this.get_text_bytes = function() {
|
||||||
|
return util.encode_utf8(this.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parsing function for a user id packet (tag 13).
|
||||||
* @param {String} input payload of a tag 13 packet
|
* @param {String} input payload of a tag 13 packet
|
||||||
* @param {Integer} position position to start reading from the input string
|
* @param {Integer} position position to start reading from the input string
|
||||||
* @param {Integer} len length of the packet or the remaining length of input at position
|
* @param {Integer} len length of the packet or the remaining length of input at position
|
||||||
* @return {openpgp_packet_encrypteddata} object representation
|
* @return {openpgp_packet_encrypteddata} object representation
|
||||||
*/
|
*/
|
||||||
function read_packet(input, position, len) {
|
this.read_packet = function(input, position, len) {
|
||||||
this.text = '';
|
|
||||||
this.packetLength = len;
|
this.packetLength = len;
|
||||||
|
|
||||||
|
var bytes = '';
|
||||||
for ( var i = 0; i < len; i++) {
|
for ( var i = 0; i < len; i++) {
|
||||||
this.text += input[position + i];
|
bytes += input[position + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set_text_bytes(bytes);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a string representation of the user id packet
|
* Creates a string representation of the user id packet
|
||||||
* @param {String} user_id the user id as string ("John Doe <john.doe@mail.us")
|
* @param {String} user_id the user id as string ("John Doe <john.doe@mail.us")
|
||||||
* @return {String} string representation
|
* @return {String} string representation
|
||||||
*/
|
*/
|
||||||
function write_packet(user_id) {
|
this.write_packet = function(user_id) {
|
||||||
this.text = user_id;
|
this.set_text(user_id);
|
||||||
var result = openpgp_packet.write_packet_header(13,this.text.length);
|
var bytes = this.get_text_bytes();
|
||||||
result += this.text;
|
|
||||||
|
var result = openpgp_packet.write_packet_header(13, bytes.length);
|
||||||
|
result += bytes;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +102,7 @@ function openpgp_packet_userid() {
|
||||||
* @param {Integer} len length of the packet(s) or remaining length of input
|
* @param {Integer} len length of the packet(s) or remaining length of input
|
||||||
* @return {Integer} length of nodes read
|
* @return {Integer} length of nodes read
|
||||||
*/
|
*/
|
||||||
function read_nodes(parent_node, input, position, len) {
|
this.read_nodes = function(parent_node, input, position, len) {
|
||||||
if (parent_node.tagType == 6) { // public key
|
if (parent_node.tagType == 6) { // public key
|
||||||
this.parentNode = parent_node;
|
this.parentNode = parent_node;
|
||||||
var pos = position;
|
var pos = position;
|
||||||
|
@ -149,7 +182,7 @@ function openpgp_packet_userid() {
|
||||||
* generates debug output (pretty print)
|
* generates debug output (pretty print)
|
||||||
* @return {String} String which gives some information about the user id packet
|
* @return {String} String which gives some information about the user id packet
|
||||||
*/
|
*/
|
||||||
function toString() {
|
this.toString = function() {
|
||||||
var result = ' 5.11. User ID Packet (Tag 13)\n' + ' text ('
|
var result = ' 5.11. User ID Packet (Tag 13)\n' + ' text ('
|
||||||
+ this.text.length + '): "' + this.text.replace("<", "<")
|
+ this.text.length + '): "' + this.text.replace("<", "<")
|
||||||
+ '"\n';
|
+ '"\n';
|
||||||
|
@ -169,7 +202,7 @@ function openpgp_packet_userid() {
|
||||||
* @param {String} keyId string containing the key id of the issuer of this signature
|
* @param {String} keyId string containing the key id of the issuer of this signature
|
||||||
* @return a CertificationRevocationSignature if found; otherwise null
|
* @return a CertificationRevocationSignature if found; otherwise null
|
||||||
*/
|
*/
|
||||||
function hasCertificationRevocationSignature(keyId) {
|
this.hasCertificationRevocationSignature = function(keyId) {
|
||||||
for (var i = 0; i < this.certificationRevocationSignatures.length; i++) {
|
for (var i = 0; i < this.certificationRevocationSignatures.length; i++) {
|
||||||
if ((this.certificationRevocationSignatures[i].version == 3 &&
|
if ((this.certificationRevocationSignatures[i].version == 3 &&
|
||||||
this.certificationRevocationSignatures[i].keyId == keyId) ||
|
this.certificationRevocationSignatures[i].keyId == keyId) ||
|
||||||
|
@ -192,7 +225,8 @@ function openpgp_packet_userid() {
|
||||||
* 5 = signature by key owner expired
|
* 5 = signature by key owner expired
|
||||||
* 6 = signature by key owner revoked
|
* 6 = signature by key owner revoked
|
||||||
*/
|
*/
|
||||||
function verifyCertificationSignatures(publicKeyPacket) {
|
this.verifyCertificationSignatures = function(publicKeyPacket) {
|
||||||
|
var bytes = this.get_text_bytes();
|
||||||
result = new Array();
|
result = new Array();
|
||||||
for (var i = 0 ; i < this.certificationSignatures.length; i++) {
|
for (var i = 0 ; i < this.certificationSignatures.length; i++) {
|
||||||
// A certification signature (type 0x10 through 0x13) hashes the User
|
// A certification signature (type 0x10 through 0x13) hashes the User
|
||||||
|
@ -235,13 +269,14 @@ function openpgp_packet_userid() {
|
||||||
var revocation = this.hasCertificationRevocationSignature(this.certificationSignatures[i].issuerKeyId);
|
var revocation = this.hasCertificationRevocationSignature(this.certificationSignatures[i].issuerKeyId);
|
||||||
if (revocation != null && revocation.creationTime >
|
if (revocation != null && revocation.creationTime >
|
||||||
this.certificationSignatures[i].creationTime) {
|
this.certificationSignatures[i].creationTime) {
|
||||||
|
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
||||||
String.fromCharCode((this.text.length >> 24) & 0xFF)+
|
String.fromCharCode((bytes.length >> 24) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 16) & 0xFF)+
|
String.fromCharCode((bytes.length >> 16) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 8) & 0xFF)+
|
String.fromCharCode((bytes.length >> 8) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length) & 0xFF)+
|
String.fromCharCode((bytes.length) & 0xFF)+
|
||||||
this.text;
|
bytes;
|
||||||
if (revocation.verify(signaturedata, signingKey)) {
|
if (revocation.verify(signaturedata, signingKey)) {
|
||||||
if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId())
|
if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId())
|
||||||
result[i] = 6;
|
result[i] = 6;
|
||||||
|
@ -250,13 +285,14 @@ function openpgp_packet_userid() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
publicKeyPacket.data+String.fromCharCode(0xB4)+
|
||||||
String.fromCharCode((this.text.length >> 24) & 0xFF)+
|
String.fromCharCode((bytes.length >> 24) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 16) & 0xFF)+
|
String.fromCharCode((bytes.length >> 16) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length >> 8) & 0xFF)+
|
String.fromCharCode((bytes.length >> 8) & 0xFF)+
|
||||||
String.fromCharCode((this.text.length) & 0xFF)+
|
String.fromCharCode((bytes.length) & 0xFF)+
|
||||||
this.text;
|
bytes;
|
||||||
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
||||||
result[i] = 4;
|
result[i] = 4;
|
||||||
} else
|
} else
|
||||||
|
@ -281,7 +317,7 @@ function openpgp_packet_userid() {
|
||||||
if (revocation != null && revocation.creationTime >
|
if (revocation != null && revocation.creationTime >
|
||||||
this.certificationSignatures[i].creationTime) {
|
this.certificationSignatures[i].creationTime) {
|
||||||
var signaturedata = String.fromCharCode(0x99)+ this.publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ this.publicKeyPacket.header.substring(1)+
|
||||||
this.publicKeyPacket.data+this.text;
|
this.publicKeyPacket.data+bytes;
|
||||||
if (revocation.verify(signaturedata, signingKey)) {
|
if (revocation.verify(signaturedata, signingKey)) {
|
||||||
if (revocation.keyId == publicKeyPacket.getKeyId())
|
if (revocation.keyId == publicKeyPacket.getKeyId())
|
||||||
result[i] = 6;
|
result[i] = 6;
|
||||||
|
@ -291,7 +327,7 @@ function openpgp_packet_userid() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+
|
||||||
publicKeyPacket.data+this.text;
|
publicKeyPacket.data + bytes;
|
||||||
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
if (this.certificationSignatures[i].verify(signaturedata, signingKey)) {
|
||||||
result[i] = 4;
|
result[i] = 4;
|
||||||
} else
|
} else
|
||||||
|
@ -307,7 +343,7 @@ function openpgp_packet_userid() {
|
||||||
* verifies the signatures of the user id
|
* verifies the signatures of the user id
|
||||||
* @return 0 if the userid is valid; 1 = userid expired; 2 = userid revoked
|
* @return 0 if the userid is valid; 1 = userid expired; 2 = userid revoked
|
||||||
*/
|
*/
|
||||||
function verify(publicKeyPacket) {
|
this.verify = function(publicKeyPacket) {
|
||||||
var result = this.verifyCertificationSignatures(publicKeyPacket);
|
var result = this.verifyCertificationSignatures(publicKeyPacket);
|
||||||
if (result.indexOf(6) != -1)
|
if (result.indexOf(6) != -1)
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -317,20 +353,12 @@ function openpgp_packet_userid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implementation missing
|
// TODO: implementation missing
|
||||||
function addCertification(publicKeyPacket, privateKeyPacket) {
|
this.addCertification = function(publicKeyPacket, privateKeyPacket) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implementation missing
|
// TODO: implementation missing
|
||||||
function revokeCertification(publicKeyPacket, privateKeyPacket) {
|
this.revokeCertification = function(publicKeyPacket, privateKeyPacket) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasCertificationRevocationSignature = hasCertificationRevocationSignature;
|
|
||||||
this.verifyCertificationSignatures = verifyCertificationSignatures;
|
|
||||||
this.verify = verify;
|
|
||||||
this.read_packet = read_packet;
|
|
||||||
this.write_packet = write_packet;
|
|
||||||
this.toString = toString;
|
|
||||||
this.read_nodes = read_nodes;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ function openpgp_type_s2k() {
|
||||||
* hashAlgorithm hash length
|
* hashAlgorithm hash length
|
||||||
*/
|
*/
|
||||||
function produce_key(passphrase, numBytes) {
|
function produce_key(passphrase, numBytes) {
|
||||||
|
passphrase = util.encode_utf8(passphrase);
|
||||||
if (this.type == 0) {
|
if (this.type == 0) {
|
||||||
return openpgp_crypto_hashData(this.hashAlgorithm,passphrase);
|
return openpgp_crypto_hashData(this.hashAlgorithm,passphrase);
|
||||||
} else if (this.type == 1) {
|
} else if (this.type == 1) {
|
||||||
|
|
|
@ -85,45 +85,68 @@ var Util = function() {
|
||||||
}
|
}
|
||||||
return r.join('');
|
return r.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a native javascript string to a string of utf8 bytes
|
||||||
|
* @param {String} str The string to convert
|
||||||
|
* @return {String} A valid squence of utf8 bytes
|
||||||
|
*/
|
||||||
|
this.encode_utf8 = function(str) {
|
||||||
|
return unescape(encodeURIComponent(str));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a string of utf8 bytes to a native javascript string
|
||||||
|
* @param {String} utf8 A valid squence of utf8 bytes
|
||||||
|
* @return {String} A native javascript string
|
||||||
|
*/
|
||||||
|
this.decode_utf8 = function(utf8) {
|
||||||
|
return decodeURIComponent(escape(utf8));
|
||||||
|
};
|
||||||
|
|
||||||
|
var str2bin = function(str, result) {
|
||||||
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
result[i] = str.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
var bin2str = function(bin) {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < bin.length; i++) {
|
||||||
|
result.push(String.fromCharCode(bin[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join('');
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string to an array of integers(0.255)
|
* Convert a string to an array of integers(0.255)
|
||||||
* @param {String} str String to convert
|
* @param {String} str String to convert
|
||||||
* @return {Integer[]} An array of (binary) integers
|
* @return {Integer[]} An array of (binary) integers
|
||||||
*/
|
*/
|
||||||
this.str2bin = function(str) {
|
this.str2bin = function(str) {
|
||||||
var result = new Array();
|
return str2bin(str, new Array(str.length));
|
||||||
for (var i = 0; i < str.length; i++) {
|
|
||||||
result[i] = str.charCodeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of integers(0.255) to a string
|
* Convert an array of integers(0.255) to a string
|
||||||
* @param {Integer[]} bin An array of (binary) integers to convert
|
* @param {Integer[]} bin An array of (binary) integers to convert
|
||||||
* @return {String} The string representation of the array
|
* @return {String} The string representation of the array
|
||||||
*/
|
*/
|
||||||
this.bin2str = function(bin) {
|
this.bin2str = bin2str;
|
||||||
var result = [];
|
|
||||||
for (var i = 0; i < bin.length; i++) {
|
|
||||||
result.push(String.fromCharCode(bin[i]));
|
|
||||||
}
|
|
||||||
return result.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string to a Uint8Array
|
* Convert a string to a Uint8Array
|
||||||
* @param {String} str String to convert
|
* @param {String} str String to convert
|
||||||
* @return {Uint8Array} The array of (binary) integers
|
* @return {Uint8Array} The array of (binary) integers
|
||||||
*/
|
*/
|
||||||
this.str2Uint8Array = function(str){
|
this.str2Uint8Array = function(str) {
|
||||||
var uintArray = new Uint8Array(new ArrayBuffer(str.length));
|
return str2bin(str, new Uint8Array(new ArrayBuffer(str.length)));
|
||||||
for(var n = 0; n < str.length; n++){
|
|
||||||
uintArray[n] = str.charCodeAt(n);
|
|
||||||
}
|
|
||||||
return uintArray;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,13 +155,7 @@ var Util = function() {
|
||||||
* @param {Uint8Array} bin An array of (binary) integers to convert
|
* @param {Uint8Array} bin An array of (binary) integers to convert
|
||||||
* @return {String} String representation of the array
|
* @return {String} String representation of the array
|
||||||
*/
|
*/
|
||||||
this.Uint8Array2str = function(bin) {
|
this.Uint8Array2str = bin2str;
|
||||||
var result = [];
|
|
||||||
for(n = 0; n< bin.length; n++){
|
|
||||||
result[n] = String.fromCharCode(bin[n]);
|
|
||||||
}
|
|
||||||
return result.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates a 16bit sum of a string by adding each character
|
* Calculates a 16bit sum of a string by adding each character
|
||||||
|
|
69
test/general/openpgp.basic.js
Normal file
69
test/general/openpgp.basic.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
|
||||||
|
unittests.register("Encryption/decryption", function() {
|
||||||
|
|
||||||
|
openpgp.init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function test(passphrase, userid, message) {
|
||||||
|
var key = openpgp.generate_key_pair(1, 512, userid, passphrase),
|
||||||
|
priv_key = key.privateKey,
|
||||||
|
pub_key = openpgp.read_publicKey(key.publicKeyArmored);
|
||||||
|
|
||||||
|
var info = '\npassphrase: ' + passphrase + '\n'
|
||||||
|
+ 'userid: ' + userid + '\n'
|
||||||
|
+ 'message: ' + message;
|
||||||
|
|
||||||
|
if(!priv_key.decryptSecretMPIs(passphrase)) {
|
||||||
|
return new test_result('Generating a decryptable private key failed'
|
||||||
|
+ info,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var encrypted = openpgp.write_signed_and_encrypted_message(priv_key,
|
||||||
|
pub_key, message);
|
||||||
|
|
||||||
|
openpgp.keyring.importPublicKey(key.publicKeyArmored)
|
||||||
|
|
||||||
|
|
||||||
|
var msg = openpgp.read_message(encrypted);
|
||||||
|
var keymat = null;
|
||||||
|
var sesskey = null;
|
||||||
|
|
||||||
|
// Find the private (sub)key for the session key of the message
|
||||||
|
for (var i = 0; i< msg[0].sessionKeys.length; i++) {
|
||||||
|
if (priv_key.privateKeyPacket.publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
|
||||||
|
keymat = { key: priv_key, keymaterial: priv_key.privateKeyPacket};
|
||||||
|
sesskey = msg[0].sessionKeys[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (var j = 0; j < priv_key.subKeys.length; j++) {
|
||||||
|
if (priv_key.subKeys[j].publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
|
||||||
|
keymat = { key: priv_key, keymaterial: priv_key.subKeys[j]};
|
||||||
|
sesskey = msg[0].sessionKeys[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var decrypted = ''
|
||||||
|
if (keymat != null) {
|
||||||
|
if (!keymat.keymaterial.decryptSecretMPIs(passphrase)) {
|
||||||
|
return new test_result("Password for secrect key was incorrect!",
|
||||||
|
+ info, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted = msg[0].decrypt(keymat, sesskey);
|
||||||
|
} else {
|
||||||
|
return new test_result("No private key found!" + info, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new test_result(message + ' == ' + decrypted + info, message == decrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = []
|
||||||
|
result.push(test('password', 'Test McTestington <test@example.com>', 'hello world'));
|
||||||
|
result.push(test('●●●●', '♔♔♔♔ <test@example.com>', 'łäóć'));
|
||||||
|
|
||||||
|
return result
|
||||||
|
});
|
|
@ -76,10 +76,9 @@
|
||||||
<script type="text/javascript" src="ciphers/openpgp.crypto.js"></script>
|
<script type="text/javascript" src="ciphers/openpgp.crypto.js"></script>
|
||||||
<script type="text/javascript" src="ciphers/openpgp.sigcheck.js"></script>
|
<script type="text/javascript" src="ciphers/openpgp.sigcheck.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="general/openpgp.basic.js"></script>
|
||||||
<title>OpenPGP.js testpage</title>
|
<title>OpenPGP.js testpage</title>
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
@ -102,8 +101,12 @@
|
||||||
#unittests {
|
#unittests {
|
||||||
width: 98%;
|
width: 98%;
|
||||||
max-width: 99%;
|
max-width: 99%;
|
||||||
|
table-layout: fixed;
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#unittests tbody tr th {
|
#unittests tbody tr th {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
border: 1px dotted #aaa;
|
border: 1px dotted #aaa;
|
||||||
|
@ -134,7 +137,6 @@ function showMessages(str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unit_tests() {
|
function unit_tests() {
|
||||||
$('#unittests').empty();
|
|
||||||
$('#unittests').append("<tr><th>Unit</th><th>Description</th><th>Result</th></tr>");
|
$('#unittests').append("<tr><th>Unit</th><th>Description</th><th>Result</th></tr>");
|
||||||
var result = unittests.runAll();
|
var result = unittests.runAll();
|
||||||
var html = "";
|
var html = "";
|
||||||
|
@ -151,11 +153,23 @@ function unit_tests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<a href="index.html">Unit Tests</a> | <a href="parser.html">Parser</a> | <a href="encryption.html">Encryption / Decryption</a> | <a href="coverage.html">Coverage</a>
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="index.html">Unit Tests</a> |
|
||||||
|
<a href="parser.html">Parser</a> |
|
||||||
|
<a href="encryption.html">Encryption / Decryption</a> |
|
||||||
|
<a href="coverage.html">Coverage</a>
|
||||||
|
|
||||||
<p><input id="enabledebug" type="checkbox" onclick="($('#enabledebug').is(':checked') ? openpgp.config.debug = true : openpgp.config.debug = false)"> Print Debug Messages </p>
|
<p><input id="enabledebug" type="checkbox" onclick="($('#enabledebug').is(':checked') ? openpgp.config.debug = true : openpgp.config.debug = false)"> Print Debug Messages </p>
|
||||||
<h1>Unit tests</h1>
|
<h1>Unit tests</h1>
|
||||||
|
|
||||||
<table id="unittests"></table><br>
|
<table id="unittests">
|
||||||
|
<colgroup>
|
||||||
|
<col style="width: 20%;">
|
||||||
|
<col>
|
||||||
|
<col style="width: 5%;">
|
||||||
|
</colgroup>
|
||||||
|
</table><br>
|
||||||
<button type="submit" onmousedown="unit_tests();">Run unit tests</button>
|
<button type="submit" onmousedown="unit_tests();">Run unit tests</button>
|
||||||
|
|
||||||
<!-- src/util/util.js print_debug() writes to -->
|
<!-- src/util/util.js print_debug() writes to -->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user