Merge branch 'master' into http-to-https

This commit is contained in:
Mahrud Sayrafi
2018-02-08 10:56:46 -08:00
committed by GitHub
82 changed files with 6622 additions and 2516 deletions

69
src/type/ecdh_symkey.js Normal file
View File

@@ -0,0 +1,69 @@
// OpenPGP.js - An OpenPGP implementation in javascript
// Copyright (C) 2015-2016 Decentral
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3.0 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
* Encoded symmetric key for ECDH<br/>
* <br/>
* @requires util
* @module type/ecdh_symkey
*/
'use strict';
import util from '../util';
module.exports = ECDHSymmetricKey;
/**
* @constructor
*/
function ECDHSymmetricKey(data) {
if (typeof data === 'undefined') {
data = new Uint8Array([]);
} else if (util.isString(data)) {
data = util.str2Uint8Array(data);
} else {
data = new Uint8Array(data);
}
this.data = data;
}
/**
* Read an ECDHSymmetricKey from an Uint8Array
* @param {Uint8Array} input Where to read the encoded symmetric key from
* @return {Number} Number of read bytes
*/
ECDHSymmetricKey.prototype.read = function (input) {
if (input.length >= 1)
{
var length = input[0];
if (input.length >= 1+length)
{
this.data = input.subarray(1, 1+length);
return 1+this.data.length;
}
}
throw new Error('Invalid symmetric key');
};
/**
* Write an ECDHSymmetricKey as an Uint8Array
* @return {Uint8Array} An array containing the value
*/
ECDHSymmetricKey.prototype.write = function () {
return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
};

70
src/type/kdf_params.js Normal file
View File

@@ -0,0 +1,70 @@
// OpenPGP.js - An OpenPGP implementation in javascript
// Copyright (C) 2015-2016 Decentral
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3.0 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
* Implementation of type KDF parameters RFC 6637<br/>
* <br/>
* @requires enums
* @module type/kdf_params
*/
'use strict';
import enums from '../enums.js';
module.exports = KDFParams;
/**
* @constructor
* @param {enums.hash} hash Hash algorithm
* @param {enums.symmetric} cipher Symmetric algorithm
*/
function KDFParams(data) {
if (data && data.length === 2) {
this.hash = data[0];
this.cipher = data[1];
} else {
this.hash = enums.hash.sha1;
this.cipher = enums.symmetric.aes128;
}
}
/**
* Read KDFParams from an Uint8Array
* @param {Uint8Array} input Where to read the KDFParams from
* @return {Number} Number of read bytes
*/
KDFParams.prototype.read = function (input) {
if (input.length < 4 || input[0] !== 3 || input[1] !== 1) {
throw new Error('Cannot read KDFParams');
}
this.hash = input[2];
this.cipher = input[3];
return 4;
};
/**
* Write KDFParams to an Uint8Array
* @return {Uint8Array} Array with the KDFParams value
*/
KDFParams.prototype.write = function () {
return new Uint8Array([3, 1, this.hash, this.cipher]);
};
KDFParams.fromClone = function (clone) {
return new KDFParams(clone.hash, clone.cipher);
};

View File

@@ -36,25 +36,32 @@
'use strict';
import BigInteger from '../crypto/public_key/jsbn.js';
import util from '../util.js';
import BigInteger from '../crypto/public_key/jsbn';
import util from '../util';
/**
* @constructor
*/
export default function MPI() {
export default function MPI(data) {
/** An implementation dependent integer */
this.data = null;
if (data instanceof BigInteger) {
this.fromBigInteger(data);
} else if (util.isString(data)) {
this.fromBytes(data);
} else {
this.data = null;
}
}
/**
* Parsing function for a mpi ({@link https://tools.ietf.org/html/rfc4880#section3.2|RFC 4880 3.2}).
* @param {String} input Payload of mpi data
* @param {String} endian Endianness of the payload; 'be' for big-endian and 'le' for little-endian
* @return {Integer} Length of data read
*/
MPI.prototype.read = function (bytes) {
MPI.prototype.read = function (bytes, endian='be') {
if(typeof bytes === 'string' || String.prototype.isPrototypeOf(bytes)) {
if(util.isString(bytes)) {
bytes = util.str2Uint8Array(bytes);
}
@@ -71,8 +78,11 @@ MPI.prototype.read = function (bytes) {
// TODO: Verification of this size method! This size calculation as
// specified above is not applicable in JavaScript
var bytelen = Math.ceil(bits / 8);
var raw = util.Uint8Array2str(bytes.subarray(2, 2 + bytelen));
var payload = bytes.subarray(2, 2 + bytelen);
if (endian === 'le') {
payload = new Uint8Array(payload).reverse();
}
var raw = util.Uint8Array2str(payload);
this.fromBytes(raw);
return 2 + bytelen;

82
src/type/oid.js Normal file
View File

@@ -0,0 +1,82 @@
// OpenPGP.js - An OpenPGP implementation in javascript
// Copyright (C) 2015-2016 Decentral
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3.0 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
* Wrapper to an OID value<br/>
* <br/>
* An object identifier type from {@link https://tools.ietf.org/html/rfc6637#section-11|RFC6637, section 11}.
* @requires util
* @module type/oid
*/
'use strict';
import util from '../util.js';
module.exports = OID;
/**
* @constructor
*/
function OID(oid) {
if (typeof oid === 'undefined') {
oid = '';
} else if (util.isArray(oid)) {
oid = util.bin2str(oid);
} else if (util.isUint8Array(oid)) {
oid = util.Uint8Array2str(oid);
}
this.oid = oid;
}
/**
* Method to read an OID object
* @param {Uint8Array} input Where to read the OID from
* @return {Number} Number of read bytes
*/
OID.prototype.read = function (input) {
if (input.length >= 1) {
var length = input[0];
if (input.length >= 1+length) {
this.oid = util.Uint8Array2str(input.subarray(1, 1+length));
return 1+this.oid.length;
}
}
throw new Error('Invalid oid');
};
/**
* Serialize an OID object
* @return {Uint8Array} Array with the serialized value the OID
*/
OID.prototype.write = function () {
return util.str2Uint8Array(
String.fromCharCode(this.oid.length)+this.oid);
};
/**
* Serialize an OID object as a hex string
* @return {string} String with the hex value of the OID
*/
OID.prototype.toHex = function() {
return util.hexstrdump(this.oid);
};
OID.fromClone = function (clone) {
var oid = new OID(clone.oid);
return oid;
};

View File

@@ -156,15 +156,11 @@ S2K.prototype.produce_key = function (passphrase, numBytes) {
util.concatUint8Array([prefix, s2k.salt, passphrase]));
case 'iterated':
var isp = [],
count = s2k.get_count(),
data = util.concatUint8Array([s2k.salt,passphrase]);
var count = s2k.get_count(),
data = util.concatUint8Array([s2k.salt,passphrase]),
isp = new Array(Math.ceil(count / data.length));
while (isp.length * data.length < count) {
isp.push(data);
}
isp = util.concatUint8Array(isp);
isp = util.concatUint8Array(isp.fill(data));
if (isp.length > count) {
isp = isp.subarray(0, count);