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

Multisig: Connect request and SignMultisigTransaction request #458

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

sisou
Copy link
Member

@sisou sisou commented Dec 1, 2022

Related: nimiq/hub#521

This PR adds two requests:

  • Connect
  • SignMultisigTransaction

Connect

For this request, I am adding deterministic RSA key generation from the user's Key's secret. The public RSA key is then shared with the connected app, to be able to encrypt data that only the Keyguard can decrypt again. Encryption and decryption uses the window.crypto.subtle APIs.

SignMultisigRequest

Nothing special added, this uses the code from the @nimiq/core SDK to do multisig signatures.

@sisou sisou requested review from danimoh and mraveux December 1, 2022 15:36
@sisou sisou self-assigned this Dec 1, 2022
@sisou
Copy link
Member Author

sisou commented Dec 1, 2022

@danimoh Do you maybe have a better idea of how to solve the double KeyguardCommand.KeyguardCommand in this commit?
2532190

@sisou sisou force-pushed the multisig branch 2 times, most recently from 08af4d0 to 08748bb Compare December 5, 2022 17:05
@sisou sisou force-pushed the multisig branch 2 times, most recently from 0482b2d to da83212 Compare May 22, 2023 10:10
@sisou sisou force-pushed the multisig branch 2 times, most recently from 26cbddd to 58a01c6 Compare October 22, 2023 14:45
Copy link
Member

@danimoh danimoh left a comment

Choose a reason for hiding this comment

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

In my opinion, quite a bit too many shortcuts have been taken, for example regarding missing i18n, unencrypted storage of private keys and omission of of relevant information in the UI.

There were also several serious security issues:

  • generated RSA keys are orders of magnitude weaker than they should be, due to the way they are generated.
  • (almost) arbitrary Nimiq messages are blindly signed, which can be used to impersonate the user.
  • malicious apps are able to trick the Keyguard into storing and using RSA private keys known to them.

Additionally, this PR points out opportunities for further security hardening, code cleanup, code deduplication, smaller fixes, stricter parsing etc..

@@ -1,3 +1,4 @@
*.min.*
src/lib/bitcoin/BitcoinJS.js
src/lib/polygon/OpenGSN.js
src/lib/multisig/wasm/pkg
Copy link
Member

Choose a reason for hiding this comment

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

This folder has been removed again in fbbcf06.

Comment on lines +212 to +217
export type SignMultisigTransactionRequestCommon = Transform<SignTransactionRequestCommon, 'keyLabel' | 'senderLabel', {
keyLabel: string, // Not optional
senderLabel: string, // Not optional
}> & {
multisigConfig: MultisigConfig,
};
Copy link
Member

Choose a reason for hiding this comment

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

Could also be

Suggested change
export type SignMultisigTransactionRequestCommon = Transform<SignTransactionRequestCommon, 'keyLabel' | 'senderLabel', {
keyLabel: string, // Not optional
senderLabel: string, // Not optional
}> & {
multisigConfig: MultisigConfig,
};
export type SignMultisigTransactionRequestCommon = Transform<
SignTransactionRequestCommon,
'keyLabel' | 'senderLabel',
Required<Pick<SignTransactionRequestCommon, 'keyLabel' | 'senderLabel'>>
> & {
multisigConfig: MultisigConfig,
};

This ensures that there are no discrepancies if the original types of keyLabel or senderLabel were to change in SignTransactionRequestCommon, or if they were to be removed there. Obviously, in this case this benefit is of a rather theoretical nature. I just wanted to mention this alternative.

@@ -94,6 +94,7 @@ export type BitcoinTransactionInfo = {
};

export type SignTransactionRequestLayout = 'standard' | 'checkout' | 'cashlink';
export type SignMultisigTransactionRequestLayout = 'standard';
Copy link
Member

Choose a reason for hiding this comment

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

Are you planning to add other layouts?

@@ -593,8 +652,11 @@ export type Result = RedirectResult | IFrameResult;
// Derived Result types

export type ResultType<T extends RedirectRequest> =
T extends Is<T, SignMessageRequest> | Is<T, SignTransactionRequest> ? SignatureResult :
T extends Is<T, SignMessageRequest> ? SignatureResult :
Copy link
Member

Choose a reason for hiding this comment

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

Should SignMessageRequest also receive an alias SignMessageResult for SignatureResult, similar to SignMultisigTransactionResult? Also in RedirectResult above and ResultByCommand below.

Comment on lines +35 to +39
type EncryptionKeyParams = {
kdf: string
iterations: number
keySize: number
}
Copy link
Member

Choose a reason for hiding this comment

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

Can be used as KeyguardRequest.EncryptionKeyParams without copying it from PublicRequest.ts.

Suggested change
type EncryptionKeyParams = {
kdf: string
iterations: number
keySize: number
}
type EncryptionKeyParams = KeyguardRequest.EncryptionKeyParams;

$badge.classList.add('multisig-badge', 'nq-blue-bg');
$badge.innerHTML = TemplateTags.hasVars(2)`
${this._addressInfo.multisig.signers}
<span class="of">of</span>
Copy link
Member

Choose a reason for hiding this comment

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

Missing i18n.

padding: 0.375rem 0.75rem;
line-height: 1;
border: 0.5rem solid white;
word-spacing: -0.071428571em; // 1/14
Copy link
Member

Choose a reason for hiding this comment

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

Invalid CSS comment (should be /* 1/14 */). But probably better as calc(-1em / 14) anyways.

Suggested change
word-spacing: -0.071428571em; // 1/14
word-spacing: calc(-1em / 14);


class LoginFileAccountIcon { // eslint-disable-line no-unused-vars
/**
* @param {string} [address]
Copy link
Member

Choose a reason for hiding this comment

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

Why is the address allowed to be undefined? It's nowhere used in such a fashion.

@@ -365,6 +366,7 @@ cp -v favicon.ico dist
cp -rv src/assets/* dist/assets/
cp -v src/lib/QrScannerWorker.js dist/lib/
cp -v node_modules/@nimiq/style/nimiq-style.icons.svg dist/assets/
cp -v src/lib/rsa/sandboxed/* dist/lib/rsa/sandboxed/
Copy link
Member

Choose a reason for hiding this comment

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

Integrity hashes on the js files would be good.

Comment on lines +27 to +29
<div><a href="/demos/SignMultisigTransaction.html">Sign Multisig TX</a></div>
<div><a href="/demos/RSAKeys.html">RSA Keys</a></div>
<div><a href="/demos/ConnectAccount.html">Connect Account</a></div>
Copy link
Member

Choose a reason for hiding this comment

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

These demos don't work currently.

danimoh

This comment was marked as duplicate.

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