From 23295342fc87114c9625b4483749f51251ca6ab9 Mon Sep 17 00:00:00 2001 From: Michal Kolodziej Date: Sat, 6 Apr 2013 11:55:52 +0200 Subject: [PATCH] Added utf8 awareness to the literal and userid packet classes. Made s2k work correctly with utf8 strings. Fixeda visibility issue with the testing suite and added relevant unit tests. --- doc/JXG.Util.html | 4 +- doc/_openpgp_packet.html | 4 +- doc/global.html | 686 ++++++++++-------- doc/index.html | 4 +- doc/jsxcompressor.js.html | 4 +- doc/md5.js.html | 4 +- doc/openpgp.cfb.js.html | 4 +- doc/openpgp.config.js.html | 4 +- doc/openpgp.crypto.js.html | 4 +- doc/openpgp.crypto.sym.js.html | 4 +- doc/openpgp.encoding.asciiarmor.js.html | 4 +- doc/openpgp.encoding.js.html | 4 +- doc/openpgp.html | 31 +- doc/openpgp.js.html | 5 +- doc/openpgp.keyring.js.html | 4 +- doc/openpgp.msg.message.js.html | 4 +- doc/openpgp.msg.privatekey.js.html | 4 +- doc/openpgp.msg.publickey.js.html | 4 +- doc/openpgp.packet.compressed.js.html | 4 +- doc/openpgp.packet.encrypteddata.js.html | 4 +- ...et.encryptedintegrityprotecteddata.js.html | 4 +- ...openpgp.packet.encryptedsessionkey.js.html | 4 +- doc/openpgp.packet.js.html | 4 +- doc/openpgp.packet.keymaterial.js.html | 4 +- doc/openpgp.packet.literaldata.js.html | 91 ++- doc/openpgp.packet.marker.js.html | 4 +- ...p.packet.modificationdetectioncode.js.html | 4 +- doc/openpgp.packet.onepasssignature.js.html | 4 +- doc/openpgp.packet.signature.js.html | 4 +- doc/openpgp.packet.userattribute.js.html | 4 +- doc/openpgp.packet.userid.js.html | 104 ++- doc/openpgp.type.keyid.js.html | 4 +- doc/openpgp.type.mpi.js.html | 4 +- doc/openpgp.type.s2k.js.html | 5 +- doc/openpgp_config.html | 4 +- doc/openpgp_keyring.html | 4 +- doc/openpgp_msg_message.html | 4 +- doc/openpgp_msg_privatekey.html | 4 +- doc/openpgp_msg_publickey.html | 4 +- doc/openpgp_packet_compressed.html | 4 +- doc/openpgp_packet_encrypteddata.html | 4 +- ...acket_encryptedintegrityprotecteddata.html | 4 +- doc/openpgp_packet_encryptedsessionkey.html | 4 +- doc/openpgp_packet_keymaterial.html | 4 +- doc/openpgp_packet_literaldata.html | 563 +++++++++++++- doc/openpgp_packet_marker.html | 4 +- ...npgp_packet_modificationdetectioncode.html | 4 +- doc/openpgp_packet_onepasssignature.html | 4 +- doc/openpgp_packet_signature.html | 4 +- doc/openpgp_packet_userattribute.html | 4 +- doc/openpgp_packet_userid.html | 364 +++++++++- doc/openpgp_type_keyid.html | 4 +- doc/openpgp_type_mpi.html | 4 +- doc/openpgp_type_s2k.html | 4 +- doc/rsa.js.html | 4 +- doc/util.js.html | 77 +- resources/openpgp.js | 264 +++++-- resources/openpgp.min.js | 50 +- src/openpgp.js | 1 + src/packet/openpgp.packet.literaldata.js | 87 ++- src/packet/openpgp.packet.userid.js | 100 ++- src/type/openpgp.type.s2k.js | 1 + src/util/util.js | 73 +- test/general/openpgp.basic.js | 69 ++ test/index.html | 24 +- 65 files changed, 2091 insertions(+), 692 deletions(-) create mode 100644 test/general/openpgp.basic.js diff --git a/doc/JXG.Util.html b/doc/JXG.Util.html index 19ab8810..7c1ca492 100644 --- a/doc/JXG.Util.html +++ b/doc/JXG.Util.html @@ -487,13 +487,13 @@ EXAMPLES:
diff --git a/doc/_openpgp_packet.html b/doc/_openpgp_packet.html index 3057dac2..5d0390d1 100644 --- a/doc/_openpgp_packet.html +++ b/doc/_openpgp_packet.html @@ -789,13 +789,13 @@ string
diff --git a/doc/global.html b/doc/global.html index 0f55353d..00f12dcf 100644 --- a/doc/global.html +++ b/doc/global.html @@ -88,6 +88,58 @@
+
+

bin2str

+ + +
+
+ +
+ Convert an array of integers(0.255) to a string +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
+ + +

crc_table

@@ -184,6 +236,59 @@ +
+ + + + + + + +
+

Uint8Array2str

+ + +
+
+ +
+ Convert a Uint8Array to a string. This currently functions +the same as bin2str. +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + +
@@ -227,7 +332,7 @@
Source:
@@ -250,145 +355,6 @@
-
-

bin2str(bin) → {String}

- - -
-
- - -
- Convert an array of integers(0.255) to a string -
- - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bin - - -Integer[] - - - - An array of (binary) integers to convert
- - - -
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - -
Returns:
- - -
- The string representation of the array -
- - - -
-
- Type -
-
- -String - - -
-
- - - - -
- - -

calc_checksum(text) → {Integer}

@@ -480,7 +446,7 @@ codes modulus 65535
Source:
@@ -526,6 +492,284 @@ codes % 65535 + + + + +
+

decode_utf8(utf8) → {String}

+ + +
+
+ + +
+ Convert a string of utf8 bytes to a native javascript string +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
utf8 + + +String + + + + A valid squence of utf8 bytes
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+ A native javascript string +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + +
+ + + +
+

encode_utf8(str) → {String}

+ + +
+
+ + +
+ Convert a native javascript string to a string of utf8 bytes +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + + The string to convert
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+ A valid squence of utf8 bytes +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + +
@@ -572,7 +816,7 @@ codes % 65535
Source:
@@ -6529,7 +6773,7 @@ are automatically converted to HTML line feeds '
'
Source:
@@ -6675,7 +6919,7 @@ Different than print_debug because will call hexstrdump iff necessary.
Source:
@@ -6818,7 +7062,7 @@ are automatically converted to HTML line feeds '
'
Source:
@@ -6961,7 +7205,7 @@ are automatically converted to HTML line feeds '
'.
Source:
@@ -7125,7 +7369,7 @@ than 9)
Source:
@@ -7264,7 +7508,7 @@ than 9)
Source:
@@ -7403,7 +7647,7 @@ than 9)
Source:
@@ -7448,146 +7692,6 @@ than 9) - - - - -
-

Uint8Array2str(bin) → {String}

- - -
-
- - -
- Convert a Uint8Array to a string. This currently functions -the same as bin2str. -
- - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bin - - -Uint8Array - - - - An array of (binary) integers to convert
- - - -
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - -
Returns:
- - -
- String representation of the array -
- - - -
-
- Type -
-
- -String - - -
-
- - - -
@@ -8109,13 +8213,13 @@ given base64 encoded checksum
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/index.html b/doc/index.html index e32350ac..8448e9c3 100644 --- a/doc/index.html +++ b/doc/index.html @@ -133,13 +133,13 @@ for extending and developing on top of the base library.
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:34 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/jsxcompressor.js.html b/doc/jsxcompressor.js.html index c505c58f..9cd6bcb7 100644 --- a/doc/jsxcompressor.js.html +++ b/doc/jsxcompressor.js.html @@ -1261,13 +1261,13 @@ JXG.Util.genUUID = function() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/md5.js.html b/doc/md5.js.html index 92594e93..b9fc7228 100644 --- a/doc/md5.js.html +++ b/doc/md5.js.html @@ -239,13 +239,13 @@ return (msw << 16) | (lsw & 0xFFFF);
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.cfb.js.html b/doc/openpgp.cfb.js.html index f9613e13..4168f6ad 100644 --- a/doc/openpgp.cfb.js.html +++ b/doc/openpgp.cfb.js.html @@ -325,13 +325,13 @@ function normal_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext, i
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.config.js.html b/doc/openpgp.config.js.html index 8c29fc92..ab45e671 100644 --- a/doc/openpgp.config.js.html +++ b/doc/openpgp.config.js.html @@ -125,13 +125,13 @@ function openpgp_config() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.crypto.js.html b/doc/openpgp.crypto.js.html index 3a6d889e..5b9f6d2a 100644 --- a/doc/openpgp.crypto.js.html +++ b/doc/openpgp.crypto.js.html @@ -465,13 +465,13 @@ function openpgp_crypto_generateKeyPair(keyType, numBits, passphrase, s2kHash, s
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.crypto.sym.js.html b/doc/openpgp.crypto.sym.js.html index 8f3018b4..fc99bbf1 100644 --- a/doc/openpgp.crypto.sym.js.html +++ b/doc/openpgp.crypto.sym.js.html @@ -129,13 +129,13 @@ function openpgp_crypto_symmetricDecrypt(algo, key, data, openpgp_cfb) {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.encoding.asciiarmor.js.html b/doc/openpgp.encoding.asciiarmor.js.html index 126f6b54..38240459 100644 --- a/doc/openpgp.encoding.asciiarmor.js.html +++ b/doc/openpgp.encoding.asciiarmor.js.html @@ -281,13 +281,13 @@ function createcrc24(input) {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.encoding.js.html b/doc/openpgp.encoding.js.html index a71a2c54..639b1a5a 100644 --- a/doc/openpgp.encoding.js.html +++ b/doc/openpgp.encoding.js.html @@ -176,13 +176,13 @@ function openpgp_encoding_emsa_pkcs1_decode(algo, data) {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.html b/doc/openpgp.html index f5e389de..7d2e1e47 100644 --- a/doc/openpgp.html +++ b/doc/openpgp.html @@ -129,7 +129,7 @@ from the beginning. To use this library call "openpgp.init()"
-

<inner> generate_key_pair(keyType, numBits, userId) → {Object}

+

<inner> generate_key_pair(keyType, numBits, userId, passphrase) → {Object}

@@ -241,6 +241,29 @@ be 1024+, generally) + + + + passphrase + + + + + +String + + + + + + + + + + The passphrase used to encrypt the resulting private key + + + @@ -268,7 +291,7 @@ be 1024+, generally)
Source:
@@ -1493,13 +1516,13 @@ This can be directly used to OpenPGP armor the message
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:34 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp.js.html b/doc/openpgp.js.html index 3e3183b2..604aadf2 100644 --- a/doc/openpgp.js.html +++ b/doc/openpgp.js.html @@ -441,6 +441,7 @@ function _openpgp () { * be 1024+, generally) * @param {String} userId assumes already in form of "User Name * <username@email.com>" + * @param {String} passphrase The passphrase used to encrypt the resulting private key * @return {Object} {privateKey: [openpgp_msg_privatekey], * privateKeyArmored: [string], publicKeyArmored: [string]} */ @@ -495,13 +496,13 @@ var openpgp = new _openpgp();
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.keyring.js.html b/doc/openpgp.keyring.js.html index 166dd126..01887845 100644 --- a/doc/openpgp.keyring.js.html +++ b/doc/openpgp.keyring.js.html @@ -299,13 +299,13 @@ function openpgp_keyring() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.msg.message.js.html b/doc/openpgp.msg.message.js.html index b7cd857a..485d0f8c 100644 --- a/doc/openpgp.msg.message.js.html +++ b/doc/openpgp.msg.message.js.html @@ -171,13 +171,13 @@ function openpgp_msg_message() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.msg.privatekey.js.html b/doc/openpgp.msg.privatekey.js.html index 508fe737..9e206dc6 100644 --- a/doc/openpgp.msg.privatekey.js.html +++ b/doc/openpgp.msg.privatekey.js.html @@ -226,13 +226,13 @@ function openpgp_msg_privatekey() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.msg.publickey.js.html b/doc/openpgp.msg.publickey.js.html index 9417250f..9a443b53 100644 --- a/doc/openpgp.msg.publickey.js.html +++ b/doc/openpgp.msg.publickey.js.html @@ -303,13 +303,13 @@ function openpgp_msg_publickey() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.compressed.js.html b/doc/openpgp.packet.compressed.js.html index 618e9812..c04bb85b 100644 --- a/doc/openpgp.packet.compressed.js.html +++ b/doc/openpgp.packet.compressed.js.html @@ -199,13 +199,13 @@ function openpgp_packet_compressed() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.encrypteddata.js.html b/doc/openpgp.packet.encrypteddata.js.html index 4041b4d6..e856fec6 100644 --- a/doc/openpgp.packet.encrypteddata.js.html +++ b/doc/openpgp.packet.encrypteddata.js.html @@ -134,13 +134,13 @@ function openpgp_packet_encrypteddata() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.encryptedintegrityprotecteddata.js.html b/doc/openpgp.packet.encryptedintegrityprotecteddata.js.html index e994f548..fde850f2 100644 --- a/doc/openpgp.packet.encryptedintegrityprotecteddata.js.html +++ b/doc/openpgp.packet.encryptedintegrityprotecteddata.js.html @@ -190,13 +190,13 @@ function openpgp_packet_encryptedintegrityprotecteddata() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.encryptedsessionkey.js.html b/doc/openpgp.packet.encryptedsessionkey.js.html index 38d36d77..ccca42d7 100644 --- a/doc/openpgp.packet.encryptedsessionkey.js.html +++ b/doc/openpgp.packet.encryptedsessionkey.js.html @@ -261,13 +261,13 @@ function openpgp_packet_encryptedsessionkey() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.js.html b/doc/openpgp.packet.js.html index e72d44f0..5ee604af 100644 --- a/doc/openpgp.packet.js.html +++ b/doc/openpgp.packet.js.html @@ -442,13 +442,13 @@ var openpgp_packet = new _openpgp_packet();
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:32 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.keymaterial.js.html b/doc/openpgp.packet.keymaterial.js.html index 9c0e6e5a..8bc37c1d 100644 --- a/doc/openpgp.packet.keymaterial.js.html +++ b/doc/openpgp.packet.keymaterial.js.html @@ -854,13 +854,13 @@ function openpgp_packet_keymaterial() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.literaldata.js.html b/doc/openpgp.packet.literaldata.js.html index 01f9a199..1605c031 100644 --- a/doc/openpgp.packet.literaldata.js.html +++ b/doc/openpgp.packet.literaldata.js.html @@ -52,6 +52,47 @@ function openpgp_packet_literaldata() { 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). * @@ -63,17 +104,22 @@ function openpgp_packet_literaldata() { * input at position * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { + this.read_packet = function(input, position, len) { this.packetLength = len; // - A one-octet field that describes how the data is formatted. - this.format = input[position]; - this.filename = input.substr(position + 2, input - .charCodeAt(position + 1)); + var format = input[position]; + + this.filename = util.decode_utf8(input.substr(position + 2, input + .charCodeAt(position + 1))); + this.date = new Date(parseInt(input.substr(position + 2 + input.charCodeAt(position + 1), 4)) * 1000); - this.data = input.substring(position + 6 + + var bytes = input.substring(position + 6 + input.charCodeAt(position + 1)); + + this.set_data_bytes(bytes, format); return this; } @@ -83,11 +129,13 @@ function openpgp_packet_literaldata() { * @param {String} data The data to be inserted as body * @return {String} string-representation of the packet */ - function write_packet(data) { - data = data.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n"); - this.filename = "msg.txt"; + this.write_packet = function(data) { + this.set_data(data, openpgp_packet_literaldata.formats.utf8); + this.filename = util.encode_utf8("msg.txt"); this.date = new Date(); - this.format = 't'; + + data = this.get_data_bytes(); + var result = openpgp_packet.write_packet_header(11, data.length + 6 + this.filename.length); result += this.format; @@ -102,7 +150,6 @@ function openpgp_packet_literaldata() { result += String .fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF); result += data; - this.data = data; return result; } @@ -111,18 +158,28 @@ function openpgp_packet_literaldata() { * * @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: ' + this.packetLength + '\n' + ' format: ' + this.format + '\n' + ' filename:' + this.filename + '\n' + ' date: ' + this.date + '\n' + ' data: |' + 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' +}; @@ -133,13 +190,13 @@ function openpgp_packet_literaldata() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.marker.js.html b/doc/openpgp.packet.marker.js.html index 532e5f43..42792782 100644 --- a/doc/openpgp.packet.marker.js.html +++ b/doc/openpgp.packet.marker.js.html @@ -100,13 +100,13 @@ function openpgp_packet_marker() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.modificationdetectioncode.js.html b/doc/openpgp.packet.modificationdetectioncode.js.html index 7704a34e..dbf74c06 100644 --- a/doc/openpgp.packet.modificationdetectioncode.js.html +++ b/doc/openpgp.packet.modificationdetectioncode.js.html @@ -114,13 +114,13 @@ function openpgp_packet_modificationdetectioncode() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.onepasssignature.js.html b/doc/openpgp.packet.onepasssignature.js.html index 0a0a6e80..6bf60d8a 100644 --- a/doc/openpgp.packet.onepasssignature.js.html +++ b/doc/openpgp.packet.onepasssignature.js.html @@ -154,13 +154,13 @@ function openpgp_packet_onepasssignature() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.signature.js.html b/doc/openpgp.packet.signature.js.html index 1eb3d54a..4f739881 100644 --- a/doc/openpgp.packet.signature.js.html +++ b/doc/openpgp.packet.signature.js.html @@ -764,13 +764,13 @@ function openpgp_packet_signature() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.userattribute.js.html b/doc/openpgp.packet.userattribute.js.html index 7f9cc23d..b89c712c 100644 --- a/doc/openpgp.packet.userattribute.js.html +++ b/doc/openpgp.packet.userattribute.js.html @@ -190,13 +190,13 @@ function openpgp_packet_userattribute() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/openpgp.packet.userid.js.html b/doc/openpgp.packet.userid.js.html index fa8c072a..79d56e55 100644 --- a/doc/openpgp.packet.userid.js.html +++ b/doc/openpgp.packet.userid.js.html @@ -53,38 +53,71 @@ */ function openpgp_packet_userid() { + this.text = '' this.tagType = 13; this.certificationSignatures = new Array(); this.certificationRevocationSignatures = new Array(); this.revocationSignatures = new Array(); 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 {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 * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { - this.text = ''; + this.read_packet = function(input, position, len) { this.packetLength = len; + var bytes = ''; for ( var i = 0; i < len; i++) { - this.text += input[position + i]; + bytes += input[position + i]; } + + this.set_text_bytes(bytes); 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") * @return {String} string representation */ - function write_packet(user_id) { - this.text = user_id; - var result = openpgp_packet.write_packet_header(13,this.text.length); - result += this.text; + this.write_packet = function(user_id) { + this.set_text(user_id); + var bytes = this.get_text_bytes(); + + var result = openpgp_packet.write_packet_header(13, bytes.length); + result += bytes; return result; } @@ -96,7 +129,7 @@ function openpgp_packet_userid() { * @param {Integer} len length of the packet(s) or remaining length of input * @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 this.parentNode = parent_node; var pos = position; @@ -176,7 +209,7 @@ function openpgp_packet_userid() { * generates debug output (pretty print) * @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 (' + this.text.length + '): "' + this.text.replace("<", "<") + '"\n'; @@ -196,7 +229,7 @@ function openpgp_packet_userid() { * @param {String} keyId string containing the key id of the issuer of this signature * @return a CertificationRevocationSignature if found; otherwise null */ - function hasCertificationRevocationSignature(keyId) { + this.hasCertificationRevocationSignature = function(keyId) { for (var i = 0; i < this.certificationRevocationSignatures.length; i++) { if ((this.certificationRevocationSignatures[i].version == 3 && this.certificationRevocationSignatures[i].keyId == keyId) || @@ -219,7 +252,8 @@ function openpgp_packet_userid() { * 5 = signature by key owner expired * 6 = signature by key owner revoked */ - function verifyCertificationSignatures(publicKeyPacket) { + this.verifyCertificationSignatures = function(publicKeyPacket) { + var bytes = this.get_text_bytes(); result = new Array(); for (var i = 0 ; i < this.certificationSignatures.length; i++) { // A certification signature (type 0x10 through 0x13) hashes the User @@ -262,13 +296,14 @@ function openpgp_packet_userid() { var revocation = this.hasCertificationRevocationSignature(this.certificationSignatures[i].issuerKeyId); if (revocation != null && revocation.creationTime > this.certificationSignatures[i].creationTime) { + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (revocation.verify(signaturedata, signingKey)) { if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -277,13 +312,14 @@ function openpgp_packet_userid() { continue; } } + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -308,7 +344,7 @@ function openpgp_packet_userid() { if (revocation != null && revocation.creationTime > this.certificationSignatures[i].creationTime) { 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.keyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -318,7 +354,7 @@ function openpgp_packet_userid() { } } var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ - publicKeyPacket.data+this.text; + publicKeyPacket.data + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -334,7 +370,7 @@ function openpgp_packet_userid() { * verifies the signatures of the user id * @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); if (result.indexOf(6) != -1) return 2; @@ -344,22 +380,14 @@ function openpgp_packet_userid() { } // TODO: implementation missing - function addCertification(publicKeyPacket, privateKeyPacket) { + this.addCertification = function(publicKeyPacket, privateKeyPacket) { } // 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; } @@ -371,13 +399,13 @@ function openpgp_packet_userid() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/openpgp.type.keyid.js.html b/doc/openpgp.type.keyid.js.html index 097a6c4a..318f9958 100644 --- a/doc/openpgp.type.keyid.js.html +++ b/doc/openpgp.type.keyid.js.html @@ -84,13 +84,13 @@ function openpgp_type_keyid() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/openpgp.type.mpi.js.html b/doc/openpgp.type.mpi.js.html index d2ba414e..5f5a3b5e 100644 --- a/doc/openpgp.type.mpi.js.html +++ b/doc/openpgp.type.mpi.js.html @@ -170,13 +170,13 @@ function openpgp_type_mpi() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/openpgp.type.s2k.js.html b/doc/openpgp.type.s2k.js.html index ab0d4894..f9bceead 100644 --- a/doc/openpgp.type.s2k.js.html +++ b/doc/openpgp.type.s2k.js.html @@ -141,6 +141,7 @@ function openpgp_type_s2k() { * hashAlgorithm hash length */ function produce_key(passphrase, numBytes) { + passphrase = util.encode_utf8(passphrase); if (this.type == 0) { return openpgp_crypto_hashData(this.hashAlgorithm,passphrase); } else if (this.type == 1) { @@ -175,13 +176,13 @@ function openpgp_type_s2k() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/openpgp_config.html b/doc/openpgp_config.html index b831a797..425b6ffd 100644 --- a/doc/openpgp_config.html +++ b/doc/openpgp_config.html @@ -660,13 +660,13 @@ if config is null the default config will be used
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:34 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_keyring.html b/doc/openpgp_keyring.html index e577d36b..f04414da 100644 --- a/doc/openpgp_keyring.html +++ b/doc/openpgp_keyring.html @@ -1715,13 +1715,13 @@ The privateKeys array and publicKeys array gets Stringified using JSON
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:34 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_msg_message.html b/doc/openpgp_msg_message.html index cdf458d9..7ad75c13 100644 --- a/doc/openpgp_msg_message.html +++ b/doc/openpgp_msg_message.html @@ -625,13 +625,13 @@ MDC will be verified as well as message signatures
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_msg_privatekey.html b/doc/openpgp_msg_privatekey.html index 55edc36e..c101f5d3 100644 --- a/doc/openpgp_msg_privatekey.html +++ b/doc/openpgp_msg_privatekey.html @@ -304,13 +304,13 @@
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_msg_publickey.html b/doc/openpgp_msg_publickey.html index 3c5fe904..29d0c7ca 100644 --- a/doc/openpgp_msg_publickey.html +++ b/doc/openpgp_msg_publickey.html @@ -466,13 +466,13 @@
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_compressed.html b/doc/openpgp_packet_compressed.html index 251d24b3..f9d2688a 100644 --- a/doc/openpgp_packet_compressed.html +++ b/doc/openpgp_packet_compressed.html @@ -832,13 +832,13 @@ input at position
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:41 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_encrypteddata.html b/doc/openpgp_packet_encrypteddata.html index 60049e41..beaabb3e 100644 --- a/doc/openpgp_packet_encrypteddata.html +++ b/doc/openpgp_packet_encrypteddata.html @@ -666,13 +666,13 @@ that form whole OpenPGP messages).
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_encryptedintegrityprotecteddata.html b/doc/openpgp_packet_encryptedintegrityprotecteddata.html index 6711c584..2d031cf8 100644 --- a/doc/openpgp_packet_encryptedintegrityprotecteddata.html +++ b/doc/openpgp_packet_encryptedintegrityprotecteddata.html @@ -680,13 +680,13 @@ Data Packet (tag 18) (see RFC4880 5.13)
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_encryptedsessionkey.html b/doc/openpgp_packet_encryptedsessionkey.html index 1f3076ae..bbea283e 100644 --- a/doc/openpgp_packet_encryptedsessionkey.html +++ b/doc/openpgp_packet_encryptedsessionkey.html @@ -1010,13 +1010,13 @@ purposes)
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_keymaterial.html b/doc/openpgp_packet_keymaterial.html index c9f16cf7..e1e57dfc 100644 --- a/doc/openpgp_packet_keymaterial.html +++ b/doc/openpgp_packet_keymaterial.html @@ -1945,13 +1945,13 @@ and initializes the openpgp_packet_keymaterial
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_literaldata.html b/doc/openpgp_packet_literaldata.html index 5478d758..d9ecab7f 100644 --- a/doc/openpgp_packet_literaldata.html +++ b/doc/openpgp_packet_literaldata.html @@ -120,6 +120,179 @@ is not to be further interpreted. +

Members

+ +
+ +
+

<static, readonly> formats :String

+ + +
+
+ +
+ Data types in the literal packet +
+ + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
binary + + +String + + + + + + b + + Binary data
text + + +String + + + + + + t + + Text data
utf8 + + +String + + + + + + u + + Utf8 data
+ + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
+ +
+

Methods

@@ -127,7 +300,98 @@ is not to be further interpreted.
-

<inner> read_packet(input, position, len) → {openpgp_packet_encrypteddata}

+

get_data_bytes() → {String}

+ + +
+
+ + +
+ Get the byte sequence representing the literal packet data +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+ A sequence of bytes +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + +
+ + + +
+

read_packet(input, position, len) → {openpgp_packet_encrypteddata}

@@ -263,7 +527,7 @@ is not to be further interpreted.
Source:
@@ -313,7 +577,290 @@ is not to be further interpreted.
-

<inner> toString() → {String}

+

set_data(str, format)

+ + +
+
+ + +
+ 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. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + + Any native javascript string
format + + +openpgp_packet_literaldata.formats + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
+ + + +
+

set_data_bytes(bytes, format)

+ + +
+
+ + +
+ Set the packet data to value represented by the provided string +of bytes together with the appropriate conversion format. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bytes + + +String + + + + The string of bytes
format + + +openpgp_packet_literaldata.formats + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
+ + + +
+

toString() → {String}

@@ -354,7 +901,7 @@ is not to be further interpreted.
Source:
@@ -404,7 +951,7 @@ is not to be further interpreted.
-

<inner> write_packet(data) → {String}

+

write_packet(data) → {String}

@@ -493,7 +1040,7 @@ is not to be further interpreted.
Source:
@@ -556,13 +1103,13 @@ is not to be further interpreted.
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_marker.html b/doc/openpgp_packet_marker.html index 4bd2a4e2..2fbb446a 100644 --- a/doc/openpgp_packet_marker.html +++ b/doc/openpgp_packet_marker.html @@ -422,13 +422,13 @@ keymaterial
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_modificationdetectioncode.html b/doc/openpgp_packet_modificationdetectioncode.html index 3eaddaea..3f61f837 100644 --- a/doc/openpgp_packet_modificationdetectioncode.html +++ b/doc/openpgp_packet_modificationdetectioncode.html @@ -422,13 +422,13 @@ modification detection code
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_onepasssignature.html b/doc/openpgp_packet_onepasssignature.html index e5be7319..7e4104d3 100644 --- a/doc/openpgp_packet_onepasssignature.html +++ b/doc/openpgp_packet_onepasssignature.html @@ -653,13 +653,13 @@ can compute the entire signed message in one pass.
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:35 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_signature.html b/doc/openpgp_packet_signature.html index 61d62fb2..f35ddf99 100644 --- a/doc/openpgp_packet_signature.html +++ b/doc/openpgp_packet_signature.html @@ -1110,13 +1110,13 @@ This can be only used on text data
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_userattribute.html b/doc/openpgp_packet_userattribute.html index 50b06340..34b6e68f 100644 --- a/doc/openpgp_packet_userattribute.html +++ b/doc/openpgp_packet_userattribute.html @@ -634,13 +634,13 @@
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_packet_userid.html b/doc/openpgp_packet_userid.html index cfdc374d..ee95ebcb 100644 --- a/doc/openpgp_packet_userid.html +++ b/doc/openpgp_packet_userid.html @@ -129,7 +129,98 @@ specifies the length of the User ID.
-

<inner> hasCertificationRevocationSignature(keyId)

+

get_text_bytes() → {String}

+ + +
+
+ + +
+ Get the byte sequence representing the text of this packet. +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+ A sequence of bytes +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + +
+ + + +
+

hasCertificationRevocationSignature(keyId)

@@ -218,7 +309,7 @@ specifies the length of the User ID.
Source:
@@ -256,7 +347,7 @@ specifies the length of the User ID.
-

<inner> read_nodes(parent_node, input, position, len) → {Integer}

+

read_nodes(parent_node, input, position, len) → {Integer}

@@ -414,7 +505,7 @@ specifies the length of the User ID.
Source:
@@ -464,7 +555,7 @@ specifies the length of the User ID.
-

<inner> read_packet(input, position, len) → {openpgp_packet_encrypteddata}

+

read_packet(input, position, len) → {openpgp_packet_encrypteddata}

@@ -472,7 +563,7 @@ specifies the length of the User ID.
- parsing function for a user id packet (tag 13). + Parsing function for a user id packet (tag 13).
@@ -599,7 +690,7 @@ specifies the length of the User ID.
Source:
@@ -649,7 +740,244 @@ specifies the length of the User ID.
-

<inner> toString() → {String}

+

set_text(str)

+ + +
+
+ + +
+ Set the packet text field to a native javascript string +Conversion to a proper utf8 encoding takes place when the +packet is written. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + + Any native javascript string
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
+ + + +
+

set_text_bytes(bytes)

+ + +
+
+ + +
+ Set the packet text to value represented by the provided string +of bytes. +
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bytes + + +String + + + + A string of bytes
+ + + +
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
+ + + +
+

toString() → {String}

@@ -690,7 +1018,7 @@ specifies the length of the User ID.
Source:
@@ -740,7 +1068,7 @@ specifies the length of the User ID.
-

<inner> verify()

+

verify()

@@ -781,7 +1109,7 @@ specifies the length of the User ID.
Source:
@@ -819,7 +1147,7 @@ specifies the length of the User ID.
-

<inner> verifyCertificationSignatures(publicKeyPacket) → {Integer[]}

+

verifyCertificationSignatures(publicKeyPacket) → {Integer[]}

@@ -908,7 +1236,7 @@ specifies the length of the User ID.
Source:
@@ -965,7 +1293,7 @@ specifies the length of the User ID.
-

<inner> write_packet(user_id) → {String}

+

write_packet(user_id) → {String}

@@ -973,7 +1301,7 @@ specifies the length of the User ID.
- creates a string representation of the user id packet + Creates a string representation of the user id packet
@@ -1054,7 +1382,7 @@ specifies the length of the User ID.
Source:
@@ -1117,13 +1445,13 @@ specifies the length of the User ID.
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:42 GMT+0200 (CEST)
diff --git a/doc/openpgp_type_keyid.html b/doc/openpgp_type_keyid.html index f2edcc5e..63cc1821 100644 --- a/doc/openpgp_type_keyid.html +++ b/doc/openpgp_type_keyid.html @@ -395,13 +395,13 @@ id from input
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:43 GMT+0200 (CEST)
diff --git a/doc/openpgp_type_mpi.html b/doc/openpgp_type_mpi.html index 72a53519..9c781cc1 100644 --- a/doc/openpgp_type_mpi.html +++ b/doc/openpgp_type_mpi.html @@ -817,13 +817,13 @@ input at position
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:43 GMT+0200 (CEST)
diff --git a/doc/openpgp_type_s2k.html b/doc/openpgp_type_s2k.html index a353ec02..2a553c0f 100644 --- a/doc/openpgp_type_s2k.html +++ b/doc/openpgp_type_s2k.html @@ -536,13 +536,13 @@ hashAlgorithm hash length
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:36 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:43 GMT+0200 (CEST)
diff --git a/doc/rsa.js.html b/doc/rsa.js.html index 5c07d159..78ffbd27 100644 --- a/doc/rsa.js.html +++ b/doc/rsa.js.html @@ -170,13 +170,13 @@ function RSA() {
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:40 GMT+0200 (CEST)
diff --git a/doc/util.js.html b/doc/util.js.html index cb8575a1..d90e97b1 100644 --- a/doc/util.js.html +++ b/doc/util.js.html @@ -112,45 +112,68 @@ var Util = function() { } 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) * @param {String} str String to convert * @return {Integer[]} An array of (binary) integers */ - this.str2bin = function(str) { - var result = new Array(); - for (var i = 0; i < str.length; i++) { - result[i] = str.charCodeAt(i); - } - - return result; + this.str2bin = function(str) { + return str2bin(str, new Array(str.length)); }; - + + /** * Convert an array of integers(0.255) to a string * @param {Integer[]} bin An array of (binary) integers to convert * @return {String} The string representation of the array */ - this.bin2str = function(bin) { - var result = []; - for (var i = 0; i < bin.length; i++) { - result.push(String.fromCharCode(bin[i])); - } - return result.join(''); - }; + this.bin2str = bin2str; /** * Convert a string to a Uint8Array * @param {String} str String to convert * @return {Uint8Array} The array of (binary) integers */ - this.str2Uint8Array = function(str){ - var uintArray = new Uint8Array(new ArrayBuffer(str.length)); - for(var n = 0; n < str.length; n++){ - uintArray[n] = str.charCodeAt(n); - } - return uintArray; + this.str2Uint8Array = function(str) { + return str2bin(str, new Uint8Array(new ArrayBuffer(str.length))); }; /** @@ -159,13 +182,7 @@ var Util = function() { * @param {Uint8Array} bin An array of (binary) integers to convert * @return {String} String representation of the array */ - this.Uint8Array2str = function(bin) { - var result = []; - for(n = 0; n< bin.length; n++){ - result[n] = String.fromCharCode(bin[n]); - } - return result.join(''); - }; + this.Uint8Array2str = bin2str; /** * Calculates a 16bit sum of a string by adding each character @@ -322,13 +339,13 @@ var util = new Util();
- Documentation generated by JSDoc 3.2.0-dev on Fri Apr 12 2013 14:20:33 GMT+0200 (CEST) + Documentation generated by JSDoc 3.2.0-dev on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
diff --git a/resources/openpgp.js b/resources/openpgp.js index 941635f3..25736fd6 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -7383,7 +7383,7 @@ function openpgp_config() { 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"; /** * Reads the config out of the HTML5 local storage @@ -8294,6 +8294,7 @@ function _openpgp () { * be 1024+, generally) * @param {String} userId assumes already in form of "User Name * " + * @param {String} passphrase The passphrase used to encrypt the resulting private key * @return {Object} {privateKey: [openpgp_msg_privatekey], * privateKeyArmored: [string], publicKeyArmored: [string]} */ @@ -11094,6 +11095,47 @@ function openpgp_packet_keymaterial() { function openpgp_packet_literaldata() { 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). * @@ -11105,17 +11147,22 @@ function openpgp_packet_literaldata() { * input at position * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { + this.read_packet = function(input, position, len) { this.packetLength = len; // - A one-octet field that describes how the data is formatted. - this.format = input[position]; - this.filename = input.substr(position + 2, input - .charCodeAt(position + 1)); + var format = input[position]; + + this.filename = util.decode_utf8(input.substr(position + 2, input + .charCodeAt(position + 1))); + this.date = new Date(parseInt(input.substr(position + 2 + input.charCodeAt(position + 1), 4)) * 1000); - this.data = input.substring(position + 6 + + var bytes = input.substring(position + 6 + input.charCodeAt(position + 1)); + + this.set_data_bytes(bytes, format); return this; } @@ -11125,11 +11172,13 @@ function openpgp_packet_literaldata() { * @param {String} data The data to be inserted as body * @return {String} string-representation of the packet */ - function write_packet(data) { - data = data.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n"); - this.filename = "msg.txt"; + this.write_packet = function(data) { + this.set_data(data, this.formats.utf8); + this.filename = util.encode_utf8("msg.txt"); this.date = new Date(); - this.format = 't'; + + data = this.get_data_bytes(); + var result = openpgp_packet.write_packet_header(11, data.length + 6 + this.filename.length); result += this.format; @@ -11144,7 +11193,6 @@ function openpgp_packet_literaldata() { result += String .fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF); result += data; - this.data = data; return result; } @@ -11153,18 +11201,28 @@ function openpgp_packet_literaldata() { * * @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: ' + this.packetLength + '\n' + ' format: ' + this.format + '\n' + ' filename:' + this.filename + '\n' + ' date: ' + this.date + '\n' + ' data: |' + 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 // Copyright (C) 2011 Recurity Labs GmbH // @@ -12340,38 +12398,71 @@ function openpgp_packet_userattribute() { */ function openpgp_packet_userid() { + this.text = '' this.tagType = 13; this.certificationSignatures = new Array(); this.certificationRevocationSignatures = new Array(); this.revocationSignatures = new Array(); 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 {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 * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { - this.text = ''; + this.read_packet = function(input, position, len) { this.packetLength = len; + var bytes = ''; for ( var i = 0; i < len; i++) { - this.text += input[position + i]; + bytes += input[position + i]; } + + this.set_text_bytes(bytes); 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 this.certificationSignatures[i].creationTime) { + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (revocation.verify(signaturedata, signingKey)) { if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -12564,13 +12657,14 @@ function openpgp_packet_userid() { continue; } } + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -12595,7 +12689,7 @@ function openpgp_packet_userid() { if (revocation != null && revocation.creationTime > this.certificationSignatures[i].creationTime) { 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.keyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -12605,7 +12699,7 @@ function openpgp_packet_userid() { } } var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ - publicKeyPacket.data+this.text; + publicKeyPacket.data + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -12621,7 +12715,7 @@ function openpgp_packet_userid() { * verifies the signatures of the user id * @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); if (result.indexOf(6) != -1) return 2; @@ -12631,22 +12725,14 @@ function openpgp_packet_userid() { } // TODO: implementation missing - function addCertification(publicKeyPacket, privateKeyPacket) { + this.addCertification = function(publicKeyPacket, privateKeyPacket) { } // 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 // Copyright (C) 2011 Recurity Labs GmbH @@ -12948,6 +13034,7 @@ function openpgp_type_s2k() { * hashAlgorithm hash length */ function produce_key(passphrase, numBytes) { + passphrase = util.encode_utf8(passphrase); if (this.type == 0) { return openpgp_crypto_hashData(this.hashAlgorithm,passphrase); } else if (this.type == 1) { @@ -13059,45 +13146,68 @@ var Util = function() { } 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) * @param {String} str String to convert * @return {Integer[]} An array of (binary) integers */ - this.str2bin = function(str) { - var result = new Array(); - for (var i = 0; i < str.length; i++) { - result[i] = str.charCodeAt(i); - } - - return result; + this.str2bin = function(str) { + return str2bin(str, new Array(str.length)); }; - + + /** * Convert an array of integers(0.255) to a string * @param {Integer[]} bin An array of (binary) integers to convert * @return {String} The string representation of the array */ - this.bin2str = function(bin) { - var result = []; - for (var i = 0; i < bin.length; i++) { - result.push(String.fromCharCode(bin[i])); - } - return result.join(''); - }; + this.bin2str = bin2str; /** * Convert a string to a Uint8Array * @param {String} str String to convert * @return {Uint8Array} The array of (binary) integers */ - this.str2Uint8Array = function(str){ - var uintArray = new Uint8Array(new ArrayBuffer(str.length)); - for(var n = 0; n < str.length; n++){ - uintArray[n] = str.charCodeAt(n); - } - return uintArray; + this.str2Uint8Array = function(str) { + return str2bin(str, new Uint8Array(new ArrayBuffer(str.length))); }; /** @@ -13106,13 +13216,7 @@ var Util = function() { * @param {Uint8Array} bin An array of (binary) integers to convert * @return {String} String representation of the array */ - this.Uint8Array2str = function(bin) { - var result = []; - for(n = 0; n< bin.length; n++){ - result[n] = String.fromCharCode(bin[n]); - } - return result.join(''); - }; + this.Uint8Array2str = bin2str; /** * Calculates a 16bit sum of a string by adding each character diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index 8402d094..0f1cf459 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -285,7 +285,7 @@ JXG.Util.asciiCharCodeAt=function(b,a){var c=b.charCodeAt(a);if(255d?(a.push(String.fromCharCode(d)),c++):191d?(e=b.charCodeAt(c+1),a.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=b.charCodeAt(c+1),f=b.charCodeAt(c+2),a.push(String.fromCharCode((d&15)<<12|(e&63)<<6|f&63)),c+=3);return a.join("")}; JXG.Util.genUUID=function(){for(var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),a=Array(36),c=0,d,e=0;36>e;e++)8==e||13==e||18==e||23==e?a[e]="-":14==e?a[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,a[e]=b[19==e?d&3|8:d]);return a.join("")}; -function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm: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>2&63),a=(c&3)<<4):1==g?(e+=b64s.charAt(a|c>>4&15),a=(c&15)<<2):2==g&&(e+=b64s.charAt(a|c>>6&3),f+=1,0==f%60&&(e+="\n"),e+=b64s.charAt(c&63)),f+=1,0==f%60&&(e+="\n"),g+=1,3==g&&(g=0);0>6-e&255)),e=e+2&7,f=a<>24&255),a=a+String.fromCharCode(Math.round(this.date.getTime()/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);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'}} +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.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)>>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_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): @@ -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 @:"+ e+" l:"+f);break}else switch(g.tagType){case 2:15g.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;athis.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)+ -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(), -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.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;dg.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+ -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:15g.signatureType?this.certificationSignatures[this.certificationSignatures.length]= -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)}} +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;eg.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+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:15g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=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)};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;athis.certificationSignatures[c].creationTime){var 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>>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>> +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> +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), 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+ 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).lengththis.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, -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;de.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;de.length;)e= -"0"+e;a.push(""+e)}return a.join("")};this.hex2bin=function(b){for(var a="",c=0;ce.length;)e="0"+e;a.push(""+e)}return a.join("")};this.str2bin=function(b){for(var a=[],c=0;c

'+ -b.replace(/\n/g,"
")+"

"))};this.print_debug_hexstr_dump=function(b,a){openpgp.config.debug&&(b+=this.hexstrdump(a),b=openpgp_encoding_html_encode(b),showMessages('

'+b.replace(/\n/g,"
")+"

"))};this.print_error=function(b){b=openpgp_encoding_html_encode(b);showMessages('

ERROR:\t'+ -b.replace(/\n/g,"
")+"

")};this.print_info=function(b){b=openpgp_encoding_html_encode(b);showMessages('

INFO:\t'+b.replace(/\n/g,"
")+"

")};this.print_warning=function(b){b=openpgp_encoding_html_encode(b);showMessages('

WARNING:\t'+ -b.replace(/\n/g,"
")+"

")};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,0this.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,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(a){for(var b=[],e=a.length,f=0,g,h=0;fg.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;fg.length;)g= +"0"+g;b.push(""+g)}return b.join("")};this.hex2bin=function(a){for(var b="",e=0;eg.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.replace(/\n/g,"
")+"

"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('

'+a.replace(/\n/g,"
")+"

"))};this.print_error= +function(a){a=openpgp_encoding_html_encode(a);showMessages('

ERROR:\t'+a.replace(/\n/g,"
")+"

")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('

INFO:\t'+ +a.replace(/\n/g,"
")+"

")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('

WARNING:\t'+a.replace(/\n/g,"
")+"

")};this.getLeftNBits=function(a,b){var e=b%8;return 0==e?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-e)/8+1),8-e)};this.shiftRight=function(a,b){var e= +util.str2bin(a);if(0!=b%8)for(var f=e.length-1;0<=f;f--)e[f]>>=b%8,0" + * @param {String} passphrase The passphrase used to encrypt the resulting private key * @return {Object} {privateKey: [openpgp_msg_privatekey], * privateKeyArmored: [string], publicKeyArmored: [string]} */ diff --git a/src/packet/openpgp.packet.literaldata.js b/src/packet/openpgp.packet.literaldata.js index 1deaa88e..4dfecd19 100644 --- a/src/packet/openpgp.packet.literaldata.js +++ b/src/packet/openpgp.packet.literaldata.js @@ -25,6 +25,47 @@ function openpgp_packet_literaldata() { 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). * @@ -36,17 +77,22 @@ function openpgp_packet_literaldata() { * input at position * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { + this.read_packet = function(input, position, len) { this.packetLength = len; // - A one-octet field that describes how the data is formatted. - this.format = input[position]; - this.filename = input.substr(position + 2, input - .charCodeAt(position + 1)); + var format = input[position]; + + this.filename = util.decode_utf8(input.substr(position + 2, input + .charCodeAt(position + 1))); + this.date = new Date(parseInt(input.substr(position + 2 + input.charCodeAt(position + 1), 4)) * 1000); - this.data = input.substring(position + 6 + + var bytes = input.substring(position + 6 + input.charCodeAt(position + 1)); + + this.set_data_bytes(bytes, format); return this; } @@ -56,11 +102,13 @@ function openpgp_packet_literaldata() { * @param {String} data The data to be inserted as body * @return {String} string-representation of the packet */ - function write_packet(data) { - data = data.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n"); - this.filename = "msg.txt"; + this.write_packet = function(data) { + this.set_data(data, openpgp_packet_literaldata.formats.utf8); + this.filename = util.encode_utf8("msg.txt"); this.date = new Date(); - this.format = 't'; + + data = this.get_data_bytes(); + var result = openpgp_packet.write_packet_header(11, data.length + 6 + this.filename.length); result += this.format; @@ -75,7 +123,6 @@ function openpgp_packet_literaldata() { result += String .fromCharCode(Math.round(this.date.getTime() / 1000) & 0xFF); result += data; - this.data = data; return result; } @@ -84,15 +131,25 @@ function openpgp_packet_literaldata() { * * @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: ' + this.packetLength + '\n' + ' format: ' + this.format + '\n' + ' filename:' + this.filename + '\n' + ' date: ' + this.date + '\n' + ' data: |' + 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' +}; diff --git a/src/packet/openpgp.packet.userid.js b/src/packet/openpgp.packet.userid.js index e7a0b7aa..dadab892 100644 --- a/src/packet/openpgp.packet.userid.js +++ b/src/packet/openpgp.packet.userid.js @@ -26,38 +26,71 @@ */ function openpgp_packet_userid() { + this.text = '' this.tagType = 13; this.certificationSignatures = new Array(); this.certificationRevocationSignatures = new Array(); this.revocationSignatures = new Array(); 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 {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 * @return {openpgp_packet_encrypteddata} object representation */ - function read_packet(input, position, len) { - this.text = ''; + this.read_packet = function(input, position, len) { this.packetLength = len; + var bytes = ''; for ( var i = 0; i < len; i++) { - this.text += input[position + i]; + bytes += input[position + i]; } + + this.set_text_bytes(bytes); 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 this.certificationSignatures[i].creationTime) { + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (revocation.verify(signaturedata, signingKey)) { if (this.certificationSignatures[i].issuerKeyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -250,13 +285,14 @@ function openpgp_packet_userid() { continue; } } + var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ publicKeyPacket.data+String.fromCharCode(0xB4)+ - String.fromCharCode((this.text.length >> 24) & 0xFF)+ - String.fromCharCode((this.text.length >> 16) & 0xFF)+ - String.fromCharCode((this.text.length >> 8) & 0xFF)+ - String.fromCharCode((this.text.length) & 0xFF)+ - this.text; + String.fromCharCode((bytes.length >> 24) & 0xFF)+ + String.fromCharCode((bytes.length >> 16) & 0xFF)+ + String.fromCharCode((bytes.length >> 8) & 0xFF)+ + String.fromCharCode((bytes.length) & 0xFF)+ + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -281,7 +317,7 @@ function openpgp_packet_userid() { if (revocation != null && revocation.creationTime > this.certificationSignatures[i].creationTime) { 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.keyId == publicKeyPacket.getKeyId()) result[i] = 6; @@ -291,7 +327,7 @@ function openpgp_packet_userid() { } } var signaturedata = String.fromCharCode(0x99)+ publicKeyPacket.header.substring(1)+ - publicKeyPacket.data+this.text; + publicKeyPacket.data + bytes; if (this.certificationSignatures[i].verify(signaturedata, signingKey)) { result[i] = 4; } else @@ -307,7 +343,7 @@ function openpgp_packet_userid() { * verifies the signatures of the user id * @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); if (result.indexOf(6) != -1) return 2; @@ -317,20 +353,12 @@ function openpgp_packet_userid() { } // TODO: implementation missing - function addCertification(publicKeyPacket, privateKeyPacket) { + this.addCertification = function(publicKeyPacket, privateKeyPacket) { } // 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; } diff --git a/src/type/openpgp.type.s2k.js b/src/type/openpgp.type.s2k.js index 3147a8bb..b0d35afa 100644 --- a/src/type/openpgp.type.s2k.js +++ b/src/type/openpgp.type.s2k.js @@ -114,6 +114,7 @@ function openpgp_type_s2k() { * hashAlgorithm hash length */ function produce_key(passphrase, numBytes) { + passphrase = util.encode_utf8(passphrase); if (this.type == 0) { return openpgp_crypto_hashData(this.hashAlgorithm,passphrase); } else if (this.type == 1) { diff --git a/src/util/util.js b/src/util/util.js index 9d6e3f6d..be9cf037 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -85,45 +85,68 @@ var Util = function() { } 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) * @param {String} str String to convert * @return {Integer[]} An array of (binary) integers */ - this.str2bin = function(str) { - var result = new Array(); - for (var i = 0; i < str.length; i++) { - result[i] = str.charCodeAt(i); - } - - return result; + this.str2bin = function(str) { + return str2bin(str, new Array(str.length)); }; - + + /** * Convert an array of integers(0.255) to a string * @param {Integer[]} bin An array of (binary) integers to convert * @return {String} The string representation of the array */ - this.bin2str = function(bin) { - var result = []; - for (var i = 0; i < bin.length; i++) { - result.push(String.fromCharCode(bin[i])); - } - return result.join(''); - }; + this.bin2str = bin2str; /** * Convert a string to a Uint8Array * @param {String} str String to convert * @return {Uint8Array} The array of (binary) integers */ - this.str2Uint8Array = function(str){ - var uintArray = new Uint8Array(new ArrayBuffer(str.length)); - for(var n = 0; n < str.length; n++){ - uintArray[n] = str.charCodeAt(n); - } - return uintArray; + this.str2Uint8Array = function(str) { + return str2bin(str, new Uint8Array(new ArrayBuffer(str.length))); }; /** @@ -132,13 +155,7 @@ var Util = function() { * @param {Uint8Array} bin An array of (binary) integers to convert * @return {String} String representation of the array */ - this.Uint8Array2str = function(bin) { - var result = []; - for(n = 0; n< bin.length; n++){ - result[n] = String.fromCharCode(bin[n]); - } - return result.join(''); - }; + this.Uint8Array2str = bin2str; /** * Calculates a 16bit sum of a string by adding each character diff --git a/test/general/openpgp.basic.js b/test/general/openpgp.basic.js new file mode 100644 index 00000000..3d2e27ef --- /dev/null +++ b/test/general/openpgp.basic.js @@ -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 ', 'hello world')); +result.push(test('●●●●', '♔♔♔♔ ', 'łäóć')); + +return result +}); diff --git a/test/index.html b/test/index.html index 20a979e2..1c4e0f14 100644 --- a/test/index.html +++ b/test/index.html @@ -76,10 +76,9 @@ + OpenPGP.js testpage - -