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

Introduce encrypted threshold decryption request/response functionality #52

Merged
merged 10 commits into from
May 23, 2023

Conversation

derekpierre
Copy link
Member

@derekpierre derekpierre commented May 11, 2023

Use Umbral keys for now for encryption/decryption - similar to the TreasureMap/EncryptedTreasureMap work; we'll move away from Umbral when the time comes i.e. we determine the appropriate crypto scheme to use.

First foray into Rust ⚙️ 🥳 .

Builds ontop of #48.

Introduces:

  1. EncryptedThresholdDecryptionRequest - encrypted version of the ThresholdDecryptionRequest
  2. E2EThresholdDecryptionRequest - intermediate struct that stores the ThresholdDecryptionRequest and the response_encrypting_key i.e. the key Ursula will use to encrypt the ThresholdDecryptionResponse. Using an intermediary allows for a single ThresholdDecryptionRequest object to be reused for different response_encrypting_keys and encrypted for different Ursulas.
  3. EncryptedThresholdDecryptionResponse - encrypted version of the ThresholdDecryptionResponse

For reviewers:

  • Looking for guidance on best-practices for Rust
  • Help with failing CI jobs which seem unrelated (at least to the untrained eye 😅 ).

@derekpierre derekpierre self-assigned this May 11, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 11, 2023

Codecov Report

Merging #52 (9cb7921) into main (198085b) will increase coverage by 8.22%.
The diff coverage is 57.89%.

@@            Coverage Diff            @@
##            main      #52      +/-   ##
=========================================
+ Coverage   7.01%   15.24%   +8.22%     
=========================================
  Files         16       16              
  Lines       2523     2841     +318     
=========================================
+ Hits         177      433     +256     
- Misses      2346     2408      +62     
Impacted Files Coverage Δ
nucypher-core-python/src/lib.rs 0.11% <0.00%> (-0.01%) ⬇️
nucypher-core-wasm/src/lib.rs 0.12% <0.00%> (-0.02%) ⬇️
nucypher-core/src/lib.rs 100.00% <ø> (ø)
nucypher-core/src/dkg.rs 92.50% <98.42%> (+92.50%) ⬆️

... and 1 file with indirect coverage changes

@derekpierre derekpierre changed the title [WIP] Introduce encrypted threshold decryption request/response functionality Introduce encrypted threshold decryption request/response functionality May 15, 2023
@derekpierre derekpierre requested a review from theref May 15, 2023 17:56
…Ursula to know what key to use to decrypt request.
@derekpierre derekpierre marked this pull request as ready for review May 16, 2023 17:50
self.backend
.decrypt(sk.as_ref())
.map(E2EEThresholdDecryptionRequest::from)
.map_err(|err| PyValueError::new_err(format!("{}", err)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR, but maybe we could turn this often-repeated conversion into a helper function, similarly how we use .map_err(map_js_err) in WASM bindings:

Suggested change
.map_err(|err| PyValueError::new_err(format!("{}", err)))
.map_err(mapy_py_err)

Copy link
Contributor

@piotr-roslaniec piotr-roslaniec left a comment

Choose a reason for hiding this comment

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

Just a few questions, looks solid overall.

Welcome onboard!

CHANGELOG.md Show resolved Hide resolved
@@ -78,6 +92,121 @@ impl<'a> ProtocolObjectInner<'a> for ThresholdDecryptionRequest {

impl<'a> ProtocolObject<'a> for ThresholdDecryptionRequest {}

/// A request for an Ursula to derive a decryption share that specifies the key to encrypt Ursula's response.
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct E2EEThresholdDecryptionRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, does the third "E" stand for something? E2E is "end to end", right?

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️ E2E is what it should be since it isn't encrypted (third E) - I modified my thinking about this functionality but never updated the class name.

Copy link
Member

@KPrasch KPrasch May 20, 2023

Choose a reason for hiding this comment

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

I find this name to be describing something too broad that it reaches the level of inaccuracy. The name "E2E" describes the wider-usage instead of this object instead of it's substance, and falls out of convention with other encrypted entities like EncryptedTreasureMap. Also, the character sequence E2EE is unreadable imo.

Suggested change
pub struct E2EEThresholdDecryptionRequest {
pub struct EncryptedThresholdDecryptionRequest {

Copy link
Member

Choose a reason for hiding this comment

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

After a re-read I think I'm mixed up here. Can you help me understand why EncryptedThesholdDecryptionRequest and E2EEThresholddecryptionRequest need to be different?

Copy link
Member Author

@derekpierre derekpierre May 20, 2023

Choose a reason for hiding this comment

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

The crux of the design is around the ability to re-use the same ThresholdDecryptionRequest:

  1. To be encrypted for different Ursulas - the request_encrypting_keys

  2. To be used by different Bobs (see #3128 where Enrico returns a decryption request that can be reused by any Bob) i.e. to be associated with different response_encrypting_keys

Therefore, we don't want to put the response_encrypring_key on the ThresholdDecryptionRequest object itself because this would be per-Bob.

Next, the response_encrypting_key needs to also be encrypted. So currently, that is done by ThresholdDecryptionRequest.encrypt(request_encrypting_key, response_encrypting_key) and the resulting object is a EncryptedThresholdDecryptionRequest which holds the request and response key both encrypted using the request_encrypting_key. This EncryptedThresholdDecryptionRequest struct only has the encrypted bytes and the ritual id.

When this object gets decrypted using EncryptedThresholdDecryptionRequest.decrypt(secret_key) it needs to return the decryption request (plain form) and the response_encrypting_key. These two items are therefore represented by this E2EThresholdDecryptionRequest. It has two members, decryption_request and response_encrypting_key. It's basically and intermediary object/struct to be consistent since JS does not allow tuples.

I'm open to alternative names.

@fjarri
Copy link
Contributor

fjarri commented May 20, 2023

Btw, heads up, wasm-bindgen 0.2.85 broke wasm-bindgen-derive, so I had to update it. If you see WASM tests failing, that may be it.

@derekpierre derekpierre merged commit 27ba90d into nucypher:main May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

5 participants