Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 91 additions & 95 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
name = "sunset"
version = "0.6.0"
edition = "2024"
license = "0BSD"
description = "A SSH library suitable for embedded and larger programs"
repository = "https://github.com/mkj/sunset"
categories = ["network-programming", "embedded", "no-std"]
license = "0BSD"
keywords = ["ssh"]
keywords = ["ssh", "ssh-client", "ssh-server"]
rust-version = "1.95"

[workspace]
Expand Down Expand Up @@ -76,7 +76,7 @@ rand_core.workspace = true

ctr = { version = "0.10", features = ["zeroize"] }
aes = { version = "0.9", features = ["zeroize"] }
chacha20 = { version = "0.9", features = ["zeroize"] }
chacha20 = { version = "0.10", features = ["zeroize"] }
sha2.workspace = true
hmac.workspace = true
poly1305 = "0.9"
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ suggest something!
non-async API, runs with `no_std` and no alloc.

- [`sunset-async`](async) - async SSH client and server library, also
`no_std` no-alloc. This is async-executor agnostic (using Embassy for mutexes, but works on std too).
`no_std` no-alloc. This is async-executor agnostic (uses embassy-sync mutexes, but works on std too).

- [`demo`](demo) has demos with Embassy executor for wifi on a Raspberry Pi
[Pico W](demo/picow) or a
Expand All @@ -35,15 +35,12 @@ Working:
- Client and server
- Shell or command connection
- Password and public key authentication
- ed25519 signatures
- curve25519 key exchange
- chacha20-poly1305, aes256-ctr ciphers
- hmac-sha256 integrity
- rsa (`std`-only unless someone writes a `no_std` crate)
- ecdsa256
- ed25519, ecdsa256, and rsa signatures (rsa requires alloc)
- curve25519 and hybrid mlkem key exchange
- chacha20-poly1305 and aes256-ctr
- `~.` client escape sequences
- Post quantum hybrid key exchange (mlkem)
- SFTP server
- standalone commandline client `sunsetc`

Desirable:

Expand Down
5 changes: 3 additions & 2 deletions async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
name = "sunset-async"
version = "0.6.0"
edition = "2024"
repository = "https://github.com/mkj/sunset"
categories = ["network-programming", "embedded", "no-std"]
license = "0BSD"
description = "Async for Sunset SSH"
repository = "https://github.com/mkj/sunset"
categories = ["network-programming", "embedded", "no-std"]
keywords = ["ssh", "ssh-client", "ssh-server", "sunset", "no-std"]

[dependencies]
embassy-sync.workspace = true
Expand Down
4 changes: 0 additions & 4 deletions build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion demo/sftp/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ env_logger = { version = "0.11", default-features = false, features = [

heapless.workspace = true

rand = { version = "0.8", features = ["getrandom"] }
getrandom.workspace = true

strict-path = "0.2"
5 changes: 2 additions & 3 deletions demo/sftp/std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::demosftpserver::DemoSftpServer;
use embassy_executor::Spawner;
use embassy_net::{Stack, StackResources, StaticConfigV4};

use rand::RngCore;
use rand::rngs::OsRng;
use getrandom::rand_core::TryRng;

use embassy_futures::select::select;
use embassy_net_tuntap::TunTapDevice;
Expand Down Expand Up @@ -65,7 +64,7 @@ async fn main_task(spawner: Spawner) {
// Init network device
let net_device = TunTapDevice::new(opt_tap0).unwrap();

let seed = OsRng.next_u64();
let seed = getrandom::SysRng.try_next_u64().unwrap();

// Init network stack
let res = Box::leak(Box::new(StackResources::<NUM_SOCKETS>::new()));
Expand Down
2 changes: 1 addition & 1 deletion demo/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ async-io = "2.6"


critical-section = "1.1"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
getrandom.workspace = true
5 changes: 2 additions & 3 deletions demo/std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use log::{debug, error, info, log, trace, warn};
use embassy_executor::Spawner;
use embassy_net::{Stack, StackResources, StaticConfigV4};

use rand::RngCore;
use rand::rngs::OsRng;
use getrandom::rand_core::TryRng;

use demo_common::menu::Runner as MenuRunner;
use embassy_futures::select::select;
Expand Down Expand Up @@ -63,7 +62,7 @@ async fn main_task(spawner: Spawner) {
// Init network device
let net_device = TunTapDevice::new(opt_tap0).unwrap();

let seed = OsRng.next_u64();
let seed = getrandom::SysRng.try_next_u64().unwrap();

// Init network stack
let res = Box::leak(Box::new(StackResources::<NUM_SOCKETS>::new()));
Expand Down
2 changes: 1 addition & 1 deletion sftp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"
license = "0BSD"
repository = "https://github.com/mkj/sunset"
categories = ["network-programming", "embedded", "no-std", "filesystem"]
keywords = ["sftp"]
keywords = ["ssh", "sftp", "sftp-server", "sunset"]
description = "SFTP for Sunset SSH"

[features]
Expand Down
16 changes: 7 additions & 9 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ impl Channels {
fn unused_chan(&self) -> Result<ChanNum> {
self.ch
.iter()
.enumerate()
.find_map(|(i, ch)| {
if ch.as_ref().is_none() { Some(ChanNum(i as u32)) } else { None }
})
.position(|ch| ch.is_none())
.map(|ch| ChanNum(ch as u32))
.ok_or(Error::NoChannels)
}

Expand Down Expand Up @@ -661,13 +659,13 @@ impl From<&ChannelOpenType<'_>> for ChanType {
}
}

#[derive(Debug)]
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
pub struct ModePair {
pub opcode: u8,
pub arg: u32,
}

#[derive(Debug)]
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
pub struct Pty {
pub term: String<MAX_TERM>,
pub cols: u32,
Expand Down Expand Up @@ -1138,14 +1136,14 @@ impl Channel {
/// Send a window adjust packet if required.
fn check_send_window_adjust(&mut self, s: &mut TrafSend) {
if self.pending_adjust > self.full_window / 2 {
let adjust = self.pending_adjust as u32;
let adjust = self.pending_adjust.max(u32::MAX as usize) as u32;
let Some(sdir) = self.send.as_mut() else {
return;
};
let num = sdir.num;
let p = packets::ChannelWindowAdjust { num, adjust };
match s.send(p) {
Ok(()) => self.pending_adjust = 0,
Ok(()) => self.pending_adjust -= adjust as usize,
Err(Error::BusySend { .. }) => {
// Do nothing, the adjustment will be sent later.
}
Expand Down Expand Up @@ -1187,7 +1185,7 @@ impl core::fmt::Display for ChanNum {
}

/// Channel data type, normal or stderr
#[derive(Debug, PartialEq, Copy, Clone)]
#[derive(Debug, PartialEq, Copy, Clone, Eq)]
pub enum ChanData {
/// `SSH_MSG_CHANNEL_DATA`
Normal,
Expand Down
4 changes: 3 additions & 1 deletion src/ident.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::error::{self, Error, Result};

// From build.rs, "SSH-2.0-Sunset-{crate_vers}"
pub(crate) const OUR_VERSION: &[u8] = env!("SUNSET_SSH_IDENT").as_bytes();
// let sunset_ssh_ident = format!(
pub(crate) const OUR_VERSION: &[u8] =
concat!("SSH-2.0-Sunset-", env!("CARGO_PKG_VERSION")).as_bytes();
pub(crate) const SSH_PREFIX: &[u8] = b"SSH-2.0-";

// RFC4253 4.2 says max length 255 incl CR LF.
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ pub use p256;

#[cfg(feature = "rsa")]
pub use rsa;

/// `ssh-key` crate re-export
///
/// This dependent crate rc version is not part of the stable API
/// of Sunset, it will update to the released version when ready.
#[cfg(feature = "openssh-key")]
pub use ssh_key;
12 changes: 6 additions & 6 deletions src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ pub struct Subsystem<'a> {
/// The contents of a `"pty-req"` request.
///
/// Note that most function arguments use [`channel::Pty`] rather than this struct.
#[derive(Debug, SSHEncode, SSHDecode, Clone)]
#[derive(Debug, SSHEncode, SSHDecode, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct PtyReq<'a> {
pub term: TextString<'a>,
Expand All @@ -872,7 +872,7 @@ pub struct PtyReq<'a> {
pub modes: BinString<'a>,
}

#[derive(Debug, Clone, SSHEncode, SSHDecode)]
#[derive(Debug, Clone, SSHEncode, SSHDecode, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct WinChange {
pub cols: u32,
Expand Down Expand Up @@ -966,7 +966,7 @@ macro_rules! messagetypes {
) => {


#[derive(Debug)]
#[derive(Debug, Hash, Ord, PartialEq, Eq, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[repr(u8)]
#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -1094,10 +1094,10 @@ impl<'a> From<$SpecificPacketType> for Packet<'a> {

pub enum Category {
/// Allowed at any time.
/// TODO: may need to limit some of these during KEX.
All,
/// After kexinit, before newkeys complete (other packets are not allowed during
/// that time).
/// After kexinit, before newkeys complete.
///
/// Other packets are not allowed during that time.
Kex,
/// Post-kex
Auth,
Expand Down
1 change: 1 addition & 0 deletions src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl SigType {
}
}

#[derive(Debug, Clone)]
pub enum OwnedSig {
// just store raw bytes here.
Ed25519([u8; 64]),
Expand Down
24 changes: 13 additions & 11 deletions src/sshnames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ pub const SSH_PORT: u16 = 22;

/// [RFC8731](https://tools.ietf.org/html/rfc8731)
pub const SSH_NAME_CURVE25519: &str = "curve25519-sha256";
/// An older alias prior to standardisation. Eventually could be removed
/// An older alias prior to standardisation. Eventually could be removed.
pub const SSH_NAME_CURVE25519_LIBSSH: &str = "curve25519-sha256@libssh.org";
/// [draft-ietf-sshm-mlkem-hybrid-kex](https://datatracker.ietf.org/doc/html/draft-ietf-sshm-mlkem-hybrid-kex)
/// [draft-ietf-sshm-mlkem-hybrid-kex](https://tools.ietf.org/html/rfc10042)
pub const SSH_NAME_MLKEM_X25519: &str = "mlkem768x25519-sha256";
/// [RFC8308](https://tools.ietf.org/html/rfc8308) Extension Negotiation
pub const SSH_NAME_EXT_INFO_S: &str = "ext-info-s";
/// [RFC8308](https://tools.ietf.org/html/rfc8308) Extension Negotiation
pub const SSH_NAME_EXT_INFO_C: &str = "ext-info-c";
/// Implemented by Dropbear to improve first_kex_packet_follows, described
/// [https://mailarchive.ietf.org/arch/msg/secsh/3n6lNzDHmsGsIQSqhmHHwigIbuo/](https://mailarchive.ietf.org/arch/msg/secsh/3n6lNzDHmsGsIQSqhmHHwigIbuo/)
/// Implemented by Dropbear to improve first_kex_packet_follows
///
/// Described [https://mailarchive.ietf.org/arch/msg/secsh/3n6lNzDHmsGsIQSqhmHHwigIbuo/](https://mailarchive.ietf.org/arch/msg/secsh/3n6lNzDHmsGsIQSqhmHHwigIbuo/)
pub const SSH_NAME_KEXGUESS2: &str = "kexguess2@matt.ucc.asn.au";
/// OpenSSH [PROTOCOL](https://cvsweb.openbsd.org/checkout/src/usr.bin/ssh/PROTOCOL?rev=HEAD)
pub const SSH_NAME_STRICT_KEX_S: &str = "kex-strict-s-v00@openssh.com";
Expand All @@ -30,18 +31,21 @@ pub const SSH_NAME_STRICT_KEX_C: &str = "kex-strict-c-v00@openssh.com";
pub const SSH_NAME_ED25519: &str = "ssh-ed25519";
/// [RFC8332](https://tools.ietf.org/html/rfc8332)
pub const SSH_NAME_RSA_SHA256: &str = "rsa-sha2-256";
/// [RFC4253](https://tools.ietf.org/html/rfc4253). Deprecated for signatures but is a valid key type.
/// [RFC4253](https://tools.ietf.org/html/rfc4253) RSA key type.
///
/// Signature format `ssh-rsa` using SHA1 is deprecated and not supported by Sunset.
pub const SSH_NAME_RSA: &str = "ssh-rsa";
/// [RFC5656](https://tools.ietf.org/html/rfc5656).
/// [RFC5656](https://tools.ietf.org/html/rfc5656)
pub const SSH_NAME_ECDSA256: &str = "ecdsa-sha2-nistp256";

/// [RFC4344](https://tools.ietf.org/html/rfc4344)
pub const SSH_NAME_AES256_CTR: &str = "aes256-ctr";
/// [draft-ietf-sshm-chacha20-poly1305](https://datatracker.ietf.org/doc/draft-ietf-sshm-chacha20-poly1305/)
pub const SSH_NAME_CHAPOLY: &str = "chacha20-poly1305@openssh.com";
/// OpenSSH [PROTOCOL](https://cvsweb.openbsd.org/checkout/src/usr.bin/ssh/PROTOCOL?rev=HEAD)
/// (No-one directly uses `AEAD_AES_256_GCM` [RFC5647](https://tools.ietf.org/html/rfc5647) from the NSA, it fails to define MAC negotiation
/// sensibly and has incongruous naming style)
///
/// No-one directly uses `AEAD_AES_256_GCM` [RFC5647](https://tools.ietf.org/html/rfc5647) from the NSA, it fails to define MAC negotiation
/// sensibly and has incongruous naming style.
pub const SSH_NAME_AES256_GCM: &str = "aes256-gcm@openssh.com";

/// [RFC6668](https://tools.ietf.org/html/rfc6668)
Expand Down Expand Up @@ -81,9 +85,7 @@ pub enum ChanFail {
SSH_OPEN_RESOURCE_SHORTAGE = 4,
}

/// Reason codes for `SSH_MSG_DISCONNECT`
///
/// [RFC4253](https://tools.ietf.org/html/rfc4253#section-11.1)
/// [RFC4253](https://tools.ietf.org/html/rfc4253#section-11.1) Reason codes for `SSH_MSG_DISCONNECT`
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum DisconnectReason {
Expand Down
4 changes: 2 additions & 2 deletions src/sshwire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<'de> SSHDecode<'de> for TextString<'de> {
}

/// A wrapper for a `u32` length prefixed data structure `B`, such as a public key blob
#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Eq, Hash, PartialOrd, Ord)]
pub struct Blob<B>(pub B);

#[cfg(feature = "arbitrary")]
Expand Down Expand Up @@ -492,7 +492,7 @@ impl<'de, B: SSHDecode<'de>> SSHDecode<'de> for Blob<B> {
let inner = SSHDecode::dec(s)?;
let rem2 = s.remaining();

// Sanity check the length matched
// Check the length matched
let used_len = rem1 - rem2;
if used_len != len {
if s.ctx().seen_unknown {
Expand Down
4 changes: 3 additions & 1 deletion stdasync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name = "sunset-stdasync"
version = "0.6.0"
edition = "2024"
repository = "https://github.com/mkj/sunset"
license = "0BSD"
description = "Sunset SSH for larger systems"
repository = "https://github.com/mkj/sunset"
categories = ["network-programming"]
keywords = ["ssh", "ssh-client", "ssh-agent", "sunset"]

[dependencies]
sunset = { workspace = true, features = ["std", "openssh-key"] }
Expand Down