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

Conversation

punto-rojo
Copy link
Member

No description provided.

private selfIdClaim: any;
private cruxProtocolMessenger: any;

constructor(selfIdClaim: any, secureCruxNetwork: any, protocolSchema?: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't make sense to take protocolSchema as optional parameter. You always need protocol schema to be Key Management Protocol.
Is there any use case you designed this for? If not, remove.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does make sense I guess because CruxServiceClient can give you the different type of clients and some might use protocolSchema some might not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add this when we add more use cases to CruxServiceClient. for now remove.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove protocolSchema from the constructor itself. Making it non optional doesn't help us. The point is that there is only 1 protocolSchema this class can be used with at the moment. does not make sense for caller to have to send it.

Just like in CruxWalletClient, the caller does NOT have any awareness of protocol schema or messenger internals or anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i will remove it

src/application/clients/crux-wallet-client.ts Outdated Show resolved Hide resolved
src/infrastructure/implementations/crux-messenger.ts Outdated Show resolved Hide resolved
src/core/domain-services/remote-key-service.ts Outdated Show resolved Hide resolved
src/core/domain-services/remote-key-service.ts Outdated Show resolved Hide resolved
src/core/domain-services/remote-key-service.ts Outdated Show resolved Hide resolved
let data;
if (message.method === "signWebToken") {
console.log("HandleMessage entrance:signWebToken");
data = await this.keyManager.signWebToken(message.args[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if function has multiple arguments? does args[0] mean only first argument will go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all functions require single or zero parameters. So args[0] will work

Copy link
Member

@quixote911 quixote911 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better way to do it which will work for any function -

            const func = (a, b) => {
                console.log(a+b);
            }
            const args = [1,2]
            // @ts-ignore
            func(...args);

or

            const func = (a, b) => {
                console.log(a+b);
            }
            const args = [1,2]
            func.apply(this, args);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood will modify it accordingly

src/core/domain-services/remote-key-service.ts Outdated Show resolved Hide resolved
@quixote911
Copy link
Member

Please fix merge conflicts carefully. There are some after I merged Sanchay's branch.

@@ -98,7 +98,7 @@ export const getCruxUserRepository = (options: IBlockstackCruxUserRepositoryOpti

export const getPubsubClientFactory = (): IPubSubClientFactory => {
return new CruxNetPubSubClientFactory({defaultLinkServer: {
host: "broker.hivemq.com",
host: "127.0.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this in code. In code we should have a globally accessible server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we put it in config??

Copy link
Member

@quixote911 quixote911 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally do it in the same way we've done it for Blockstack user repository. It also requires such a default for Blockstack stuff.

Look at line 127 of crux-wallet-client.ts

this.cruxBlockstackInfrastructure = options.blockstackInfrastructure || CruxSpec.blockstack.infrastructure;

Defaults are defined in CruxSpec. just read directly from there. No need to do the options.blockstackInfrastructure || part.

@@ -71,7 +71,8 @@ export class RemoteKeyHost {
console.log("Inside RemoteKeyHost::in::Msg, senderId: ", msg, senderId);
const data = await this.handleMessage(msg);
console.log("Inside RemoteKeyHost::initialize::Data(handleMessage): ", data);
this.sendInvocationResult(data, senderId!);
// @ts-ignore
await this.sendInvocationResult(data, CruxId.fromString(senderId!)); // getting senderId as string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID should be coming as object here. If it isn't then it's a bug! Can you fix it?
SecureReceiveSocket will be the right place to do it. Please think about why it's the right place to do it, let me know if you disagree.

Copy link
Member Author

@punto-rojo punto-rojo Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah seems so. will check it again and fix it. And yes SecureRecieveSocket will be best as it will make sure that it's consistent throughout (CruxID)

return this.makeRemoteMessageCall("deriveSharedSecret", [args]);
}
// @ts-ignore
public decryptMessage = async (args: string) => {
Copy link
Member

@quixote911 quixote911 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong naming of parameter in all methods - look at other KeyManager implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry will take care of it

}
// @ts-ignore
public getPubKey = async () => {
return this.makeRemoteMessageCall("getPubKey");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do an optimization here -
We know the Crux ID. And we're doing secure communication on the sole basis of the fact that we know the ID's Public Key. So we don't need to do makeRemoteMessageCall to getPubKey. You can get a CruxUser from CruxId and get Public Key from there. How to get CruxUser? We need UserRepository. SecureCruxNetwork already has a userRepository, Just that it's a private variable at the moment. You can make it public, and access it via CruxProtocolMessenger->SecureCruxNetwork->userRepository

public signWebToken = async (args: any) => {
return this.makeRemoteMessageCall("signWebToken", [args]);
}
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ts ignore and fix errors. Let me know if you're getting confused with 'args' and how to make it generic for arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants