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

Generate and write public and private key using HPKE. #654

Merged
merged 8 commits into from
May 26, 2023

Conversation

richajaindce
Copy link
Contributor

These will be used to encrypt and decrypt match key shares

These will be used to encrypt and decrypt match key shares
Copy link
Member

@martinthomson martinthomson left a comment

Choose a reason for hiding this comment

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

I assume that this is only part of the whole. I don't see the use of these keys anywhere.

With that in mind, this is good, but I would avoid using Option<T> for these. It will be easier if we retain a code path where possible.

src/config.rs Outdated
@@ -96,13 +96,16 @@ pub struct PeerConfig {
/// If a certificate is specified here, only the specified certificate will be accepted. The system
/// truststore will not be used.
pub certificate: Option<String>,

pub matchkey_encryption_key: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

This won't be optional in practice, so maybe just make this a String directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Although do we need to pass the matchkey public key to the peers?
I think we should also add it to ServerConfig. Will do that

Copy link
Member

Choose a reason for hiding this comment

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

The other peers won't need this, but it probably makes sense to reuse the same configuration (or at least a subset of it) for client configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I hope ServerConfig is the right place to put it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think ServerConfig indeed needs both the private key and the public key (in some formats, the private key is stored with a copy of the public key, but if we're just using raw bytes, that won't be the case).

I also think that the public key should go in NetworkConfig (network.toml). The idea is that network.toml gets distributed to clients of the helper network. test_mpc already takes an argument --network network.toml, and the event generation stuff that @akoshelev is adding to it will soon (possibly immediately, if configuration/use of the report key is mandatory) need to support encrypting the reports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Within NetworkConfig we have a PeerConfig. Should we add a ClientConfig which will store the public key needed for encryption? There might be other information which would be needed to communicated to clients which can go there. @andyleiserson

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the public key could go directly in PeerConfig. The only significance that I had in mind for PeerConfig was that it was a container for the configuration that needed to be replicated 3x for the helpers.

Another possibility is to represent the key information in the OHTTP key configuration format mentioned in https://github.com/patcg-individual-drafts/ipa/blob/main/details/encryption.md#helper-key-configuration, but that doesn't seem important to do right now, and even using that format I think we could nest it within PeerConfig.

Copy link
Contributor Author

@richajaindce richajaindce May 19, 2023

Choose a reason for hiding this comment

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

There are a few things in PeerConfig (e.g. port) which advertisers/publishers don't care about. I will move public_key inside PeerConfig and then we can see how it evolves. The other configuration stuff will be added as we implement decryption

src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
@andyleiserson
Copy link
Collaborator

With that in mind, this is good, but I would avoid using Option for these. It will be easier if we retain a code path where possible.

I agree that these aren't really optional, in the long term. There is a question of whether we want to support bypassing the match key encryption for some kinds of testing / protocol development work, like how we support HTTP for testing.

Another issue that may come up is how the encryption interacts with the choice between real-world-infra and in-memory-infra. There's no reason that match keys can't be encrypted in both cases, but a couple reasons we might not want that:

  1. It may be useful to skip match key encryption for some kinds of MPC protocol development work where it isn't relevant. (Either for ease of interpreting the test data, or to reduce the number of build dependencies.)
  2. network.toml and ServerConfig (which should soon be server.toml) are currently only used for the real-world-infra. If we do want to use match key encryption with in-memory-infra, that may require some more tinkering with the test setup stuff.

@richajaindce
Copy link
Contributor Author

With that in mind, this is good, but I would avoid using Option for these. It will be easier if we retain a code path where possible.

I agree that these aren't really optional, in the long term. There is a question of whether we want to support bypassing the match key encryption for some kinds of testing / protocol development work, like how we support HTTP for testing.

Another issue that may come up is how the encryption interacts with the choice between real-world-infra and in-memory-infra. There's no reason that match keys can't be encrypted in both cases, but a couple reasons we might not want that:

  1. It may be useful to skip match key encryption for some kinds of MPC protocol development work where it isn't relevant. (Either for ease of interpreting the test data, or to reduce the number of build dependencies.)
  2. network.toml and ServerConfig (which should soon be server.toml) are currently only used for the real-world-infra. If we do want to use match key encryption with in-memory-infra, that may require some more tinkering with the test setup stuff.

I think we should support bypassing encryption for now.

src/config.rs Outdated
@@ -167,24 +183,37 @@ pub struct ServerConfig {

/// TLS configuration for helper-to-helper communication
pub tls: Option<TlsConfig>,

/// Configuration needed for encrypting and decrypting match keys
pub matchkey_encryption_info: Option<MatchKeyEncryptionConfig>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andyleiserson I have stored public and private keys as optional as MatchKeyEncryptionConfig in ServerConfig. Lets leave it optional for now to support disabling encryption of match keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a flag in net/test.rs for disable_matchkey_encryption but not adding any test for that as yet. Will add it along with coding decryption handling of the reports

@andyleiserson
Copy link
Collaborator

I resolved the merge conflicts with #653 and #647, you can pull the resolved version from the report_key branch in my fork. I'm not sure how to get a concise rendering of a merge commit out of github, but if you do git show, the lines marked with ++ are the ones that were introduced or changed by my conflict resolutions.

@richajaindce
Copy link
Contributor Author

I resolved the merge conflicts with #653 and #647, you can pull the resolved version from the report_key branch in my fork. I'm not sure how to get a concise rendering of a merge commit out of github, but if you do git show, the lines marked with ++ are the ones that were introduced or changed by my conflict resolutions.

Thanks a lot for that! Will take a look

richajaindce and others added 3 commits May 25, 2023 10:12
* HPKE module encapsulates the actual encryption type we use and it should not be visible to the other modules. So now it exposes `KeyPair` type and serialization methods on it. That allows keygen not to worry about the actual encryption type used.

* Rename HPKE encryption parameters to make it a bit easier to type and consistent with TLS arguments naming

This is how `network.toml` looks like

```toml
[client.http_config]
version = "http2"

[[peers]]
certificate = """
-----BEGIN CERTIFICATE-----
MIIBZTCCAQugAwIBAgIIbSvJ07OOLJwwCgYIKoZIzj0EAwIwFDESMBAGA1UEAwwJ
bG9jYWxob3N0MB4XDTIzMDUyNDE4MzMyOVoXDTIzMDgyMzE4MzMyOVowFDESMBAG
A1UEAwwJbG9jYWxob3N0MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1hGZwFS6
gMHLsyzKK6voi4sNCMuhyAUkeib8PgDE8Sw1r5hAkuOd582gXaO3hske2NAbx1DB
PFNX64l06N2vHqNHMEUwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA4GA1UdDwEB/wQE
AwICpDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwCgYIKoZIzj0EAwID
SAAwRQIgJzHHbPDNcyA0qeTvX3k6PB7Ecapr4xI8zkn4T/Njyb8CIQDA+IB5QBgI
JlilqZIGGNpVqMXBgVK/KdaxurK/NqgJsA==
-----END CERTIFICATE-----
"""
url = "localhost:51126"

[peers.hpke]
public_key = "5c0376ff2746767deb791219c0853325b49301081a009bcc133582ae8ee24e22"
```
@akoshelev
Copy link
Collaborator

@richajaindce I made some small changes, lmk what you think, if you are ok with these, we probably can push it

@richajaindce
Copy link
Contributor Author

@richajaindce I made some small changes, lmk what you think, if you are ok with these, we probably can push it

The changes look great!! Thanks for them. Lets ship it!

@akoshelev akoshelev merged commit 5221bf8 into private-attribution:main May 26, 2023
@richajaindce richajaindce deleted the report_key branch July 21, 2023 04:42
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.

4 participants