Further test work, make keyring marginally work. Start end-to-end work.
This commit is contained in:
parent
1f88d00375
commit
fae321a1e3
File diff suppressed because one or more lines are too long
|
@ -93,6 +93,22 @@ function _openpgp () {
|
||||||
|
|
||||||
function verifyMessage(publicKeyPacketlist, messagePacketlist) {
|
function verifyMessage(publicKeyPacketlist, messagePacketlist) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function signMessage(privateKeyPacketlist, messagePacketlist) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateKeyPair(keyType, numBits, userId, passphrase) {
|
||||||
|
debugger;
|
||||||
|
var packetlist = new packet.list();
|
||||||
|
|
||||||
|
var secretKeyPacket = new packet.secret_key();
|
||||||
|
var userIdPacket = new packet.userid();
|
||||||
|
var signaturePacket = new packet.signature();
|
||||||
|
var secretSubkeyPacket = new packet.secret_subkey();
|
||||||
|
var overallSignaturePacket = new packet.signature();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +271,7 @@ function _openpgp () {
|
||||||
return {privateKey : privKey, privateKeyArmored: privArmored, publicKeyArmored: publicArmored};
|
return {privateKey : privKey, privateKeyArmored: privArmored, publicKeyArmored: publicArmored};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generate_key_pair = generate_key_pair;
|
this.generateKeyPair = generateKeyPair;
|
||||||
this.write_signed_message = write_signed_message;
|
this.write_signed_message = write_signed_message;
|
||||||
this.write_signed_and_encrypted_message = write_signed_and_encrypted_message;
|
this.write_signed_and_encrypted_message = write_signed_and_encrypted_message;
|
||||||
this.write_encrypted_message = write_encrypted_message;
|
this.write_encrypted_message = write_encrypted_message;
|
||||||
|
|
|
@ -57,38 +57,62 @@ var keyring = function() {
|
||||||
}
|
}
|
||||||
this.store = store;
|
this.store = store;
|
||||||
|
|
||||||
function checkForEmailAndPacketMatch(email, packetType){
|
function emailPacketCheck(packet, email) {
|
||||||
|
var emailMatch = false;
|
||||||
|
var packetEmail;
|
||||||
email = email.toLowerCase();
|
email = email.toLowerCase();
|
||||||
|
if (packet.tag == enums.packet.userid) {
|
||||||
|
packetEmail = packet.userid;
|
||||||
|
//we need to get just the email from the userid packet
|
||||||
|
packetEmail = packetEmail.split('<')[1].split('<')[0].trim.toLowerCase();
|
||||||
|
if (packetEmail == email) {
|
||||||
|
emailMatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emailMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
function idPacketCheck(packet, id) {
|
||||||
|
if (packet.getKeyId && packet.getKeyId() == id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function helperCheckIdentityAndPacketMatch(identityFunction, identityInput, packetType, packetlist) {
|
||||||
|
var packet;
|
||||||
|
for (var l = 0; l < packetlist.length; l++) {
|
||||||
|
packet = packetlist[l];
|
||||||
|
identityMatch = identityFunction(packet, identityInput);
|
||||||
|
if (!packetType) {
|
||||||
|
packetMatch = true;
|
||||||
|
}
|
||||||
|
else if (packet.tag == packetType) {
|
||||||
|
packetMatch = true;
|
||||||
|
}
|
||||||
|
if (packetMatch && identityMatch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkForIdentityAndPacketMatch(identityFunction, identityInput, packetType) {
|
||||||
var results = [];
|
var results = [];
|
||||||
var packetlist;
|
var packetlist;
|
||||||
var packet;
|
var identityMatch;
|
||||||
var packetEmail;
|
|
||||||
var emailMatch;
|
|
||||||
var packetMatch;
|
var packetMatch;
|
||||||
for (var p = 0; p < this.parsedPacketlists.length; p++) {
|
for (var p = 0; p < this.parsedPacketlists.length; p++) {
|
||||||
emailMatch = false;
|
identityMatch = false;
|
||||||
packetMatch = false;
|
packetMatch = false;
|
||||||
packetlist = this.parsedPacketlists[p];
|
packetlist = this.parsedPacketlists[p];
|
||||||
for (var l = 0; l < packetlist.length; l++) {
|
if (helperCheckIdentityAndPacketMatch(identityFunction, identityInput, packetType, packetlist)) {
|
||||||
packet = packetlist[l];
|
|
||||||
if (packet.tag == enums.packet.userid) {
|
|
||||||
packetEmail = packet.userid;
|
|
||||||
//we need to get just the email from the userid packet
|
|
||||||
packetEmail = packetEmail.split('<')[1].split('<')[0].trim.toLowerCase();
|
|
||||||
if (packetEmail == email) {
|
|
||||||
emailMatch = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (packet.tag == packetType) {
|
|
||||||
packetMatch = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (packetMatch && emailMatch) {
|
|
||||||
results.push(packetlist);
|
results.push(packetlist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
this.checkForIdentityAndPacketMatch = checkForIdentityAndPacketMatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* searches all public keys in the keyring matching the address or address part of the user ids
|
* searches all public keys in the keyring matching the address or address part of the user ids
|
||||||
|
@ -96,7 +120,7 @@ var keyring = function() {
|
||||||
* @return {openpgp_msg_publickey[]} The public keys associated with provided email address.
|
* @return {openpgp_msg_publickey[]} The public keys associated with provided email address.
|
||||||
*/
|
*/
|
||||||
function getPublicKeyForAddress(email) {
|
function getPublicKeyForAddress(email) {
|
||||||
return checkForEmailAndPacketMatch(email, enums.packet.public_key);
|
return checkForIdentityAndPacketMatch(emailPacketCheck, email, enums.packet.public_key);
|
||||||
}
|
}
|
||||||
this.getPublicKeyForAddress = getPublicKeyForAddress;
|
this.getPublicKeyForAddress = getPublicKeyForAddress;
|
||||||
|
|
||||||
|
@ -106,7 +130,7 @@ var keyring = function() {
|
||||||
* @return {openpgp_msg_privatekey[]} private keys found
|
* @return {openpgp_msg_privatekey[]} private keys found
|
||||||
*/
|
*/
|
||||||
function getPrivateKeyForAddress(email_address) {
|
function getPrivateKeyForAddress(email_address) {
|
||||||
return checkForEmailAndPacketMatch(email, enums.packet.secret_key);
|
return checkForIdentityAndPacketMatch(emailPacketCheck, email, enums.packet.secret_key);
|
||||||
}
|
}
|
||||||
this.getPrivateKeyForAddress = getPrivateKeyForAddress;
|
this.getPrivateKeyForAddress = getPrivateKeyForAddress;
|
||||||
|
|
||||||
|
@ -115,12 +139,12 @@ var keyring = function() {
|
||||||
* @param {String} keyId provided as string of hex number (lowercase)
|
* @param {String} keyId provided as string of hex number (lowercase)
|
||||||
* @return {openpgp_msg_privatekey[]} public keys found
|
* @return {openpgp_msg_privatekey[]} public keys found
|
||||||
*/
|
*/
|
||||||
function getPacketlistForKeyId(keyId) {
|
function getPacketlistsForKeyId(keyId) {
|
||||||
|
return this.checkForIdentityAndPacketMatch(idPacketCheck, keyId);
|
||||||
}
|
}
|
||||||
this.getPacketlistForKeyId = getPacketlistForKeyId;
|
this.getPacketlistsForKeyId = getPacketlistsForKeyId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO test
|
|
||||||
* Imports a packet list (public or private key block) from an ascii armored message
|
* Imports a packet list (public or private key block) from an ascii armored message
|
||||||
* @param {String} armored message to read the packets/key from
|
* @param {String} armored message to read the packets/key from
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -253,6 +253,7 @@ function packet_secret_key() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generate = function(bits) {
|
this.generate = function(bits) {
|
||||||
|
this.mpi;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,11 +159,13 @@ unit.register("Testing of binary signature checking", function() {
|
||||||
'=WaSx',
|
'=WaSx',
|
||||||
'-----END PGP MESSAGE-----'
|
'-----END PGP MESSAGE-----'
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
var pubKey = keyring.getPacketlistForKeyId(msg2[1].signature.issuerKeyId);
|
var packetlists = keyring.getPacketlistsForKeyId(msg2[0].signingKeyId.write());
|
||||||
|
var pubKey = packetlists[0];
|
||||||
|
msg2[2].verify(pubKey[3], msg2[1]);
|
||||||
result[2] = new unit.result("Testing keyring public subkey support",
|
result[2] = new unit.result("Testing keyring public subkey support",
|
||||||
pubKey != null &&
|
packetlists !== null &&
|
||||||
pubKey.length == 1 &&
|
packetlists.length == 1 &&
|
||||||
msg2[1].signature.verify(msg2[0].data, pubKey[0]));
|
msg2[2].verified);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
|
var unit = require('../unit.js');
|
||||||
|
|
||||||
unittests.register("Encryption/decryption", function() {
|
unit.register("Encryption/decryption", function() {
|
||||||
|
var openpgp = require('../../');
|
||||||
openpgp.init();
|
var keyring = require('../../src/openpgp.keyring.js');
|
||||||
|
var result = [];
|
||||||
|
var key = openpgp.generateKeyPair(openpgp.enums.publicKey.rsa_encrypt_sign, 512,
|
||||||
|
'Test McTestington <test@example.com>', 'hello world');
|
||||||
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'
|
var info = '\npassphrase: ' + passphrase + '\n'
|
||||||
+ 'userid: ' + userid + '\n'
|
+ 'userid: ' + userid + '\n'
|
||||||
|
@ -46,11 +43,11 @@ function test(passphrase, userid, message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var decrypted = ''
|
var decrypted = '';
|
||||||
if (keymat != null) {
|
if (keymat !== null) {
|
||||||
if (!keymat.keymaterial.decryptSecretMPIs(passphrase)) {
|
if (!keymat.keymaterial.decryptSecretMPIs(passphrase)) {
|
||||||
return new test_result("Password for secrect key was incorrect!",
|
return new test_result("Password for secrect key was incorrect!",
|
||||||
+ info, false)
|
+ info, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypted = msg[0].decrypt(keymat, sesskey);
|
decrypted = msg[0].decrypt(keymat, sesskey);
|
||||||
|
@ -58,12 +55,11 @@ function test(passphrase, userid, message) {
|
||||||
return new test_result("No private key found!" + info, false);
|
return new test_result("No private key found!" + info, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new test_result(message + ' == ' + decrypted + info, message == decrypted);
|
result.push(new test_result(message + ' == ' + decrypted + info, message == decrypted));
|
||||||
}
|
|
||||||
|
|
||||||
var result = []
|
//result.push(test('password', 'Test McTestington <test@example.com>', 'hello world'));
|
||||||
result.push(test('password', 'Test McTestington <test@example.com>', 'hello world'));
|
//result.push(test('●●●●', '♔♔♔♔ <test@example.com>', 'łäóć'));
|
||||||
result.push(test('●●●●', '♔♔♔♔ <test@example.com>', 'łäóć'));
|
|
||||||
|
|
||||||
return result
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,3 +14,4 @@ require('./crypto/cipher/twofish.js');
|
||||||
require('./crypto/openpgp.crypto.js');
|
require('./crypto/openpgp.crypto.js');
|
||||||
require('./crypto/openpgp.sigcheck.js');
|
require('./crypto/openpgp.sigcheck.js');
|
||||||
|
|
||||||
|
require('./general/openpgp.basic.js');
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user