Skip to content

Commit 1ea6755

Browse files
committed
ts_control_noise: use handshake primitives from ts_noise
Signed-off-by: David Anderson <danderson@tailscale.com> Change-Id: Iffa6cb966097979b738ae22a946ac2aa6a6a6964
1 parent 3bb16e5 commit 1ea6755

9 files changed

Lines changed: 132 additions & 281 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts_control/src/control_dialer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ where
255255
CapabilityVersion::CURRENT,
256256
);
257257

258-
let conn = crate::tokio::upgrade_ts2021(url, &init_msg, handshake, h1_client).await?;
258+
let conn =
259+
crate::tokio::upgrade_ts2021(url, &init_msg, handshake, machine_keys.private, h1_client)
260+
.await?;
259261
let conn = crate::tokio::read_challenge_packet(conn).await?;
260262

261263
let h2_conn = ts_http_util::http2::connect(conn).await?;

ts_control/src/tokio/connect.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bytes::Bytes;
55
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
66
use ts_capabilityversion::CapabilityVersion;
77
use ts_http_util::{BytesBody, ClientExt, EmptyBody, HeaderName, HeaderValue, Http2, ResponseExt};
8-
use ts_keys::{MachineKeyPair, MachinePublicKey};
8+
use ts_keys::{MachineKeyPair, MachinePrivateKey, MachinePublicKey};
99
use url::Url;
1010
use zerocopy::network_endian::U32;
1111

@@ -166,7 +166,14 @@ pub async fn connect(
166166
CapabilityVersion::CURRENT,
167167
);
168168

169-
let conn = upgrade_ts2021(control_url, &init_msg, handshake, h1_client).await?;
169+
let conn = upgrade_ts2021(
170+
control_url,
171+
&init_msg,
172+
handshake,
173+
machine_keys.private,
174+
h1_client,
175+
)
176+
.await?;
170177

171178
// The early payload (challenge packet) is optional. The server may send
172179
// the magic prefix [FF FF FF 'T' 'S'] followed by a JSON challenge, or it
@@ -225,7 +232,8 @@ pub async fn fetch_control_key(control_url: &Url) -> Result<MachinePublicKey, Co
225232
pub async fn upgrade_ts2021(
226233
control_url: &Url,
227234
init_msg: &str,
228-
mut handshake: ts_control_noise::Handshake,
235+
handshake: ts_control_noise::Handshake,
236+
machine_private_key: MachinePrivateKey,
229237
h1_client: impl ts_http_util::Client<EmptyBody>,
230238
) -> Result<impl AsyncRead + AsyncWrite + Unpin + 'static, ConnectionError> {
231239
let ts2021_url = control_url.join("/ts2021")?;
@@ -251,7 +259,7 @@ pub async fn upgrade_ts2021(
251259
ConnectionError::Internal(InternalErrorKind::Http)
252260
})?;
253261

254-
let conn = handshake.complete(upgraded).await?;
262+
let conn = handshake.complete(upgraded, &machine_private_key).await?;
255263

256264
tracing::debug!("upgraded control connection from HTTP/1.1 to TS2021");
257265

ts_control_noise/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ rust-version.workspace = true
1515
ts_capabilityversion.workspace = true
1616
ts_hexdump.workspace = true
1717
ts_keys.workspace = true
18+
ts_noise.workspace = true
1819

1920
# Unconditionally required dependencies.
2021
base64.workspace = true
2122
bytes.workspace = true
2223
chacha20poly1305 = "0.10"
2324
futures-util = { workspace = true, features = ["sink"] }
24-
noise-protocol = "0.2"
25-
noise-rust-crypto = "0.6"
2625
pin-project-lite.workspace = true
2726
static_assertions.workspace = true
2827
thiserror.workspace = true
2928
tokio = { workspace = true, features = ["io-util"] }
3029
tokio-util = { workspace = true, features = ["codec"] }
3130
tracing.workspace = true
3231
zerocopy.workspace = true
33-
zeroize = "1.8"
3432

3533
[dev-dependencies]
3634
rand = "0.10"

ts_control_noise/src/cipher.rs

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)