Update fingerprint to match UID from rdsys

This commit is contained in:
onyinyang 2023-04-04 18:39:28 -04:00
parent dc11cd9f38
commit a5c3d4f77b
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 /// port
pub port: u16, pub port: u16,
/// fingerprint /// fingerprint
#[serde_as(as = "[_; 40]")] pub uid_fingerprint: u64,
pub fingerprint: [u8; 40],
/// other protocol information, including pluggable transport, /// other protocol information, including pluggable transport,
/// public key, etc. /// public key, etc.
#[serde_as(as = "[_; BRIDGE_BYTES - 58]")] #[serde_as(as = "[_; BRIDGE_BYTES - 26]")]
pub info: [u8; BRIDGE_BYTES - 58], pub info: [u8; BRIDGE_BYTES - 26],
} }
/// A bucket contains MAX_BRIDGES_PER_BUCKET bridges plus the /// A bucket contains MAX_BRIDGES_PER_BUCKET bridges plus the
@ -73,8 +72,8 @@ impl Default for BridgeLine {
Self { Self {
addr: [0; 16], addr: [0; 16],
port: 0, port: 0,
fingerprint: [0; 40], uid_fingerprint: 0,
info: [0; BRIDGE_BYTES - 58], info: [0; BRIDGE_BYTES - 26],
} }
} }
} }
@ -85,8 +84,8 @@ impl BridgeLine {
let mut res: [u8; BRIDGE_BYTES] = [0; BRIDGE_BYTES]; let mut res: [u8; BRIDGE_BYTES] = [0; BRIDGE_BYTES];
res[0..16].copy_from_slice(&self.addr); res[0..16].copy_from_slice(&self.addr);
res[16..18].copy_from_slice(&self.port.to_be_bytes()); res[16..18].copy_from_slice(&self.port.to_be_bytes());
res[18..58].copy_from_slice(&self.fingerprint); res[18..26].copy_from_slice(&self.uid_fingerprint.to_be_bytes());
res[58..].copy_from_slice(&self.info); res[26..].copy_from_slice(&self.info);
res res
} }
/// Decode a BridgeLine from a byte array /// Decode a BridgeLine from a byte array
@ -94,8 +93,8 @@ impl BridgeLine {
let mut res: Self = Default::default(); let mut res: Self = Default::default();
res.addr.copy_from_slice(&data[0..16]); res.addr.copy_from_slice(&data[0..16]);
res.port = u16::from_be_bytes(data[16..18].try_into().unwrap()); res.port = u16::from_be_bytes(data[16..18].try_into().unwrap());
res.fingerprint.copy_from_slice(&data[18..58]); res.uid_fingerprint = u64::from_be_bytes(data[18..26].try_into().unwrap());
res.info.copy_from_slice(&data[58..]); res.info.copy_from_slice(&data[26..]);
res res
} }
/// Encode a bucket to a byte array, including a Bucket Reachability /// 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 ports: [u16; 4] = [443, 4433, 8080, 43079];
let portidx = (rng.next_u32() % 4) as usize; let portidx = (rng.next_u32() % 4) as usize;
res.port = ports[portidx]; res.port = ports[portidx];
let mut fingerprint: [u8; 40] = [0; 40]; res.uid_fingerprint = rng.next_u64();
rng.fill_bytes(&mut fingerprint);
let mut cert: [u8; 52] = [0; 52]; 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); rng.fill_bytes(&mut cert);
let infostr: String = format!( let infostr: String = format!(
"obfs4 cert={}, iat-mode=0", "obfs4 cert={}, iat-mode=0",

View File

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

View File

@ -621,22 +621,22 @@ fn test_update_bridge() {
"obfs2".to_string(), "obfs2".to_string(),
"moat".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()); updated_info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes());
let updated_bridgeline = BridgeLine { let updated_bridgeline = BridgeLine {
addr: bridgeline_to_update.addr, addr: bridgeline_to_update.addr,
port: bridgeline_to_update.port, port: bridgeline_to_update.port,
fingerprint: bridgeline_to_update.fingerprint, uid_fingerprint: bridgeline_to_update.uid_fingerprint,
info: updated_info_bytes, info: updated_info_bytes,
}; };
assert!( 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 {:?}", "Bridge entering the bridgepool {:?} did not have the same fingerprint as the updating bridge {:?}",
bridgeline_to_update, bridgeline_to_update,
updated_bridgeline.fingerprint updated_bridgeline.uid_fingerprint
); );
assert!(updated_bridgeline.info != bridgeline_to_update.info); assert!(updated_bridgeline.info != bridgeline_to_update.info);
println!( println!(