1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 15:22:18 +01:00

Replace outdated rust-crypto dependency:

`rust-crypto` has not been updated for 8 years.
One of its dependencies, `rustc-serialize` is deprecated and does not build on Redox.

builts on `ed324eb4391491c3b1897a8ee0671533ccb41c13`
This commit is contained in:
Laurenz 2024-09-27 21:55:10 +02:00
parent ed324eb439
commit d582aca73f
Signed by: C0ffeeCode
SSH key fingerprint: SHA256:jnEltBNftC3wUZESLSMvM9zVPOkkevGRzqqoW2k2ORI
7 changed files with 141 additions and 230 deletions

51
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,51 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'ssh-keygen'",
"cargo": {
"args": [
"build",
"--bin=ssh-keygen",
"--package=redox-ssh"
],
"filter": {
"name": "ssh-keygen",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'sshd'",
"cargo": {
"args": [
"build",
"--bin=sshd",
"--package=redox-ssh"
],
"filter": {
"name": "sshd",
"kind": "bin"
}
},
"env": {
"RUST_BACKTRACE": "1"
},
"args": [
"-p", "2222",
"-vvv",
"-f"
],
"cwd": "${workspaceFolder}"
}
]
}

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
"lldb.displayFormat": "auto",
"lldb.showDisassembly": "never",
// "rust-analyzer.cargo.allTargets": true,
"rust-analyzer.cargo.target": "x86_64-unknown-redox",
// "rust-analyzer.check.targets": [
// "x86_64-unknown-redox",
// "x86_64-unknown-linux-gnu"
// ]
}

204
Cargo.lock generated
View file

@ -2,16 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aead"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"generic-array",
]
[[package]]
name = "aes"
version = "0.8.4"
@ -23,25 +13,11 @@ dependencies = [
"cpufeatures",
]
[[package]]
name = "aes-gcm"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "autocfg"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "base64ct"
@ -108,7 +84,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"rand_core 0.6.4",
"typenum",
]
@ -187,7 +162,7 @@ checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871"
dependencies = [
"curve25519-dalek",
"ed25519",
"rand_core 0.6.4",
"rand_core",
"serde",
"sha2",
"subtle",
@ -200,18 +175,6 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "gcc"
version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
[[package]]
name = "generic-array"
version = "0.14.7"
@ -230,17 +193,7 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "ghash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
dependencies = [
"opaque-debug",
"polyval",
"wasi",
]
[[package]]
@ -301,12 +254,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "opaque-debug"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "pkcs8"
version = "0.10.2"
@ -317,18 +264,6 @@ dependencies = [
"spki",
]
[[package]]
name = "polyval"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash",
]
[[package]]
name = "ppv-lite86"
version = "0.2.20"
@ -356,29 +291,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = [
"libc",
"rand 0.4.6",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
@ -387,7 +299,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core 0.6.4",
"rand_core",
]
[[package]]
@ -397,24 +309,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
@ -424,30 +321,21 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox-ssh"
version = "0.1.0"
dependencies = [
"aes-gcm",
"aes",
"byteorder",
"ctr",
"curve25519-dalek",
"ed25519-dalek",
"hmac",
"libc",
"log",
"num-bigint",
"rand 0.8.5",
"rand",
"redox_syscall",
"rust-crypto",
"sha2",
]
@ -460,25 +348,6 @@ dependencies = [
"bitflags",
]
[[package]]
name = "rust-crypto"
version = "0.2.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
dependencies = [
"gcc",
"libc",
"rand 0.3.23",
"rustc-serialize",
"time",
]
[[package]]
name = "rustc-serialize"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401"
[[package]]
name = "rustc_version"
version = "0.4.1"
@ -531,7 +400,7 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"rand_core 0.6.4",
"rand_core",
]
[[package]]
@ -552,26 +421,15 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.77"
version = "2.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "typenum"
version = "1.17.0"
@ -584,56 +442,18 @@ version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "universal-hash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"crypto-common",
"subtle",
]
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.7.35"

View file

@ -28,21 +28,21 @@ byteorder = "^1.5.0"
log = "^0.4.22"
num-bigint = "0.4.6"
rand = "^0.8.5"
# This crate is deprecated in favor of serde:
# rustc-serialize = "^0.3.25"
# Not updated for 8 years, depends and blocks build on Redox
rust-crypto = "^0.2.36"
# rust-crypto = "^0.2.36"
curve25519-dalek = "^4.1.3"
ed25519-dalek = { version = "^2.1.1", features = ["rand_core"]}
ed25519-dalek = { version = "^2.1.1", features = ["rand_core"] }
sha2 = { version = "^0.10.8" }
hmac = { version = "^0.12.1", features = ["std", "reset"]}
aes-gcm = "0.10.3"
hmac = { version = "^0.12.1", features = ["std", "reset"] }
ctr = "^0.9.2"
aes = "^0.8.4"
[target.'cfg(not(target_os = "redox"))'.dependencies]
libc = "^0.2.159"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.2"

View file

@ -170,8 +170,7 @@ impl Connection {
info!("Peer identifies as {:?}", id);
self.hash_data.client_id = Some(id.to_owned());
Ok(())
}
else {
} else {
Err(io::Error::new(io::ErrorKind::InvalidData, "invalid id"))
}
}
@ -199,8 +198,7 @@ impl Connection {
}
pub fn process(&mut self, packet: Packet) -> Result<Option<Packet>> {
match packet.msg_type()
{
match packet.msg_type() {
MessageType::KexInit => self.kex_init(packet),
MessageType::NewKeys => self.new_keys(packet),
MessageType::ServiceRequest => self.service_request(packet),
@ -265,8 +263,7 @@ impl Connection {
assert!(!(reader.read_bool()?));
let pass = reader.read_utf8()?;
pass == "hunter2"
}
else {
} else {
false
};
@ -274,8 +271,7 @@ impl Connection {
if success {
Ok(Some(Packet::new(MessageType::UserAuthSuccess)))
}
else {
} else {
let mut res = Packet::new(MessageType::UserAuthFailure);
res.write_string("password")?;
res.write_bool(false)?;
@ -293,8 +289,7 @@ impl Connection {
let id = if let Some((id, chan)) = self.channels.iter().next_back() {
id + 1
}
else {
} else {
0
};
@ -319,9 +314,7 @@ impl Connection {
let name = reader.read_utf8()?;
let want_reply = reader.read_bool()?;
let request = match &*name
{
let request = match &*name {
"pty-req" => Some(ChannelRequest::Pty {
term: reader.read_utf8()?,
chars: reader.read_uint32()? as u16,
@ -334,12 +327,10 @@ impl Connection {
_ => None,
};
if let Some(request) = request {
let channel = self.channels.get_mut(&channel_id).unwrap();
channel.request(request);
}
else {
} else {
warn!("Unkown channel request {}", name);
}
@ -347,8 +338,7 @@ impl Connection {
let mut res = Packet::new(MessageType::ChannelSuccess);
res.write_uint32(0)?;
Ok(Some(res))
}
else {
} else {
Ok(None)
}
}
@ -375,16 +365,18 @@ impl Connection {
let srv_host_key_algos =
reader.read_enum_list::<PublicKeyAlgorithm>()?;
let enc_algos_c2s = reader.read_enum_list::<EncryptionAlgorithm>()?;
let enc_algos_s2c = reader.read_enum_list::<EncryptionAlgorithm>()?;
let enc_algos_c2s =
reader.read_enum_list::<EncryptionAlgorithm>()?;
let enc_algos_s2c =
reader.read_enum_list::<EncryptionAlgorithm>()?;
let mac_algos_c2s = reader.read_enum_list::<MacAlgorithm>()?;
let mac_algos_s2c = reader.read_enum_list::<MacAlgorithm>()?;
let comp_algos_c2s = reader
.read_enum_list::<CompressionAlgorithm>()?;
let comp_algos_s2c = reader
.read_enum_list::<CompressionAlgorithm>()?;
let comp_algos_c2s =
reader.read_enum_list::<CompressionAlgorithm>()?;
let comp_algos_s2c =
reader.read_enum_list::<CompressionAlgorithm>()?;
(
negotiate(KEY_EXCHANGE, kex_algos.as_slice())?,
@ -434,12 +426,12 @@ impl Connection {
}
fn key_exchange(&mut self, packet: Packet) -> Result<Option<Packet>> {
let mut kex = self.key_exchange.take().ok_or(
ConnectionError::KeyExchange,
)?;
let mut kex = self
.key_exchange
.take()
.ok_or(ConnectionError::KeyExchange)?;
let result = match kex.process(self, packet)
{
let result = match kex.process(self, packet) {
KexResult::Done(packet) => {
self.state = ConnectionState::Established;
@ -455,7 +447,6 @@ impl Connection {
KexResult::Error => Err(ConnectionError::KeyExchange),
};
self.key_exchange = Some(kex);
result
}

View file

@ -0,0 +1,37 @@
use aes::cipher::generic_array::GenericArray;
use aes::cipher::{KeyIvInit, StreamCipher};
use super::Encryption;
type ThisCipher = ctr::Ctr128BE<aes::Aes256>;
pub struct AesCtr {
cipher: ThisCipher,
}
impl AesCtr {
pub fn new(key: &[u8], iv: &[u8]) -> Self {
let key: [u8; 32] = key.try_into().expect("slice with incorrect length");
let key = GenericArray::from_slice(&key);
let iv: [u8; 16] = iv[..16].try_into().expect("slice with incorrect length");
let iv = GenericArray::from_slice(&iv);
let cipher = ThisCipher::new(key, iv);
Self { cipher }
}
}
impl AesCtr {
fn apply(&mut self, input: &[u8], output: &mut [u8]) {
self.cipher.apply_keystream_b2b(input, output).unwrap();
}
}
impl Encryption for AesCtr {
fn encrypt(&mut self, data: &[u8], buf: &mut [u8]) {
self.apply(data, buf)
}
fn decrypt(&mut self, data: &[u8], buf: &mut [u8]) {
self.apply(data, buf)
}
}

View file

@ -1,8 +1,10 @@
use std::io::{self, Read};
mod aes_ctr;
// mod aes_ctr;
mod aes_ctr_new;
pub use self::aes_ctr::AesCtr;
// pub use self::aes_ctr::AesCtr;
pub use self::aes_ctr_new::AesCtr;
pub trait Encryption {
fn encrypt(&mut self, data: &[u8], buf: &mut [u8]);