234 lines
20 KiB
JavaScript
234 lines
20 KiB
JavaScript
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"RRTcVk":[function(require,module,exports){
|
|
|
|
module.exports = require('./keyring.js');
|
|
module.exports.localstore = require('./localstore.js');
|
|
|
|
},{"./keyring.js":3,"./localstore.js":4}],"keyring":[function(require,module,exports){
|
|
module.exports=require('RRTcVk');
|
|
},{}],3:[function(require,module,exports){
|
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
// Copyright (C) 2011 Recurity Labs GmbH
|
|
//
|
|
// 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 2.1 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
|
|
|
|
var openpgp = require('openpgp');
|
|
|
|
/**
|
|
* @class
|
|
* @classdesc The class that deals with storage of the keyring. Currently the only option is to use HTML5 local storage.
|
|
*/
|
|
var keyring = function() {
|
|
this.keys = [];
|
|
|
|
/**
|
|
* Initialization routine for the keyring. This method reads the
|
|
* keyring from HTML5 local storage and initializes this instance.
|
|
* This method is called by openpgp.init().
|
|
*/
|
|
function init(storeHandler) {
|
|
this.storeHandler = storeHandler ? storeHandler : require('./localstore');
|
|
this.keys = [];
|
|
this.storeHandler.init(this.keys);
|
|
}
|
|
this.init = init;
|
|
|
|
this.store = function () {
|
|
this.storeHandler.store(this.keys);
|
|
}
|
|
|
|
function emailCheck(email, key) {
|
|
email = email.toLowerCase();
|
|
var keyEmails = key.getUserIds();
|
|
for (var i; i < keyEmails.length; i++) {
|
|
//we need to get just the email from the userid key
|
|
keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();
|
|
if (keyEmail == email) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function idCheck(id, key) {
|
|
var keyids = key.getKeyIds();
|
|
for (var i = 0; i < keyids.length; i++) {
|
|
if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) {
|
|
var results = [];
|
|
for (var p = 0; p < keys.length; p++) {
|
|
var key = keys[p];
|
|
switch (keyType) {
|
|
case openpgp.enums.packet.public_key:
|
|
if (key.isPublic() && identityFunction(identityInput, key)) {
|
|
results.push(key);
|
|
}
|
|
break;
|
|
case openpgp.enums.packet.private_key:
|
|
if (key.isPrivate() && identityFunction(identityInput, key)) {
|
|
results.push(key);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
this.checkForIdentityAndKeyTypeMatch = checkForIdentityAndKeyTypeMatch;
|
|
|
|
/**
|
|
* searches all public keys in the keyring matching the address or address part of the user ids
|
|
* @param {String} email email address to search for
|
|
* @return {openpgp.key.Key[]} The public keys associated with provided email address.
|
|
*/
|
|
function getPublicKeyForAddress(email) {
|
|
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.public_key);
|
|
}
|
|
this.getPublicKeyForAddress = getPublicKeyForAddress;
|
|
|
|
/**
|
|
* Searches the keyring for a private key containing the specified email address
|
|
* @param {String} email email address to search for
|
|
* @return {openpgp.key.Key[]} private keys found
|
|
*/
|
|
function getPrivateKeyForAddress(email) {
|
|
return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secret_key);
|
|
}
|
|
this.getPrivateKeyForAddress = getPrivateKeyForAddress;
|
|
|
|
/**
|
|
* Searches the keyring for public keys having the specified key id
|
|
* @param {String} keyId provided as string of hex number (lowercase)
|
|
* @return {openpgp.key.Key[]} public keys found
|
|
*/
|
|
function getKeysForKeyId(keyId) {
|
|
return this.checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.public_key);
|
|
}
|
|
this.getKeysForKeyId = getKeysForKeyId;
|
|
|
|
/**
|
|
* Imports a key from an ascii armored message
|
|
* @param {String} armored message to read the keys/key from
|
|
*/
|
|
function importKey(armored) {
|
|
this.keys.push(openpgp.key.readArmored(armored));
|
|
|
|
return true;
|
|
}
|
|
this.importKey = importKey;
|
|
|
|
/**
|
|
* returns the armored message representation of the key at key ring index
|
|
* @param {Integer} index the index of the key within the array
|
|
* @return {String} armored message representing the key object
|
|
*/
|
|
function exportKey(index) {
|
|
return this.keys[index].armor();
|
|
}
|
|
this.exportKey = exportKey;
|
|
|
|
/**
|
|
* Removes a public key from the public key keyring at the specified index
|
|
* @param {Integer} index the index of the public key within the publicKeys array
|
|
* @return {openpgp.key.Key} The public key object which has been removed
|
|
*/
|
|
function removeKey(index) {
|
|
var removed = this.keys.splice(index, 1);
|
|
|
|
return removed;
|
|
}
|
|
this.removeKey = removeKey;
|
|
|
|
/**
|
|
* returns the armored message representation of the public key portion of the key at key ring index
|
|
* @param {Integer} index the index of the key within the array
|
|
* @return {String} armored message representing the public key object
|
|
*/
|
|
function exportPublicKey(index) {
|
|
return this.keys[index].toPublic().armor();
|
|
}
|
|
this.exportPublicKey = exportPublicKey;
|
|
|
|
};
|
|
|
|
module.exports = new keyring();
|
|
|
|
},{"./localstore":4}],4:[function(require,module,exports){
|
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
// Copyright (C) 2011 Recurity Labs GmbH
|
|
//
|
|
// 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 2.1 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
|
|
|
|
var openpgp = require('openpgp');
|
|
|
|
/**
|
|
* @class
|
|
* @classdesc The class that deals with storage of the keyring. Currently the only option is to use HTML5 local storage.
|
|
*/
|
|
var localstore = function() {
|
|
/**
|
|
* Initialization routine for the keyring. This method reads the
|
|
* keyring from HTML5 local storage and initializes this instance.
|
|
* This method is called by openpgp.init().
|
|
*/
|
|
function init(keys) {
|
|
var armoredKeys = JSON.parse(window.localStorage.getItem("armoredKeys"));
|
|
if (armoredKeys !== null && armoredKeys.length === 0) {
|
|
var key;
|
|
for (var i = 0; i < armoredKeys.length; i++) {
|
|
key = openpgp.key.readArmored(armoredKeys[i]);
|
|
keys.push(key);
|
|
}
|
|
} else {
|
|
this.keys = [];
|
|
}
|
|
}
|
|
this.init = init;
|
|
|
|
/**
|
|
* Saves the current state of the keyring to HTML5 local storage.
|
|
* The privateKeys array and publicKeys array gets Stringified using JSON
|
|
*/
|
|
function store(keys) {
|
|
var armoredKeys = [];
|
|
for (var i = 0; i < keys.length; i++) {
|
|
armoredKeys.push(keys[i].armor());
|
|
}
|
|
window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
|
|
}
|
|
this.store = store;
|
|
};
|
|
|
|
module.exports = new localstore();
|
|
|
|
},{}]},{},[])
|
|
//@ sourceMappingURL=data:application/json;base64,ey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