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

First step in adding encryption: #99

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/session_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl SessionManager {
challenge_req: None,
node_id: node_id.into_array().to_vec(),
public_key: public_key.bytes().to_vec(),
supported_encryptions: vec![],
};
let response = tmp_session
.request::<proto::response::Session>(
Expand Down
1 change: 1 addition & 0 deletions client/src/session_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl StartingSessions {
.map_err(|e| InternalError::Generic(e.to_string()))?,
challenge_req: None,
public_key: self.layer.config.public_key().await?.bytes().to_vec(),
supported_encryptions: vec![],
};

tmp_session
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub fn prepare_challenge_request() -> (proto::request::Session, [u8; CHALLENGE_S
public_key: vec![],
challenge_req: Some(challenge),
challenge_resp: vec![],
supported_encryptions: vec![],
};
(request, raw_challenge)
}
Expand All @@ -174,6 +175,7 @@ pub fn prepare_challenge_response() -> (proto::response::Session, [u8; CHALLENGE
public_key: vec![],
challenge_req: Some(challenge),
challenge_resp: vec![],
supported_encryptions: vec![],
};
(response, raw_challenge)
}
1 change: 1 addition & 0 deletions crates/core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct NodeInfo {

/// Endpoints registered by Node.
pub endpoints: Vec<Endpoint>,
pub supported_encryptions: Vec<String>,
}

#[derive(Clone)]
Expand Down
6 changes: 5 additions & 1 deletion crates/proto/protobuf/ya_relay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ message Packet {
message Forward {
bytes session_id = 1;
uint32 slot = 2; // either sender or receiver slot id
bytes payload = 3;
uint16 flags = 3;
bytes payload = 4;
}
*/

Expand Down Expand Up @@ -99,6 +100,7 @@ message Request {
bytes public_key = 3;
ChallengeRequest challenge_req = 4;
bytes challenge_resp = 5;
repeated string supported_encryptions = 6;
}

message Register {
Expand Down Expand Up @@ -153,6 +155,7 @@ message Response {
bytes public_key = 3;
ChallengeRequest challenge_req = 4;
bytes challenge_resp = 5;
repeated string supported_encryptions = 6;
}

/* Registered endpoints */
Expand All @@ -168,6 +171,7 @@ message Response {
repeated Endpoint endpoints = 4;
uint32 seen_ts = 5;
uint32 slot = 6;
repeated string supported_encryptions = 7;
}

/* Neighbourhood */
Expand Down
3 changes: 3 additions & 0 deletions crates/proto/src/codec/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {
node_id: vec![],
public_key: vec![],
challenge_req: None,
supported_encryptions: vec![],
})
}

Expand All @@ -87,6 +88,7 @@ mod tests {
node_id: vec![0x0c, 0x00, 0x0f, 0x0f, 0x0e, 0x0e],
public_key: vec![0x05, 0x0e, 0x0c],
challenge_req: None,
supported_encryptions: vec![],
},
)
.into(),
Expand All @@ -97,6 +99,7 @@ mod tests {
node_id: vec![0x0c, 0x00, 0x0f, 0x0f, 0x0e, 0x0e],
public_key: vec![0x05, 0x0e, 0x0c],
challenge_req: None,
supported_encryptions: vec![],
},
)
.into(),
Expand Down
2 changes: 2 additions & 0 deletions crates/proto/src/codec/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ mod tests {
node_id: vec![0x0c, 0x00, 0x0f, 0x0f, 0x0e, 0x0e],
public_key: vec![0x05, 0x0e, 0x0c],
challenge_req: None,
supported_encryptions: vec![],
},
)
.into(),
Expand Down Expand Up @@ -408,6 +409,7 @@ mod tests {
node_id: vec![],
public_key: vec![],
challenge_req: None,
supported_encryptions: vec![],
})),
})),
}),
Expand Down
1 change: 1 addition & 0 deletions crates/proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const FORWARD_TAG: u32 = 1;
pub const SESSION_ID_SIZE: usize = 16;
pub const KEY_SIZE: usize = 1;
pub const UNRELIABLE_FLAG: u16 = 0x01;
pub const ENCRYPTED_FLAG: u16 = 0x02;

static REQUEST_ID: AtomicU64 = AtomicU64::new(0);

Expand Down
2 changes: 2 additions & 0 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ impl Server {
public_key: session.public_key,
slot: u32::MAX,
endpoints: vec![],
supported_encryptions: vec![],
};

let node = NodeSession {
Expand Down Expand Up @@ -962,5 +963,6 @@ pub fn to_node_response(node_info: NodeSession, public_key: bool) -> proto::resp
.collect(),
seen_ts: node_info.last_seen.timestamp() as u32,
slot: node_info.info.slot,
supported_encryptions: node_info.info.supported_encryptions,
}
}