Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem: didn't verify secrets against public key in DirectPath #2018

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Jul 24, 2020

Solution:

  • verify decrypted secret against public key
  • also verify leaf keypackage against leaf secret

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

would be good to add a test + document (some explanation why) the "non-obvious" part:

kp_secret_pending has newer signature key but older kem key, new signature key is generated when preparing update proposal.
kp_secret has newer kem key but older signature key, new kem key is generated when commit the self-updating proposal.

let self_update_proposal = commit_content
.updates
.iter()
.filter_map(|(sender, update)| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can use find? because it's finding the first one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@leejw51crypto leejw51crypto left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -835,6 +848,8 @@ pub enum ProcessCommitError {
CommitError,
#[error("decrypted path secret don't match the public key")]
PathSecretPublicKeyDontMatch,
#[error("cached secret key don't match commit leaf keypackage")]
LeafSecretPublicKeyDontMatch,
Copy link
Contributor

Choose a reason for hiding this comment

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

seems this error is not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, let me remove it, this error case is now keypackage verify error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -570,6 +570,28 @@ impl TreePublicKey {
}
self.nodes[path[0].node_index()].compute_parent_hash(self.cs)
}

fn verify_node_private_key(
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok to make this pub(crate)? I may need to use this -- just document the intended usage/args

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

tomtau added a commit to tomtau/chain that referenced this pull request Jul 27, 2020
…pto-com#1797)

Solution: sketched out core of "NACK" mechanism
which involves revealing shared secrets from invalid
message parts and including DLEQ proofs.

-- currently, needs:
1) latest master of p256 which contains scalar arithmetic (not yet released)
2) for the high-level API, it needs to directly decrypt HPKE ciphertext
from a shared secret -- this may not ever be released

also needs "verify_node_private_key" from crypto-com#2018
@yihuang yihuang force-pushed the verify-path-secrets branch from fab1218 to 169fffa Compare July 28, 2020 01:15
@yihuang
Copy link
Collaborator Author

yihuang commented Jul 28, 2020

Added pending_updates(record pending credential private keys for self update proposals) and pending_commit (record pending init private keys for pending commits), it's more clear to handle pending private keys this way.

Comment on lines 578 to 590
if !bool::from(
private_key
.public_key()
.marshal()
.ct_eq(&node.public_key.marshal()),
) {
false
} else {
true
}
Copy link
Contributor

@tomtau tomtau Jul 28, 2020

Choose a reason for hiding this comment

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

could this be rewritten as:

bool::from(private_key
                      .public_key()
                      .marshal()
                      .ct_eq(&node.public_key.marshal())

or private_key.public_key().marshal().ct_eq(&node.public_key.marshal().into() without this extra if branching?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, nice catch

}
}

self.path_secrets.truncate(overlap_pos);
Copy link
Contributor

Choose a reason for hiding this comment

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

was a bit puzzled about truncate here -- I guess the meaning is that it'll keep secrets up to the overlap start (as they are unchanged), and then replace with was decrypted / computed?
a comment could be good here

Copy link
Collaborator Author

@yihuang yihuang Jul 28, 2020

Choose a reason for hiding this comment

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

yes, added a comment now.

@yihuang yihuang force-pushed the verify-path-secrets branch from 169fffa to 4e7cae6 Compare July 28, 2020 02:15
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

looks all right, but would be good to add a test where the encrypted secret doesn't match, so ProcessCommitError is correctly returned (and group state etc. wasn't changed)

@yihuang yihuang force-pushed the verify-path-secrets branch from 4e7cae6 to 4deeb28 Compare July 28, 2020 02:17
@yihuang
Copy link
Collaborator Author

yihuang commented Jul 28, 2020

looks all right, but would be good to add a test where the encrypted secret doesn't match, so ProcessCommitError is correctly returned (and group state etc. wasn't changed)

Another issue is, for multiple pending commits, there'll be only one is valid, the pending secrets for other commits will not cleaned up. don't know when or how to cleanup the pending_updates/pending_commits of unconfirmed commits currently.

@tomtau
Copy link
Contributor

tomtau commented Jul 28, 2020

looks all right, but would be good to add a test where the encrypted secret doesn't match, so ProcessCommitError is correctly returned (and group state etc. wasn't changed)

Another issue is, for multiple pending commits, there'll be only one is valid, the pending secrets for other commits will not cleaned up. don't know when or how to cleanup the pending_updates/pending_commits of unconfirmed commits currently.

cleanup after applying the "committed" commit (block time when it was included + NACK timeout)?

@yihuang
Copy link
Collaborator Author

yihuang commented Jul 28, 2020

looks all right, but would be good to add a test where the encrypted secret doesn't match, so ProcessCommitError is correctly returned (and group state etc. wasn't changed)

Another issue is, for multiple pending commits, there'll be only one is valid, the pending secrets for other commits will not cleaned up. don't know when or how to cleanup the pending_updates/pending_commits of unconfirmed commits currently.

cleanup after applying the "committed" commit (block time when it was included + NACK timeout)?

I guess just remove all the pending secrets after processing any commit, because all the pending commits will be invalid anyway(the epoch is old)?

@tomtau
Copy link
Contributor

tomtau commented Jul 28, 2020

@tomtau
Copy link
Contributor

tomtau commented Jul 28, 2020

I guess just remove all the pending secrets after processing any commit, because all the pending commits will be invalid anyway(the epoch is old)?

Yes, I think so -- if e.g. you happen to generate self update proposal while there was another on-going update/removal, it'll be rejected... so you'll need to re-generate and re-submit.

@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #2018 into master will increase coverage by 0.13%.
The diff coverage is 88.46%.

@@            Coverage Diff             @@
##           master    #2018      +/-   ##
==========================================
+ Coverage   65.01%   65.15%   +0.13%     
==========================================
  Files         213      212       -1     
  Lines       26520    26649     +129     
==========================================
+ Hits        17242    17363     +121     
- Misses       9278     9286       +8     
Impacted Files Coverage Δ
chain-tx-enclave-next/mls/src/key.rs 71.25% <ø> (+4.58%) ⬆️
chain-tx-enclave-next/mls/src/keypackage.rs 77.43% <80.95%> (-4.51%) ⬇️
chain-tx-enclave-next/mls/src/tree.rs 79.87% <81.42%> (-0.39%) ⬇️
chain-tx-enclave-next/mls/src/message.rs 67.74% <85.71%> (+0.27%) ⬆️
chain-tx-enclave-next/mls/src/group.rs 85.77% <93.23%> (+0.83%) ⬆️
chain-tx-enclave-next/mls/src/ciphersuite.rs 78.23% <100.00%> (+0.52%) ⬆️
chain-abci/src/app/end_block.rs 97.29% <0.00%> (-2.71%) ⬇️
client-common/src/storage/sled_storage.rs 50.28% <0.00%> (-0.87%) ⬇️
...ommon/src/tendermint/rpc_client/sync_rpc_client.rs 0.00% <0.00%> (ø)
... and 16 more

@yihuang yihuang force-pushed the verify-path-secrets branch 2 times, most recently from 7106922 to 2d6c0b8 Compare July 29, 2020 00:51
@yihuang yihuang requested a review from tomtau July 29, 2020 00:52
@yihuang yihuang force-pushed the verify-path-secrets branch from 2d6c0b8 to fb59df2 Compare July 29, 2020 00:56
@yihuang
Copy link
Collaborator Author

yihuang commented Jul 29, 2020

Fixed partial mutation when process invalid commit.

@yihuang yihuang force-pushed the verify-path-secrets branch from fb59df2 to b817a6b Compare July 29, 2020 00:58
Solution:
- verify decreted secret against public key
- also verify leaf keypackage against leaf secret
@yihuang yihuang force-pushed the verify-path-secrets branch from b817a6b to 7566540 Compare July 29, 2020 02:01
@tomtau
Copy link
Contributor

tomtau commented Jul 29, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 29, 2020

Build succeeded:

@bors bors bot merged commit d6fe742 into crypto-com:master Jul 29, 2020
tomtau added a commit to tomtau/chain that referenced this pull request Jul 30, 2020
…pto-com#1797)

Solution: sketched out core of "NACK" mechanism
which involves revealing shared secrets from invalid
message parts and including DLEQ proofs.

-- currently, needs:
1) latest master of p256 which contains scalar arithmetic (not yet released)
2) for the high-level API, it needs to directly decrypt HPKE ciphertext
from a shared secret -- this may not ever be released

also needs "verify_node_private_key" from crypto-com#2018
bors bot added a commit that referenced this pull request Jul 30, 2020
2029: Problem: no way for mls member to prove invalid ciphertext (fixes #1797) r=tomtau a=tomtau

Solution: sketched out core of "NACK" mechanism
which involves revealing shared secrets from invalid
message parts and including DLEQ proofs.

-- currently, needs:
1) latest master of p256 which contains scalar arithmetic (not yet released)
2) for the high-level API, it needs to directly decrypt HPKE ciphertext
from a shared secret -- this may not ever be released

also needs "verify_node_private_key" from #2018




Co-authored-by: Tomas Tauber <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants