Merge branch 'cell-introduce2' into 'main'

Implement Introduce2 tor cell

See merge request tpo/core/arti!736
This commit is contained in:
Ian Jackson 2022-09-26 12:07:33 +00:00
commit 0154d82522
3 changed files with 68 additions and 17 deletions

View File

@ -75,6 +75,9 @@ pub enum RelayMsg {
/// Introduce1
#[cfg(feature = "onion-service")]
Introduce1(onion_service::Introduce1),
/// Introduce2
#[cfg(feature = "onion-service")]
Introduce2(onion_service::Introduce2),
/// An unrecognized command.
Unrecognized(Unrecognized),
@ -128,6 +131,8 @@ impl RelayMsg {
EstablishRendezvous(_) => RelayCmd::ESTABLISH_RENDEZVOUS,
#[cfg(feature = "onion-service")]
Introduce1(_) => RelayCmd::INTRODUCE1,
#[cfg(feature = "onion-service")]
Introduce2(_) => RelayCmd::INTRODUCE2,
Unrecognized(u) => u.cmd(),
}
}
@ -203,6 +208,8 @@ impl RelayMsg {
EstablishRendezvous(b) => b.encode_onto(w),
#[cfg(feature = "onion-service")]
Introduce1(b) => b.encode_onto(w),
#[cfg(feature = "onion-service")]
Introduce2(b) => b.encode_onto(w),
Unrecognized(b) => b.encode_onto(w),
}
}

View File

@ -253,9 +253,55 @@ impl msg::Body for EstablishRendezvous {
}
}
/// A message sent from client to introduction point.
#[derive(Debug, Clone)]
pub struct Introduce1 {
/// A message sent from client to introduction point.
pub struct Introduce1(Introduce);
impl msg::Body for Introduce1 {
fn into_message(self) -> msg::RelayMsg {
msg::RelayMsg::Introduce1(self)
}
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
Ok(Self(Introduce::decode_from_reader(r)?))
}
fn encode_onto(self, w: &mut Vec<u8>) -> EncodeResult<()> {
self.0.encode_onto(w)
}
}
impl Introduce1 {
/// All arguments constructor
pub fn new(auth_key_type: AuthKeyType, auth_key: Vec<u8>, encrypted: Vec<u8>) -> Self {
Self(Introduce::new(auth_key_type, auth_key, encrypted))
}
}
#[derive(Debug, Clone)]
/// A message sent from introduction point to hidden service host.
pub struct Introduce2(Introduce);
impl msg::Body for Introduce2 {
fn into_message(self) -> msg::RelayMsg {
msg::RelayMsg::Introduce2(self)
}
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
Ok(Self(Introduce::decode_from_reader(r)?))
}
fn encode_onto(self, w: &mut Vec<u8>) -> EncodeResult<()> {
self.0.encode_onto(w)
}
}
impl Introduce2 {
/// All arguments constructor
pub fn new(auth_key_type: AuthKeyType, auth_key: Vec<u8>, encrypted: Vec<u8>) -> Self {
Self(Introduce::new(auth_key_type, auth_key, encrypted))
}
}
#[derive(Debug, Clone)]
/// A message body shared by Introduce1 and Introduce2
struct Introduce {
/// Introduction point auth key type and the type of
/// the MAC used in `handshake_auth`.
auth_key_type: AuthKeyType,
@ -265,10 +311,16 @@ pub struct Introduce1 {
encrypted: Vec<u8>,
}
impl msg::Body for Introduce1 {
fn into_message(self) -> msg::RelayMsg {
msg::RelayMsg::Introduce1(self)
impl Introduce {
/// All arguments constructor
fn new(auth_key_type: AuthKeyType, auth_key: Vec<u8>, encrypted: Vec<u8>) -> Self {
Self {
auth_key_type,
auth_key,
encrypted,
}
}
/// Decode an Introduce message body from the given reader
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
let legacy_key_id: RsaIdentity = r.extract()?;
if !legacy_key_id.is_zero() {
@ -292,6 +344,7 @@ impl msg::Body for Introduce1 {
encrypted,
})
}
/// Encode an Introduce message body onto the given writer
fn encode_onto(self, w: &mut Vec<u8>) -> EncodeResult<()> {
w.write_all(&[0_u8; 20]);
w.write_u8(self.auth_key_type.get());
@ -303,14 +356,3 @@ impl msg::Body for Introduce1 {
Ok(())
}
}
impl Introduce1 {
/// All arguments constructor
pub fn new(auth_key_type: AuthKeyType, auth_key: Vec<u8>, encrypted: Vec<u8>) -> Self {
Self {
auth_key_type,
auth_key,
encrypted,
}
}
}

View File

@ -722,12 +722,14 @@ fn test_establish_intro() {
#[cfg(feature = "onion-service")]
#[test]
fn test_introduce1() {
fn test_introduce() {
use tor_cell::relaycell::{
msg::RelayMsg,
onion_service::{AuthKeyType, Introduce1},
};
// Testing with Introduce1 only should be sufficient as long as
// Introduce1 and Introduce2 share the same inner body
let cmd = RelayCmd::INTRODUCE1;
let auth_key_type = AuthKeyType::ED25519_SHA3_256;
let auth_key = vec![0, 1, 2, 3];