Skip to content

Commit 1f0c0c7

Browse files
committed
[nexus] base64 decode SSH private key before use
1 parent 3d55789 commit 1f0c0c7

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

nexus/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nexus/catalog/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,14 @@ impl Catalog {
390390
.prepare_typed(
391391
"INSERT INTO flows (name, source_peer, destination_peer, description,
392392
query_string, flow_metadata) VALUES ($1, $2, $3, $4, $5, $6, $7)",
393-
&[types::Type::TEXT, types::Type::INT4, types::Type::INT4, types::Type::TEXT,
394-
types::Type::TEXT, types::Type::JSONB],
393+
&[
394+
types::Type::TEXT,
395+
types::Type::INT4,
396+
types::Type::INT4,
397+
types::Type::TEXT,
398+
types::Type::TEXT,
399+
types::Type::JSONB,
400+
],
395401
)
396402
.await?;
397403

nexus/postgres-connection/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ tokio-util = { version = "0.7", features = ["compat"] }
1818
tokio-stream = "0.1"
1919
tracing.workspace = true
2020
urlencoding = "2"
21+
base64 = "0.22"

nexus/postgres-connection/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use base64::Engine;
12
use pt::peerdb_peers::{PostgresConfig, SshConfig};
23
use rustls::pki_types::{CertificateDer, ServerName, UnixTime};
34
use rustls::{ClientConfig, DigitallySignedStruct, RootCertStore, SignatureScheme};
@@ -94,7 +95,21 @@ pub async fn create_tunnel(
9495
session.userauth_password(&ssh_config.user, &ssh_config.password)?;
9596
}
9697
if !ssh_config.private_key.is_empty() {
97-
session.userauth_pubkey_memory(&ssh_config.user, None, &ssh_config.private_key, None)?;
98+
let private_key_bytes = base64::engine::general_purpose::STANDARD
99+
.decode(&ssh_config.private_key)
100+
.map_err(|e| {
101+
io::Error::new(
102+
io::ErrorKind::InvalidData,
103+
format!("Failed to decode private key: {e}"),
104+
)
105+
})?;
106+
let private_key = String::from_utf8(private_key_bytes).map_err(|e| {
107+
io::Error::new(
108+
io::ErrorKind::InvalidData,
109+
format!("Invalid UTF-8 in private key: {e}"),
110+
)
111+
})?;
112+
session.userauth_pubkey_memory(&ssh_config.user, None, &private_key, None)?;
98113
}
99114
if !ssh_config.host_key.is_empty() {
100115
let mut known_hosts = session.known_hosts()?;

0 commit comments

Comments
 (0)