Update fingerprint to match UID from rdsys

This commit is contained in:
onyinyang 2023-04-04 18:39:28 -04:00
parent a3a693d45a
commit 11d4678be8
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
3 changed files with 19 additions and 19 deletions

View File

@ -45,12 +45,11 @@ pub struct BridgeLine {
/// port
pub port: u16,
/// fingerprint
#[serde_as(as = "[_; 40]")]
pub fingerprint: [u8; 40],
pub uid_fingerprint: u64,
/// other protocol information, including pluggable transport,
/// public key, etc.
#[serde_as(as = "[_; BRIDGE_BYTES - 58]")]
pub info: [u8; BRIDGE_BYTES - 58],
#[serde_as(as = "[_; BRIDGE_BYTES - 26]")]
pub info: [u8; BRIDGE_BYTES - 26],
}
/// A bucket contains MAX_BRIDGES_PER_BUCKET bridges plus the
@ -73,8 +72,8 @@ impl Default for BridgeLine {
Self {
addr: [0; 16],
port: 0,
fingerprint: [0; 40],
info: [0; BRIDGE_BYTES - 58],
uid_fingerprint: 0,
info: [0; BRIDGE_BYTES - 26],
}
}
}
@ -85,8 +84,8 @@ impl BridgeLine {
let mut res: [u8; BRIDGE_BYTES] = [0; BRIDGE_BYTES];
res[0..16].copy_from_slice(&self.addr);
res[16..18].copy_from_slice(&self.port.to_be_bytes());
res[18..58].copy_from_slice(&self.fingerprint);
res[58..].copy_from_slice(&self.info);
res[18..26].copy_from_slice(&self.uid_fingerprint.to_be_bytes());
res[26..].copy_from_slice(&self.info);
res
}
/// Decode a BridgeLine from a byte array
@ -94,8 +93,8 @@ impl BridgeLine {
let mut res: Self = Default::default();
res.addr.copy_from_slice(&data[0..16]);
res.port = u16::from_be_bytes(data[16..18].try_into().unwrap());
res.fingerprint.copy_from_slice(&data[18..58]);
res.info.copy_from_slice(&data[58..]);
res.uid_fingerprint = u64::from_be_bytes(data[18..26].try_into().unwrap());
res.info.copy_from_slice(&data[26..]);
res
}
/// Encode a bucket to a byte array, including a Bucket Reachability
@ -194,11 +193,8 @@ impl BridgeLine {
let ports: [u16; 4] = [443, 4433, 8080, 43079];
let portidx = (rng.next_u32() % 4) as usize;
res.port = ports[portidx];
let mut fingerprint: [u8; 40] = [0; 40];
rng.fill_bytes(&mut fingerprint);
res.uid_fingerprint = rng.next_u64();
let mut cert: [u8; 52] = [0; 52];
rng.fill_bytes(&mut fingerprint);
res.fingerprint[0..40].copy_from_slice(&fingerprint);
rng.fill_bytes(&mut cert);
let infostr: String = format!(
"obfs4 cert={}, iat-mode=0",

View File

@ -331,7 +331,7 @@ impl BridgeAuth {
let reachable_bridges = self.bridge_table.reachable.clone();
for reachable_bridge in reachable_bridges {
if reachable_bridge.0.fingerprint == bridge.fingerprint {
if reachable_bridge.0.uid_fingerprint == bridge.uid_fingerprint {
println!(
"Bridge from table: {:?} has same IP and Port as bridge {:?}!",
reachable_bridge.0, bridge
@ -366,6 +366,10 @@ impl BridgeAuth {
return res;
}
}
if !res {
// Assume the bridge is new and should be added to unallocated bridges or else a new bucket
}
res
}

View File

@ -621,22 +621,22 @@ fn test_update_bridge() {
"obfs2".to_string(),
"moat".to_string(),
);
let mut updated_info_bytes: [u8; BRIDGE_BYTES - 58] = [0; BRIDGE_BYTES - 58];
let mut updated_info_bytes: [u8; BRIDGE_BYTES - 26] = [0; BRIDGE_BYTES - 26];
updated_info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes());
let updated_bridgeline = BridgeLine {
addr: bridgeline_to_update.addr,
port: bridgeline_to_update.port,
fingerprint: bridgeline_to_update.fingerprint,
uid_fingerprint: bridgeline_to_update.uid_fingerprint,
info: updated_info_bytes,
};
assert!(
updated_bridgeline.fingerprint == bridgeline_to_update.fingerprint,
updated_bridgeline.uid_fingerprint == bridgeline_to_update.uid_fingerprint,
"Bridge entering the bridgepool {:?} did not have the same fingerprint as the updating bridge {:?}",
bridgeline_to_update,
updated_bridgeline.fingerprint
updated_bridgeline.uid_fingerprint
);
assert!(updated_bridgeline.info != bridgeline_to_update.info);
println!(