Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Apr 24, 2024
1 parent f1bad2f commit fade996
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions rust/sbd-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ mod default_crypto {

impl Default for DefaultCrypto {
fn default() -> Self {
let k =
ed25519_dalek::SigningKey::generate(&mut rand::thread_rng());
let pk = k.verifying_key().to_bytes();
Self(pk, k)
loop {
let k = ed25519_dalek::SigningKey::generate(
&mut rand::thread_rng(),
);
let pk = k.verifying_key().to_bytes();
if &pk[..28] == CMD_PREFIX {
continue;
} else {
return Self(pk, k);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/sbd-server/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum SbdCmd<'c> {
Unknown,
}

const CMD_PREFIX: &[u8; 28] = &[0; 28];
pub(crate) const CMD_PREFIX: &[u8; 28] = &[0; 28];

impl<'c> SbdCmd<'c> {
pub fn parse(payload: Payload<'c>) -> Result<Self> {
Expand Down
5 changes: 5 additions & 0 deletions rust/sbd-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ async fn check_accept_connection(
Err(_) => return,
};

// illegal pub key
if &pub_key.0[..28] == cmd::CMD_PREFIX {
return;
}

let ws = Arc::new(ws);

if let Some(ip) = ip {
Expand Down

0 comments on commit fade996

Please sign in to comment.