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

feat(nodes): encrypt all records before disk, decrypt on get #1229

Merged
merged 1 commit into from Jan 30, 2024

Conversation

joshuef
Copy link
Contributor

@joshuef joshuef commented Jan 25, 2024

fixes #1158

Description

Summary generated by Reviewpad on 25 Jan 24 15:08 UTC

This pull request introduces a new feature to the codebase. It modifies the NodeRecordStore to encrypt all records before writing them to disk and decrypts them when retrieving. The encryption key is randomly generated at node startup. Additionally, the patch includes some bug fixes and code improvements.

@reviewpad reviewpad bot added the Small Pull request is small label Jan 25, 2024
@joshuef joshuef marked this pull request as ready for review January 25, 2024 15:33
@reviewpad reviewpad bot requested a review from maqi January 25, 2024 15:34
@joshuef joshuef force-pushed the NodesEncrypt branch 3 times, most recently from 643e41c to 23d4f49 Compare January 29, 2024 10:26
@reviewpad reviewpad bot added Medium Medium sized PR and removed Small Pull request is small labels Jan 29, 2024
@joshuef joshuef force-pushed the NodesEncrypt branch 4 times, most recently from 82176d4 to c52952c Compare January 29, 2024 15:57
nonce_bytes.extend_from_slice(r.key.as_ref());
// Ensure the final nonce is exactly 96 bits long by padding or truncating as necessary
// https://crypto.stackexchange.com/questions/26790/how-bad-it-is-using-the-same-iv-twice-with-aes-gcm
nonce_bytes.resize(12, 0); // 12 (u8) * 8 = 96 bits
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a function nonce(starter, key) -> GenericArray could help keep consistency instead of repeating the logic from L144?
The println below on L302 looks like a leftover, should it be removed?
Otherwise looking good :)

@happybeing
Copy link
Contributor

I thought this was no longer needed when the minimum file size for encryption was reduced to three bytes.

Is there still a need for this?

@joshuef
Copy link
Contributor Author

joshuef commented Jan 30, 2024

@happybeing this is not about users encrypting data, but preventing node operators from storing unencrypted data to disk.

@joshuef joshuef force-pushed the NodesEncrypt branch 2 times, most recently from 8ca0942 to 69933b8 Compare January 30, 2024 08:36
Copy link

reviewpad bot commented Jan 30, 2024

Reviewpad Report

‼️ Errors

  • Unconventional commit detected: 'feat(nodes): encrypt all records before disk, decrypt on get

fixes #1158

  • also icnrases benchmark limit to account for extra work done here' (cb01f9a)

@joshuef
Copy link
Contributor Author

joshuef commented Jan 30, 2024

Updated for that @iancoleman . Looking pretty tidy there at last I think.

@happybeing
Copy link
Contributor

@happybeing this is not about users encrypting data, but preventing node operators from storing unencrypted data to disk

Exactly, and no longer needed because of the reduction of min chunk size for encryption to three bytes.

Since all chunks are now encrypted before upload there's no need for nodes to do this. Unless you are worried about one and two byte chunks?

@iancoleman
Copy link
Contributor

chunks are now encrypted before upload

A malicious client may not encrypt before upload, ie send plaintext bytes to nodes, so the node protects itself by encrypting before storing on disk.

sn_networking/src/record_store.rs Outdated Show resolved Hide resolved
sn_networking/src/record_store.rs Outdated Show resolved Hide resolved
@@ -56,6 +61,9 @@ pub struct NodeRecordStore {
record_count_metric: Option<Gauge>,
/// Counting how many times got paid
received_payment_count: usize,
/// Encyption cipher for the records, randomly generated at node startup
/// Plus a 4 byte nonce starter
encryption_details: (Aes256GcmSiv, [u8; 4]),
Copy link
Member

Choose a reason for hiding this comment

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

As I understand, this encryption_details shall be written to disk in case restart of node is allowed.
Otherwise, if a node restart with the same key, it won't be able to read the previously stored records.

ideally, I think the Aes cipher and the nonce shall be deduced from the private key instead, to avoid have to store extra stuff to disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not imagining to store this to disk. Node restart here will necesitate wiping the data (I thought any restart is always with new keys at the moment, eg).

fixes maidsafe#1158

+ also icnrases benchmark limit to account for extra work done here
@joshuef joshuef added this pull request to the merge queue Jan 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 30, 2024
@joshuef joshuef merged commit 5424fdc into maidsafe:main Jan 30, 2024
39 checks passed
@joshuef joshuef deleted the NodesEncrypt branch January 30, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Medium sized PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define High Level Client APIs, improvements and account packets
4 participants