node: Implement signed refs

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 6e86218c36
commit cd7421eb86
14 changed files with 776 additions and 172 deletions
+2 -3
View File
@@ -7,6 +7,7 @@ use crate::crypto;
use crate::identity::{ProjId, UserId};
use crate::protocol::{Context, NodeId, Timestamp, PROTOCOL_VERSION};
use crate::storage;
use crate::storage::refs::SignedRefs;
/// Message envelope. All messages sent over the network are wrapped in this type.
#[derive(Debug, Serialize, Deserialize)]
@@ -104,9 +105,7 @@ pub enum Message {
/// User signing.
user: UserId,
/// Updated refs.
refs: storage::Refs,
/// Signature over the refs.
signature: crypto::Signature,
refs: SignedRefs<crypto::Unverified>,
},
}
+2 -12
View File
@@ -194,18 +194,8 @@ impl Peer {
}));
}
}
(
PeerState::Negotiated { git, .. },
Message::RefsUpdate {
proj,
user,
refs,
signature,
},
) => {
let bytes = serde_json::to_vec(&refs).unwrap();
if user.verify(&signature, &bytes).is_ok() {
(PeerState::Negotiated { git, .. }, Message::RefsUpdate { proj, user, refs }) => {
if refs.verified(&user).is_ok() {
// TODO: Buffer/throttle fetches.
// TODO: Also pass the updated refs so that we can check whether
// we need to fetch or not.