Merge pull request #137 from Robert-Nelson/devel-signature-fixes
Merge signature changes from master
This commit is contained in:
commit
5d6e1a9506
|
@ -1,4 +1,4 @@
|
||||||
[](http://travis-ci.org/openpgpjs/openpgpjs)
|
[](http://travis-ci.org/openpgpjs/openpgpjs)
|
||||||
|
|
||||||
# What is OpenPGP.js?
|
# What is OpenPGP.js?
|
||||||
[OpenPGP.js](http://openpgpjs.org/) is a Javascript implementation of the OpenPGP protocol. This is defined in [RFC 4880](http://tools.ietf.org/html/rfc4880).
|
[OpenPGP.js](http://openpgpjs.org/) is a Javascript implementation of the OpenPGP protocol. This is defined in [RFC 4880](http://tools.ietf.org/html/rfc4880).
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -33,7 +33,7 @@ function CleartextMessage(text, packetlist) {
|
||||||
if (!(this instanceof CleartextMessage)) {
|
if (!(this instanceof CleartextMessage)) {
|
||||||
return new CleartextMessage(packetlist);
|
return new CleartextMessage(packetlist);
|
||||||
}
|
}
|
||||||
this.text = text;
|
this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n");
|
||||||
this.packets = packetlist || new packet.list();
|
this.packets = packetlist || new packet.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ CleartextMessage.prototype.getSigningKeyIds = function() {
|
||||||
*/
|
*/
|
||||||
CleartextMessage.prototype.sign = function(privateKeys) {
|
CleartextMessage.prototype.sign = function(privateKeys) {
|
||||||
var packetlist = new packet.list();
|
var packetlist = new packet.list();
|
||||||
|
var literalDataPacket = new packet.literal();
|
||||||
|
literalDataPacket.setBytes(this.text, enums.read(enums.literal, enums.literal.utf8));
|
||||||
for (var i = 0; i < privateKeys.length; i++) {
|
for (var i = 0; i < privateKeys.length; i++) {
|
||||||
var signaturePacket = new packet.signature();
|
var signaturePacket = new packet.signature();
|
||||||
signaturePacket.signatureType = enums.signature.text;
|
signaturePacket.signatureType = enums.signature.text;
|
||||||
|
@ -63,9 +65,6 @@ CleartextMessage.prototype.sign = function(privateKeys) {
|
||||||
var signingKeyPacket = privateKeys[i].getSigningKeyPacket();
|
var signingKeyPacket = privateKeys[i].getSigningKeyPacket();
|
||||||
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
|
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
|
||||||
if (!signingKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.');
|
if (!signingKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.');
|
||||||
// use literal data packet to convert to canonical <CR><LF> line endings
|
|
||||||
var literalDataPacket = new packet.literal();
|
|
||||||
literalDataPacket.setBytes(this.text, enums.read(enums.literal, enums.literal.text));
|
|
||||||
signaturePacket.sign(signingKeyPacket, literalDataPacket);
|
signaturePacket.sign(signingKeyPacket, literalDataPacket);
|
||||||
packetlist.push(signaturePacket);
|
packetlist.push(signaturePacket);
|
||||||
}
|
}
|
||||||
|
@ -81,15 +80,14 @@ CleartextMessage.prototype.verify = function(publicKeys) {
|
||||||
var result = [];
|
var result = [];
|
||||||
var signatureList = this.packets.filterByTag(enums.packet.signature);
|
var signatureList = this.packets.filterByTag(enums.packet.signature);
|
||||||
var that = this;
|
var that = this;
|
||||||
|
var literalDataPacket = new packet.literal();
|
||||||
|
literalDataPacket.setBytes(that.text, enums.read(enums.literal, enums.literal.utf8));
|
||||||
publicKeys.forEach(function(pubKey) {
|
publicKeys.forEach(function(pubKey) {
|
||||||
for (var i = 0; i < signatureList.length; i++) {
|
for (var i = 0; i < signatureList.length; i++) {
|
||||||
var publicKeyPacket = pubKey.getPublicKeyPacket([signatureList[i].issuerKeyId]);
|
var publicKeyPacket = pubKey.getPublicKeyPacket([signatureList[i].issuerKeyId]);
|
||||||
if (publicKeyPacket) {
|
if (publicKeyPacket) {
|
||||||
var verifiedSig = {};
|
var verifiedSig = {};
|
||||||
verifiedSig.keyid = signatureList[i].issuerKeyId;
|
verifiedSig.keyid = signatureList[i].issuerKeyId;
|
||||||
// use literal data packet to convert to canonical <CR><LF> line endings
|
|
||||||
var literalDataPacket = new packet.literal();
|
|
||||||
literalDataPacket.setBytes(that.text, enums.read(enums.literal, enums.literal.text));
|
|
||||||
verifiedSig.status = signatureList[i].verify(publicKeyPacket, literalDataPacket);
|
verifiedSig.status = signatureList[i].verify(publicKeyPacket, literalDataPacket);
|
||||||
result.push(verifiedSig);
|
result.push(verifiedSig);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -353,9 +353,6 @@ JXG.Util.Unzip = function(barray) {
|
||||||
X = currentTree[xtreepos];
|
X = currentTree[xtreepos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (debug)
|
|
||||||
document.write("ret3");
|
|
||||||
return -1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function DeflateLoop() {
|
function DeflateLoop() {
|
||||||
|
@ -797,7 +794,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
CRC = 0xffffffff;
|
CRC = 0xffffffff;
|
||||||
SIZE = 0;
|
SIZE = 0;
|
||||||
|
|
||||||
if (size = 0 && fileOut.charAt(fileout.length - 1) == "/") {
|
if (size == 0 && fileOut.charAt(fileout.length - 1) == "/") {
|
||||||
//skipdir
|
//skipdir
|
||||||
if (debug)
|
if (debug)
|
||||||
alert("skipdir");
|
alert("skipdir");
|
||||||
|
|
|
@ -31,18 +31,21 @@ var config = require('../config');
|
||||||
* null = unknown
|
* null = unknown
|
||||||
*/
|
*/
|
||||||
function get_type(text) {
|
function get_type(text) {
|
||||||
var splittedtext = text.split('-----');
|
var reHeader = /^-----([^-]+)-----$\n/m;
|
||||||
|
|
||||||
|
var header = text.match(reHeader);
|
||||||
|
|
||||||
// BEGIN PGP MESSAGE, PART X/Y
|
// BEGIN PGP MESSAGE, PART X/Y
|
||||||
// Used for multi-part messages, where the armor is split amongst Y
|
// Used for multi-part messages, where the armor is split amongst Y
|
||||||
// parts, and this is the Xth part out of Y.
|
// parts, and this is the Xth part out of Y.
|
||||||
if (splittedtext[1].match(/BEGIN PGP MESSAGE, PART \d+\/\d+/)) {
|
if (header[1].match(/BEGIN PGP MESSAGE, PART \d+\/\d+/)) {
|
||||||
return enums.armor.multipart_section;
|
return enums.armor.multipart_section;
|
||||||
} else
|
} else
|
||||||
// BEGIN PGP MESSAGE, PART X
|
// BEGIN PGP MESSAGE, PART X
|
||||||
// Used for multi-part messages, where this is the Xth part of an
|
// Used for multi-part messages, where this is the Xth part of an
|
||||||
// unspecified number of parts. Requires the MESSAGE-ID Armor
|
// unspecified number of parts. Requires the MESSAGE-ID Armor
|
||||||
// Header to be used.
|
// Header to be used.
|
||||||
if (splittedtext[1].match(/BEGIN PGP MESSAGE, PART \d+/)) {
|
if (header[1].match(/BEGIN PGP MESSAGE, PART \d+/)) {
|
||||||
return enums.armor.multipart_last;
|
return enums.armor.multipart_last;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
@ -50,25 +53,25 @@ function get_type(text) {
|
||||||
// Used for detached signatures, OpenPGP/MIME signatures, and
|
// Used for detached signatures, OpenPGP/MIME signatures, and
|
||||||
// cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE
|
// cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE
|
||||||
// for detached signatures.
|
// for detached signatures.
|
||||||
if (splittedtext[1].match(/BEGIN PGP SIGNED MESSAGE/)) {
|
if (header[1].match(/BEGIN PGP SIGNED MESSAGE/)) {
|
||||||
return enums.armor.signed;
|
return enums.armor.signed;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
// BEGIN PGP MESSAGE
|
// BEGIN PGP MESSAGE
|
||||||
// Used for signed, encrypted, or compressed files.
|
// Used for signed, encrypted, or compressed files.
|
||||||
if (splittedtext[1].match(/BEGIN PGP MESSAGE/)) {
|
if (header[1].match(/BEGIN PGP MESSAGE/)) {
|
||||||
return enums.armor.message;
|
return enums.armor.message;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
// BEGIN PGP PUBLIC KEY BLOCK
|
// BEGIN PGP PUBLIC KEY BLOCK
|
||||||
// Used for armoring public keys.
|
// Used for armoring public keys.
|
||||||
if (splittedtext[1].match(/BEGIN PGP PUBLIC KEY BLOCK/)) {
|
if (header[1].match(/BEGIN PGP PUBLIC KEY BLOCK/)) {
|
||||||
return enums.armor.public_key;
|
return enums.armor.public_key;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
// BEGIN PGP PRIVATE KEY BLOCK
|
// BEGIN PGP PRIVATE KEY BLOCK
|
||||||
// Used for armoring private keys.
|
// Used for armoring private keys.
|
||||||
if (splittedtext[1].match(/BEGIN PGP PRIVATE KEY BLOCK/)) {
|
if (header[1].match(/BEGIN PGP PRIVATE KEY BLOCK/)) {
|
||||||
return enums.armor.private_key;
|
return enums.armor.private_key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +111,7 @@ function getCheckSum(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the checksum over the given data and compares it with the
|
* Calculates the checksum over the given data and compares it with the
|
||||||
* given base64 encoded checksum
|
* given base64 encoded checksum
|
||||||
* @param {String} data Data to create a CRC-24 checksum for
|
* @param {String} data Data to create a CRC-24 checksum for
|
||||||
* @param {String} checksum Base64 encoded checksum
|
* @param {String} checksum Base64 encoded checksum
|
||||||
|
@ -190,66 +193,109 @@ function createcrc24(input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeArmor an OpenPGP armored message; verify the checksum and return
|
* Splits a message into two parts, the headers and the body. This is an internal function
|
||||||
|
* @param {String} text OpenPGP armored message part
|
||||||
|
* @returns {(Boolean|Object)} Either false in case of an error
|
||||||
|
* or an object with attribute "headers" containing the headers and
|
||||||
|
* and an attribute "body" containing the body.
|
||||||
|
*/
|
||||||
|
function split_headers(text) {
|
||||||
|
var reEmptyLine = /^[\t ]*\n/m;
|
||||||
|
var headers = "";
|
||||||
|
var body = text;
|
||||||
|
|
||||||
|
var matchResult = reEmptyLine.exec(text);
|
||||||
|
|
||||||
|
if (matchResult != null) {
|
||||||
|
headers = text.slice(0, matchResult.index);
|
||||||
|
body = text.slice(matchResult.index + matchResult[0].length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { headers: headers, body: body };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a message into two parts, the body and the checksum. This is an internal function
|
||||||
|
* @param {String} text OpenPGP armored message part
|
||||||
|
* @returns {(Boolean|Object)} Either false in case of an error
|
||||||
|
* or an object with attribute "body" containing the body
|
||||||
|
* and an attribute "checksum" containing the checksum.
|
||||||
|
*/
|
||||||
|
function split_checksum(text) {
|
||||||
|
var reChecksumStart = /^=/m;
|
||||||
|
var body = text;
|
||||||
|
var checksum = "";
|
||||||
|
|
||||||
|
var matchResult = reChecksumStart.exec(text);
|
||||||
|
|
||||||
|
if (matchResult != null) {
|
||||||
|
body = text.slice(0, matchResult.index);
|
||||||
|
checksum = text.slice(matchResult.index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { body: body, checksum: checksum };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeArmor an OpenPGP armored message; verify the checksum and return
|
||||||
* the encoded bytes
|
* the encoded bytes
|
||||||
* @param {String} text OpenPGP armored message
|
* @param {String} text OpenPGP armored message
|
||||||
* @returns {(Boolean|Object)} Either false in case of an error
|
* @returns {(Boolean|Object)} Either false in case of an error
|
||||||
* or an object with attribute "text" containing the message text
|
* or an object with attribute "text" containing the message text
|
||||||
* and an attribute "data" containing the bytes.
|
* and an attribute "data" containing the bytes.
|
||||||
*/
|
*/
|
||||||
function dearmor(text) {
|
function dearmor(text) {
|
||||||
|
var reSplit = /^-----[^-]+-----$\n/m;
|
||||||
|
|
||||||
text = text.replace(/\r/g, '');
|
text = text.replace(/\r/g, '');
|
||||||
|
|
||||||
var type = get_type(text);
|
var type = get_type(text);
|
||||||
|
|
||||||
|
var splittext = text.split(reSplit);
|
||||||
|
|
||||||
|
// IE has a bug in split with a re. If the pattern matches the beginning of the
|
||||||
|
// string it doesn't create an empty array element 0. So we need to detect this
|
||||||
|
// so we know the index of the data we are interested in.
|
||||||
|
var indexBase = 1;
|
||||||
|
|
||||||
|
var result, checksum;
|
||||||
|
|
||||||
|
if (text.search(reSplit) != splittext[0].length) {
|
||||||
|
indexBase = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (type != 2) {
|
if (type != 2) {
|
||||||
var splittedtext = text.split('-----');
|
var msg = split_headers(splittext[indexBase].replace(/^- /mg, ''));
|
||||||
|
var msg_sum = split_checksum(msg.body);
|
||||||
|
|
||||||
var result = {
|
result = {
|
||||||
data: base64.decode(
|
data: base64.decode(msg_sum.body),
|
||||||
splittedtext[2]
|
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[0]
|
|
||||||
.replace(/\n- /g, "\n")),
|
|
||||||
type: type
|
type: type
|
||||||
};
|
};
|
||||||
|
|
||||||
if (verifyCheckSum(result.data,
|
checksum = msg_sum.checksum;
|
||||||
splittedtext[2]
|
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[1]
|
|
||||||
.split('\n')[0]))
|
|
||||||
|
|
||||||
return result;
|
|
||||||
else {
|
|
||||||
util.print_error("Ascii armor integrity check on message failed: '" + splittedtext[2]
|
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[1]
|
|
||||||
.split('\n')[0] + "' should be '" + getCheckSum(result.data)) + "'";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var splittedtext = text.split('-----');
|
var msg = split_headers(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
|
||||||
|
var sig = split_headers(splittext[indexBase + 1].replace(/^- /mg, ''));
|
||||||
|
var sig_sum = split_checksum(sig.body);
|
||||||
|
|
||||||
var result = {
|
result = {
|
||||||
text: splittedtext[2]
|
text: msg.body.replace(/\n$/, '').replace(/\n/g, "\r\n"),
|
||||||
.replace(/\n- /g, "\n")
|
data: base64.decode(sig_sum.body),
|
||||||
.split("\n\n")[1],
|
|
||||||
data: base64.decode(splittedtext[4]
|
|
||||||
.split("\n\n")[1]
|
|
||||||
.split("\n=")[0]),
|
|
||||||
type: type
|
type: type
|
||||||
};
|
};
|
||||||
|
|
||||||
if (verifyCheckSum(result.data, splittedtext[4]
|
checksum = sig_sum.checksum;
|
||||||
.split("\n\n")[1]
|
}
|
||||||
.split("\n=")[1]))
|
|
||||||
|
|
||||||
return result;
|
if (!verifyCheckSum(result.data, checksum)) {
|
||||||
else {
|
util.print_error("Ascii armor integrity check on message failed: '"
|
||||||
util.print_error("Ascii armor integrity check on message failed");
|
+ checksum
|
||||||
return false;
|
+ "' should be '"
|
||||||
}
|
+ getCheckSum(result) + "'");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,4 +288,4 @@ function fromText(text) {
|
||||||
|
|
||||||
exports.Message = Message;
|
exports.Message = Message;
|
||||||
exports.readArmored = readArmored;
|
exports.readArmored = readArmored;
|
||||||
exports.fromText = fromText;
|
exports.fromText = fromText;
|
||||||
|
|
|
@ -51,38 +51,19 @@ module.exports = function packet_literal() {
|
||||||
*/
|
*/
|
||||||
this.setBytes = function(bytes, format) {
|
this.setBytes = function(bytes, format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
switch (format) {
|
this.data = format == 'utf8' ? util.decode_utf8(bytes) : bytes;
|
||||||
case 'utf8':
|
|
||||||
bytes = util.decode_utf8(bytes);
|
|
||||||
bytes = bytes.replace(/\r\n/g, '\n');
|
|
||||||
break;
|
|
||||||
case 'text':
|
|
||||||
bytes = bytes.replace(/\r\n/g, '\n');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.data = bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the byte sequence representing the literal packet data
|
* Get the byte sequence representing the literal packet data
|
||||||
* @returns {String} A sequence of bytes
|
* @returns {String} A sequence of bytes
|
||||||
*/
|
*/
|
||||||
this.getBytes = function() {
|
this.getBytes = function() {
|
||||||
var bytes = this.data;
|
return this.format == 'utf8' ? util.encode_utf8(this.data) : this.data;
|
||||||
switch (this.format) {
|
|
||||||
case 'utf8':
|
|
||||||
bytes = bytes.replace(/\n/g, '\r\n');
|
|
||||||
bytes = util.encode_utf8(bytes);
|
|
||||||
break;
|
|
||||||
case 'text':
|
|
||||||
bytes = bytes.replace(/\n/g, '\r\n');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parsing function for a literal data packet (tag 11).
|
* Parsing function for a literal data packet (tag 11).
|
||||||
*
|
*
|
||||||
|
@ -97,7 +78,7 @@ module.exports = function packet_literal() {
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
// - A one-octet field that describes how the data is formatted.
|
// - A one-octet field that describes how the data is formatted.
|
||||||
|
|
||||||
var format = enums.read(enums.literal, bytes[0].charCodeAt());
|
var format = enums.read(enums.literal, bytes.charCodeAt(0));
|
||||||
|
|
||||||
var filename_len = bytes.charCodeAt(1);
|
var filename_len = bytes.charCodeAt(1);
|
||||||
this.filename = util.decode_utf8(bytes.substr(2, filename_len));
|
this.filename = util.decode_utf8(bytes.substr(2, filename_len));
|
||||||
|
|
|
@ -39,9 +39,9 @@ function packet_marker() {
|
||||||
* @return {openpgp_packet_encrypteddata} Object representation
|
* @return {openpgp_packet_encrypteddata} Object representation
|
||||||
*/
|
*/
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
if (bytes[0].charCodeAt() == 0x50 && // P
|
if (bytes.charCodeAt(0) == 0x50 && // P
|
||||||
bytes[1].charCodeAt() == 0x47 && // G
|
bytes.charCodeAt(1) == 0x47 && // G
|
||||||
bytes[2].charCodeAt() == 0x50) // P
|
bytes.charCodeAt(2) == 0x50) // P
|
||||||
return true;
|
return true;
|
||||||
// marker packet does not contain "PGP"
|
// marker packet does not contain "PGP"
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,14 +23,14 @@ module.exports = {
|
||||||
readSimpleLength: function(bytes) {
|
readSimpleLength: function(bytes) {
|
||||||
var len = 0,
|
var len = 0,
|
||||||
offset,
|
offset,
|
||||||
type = bytes[0].charCodeAt();
|
type = bytes.charCodeAt(0);
|
||||||
|
|
||||||
|
|
||||||
if (type < 192) {
|
if (type < 192) {
|
||||||
len = bytes[0].charCodeAt();
|
len = bytes.charCodeAt(0);
|
||||||
offset = 1;
|
offset = 1;
|
||||||
} else if (type < 255) {
|
} else if (type < 255) {
|
||||||
len = ((bytes[0].charCodeAt() - 192) << 8) + (bytes[1].charCodeAt()) + 192;
|
len = ((bytes.charCodeAt(0) - 192) << 8) + (bytes.charCodeAt(1)) + 192;
|
||||||
offset = 2;
|
offset = 2;
|
||||||
} else if (type == 255) {
|
} else if (type == 255) {
|
||||||
len = util.readNumber(bytes.substr(1, 4));
|
len = util.readNumber(bytes.substr(1, 4));
|
||||||
|
@ -117,7 +117,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
read: function(input, position, len) {
|
read: function(input, position, len) {
|
||||||
// some sanity checks
|
// some sanity checks
|
||||||
if (input == null || input.length <= position || input.substring(position).length < 2 || (input[position].charCodeAt() &
|
if (input == null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) &
|
||||||
0x80) == 0) {
|
0x80) == 0) {
|
||||||
util
|
util
|
||||||
.print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
|
.print_error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
|
||||||
|
@ -129,18 +129,18 @@ module.exports = {
|
||||||
var packet_length;
|
var packet_length;
|
||||||
|
|
||||||
format = 0; // 0 = old format; 1 = new format
|
format = 0; // 0 = old format; 1 = new format
|
||||||
if ((input[mypos].charCodeAt() & 0x40) != 0) {
|
if ((input.charCodeAt(mypos) & 0x40) != 0) {
|
||||||
format = 1;
|
format = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var packet_length_type;
|
var packet_length_type;
|
||||||
if (format) {
|
if (format) {
|
||||||
// new format header
|
// new format header
|
||||||
tag = input[mypos].charCodeAt() & 0x3F; // bit 5-0
|
tag = input.charCodeAt(mypos) & 0x3F; // bit 5-0
|
||||||
} else {
|
} else {
|
||||||
// old format header
|
// old format header
|
||||||
tag = (input[mypos].charCodeAt() & 0x3F) >> 2; // bit 5-2
|
tag = (input.charCodeAt(mypos) & 0x3F) >> 2; // bit 5-2
|
||||||
packet_length_type = input[mypos].charCodeAt() & 0x03; // bit 1-0
|
packet_length_type = input.charCodeAt(mypos) & 0x03; // bit 1-0
|
||||||
}
|
}
|
||||||
|
|
||||||
// header octet parsing done
|
// header octet parsing done
|
||||||
|
@ -157,18 +157,18 @@ module.exports = {
|
||||||
case 0:
|
case 0:
|
||||||
// The packet has a one-octet length. The header is 2 octets
|
// The packet has a one-octet length. The header is 2 octets
|
||||||
// long.
|
// long.
|
||||||
packet_length = input[mypos++].charCodeAt();
|
packet_length = input.charCodeAt(mypos++);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// The packet has a two-octet length. The header is 3 octets
|
// The packet has a two-octet length. The header is 3 octets
|
||||||
// long.
|
// long.
|
||||||
packet_length = (input[mypos++].charCodeAt() << 8) | input[mypos++].charCodeAt();
|
packet_length = (input.charCodeAt(mypos++) << 8) | input.charCodeAt(mypos++);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// The packet has a four-octet length. The header is 5
|
// The packet has a four-octet length. The header is 5
|
||||||
// octets long.
|
// octets long.
|
||||||
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() <<
|
packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) <<
|
||||||
8) | input[mypos++].charCodeAt();
|
8) | input.charCodeAt(mypos++);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// 3 - The packet is of indeterminate length. The header is 1
|
// 3 - The packet is of indeterminate length. The header is 1
|
||||||
|
@ -189,42 +189,42 @@ module.exports = {
|
||||||
{
|
{
|
||||||
|
|
||||||
// 4.2.2.1. One-Octet Lengths
|
// 4.2.2.1. One-Octet Lengths
|
||||||
if (input[mypos].charCodeAt() < 192) {
|
if (input.charCodeAt(mypos) < 192) {
|
||||||
packet_length = input[mypos++].charCodeAt();
|
packet_length = input.charCodeAt(mypos++);
|
||||||
util.print_debug("1 byte length:" + packet_length);
|
util.print_debug("1 byte length:" + packet_length);
|
||||||
// 4.2.2.2. Two-Octet Lengths
|
// 4.2.2.2. Two-Octet Lengths
|
||||||
} else if (input[mypos].charCodeAt() >= 192 && input[mypos].charCodeAt() < 224) {
|
} else if (input.charCodeAt(mypos) >= 192 && input.charCodeAt(mypos) < 224) {
|
||||||
packet_length = ((input[mypos++].charCodeAt() - 192) << 8) + (input[mypos++].charCodeAt()) + 192;
|
packet_length = ((input.charCodeAt(mypos++) - 192) << 8) + (input.charCodeAt(mypos++)) + 192;
|
||||||
util.print_debug("2 byte length:" + packet_length);
|
util.print_debug("2 byte length:" + packet_length);
|
||||||
// 4.2.2.4. Partial Body Lengths
|
// 4.2.2.4. Partial Body Lengths
|
||||||
} else if (input[mypos].charCodeAt() > 223 && input[mypos].charCodeAt() < 255) {
|
} else if (input.charCodeAt(mypos) > 223 && input.charCodeAt(mypos) < 255) {
|
||||||
packet_length = 1 << (input[mypos++].charCodeAt() & 0x1F);
|
packet_length = 1 << (input.charCodeAt(mypos++) & 0x1F);
|
||||||
util.print_debug("4 byte length:" + packet_length);
|
util.print_debug("4 byte length:" + packet_length);
|
||||||
// EEEK, we're reading the full data here...
|
// EEEK, we're reading the full data here...
|
||||||
var mypos2 = mypos + packet_length;
|
var mypos2 = mypos + packet_length;
|
||||||
bodydata = input.substring(mypos, mypos + packet_length);
|
bodydata = input.substring(mypos, mypos + packet_length);
|
||||||
while (true) {
|
while (true) {
|
||||||
if (input[mypos2].charCodeAt() < 192) {
|
if (input.charCodeAt(mypos2) < 192) {
|
||||||
var tmplen = input[mypos2++].charCodeAt();
|
var tmplen = input.charCodeAt(mypos2++);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
break;
|
break;
|
||||||
} else if (input[mypos2].charCodeAt() >= 192 && input[mypos2].charCodeAt() < 224) {
|
} else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) {
|
||||||
var tmplen = ((input[mypos2++].charCodeAt() - 192) << 8) + (input[mypos2++].charCodeAt()) + 192;
|
var tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192;
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
break;
|
break;
|
||||||
} else if (input[mypos2].charCodeAt() > 223 && input[mypos2].charCodeAt() < 255) {
|
} else if (input.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) {
|
||||||
var tmplen = 1 << (input[mypos2++].charCodeAt() & 0x1F);
|
var tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
} else {
|
} else {
|
||||||
mypos2++;
|
mypos2++;
|
||||||
var tmplen = (input[mypos2++].charCodeAt() << 24) | (input[mypos2++].charCodeAt() << 16) | (input[mypos2++]
|
var tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input[mypos2++]
|
||||||
.charCodeAt() << 8) | input[mypos2++].charCodeAt();
|
.charCodeAt() << 8) | input.charCodeAt(mypos2++);
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
|
@ -235,8 +235,8 @@ module.exports = {
|
||||||
// 4.2.2.3. Five-Octet Lengths
|
// 4.2.2.3. Five-Octet Lengths
|
||||||
} else {
|
} else {
|
||||||
mypos++;
|
mypos++;
|
||||||
packet_length = (input[mypos++].charCodeAt() << 24) | (input[mypos++].charCodeAt() << 16) | (input[mypos++].charCodeAt() <<
|
packet_length = (input.charCodeAt(mypos++) << 24) | (input.charCodeAt(mypos++) << 16) | (input.charCodeAt(mypos++) <<
|
||||||
8) | input[mypos++].charCodeAt();
|
8) | input.charCodeAt(mypos++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,14 +53,14 @@ module.exports = function packet_public_key() {
|
||||||
*/
|
*/
|
||||||
this.readPublicKey = this.read = function(bytes) {
|
this.readPublicKey = this.read = function(bytes) {
|
||||||
// A one-octet version number (3 or 4).
|
// A one-octet version number (3 or 4).
|
||||||
var version = bytes[0].charCodeAt();
|
var version = bytes.charCodeAt(0);
|
||||||
|
|
||||||
if (version == 4) {
|
if (version == 4) {
|
||||||
// - A four-octet number denoting the time that the key was created.
|
// - A four-octet number denoting the time that the key was created.
|
||||||
this.created = util.readDate(bytes.substr(1, 4));
|
this.created = util.readDate(bytes.substr(1, 4));
|
||||||
|
|
||||||
// - A one-octet number denoting the public-key algorithm of this key.
|
// - A one-octet number denoting the public-key algorithm of this key.
|
||||||
this.algorithm = enums.read(enums.publicKey, bytes[5].charCodeAt());
|
this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(5));
|
||||||
|
|
||||||
var mpicount = crypto.getPublicMpiCount(this.algorithm);
|
var mpicount = crypto.getPublicMpiCount(this.algorithm);
|
||||||
this.mpi = [];
|
this.mpi = [];
|
||||||
|
|
|
@ -61,9 +61,9 @@ module.exports = function packet_public_key_encrypted_session_key() {
|
||||||
*/
|
*/
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
|
|
||||||
this.version = bytes[0].charCodeAt();
|
this.version = bytes.charCodeAt(0);
|
||||||
this.publicKeyId.read(bytes.substr(1));
|
this.publicKeyId.read(bytes.substr(1));
|
||||||
this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes[9].charCodeAt());
|
this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
|
||||||
|
|
||||||
var i = 10;
|
var i = 10;
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ function packet_secret_key() {
|
||||||
// indicates that the secret-key data is not encrypted. 255 or 254
|
// indicates that the secret-key data is not encrypted. 255 or 254
|
||||||
// indicates that a string-to-key specifier is being given. Any
|
// indicates that a string-to-key specifier is being given. Any
|
||||||
// other value is a symmetric-key encryption algorithm identifier.
|
// other value is a symmetric-key encryption algorithm identifier.
|
||||||
var isEncrypted = bytes[0].charCodeAt();
|
var isEncrypted = bytes.charCodeAt(0);
|
||||||
|
|
||||||
if (isEncrypted) {
|
if (isEncrypted) {
|
||||||
this.encrypted = bytes;
|
this.encrypted = bytes;
|
||||||
|
@ -199,12 +199,12 @@ function packet_secret_key() {
|
||||||
symmetric,
|
symmetric,
|
||||||
key;
|
key;
|
||||||
|
|
||||||
var s2k_usage = this.encrypted[i++].charCodeAt();
|
var s2k_usage = this.encrypted.charCodeAt(i++);
|
||||||
|
|
||||||
// - [Optional] If string-to-key usage octet was 255 or 254, a one-
|
// - [Optional] If string-to-key usage octet was 255 or 254, a one-
|
||||||
// octet symmetric encryption algorithm.
|
// octet symmetric encryption algorithm.
|
||||||
if (s2k_usage == 255 || s2k_usage == 254) {
|
if (s2k_usage == 255 || s2k_usage == 254) {
|
||||||
symmetric = this.encrypted[i++].charCodeAt();
|
symmetric = this.encrypted.charCodeAt(i++);
|
||||||
symmetric = enums.read(enums.symmetric, symmetric);
|
symmetric = enums.read(enums.symmetric, symmetric);
|
||||||
|
|
||||||
// - [Optional] If string-to-key usage octet was 255 or 254, a
|
// - [Optional] If string-to-key usage octet was 255 or 254, a
|
||||||
|
|
|
@ -86,19 +86,19 @@ module.exports = function packet_signature() {
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
this.version = bytes[i++].charCodeAt();
|
this.version = bytes.charCodeAt(i++);
|
||||||
// switch on version (3 and 4)
|
// switch on version (3 and 4)
|
||||||
switch (this.version) {
|
switch (this.version) {
|
||||||
case 3:
|
case 3:
|
||||||
// One-octet length of following hashed material. MUST be 5.
|
// One-octet length of following hashed material. MUST be 5.
|
||||||
if (bytes[i++].charCodeAt() != 5)
|
if (bytes.charCodeAt(i++) != 5)
|
||||||
util.print_debug("openpgp.packet.signature.js\n" +
|
util.print_debug("openpgp.packet.signature.js\n" +
|
||||||
'invalid One-octet length of following hashed material.' +
|
'invalid One-octet length of following hashed material.' +
|
||||||
'MUST be 5. @:' + (i - 1));
|
'MUST be 5. @:' + (i - 1));
|
||||||
|
|
||||||
var sigpos = i;
|
var sigpos = i;
|
||||||
// One-octet signature type.
|
// One-octet signature type.
|
||||||
this.signatureType = bytes[i++].charCodeAt();
|
this.signatureType = bytes.charCodeAt(i++);
|
||||||
|
|
||||||
// Four-octet creation time.
|
// Four-octet creation time.
|
||||||
this.created = util.readDate(bytes.substr(i, 4));
|
this.created = util.readDate(bytes.substr(i, 4));
|
||||||
|
@ -112,15 +112,15 @@ module.exports = function packet_signature() {
|
||||||
i += 8;
|
i += 8;
|
||||||
|
|
||||||
// One-octet public-key algorithm.
|
// One-octet public-key algorithm.
|
||||||
this.publicKeyAlgorithm = bytes[i++].charCodeAt();
|
this.publicKeyAlgorithm = bytes.charCodeAt(i++);
|
||||||
|
|
||||||
// One-octet hash algorithm.
|
// One-octet hash algorithm.
|
||||||
this.hashAlgorithm = bytes[i++].charCodeAt();
|
this.hashAlgorithm = bytes.charCodeAt(i++);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
this.signatureType = bytes[i++].charCodeAt();
|
this.signatureType = bytes.charCodeAt(i++);
|
||||||
this.publicKeyAlgorithm = bytes[i++].charCodeAt();
|
this.publicKeyAlgorithm = bytes.charCodeAt(i++);
|
||||||
this.hashAlgorithm = bytes[i++].charCodeAt();
|
this.hashAlgorithm = bytes.charCodeAt(i++);
|
||||||
|
|
||||||
function subpackets(bytes) {
|
function subpackets(bytes) {
|
||||||
// Two-octet scalar octet count for following subpacket data.
|
// Two-octet scalar octet count for following subpacket data.
|
||||||
|
@ -347,12 +347,12 @@ module.exports = function packet_signature() {
|
||||||
this[prop] = [];
|
this[prop] = [];
|
||||||
|
|
||||||
for (var i = 0; i < bytes.length; i++) {
|
for (var i = 0; i < bytes.length; i++) {
|
||||||
this[prop].push(bytes[i].charCodeAt());
|
this[prop].push(bytes.charCodeAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The leftwost bit denotes a "critical" packet, but we ignore it.
|
// The leftwost bit denotes a "critical" packet, but we ignore it.
|
||||||
var type = bytes[mypos++].charCodeAt() & 0x7F;
|
var type = bytes.charCodeAt(mypos++) & 0x7F;
|
||||||
|
|
||||||
// subpacket type
|
// subpacket type
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -370,12 +370,12 @@ module.exports = function packet_signature() {
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// Exportable Certification
|
// Exportable Certification
|
||||||
this.exportable = bytes[mypos++].charCodeAt() == 1;
|
this.exportable = bytes.charCodeAt(mypos++) == 1;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Trust Signature
|
// Trust Signature
|
||||||
this.trustLevel = bytes[mypos++].charCodeAt();
|
this.trustLevel = bytes.charCodeAt(mypos++);
|
||||||
this.trustAmount = bytes[mypos++].charCodeAt();
|
this.trustAmount = bytes.charCodeAt(mypos++);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
// Regular Expression
|
// Regular Expression
|
||||||
|
@ -383,7 +383,7 @@ module.exports = function packet_signature() {
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
// Revocable
|
// Revocable
|
||||||
this.revocable = bytes[mypos++].charCodeAt() == 1;
|
this.revocable = bytes.charCodeAt(mypos++) == 1;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
// Key Expiration Time
|
// Key Expiration Time
|
||||||
|
@ -398,7 +398,7 @@ module.exports = function packet_signature() {
|
||||||
this.preferredSymmetricAlgorithms = [];
|
this.preferredSymmetricAlgorithms = [];
|
||||||
|
|
||||||
while (mypos != bytes.length) {
|
while (mypos != bytes.length) {
|
||||||
this.preferredSymmetricAlgorithms.push(bytes[mypos++].charCodeAt());
|
this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -407,8 +407,8 @@ module.exports = function packet_signature() {
|
||||||
// (1 octet of class, 1 octet of public-key algorithm ID, 20
|
// (1 octet of class, 1 octet of public-key algorithm ID, 20
|
||||||
// octets of
|
// octets of
|
||||||
// fingerprint)
|
// fingerprint)
|
||||||
this.revocationKeyClass = bytes[mypos++].charCodeAt();
|
this.revocationKeyClass = bytes.charCodeAt(mypos++);
|
||||||
this.revocationKeyAlgorithm = bytes[mypos++].charCodeAt();
|
this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
|
||||||
this.revocationKeyFingerprint = bytes.substr(mypos, 20);
|
this.revocationKeyFingerprint = bytes.substr(mypos, 20);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ module.exports = function packet_signature() {
|
||||||
case 20:
|
case 20:
|
||||||
// Notation Data
|
// Notation Data
|
||||||
// We don't know how to handle anything but a text flagged data.
|
// We don't know how to handle anything but a text flagged data.
|
||||||
if (bytes[mypos].charCodeAt() == 0x80) {
|
if (bytes.charCodeAt(mypos) == 0x80) {
|
||||||
|
|
||||||
// We extract key/value tuple from the byte stream.
|
// We extract key/value tuple from the byte stream.
|
||||||
mypos += 4;
|
mypos += 4;
|
||||||
|
@ -470,7 +470,7 @@ module.exports = function packet_signature() {
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 29:
|
||||||
// Reason for Revocation
|
// Reason for Revocation
|
||||||
this.reasonForRevocationFlag = bytes[mypos++].charCodeAt();
|
this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
|
||||||
this.reasonForRevocationString = bytes.substr(mypos);
|
this.reasonForRevocationString = bytes.substr(mypos);
|
||||||
break;
|
break;
|
||||||
case 30:
|
case 30:
|
||||||
|
@ -480,8 +480,8 @@ module.exports = function packet_signature() {
|
||||||
case 31:
|
case 31:
|
||||||
// Signature Target
|
// Signature Target
|
||||||
// (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
|
// (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
|
||||||
this.signatureTargetPublicKeyAlgorithm = bytes[mypos++].charCodeAt();
|
this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
|
||||||
this.signatureTargetHashAlgorithm = bytes[mypos++].charCodeAt();
|
this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
|
||||||
|
|
||||||
var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
|
var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
|
||||||
|
|
||||||
|
@ -506,10 +506,11 @@ module.exports = function packet_signature() {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case t.binary:
|
case t.binary:
|
||||||
// conversion to CRLF line endings done in literal data packet
|
|
||||||
case t.text:
|
|
||||||
return data.getBytes();
|
return data.getBytes();
|
||||||
|
|
||||||
|
case t.text:
|
||||||
|
return data.getBytes().replace(/\r/g, '').replace(/\n/g, "\r\n");
|
||||||
|
|
||||||
case t.standalone:
|
case t.standalone:
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ module.exports = function packet_sym_encrypted_integrity_protected() {
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
// - A one-octet version number. The only currently defined value is
|
// - A one-octet version number. The only currently defined value is
|
||||||
// 1.
|
// 1.
|
||||||
var version = bytes[0].charCodeAt();
|
var version = bytes.charCodeAt(0);
|
||||||
|
|
||||||
if (version != 1) {
|
if (version != 1) {
|
||||||
throw new Error('Invalid packet version.');
|
throw new Error('Invalid packet version.');
|
||||||
|
|
|
@ -54,10 +54,10 @@ module.exports = function packet_sym_encrypted_session_key() {
|
||||||
*/
|
*/
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
// A one-octet version number. The only currently defined version is 4.
|
// A one-octet version number. The only currently defined version is 4.
|
||||||
this.version = bytes[0].charCodeAt();
|
this.version = bytes.charCodeAt(0);
|
||||||
|
|
||||||
// A one-octet number describing the symmetric algorithm used.
|
// A one-octet number describing the symmetric algorithm used.
|
||||||
var algo = enums.read(enums.symmetric, bytes[1].charCodeAt());
|
var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
|
||||||
|
|
||||||
// A string-to-key (S2K) specifier, length as defined above.
|
// A string-to-key (S2K) specifier, length as defined above.
|
||||||
var s2klength = this.s2k.read(bytes.substr(2));
|
var s2klength = this.s2k.read(bytes.substr(2));
|
||||||
|
|
|
@ -47,7 +47,7 @@ module.exports = function mpi() {
|
||||||
* @return {openpgp_type_mpi} Object representation
|
* @return {openpgp_type_mpi} Object representation
|
||||||
*/
|
*/
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
var bits = (bytes[0].charCodeAt() << 8) | bytes[1].charCodeAt();
|
var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
|
||||||
|
|
||||||
// Additional rules:
|
// Additional rules:
|
||||||
//
|
//
|
||||||
|
|
|
@ -53,8 +53,8 @@ module.exports = function s2k() {
|
||||||
*/
|
*/
|
||||||
this.read = function(bytes) {
|
this.read = function(bytes) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
this.type = enums.read(enums.s2k, bytes[i++].charCodeAt());
|
this.type = enums.read(enums.s2k, bytes.charCodeAt(i++));
|
||||||
this.algorithm = enums.read(enums.hash, bytes[i++].charCodeAt());
|
this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++));
|
||||||
|
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case 'simple':
|
case 'simple':
|
||||||
|
@ -70,13 +70,13 @@ module.exports = function s2k() {
|
||||||
i += 8;
|
i += 8;
|
||||||
|
|
||||||
// Octet 10: count, a one-octet, coded value
|
// Octet 10: count, a one-octet, coded value
|
||||||
this.c = bytes[i++].charCodeAt();
|
this.c = bytes.charCodeAt(i++);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'gnu':
|
case 'gnu':
|
||||||
if (bytes.substr(i, 3) == "GNU") {
|
if (bytes.substr(i, 3) == "GNU") {
|
||||||
i += 3; // GNU
|
i += 3; // GNU
|
||||||
var gnuExtType = 1000 + bytes[i++].charCodeAt();
|
var gnuExtType = 1000 + bytes.charCodeAt(i++);
|
||||||
if (gnuExtType == 1001) {
|
if (gnuExtType == 1001) {
|
||||||
this.type = gnuExtType;
|
this.type = gnuExtType;
|
||||||
// GnuPG extension mode 1001 -- don't write secret key at all
|
// GnuPG extension mode 1001 -- don't write secret key at all
|
||||||
|
|
|
@ -24,7 +24,7 @@ var Util = function() {
|
||||||
|
|
||||||
for (var i = 0; i < bytes.length; i++) {
|
for (var i = 0; i < bytes.length; i++) {
|
||||||
n <<= 8;
|
n <<= 8;
|
||||||
n += bytes[i].charCodeAt();
|
n += bytes.charCodeAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
@ -88,7 +88,7 @@ var Util = function() {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
var h;
|
var h;
|
||||||
while (c < e) {
|
while (c < e) {
|
||||||
h = str[c++].charCodeAt().toString(16);
|
h = str.charCodeAt(c++).toString(16);
|
||||||
while (h.length < 2) h = "0" + h;
|
while (h.length < 2) h = "0" + h;
|
||||||
r.push("" + h);
|
r.push("" + h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,7 +310,7 @@ var pub_key_arm3 =
|
||||||
'=nx90',
|
'=nx90',
|
||||||
'-----END PGP MESSAGE-----'].join('\n');
|
'-----END PGP MESSAGE-----'].join('\n');
|
||||||
|
|
||||||
var plaintext = 'short message\nnext line\n한국어/조선말\n\n';
|
var plaintext = 'short message\r\nnext line\r\n한국어/조선말\r\n\r\n';
|
||||||
var esMsg = openpgp.message.readArmored(msg_armor);
|
var esMsg = openpgp.message.readArmored(msg_armor);
|
||||||
var pubKey = openpgp.key.readArmored(pub_key_arm2);
|
var pubKey = openpgp.key.readArmored(pub_key_arm2);
|
||||||
var privKey = openpgp.key.readArmored(priv_key_arm2);
|
var privKey = openpgp.key.readArmored(priv_key_arm2);
|
||||||
|
@ -394,7 +394,7 @@ var pub_key_arm3 =
|
||||||
|
|
||||||
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey2, pubKey3], csMsg);
|
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey2, pubKey3], csMsg);
|
||||||
|
|
||||||
verified = verified && cleartextSig.text == plaintext;
|
verified = verified && cleartextSig.text == plaintext.replace(/\r/g,'').replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");
|
||||||
|
|
||||||
verified = verified && cleartextSig.signatures[0].status && cleartextSig.signatures[1].status;
|
verified = verified && cleartextSig.signatures[0].status && cleartextSig.signatures[1].status;
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ var pub_key_arm3 =
|
||||||
|
|
||||||
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey], csMsg);
|
var cleartextSig = openpgp.verifyClearSignedMessage([pubKey], csMsg);
|
||||||
|
|
||||||
var verified = cleartextSig.text == plaintext;
|
var verified = cleartextSig.text == plaintext.replace(/\r/g,'').replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");
|
||||||
|
|
||||||
verified = verified && cleartextSig.signatures[0].status;
|
verified = verified && cleartextSig.signatures[0].status;
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user