Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remote key manager #202

Open
wants to merge 17 commits into
base: feature/p2pmessaging
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added remote key client test
indramalav committed May 27, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 706be90ee3b037e7acdd8fb6e7f66881e381893b
4 changes: 3 additions & 1 deletion src/core/domain-services/crux-messenger.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ export class CertificateManager {
public static make = async (idClaim: ICruxIdClaim): Promise<ICruxIdCertificate> => {
const payload = idClaim.cruxId.toString();
console.log("%&%&%&%&%", idClaim.keyManager);
console.log(payload);
console.log("@@#@#@#@", idClaim.keyManager.getPubKey(), payload);
const signedProof = await idClaim.keyManager.signWebToken(payload);
return {
claim: idClaim.cruxId.toString(),
@@ -173,7 +173,9 @@ export class SecureCruxIdMessenger {
const securePacket: ISecurePacket = JSON.parse(serializedSecurePacket);
let senderUser: CruxUser | undefined;
if (securePacket.certificate) {
console.log("~~!!!!!~~~", securePacket.certificate.claim);
senderUser = await this.cruxUserRepo.getByCruxId(CruxId.fromString(securePacket.certificate.claim));
console.log(senderUser);
if (!senderUser) {
errorCallback(new Error("Claimed sender user in certificate does not exist"));
return;
1 change: 1 addition & 0 deletions src/core/domain-services/remote-key-service.ts
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ export class RemoteKeyClient {
if (!this.secureCruxIdMessenger) {
throw Error("RemoteKeyClient cannot listen with no selfMessenger");
}
console.log("%$%$%^%$%^%", invocationId);
this.emitter.on(invocationId, resultCallback);
this.emitter.on("error", errorCallback);
}
105 changes: 105 additions & 0 deletions src/test/crux-messenger/test-remote-key-client-prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import * as chai from "chai";
import sinon from "sinon";
import chaiAsPromised from "chai-as-promised";
import 'mocha';
import * as blockstack from "blockstack";
import {SecureCruxIdMessenger, RemoteKeyClient, RemoteKeyHost, RemoteKeyManager} from "../../core/domain-services";
import {BasicKeyManager, CruxNetPubSubClientFactory} from "../../infrastructure/implementations";
import {CruxId} from "../../packages";
import {InMemoryCruxUserRepository, MockUserStore, patchMissingDependencies, getCruxdevCruxDomain} from "../test-utils";
import { bip32 } from "bitcoinjs-lib";
import * as bip39 from "bip39";
import { getCruxUserRepository } from "../../application/clients";
import { CruxSpec } from "../../core/entities";

patchMissingDependencies();

chai.use(chaiAsPromised);
chai.should();
const expect = require('chai').expect;

const _generateMnemonic = (): string => {
return blockstack.BlockstackWallet.generateMnemonic();
}

const _generateIdentityKeyPair = async (mnemonic: string): Promise<any> => {
const wallet = new blockstack.BlockstackWallet(bip32.fromSeed(bip39.mnemonicToSeedSync(mnemonic)));
const { address, key, keyID} = wallet.getIdentityKeyPair(0);
const identityKeyPair: any = {
address,
privKey: key,
pubKey: keyID,
};
return identityKeyPair;
}

const user1PvtKey = "cdf2d276caf0c9c34258ed6ebd0e60e0e8b3d9a7b8a9a717f2e19ed9b37f7c6f"; // [email protected]
const user2PvtKey = "KyBuSe1MMV6NjJgZfyWuvgmxUeAYswLC2HrfYLUri9aP3AS5FBfr"; // [email protected]

describe('Test RemoteKeyClient - PROD', function() {
beforeEach(async function() {
const HOST = "127.0.0.1";
const PORT = 1883;
const newMnemonic = _generateMnemonic();
const identityKeyPair = await _generateIdentityKeyPair(newMnemonic);
console.log("+++++()()()", identityKeyPair, identityKeyPair.privKey);
// const keyPair = curve.genKeyPair();
// console.log(keyPair.getPublic('hex'));
this.user2CruxId = "[email protected]";
this.user1KeyManager = new BasicKeyManager(user1PvtKey);
console.log("!!!", this.user1KeyManager);
this.user2KeyManager = new BasicKeyManager(user2PvtKey);
console.log("===", this.user2KeyManager);
this.userRepo = getCruxUserRepository({
blockstackInfrastructure: CruxSpec.blockstack.infrastructure,
cruxDomain: getCruxdevCruxDomain()
});
this.user1Data = await this.userRepo.getWithKey(this.user1KeyManager);
this.user2Data = await this.userRepo.getWithKey(this.user2KeyManager);
this.pubsubClientFactory = new CruxNetPubSubClientFactory({
defaultLinkServer: {
host: HOST,
port: PORT,
}
});
});

it('Basic Key Manager Send Receive - RemoteKeyManager - Prod', async function() {
const testPubKey = "03e6bbc79879d37473836771441a79d3d9dddfabacdac22ed315e5636ff819a318";
return new Promise(async (resolve, reject) => {
const remoteKeyManager = new RemoteKeyManager(new SecureCruxIdMessenger(this.userRepo, this.pubsubClientFactory, {
cruxId: this.user2Data.cruxID,
keyManager: this.user2KeyManager
}), this.user1Data.cruxID);

const remoteKeyHost = new RemoteKeyHost(new SecureCruxIdMessenger(this.userRepo, this.pubsubClientFactory, {
cruxId: this.user1Data.cruxID,
keyManager: this.user1KeyManager
}), this.user1KeyManager);

remoteKeyHost.invocationListener((msg, senderId) => {
new Promise(async (resolve, reject) => {
console.log("&^%$#%^&*&^%$", msg);
const data = await remoteKeyHost.handleMessage(msg);
console.log("+++^^^&^^", data);
remoteKeyHost.sendInvocationResult(data, senderId);
resolve();
});
},(err) => {
});
const signedWebToken = await remoteKeyManager.signWebToken("1234567")
console.log(signedWebToken);
expect(signedWebToken).to.have.length(138);
const publicKey = await remoteKeyManager.getPubKey();
console.log(publicKey);
// expect(publicKey).to.equals(testPubKey);
const sharedSecret = await remoteKeyManager.deriveSharedSecret(testPubKey)
console.log(sharedSecret);
// expect(sharedSecret).to.equals("3380b4752c9cebf96bc55491ef0ee67ae1d564c0bb931a0c6e8875be6e3bee5");
// const decryptedMessage = await remoteKeyManager.decryptMessage("4b4f34746f434c30354349312b41314b554f644542773d3d");
// console.log(decryptedMessage);
// expect(decryptedMessage).to.equals("");
resolve();
});
});
})