netdoc: Add a workaround for C Tor's lack of mid-layer NL
It turns out that C Tor doesn't add a newline at the end of the middle layer of an onion service descriptor. I've made a spec MR (torspec!109) to document this: here, it's time to work around the issue.
This commit is contained in:
parent
4be4d178fa
commit
6817f61641
|
@ -233,8 +233,7 @@ mod test {
|
|||
.dangerously_assume_wellsigned()
|
||||
.dangerously_assume_timely();
|
||||
let subcred = TEST_SUBCREDENTIAL.into();
|
||||
let mut body = desc.decrypt_body(&subcred).unwrap();
|
||||
body.push(b'\n'); // XXXX BUG in C tor: this \n is really supposed to be there!
|
||||
let body = desc.decrypt_body(&subcred).unwrap();
|
||||
let body = std::str::from_utf8(&body[..]).unwrap();
|
||||
|
||||
let middle = HsDescMiddle::parse(body)?;
|
||||
|
|
|
@ -73,6 +73,11 @@ impl HsDescOuter {
|
|||
let mut body = decrypt.decrypt(&self.encrypted_body[..])?;
|
||||
let n_padding = body.iter().rev().take_while(|n| **n == 0).count();
|
||||
body.truncate(body.len() - n_padding);
|
||||
// Work around a bug in the C tor implementation: it doesn't
|
||||
// NL-terminate the final line of the middle layer.
|
||||
if !body.ends_with(b"\n") {
|
||||
body.push(b'\n');
|
||||
}
|
||||
Ok(body)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue