mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 17:02:19 +01:00
Fix (lints): Run clippy automatic fixes
This commit is contained in:
parent
d25d37a751
commit
086b65038d
10 changed files with 50 additions and 53 deletions
|
|
@ -3,7 +3,6 @@ extern crate log;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
|
@ -21,8 +20,7 @@ impl log::Log for StdErrLogger {
|
||||||
|
|
||||||
fn log(&self, record: &Record) {
|
fn log(&self, record: &Record) {
|
||||||
if self.enabled(record.metadata()) {
|
if self.enabled(record.metadata()) {
|
||||||
writeln!(io::stderr(), "{} - {}", record.level(), record.args())
|
eprintln!("{} - {}", record.level(), record.args());
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,8 +38,7 @@ pub fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(ref err) = key_pair.as_ref().err() {
|
if let Some(ref err) = key_pair.as_ref().err() {
|
||||||
writeln!(io::stderr(), "sshd: failed to open server.key: {}", err)
|
eprintln!("sshd: failed to open server.key: {}", err);
|
||||||
.unwrap();
|
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +79,7 @@ pub fn main() {
|
||||||
let server = Server::with_config(config);
|
let server = Server::with_config(config);
|
||||||
|
|
||||||
if let Err(err) = server.run() {
|
if let Err(err) = server.run() {
|
||||||
writeln!(io::stderr(), "sshd: {}", err).unwrap();
|
eprintln!("sshd: {}", err);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,14 @@ impl Channel {
|
||||||
max_packet_size: u32
|
max_packet_size: u32
|
||||||
) -> Channel {
|
) -> Channel {
|
||||||
Channel {
|
Channel {
|
||||||
id: id,
|
id,
|
||||||
peer_id: peer_id,
|
peer_id,
|
||||||
process: None,
|
process: None,
|
||||||
master: None,
|
master: None,
|
||||||
pty: None,
|
pty: None,
|
||||||
window_size: peer_window_size,
|
window_size: peer_window_size,
|
||||||
peer_window_size: peer_window_size,
|
peer_window_size,
|
||||||
max_packet_size: max_packet_size,
|
max_packet_size,
|
||||||
read_thread: None,
|
read_thread: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,25 +118,25 @@ impl Channel {
|
||||||
self.master = Some(unsafe { File::from_raw_fd(master_fd) });
|
self.master = Some(unsafe { File::from_raw_fd(master_fd) });
|
||||||
}
|
}
|
||||||
ChannelRequest::Shell => {
|
ChannelRequest::Shell => {
|
||||||
if let Some(&(_, ref tty_path)) = self.pty.as_ref() {
|
if let Some((_, tty_path)) = self.pty.as_ref() {
|
||||||
let stdin = OpenOptions::new()
|
let stdin = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(&tty_path)
|
.open(tty_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_raw_fd();
|
.into_raw_fd();
|
||||||
|
|
||||||
let stdout = OpenOptions::new()
|
let stdout = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(&tty_path)
|
.open(tty_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_raw_fd();
|
.into_raw_fd();
|
||||||
|
|
||||||
let stderr = OpenOptions::new()
|
let stderr = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(&tty_path)
|
.open(tty_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_raw_fd();
|
.into_raw_fd();
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ impl Channel {
|
||||||
.stdin(Stdio::from_raw_fd(stdin))
|
.stdin(Stdio::from_raw_fd(stdin))
|
||||||
.stdout(Stdio::from_raw_fd(stdout))
|
.stdout(Stdio::from_raw_fd(stdout))
|
||||||
.stderr(Stdio::from_raw_fd(stderr))
|
.stderr(Stdio::from_raw_fd(stderr))
|
||||||
.pre_exec(|| sys::before_exec())
|
.pre_exec(sys::before_exec)
|
||||||
}
|
}
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ pub struct Connection {
|
||||||
impl<'a> Connection {
|
impl<'a> Connection {
|
||||||
pub fn new(conn_type: ConnectionType) -> Connection {
|
pub fn new(conn_type: ConnectionType) -> Connection {
|
||||||
Connection {
|
Connection {
|
||||||
conn_type: conn_type,
|
conn_type,
|
||||||
hash_data: HashData::default(),
|
hash_data: HashData::default(),
|
||||||
state: ConnectionState::Initial,
|
state: ConnectionState::Initial,
|
||||||
key_exchange: None,
|
key_exchange: None,
|
||||||
|
|
@ -147,8 +147,8 @@ impl<'a> Connection {
|
||||||
let id = format!("SSH-2.0-RedoxSSH_{}", env!("CARGO_PKG_VERSION"));
|
let id = format!("SSH-2.0-RedoxSSH_{}", env!("CARGO_PKG_VERSION"));
|
||||||
info!("Identifying as {:?}", id);
|
info!("Identifying as {:?}", id);
|
||||||
|
|
||||||
stream.write(id.as_bytes())?;
|
stream.write_all(id.as_bytes())?;
|
||||||
stream.write(b"\r\n")?;
|
stream.write_all(b"\r\n")?;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
||||||
self.hash_data.server_id = Some(id);
|
self.hash_data.server_id = Some(id);
|
||||||
|
|
@ -246,7 +246,7 @@ impl<'a> Connection {
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
"Service Request {:?}",
|
"Service Request {:?}",
|
||||||
::std::str::from_utf8(&name.as_slice()).unwrap()
|
::std::str::from_utf8(name.as_slice()).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut res = Packet::new(MessageType::ServiceAccept);
|
let mut res = Packet::new(MessageType::ServiceAccept);
|
||||||
|
|
@ -262,7 +262,7 @@ impl<'a> Connection {
|
||||||
let method = reader.read_utf8()?;
|
let method = reader.read_utf8()?;
|
||||||
|
|
||||||
let success = if method == "password" {
|
let success = if method == "password" {
|
||||||
assert!(reader.read_bool()? == false);
|
assert!(!(reader.read_bool()?));
|
||||||
let pass = reader.read_utf8()?;
|
let pass = reader.read_utf8()?;
|
||||||
pass == "hunter2"
|
pass == "hunter2"
|
||||||
}
|
}
|
||||||
|
|
@ -406,7 +406,7 @@ impl<'a> Connection {
|
||||||
|
|
||||||
// Create a random 16 byte cookie
|
// Create a random 16 byte cookie
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
let mut rng = rand::thread_rng();
|
let rng = rand::thread_rng();
|
||||||
let cookie: Vec<u8> = rng.sample_iter(Standard).take(16).collect();
|
let cookie: Vec<u8> = rng.sample_iter(Standard).take(16).collect();
|
||||||
|
|
||||||
let mut packet = Packet::new(MessageType::KexInit);
|
let mut packet = Packet::new(MessageType::KexInit);
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ impl<'a> Decryptor<'a> {
|
||||||
pub fn new(encryption: &'a mut dyn Encryption, stream: &'a mut dyn Read)
|
pub fn new(encryption: &'a mut dyn Encryption, stream: &'a mut dyn Read)
|
||||||
-> Decryptor<'a> {
|
-> Decryptor<'a> {
|
||||||
Decryptor {
|
Decryptor {
|
||||||
encryption: encryption,
|
encryption,
|
||||||
stream: stream,
|
stream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ impl Curve25519 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyExchange for Curve25519 {
|
impl KeyExchange for Curve25519 {
|
||||||
fn shared_secret<'a>(&'a self) -> Option<&'a [u8]> {
|
fn shared_secret(&self) -> Option<&[u8]> {
|
||||||
self.shared_secret.as_ref().map(|x| x as &[u8])
|
self.shared_secret.as_ref().map(|x| x as &[u8])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exchange_hash<'a>(&'a self) -> Option<&'a [u8]> {
|
fn exchange_hash(&self) -> Option<&[u8]> {
|
||||||
self.exchange_hash.as_ref().map(|x| x.as_slice())
|
self.exchange_hash.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash(&self, data: &[&[u8]]) -> Vec<u8> {
|
fn hash(&self, data: &[&[u8]]) -> Vec<u8> {
|
||||||
|
|
@ -56,7 +56,7 @@ impl KeyExchange for Curve25519 {
|
||||||
|
|
||||||
let config = match &conn.conn_type
|
let config = match &conn.conn_type
|
||||||
{
|
{
|
||||||
&ConnectionType::Server(ref config) => config.clone(),
|
ConnectionType::Server(config) => config.clone(),
|
||||||
_ => return KexResult::Error,
|
_ => return KexResult::Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ pub enum KexResult {
|
||||||
|
|
||||||
pub trait KeyExchange {
|
pub trait KeyExchange {
|
||||||
fn process(&mut self, conn: &mut Connection, packet: Packet) -> KexResult;
|
fn process(&mut self, conn: &mut Connection, packet: Packet) -> KexResult;
|
||||||
fn shared_secret<'a>(&'a self) -> Option<&'a [u8]>;
|
fn shared_secret(&self) -> Option<&[u8]>;
|
||||||
fn exchange_hash<'a>(&'a self) -> Option<&'a [u8]>;
|
fn exchange_hash(&self) -> Option<&[u8]>;
|
||||||
fn hash(&self, data: &[&[u8]]) -> Vec<u8>;
|
fn hash(&self, data: &[&[u8]]) -> Vec<u8>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,10 @@ impl From<u8> for MessageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<u8> for MessageType {
|
impl From<MessageType> for u8 {
|
||||||
fn into(self) -> u8 {
|
fn from(val: MessageType) -> Self {
|
||||||
use self::MessageType::*;
|
use self::MessageType::*;
|
||||||
match self
|
match val
|
||||||
{
|
{
|
||||||
Disconnect => 1,
|
Disconnect => 1,
|
||||||
Ignore => 2,
|
Ignore => 2,
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ impl Packet {
|
||||||
pub fn msg_type(&self) -> MessageType {
|
pub fn msg_type(&self) -> MessageType {
|
||||||
match self
|
match self
|
||||||
{
|
{
|
||||||
&Packet::Raw(ref data, _) => data[5],
|
Packet::Raw(data, _) => data[5],
|
||||||
&Packet::Payload(ref data) => data[0],
|
Packet::Payload(data) => data[0],
|
||||||
}.into()
|
}.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,17 +50,17 @@ impl Packet {
|
||||||
pub fn write_to<W: io::Write>(&self, stream: &mut W) -> Result<()> {
|
pub fn write_to<W: io::Write>(&self, stream: &mut W) -> Result<()> {
|
||||||
match self
|
match self
|
||||||
{
|
{
|
||||||
&Packet::Raw(ref data, _) => {
|
Packet::Raw(data, _) => {
|
||||||
stream.write_all(data)?;
|
stream.write_all(data)?;
|
||||||
stream.flush()
|
stream.flush()
|
||||||
}
|
}
|
||||||
&Packet::Payload(ref payload) => {
|
Packet::Payload(payload) => {
|
||||||
let padding_len = self.padding_len();
|
let padding_len = self.padding_len();
|
||||||
let packet_len = payload.len() + padding_len + 1;
|
let packet_len = payload.len() + padding_len + 1;
|
||||||
|
|
||||||
stream.write_u32::<BigEndian>(packet_len as u32)?;
|
stream.write_u32::<BigEndian>(packet_len as u32)?;
|
||||||
stream.write_u8(padding_len as u8)?;
|
stream.write_u8(padding_len as u8)?;
|
||||||
stream.write_all(&payload)?;
|
stream.write_all(payload)?;
|
||||||
stream.write_all(&[0u8; 255][..padding_len])?;
|
stream.write_all(&[0u8; 255][..padding_len])?;
|
||||||
|
|
||||||
stream.flush()
|
stream.flush()
|
||||||
|
|
@ -76,11 +76,11 @@ impl Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data<'a>(&'a self) -> &'a [u8] {
|
pub fn data(&self) -> &[u8] {
|
||||||
match self
|
match self
|
||||||
{
|
{
|
||||||
&Packet::Raw(ref data, _) => &data,
|
Packet::Raw(data, _) => data,
|
||||||
&Packet::Payload(ref payload) => &payload,
|
Packet::Payload(payload) => payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,13 +96,13 @@ impl Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reader<'a>(&'a self) -> BufReader<&'a [u8]> {
|
pub fn reader(&self) -> BufReader<&[u8]> {
|
||||||
match self
|
match self
|
||||||
{
|
{
|
||||||
&Packet::Raw(ref data, payload_len) => {
|
&Packet::Raw(ref data, payload_len) => {
|
||||||
BufReader::new(&data.as_slice()[6..payload_len + 5])
|
BufReader::new(&data.as_slice()[6..payload_len + 5])
|
||||||
}
|
}
|
||||||
&Packet::Payload(ref payload) => {
|
Packet::Payload(payload) => {
|
||||||
BufReader::new(&payload.as_slice()[1..])
|
BufReader::new(&payload.as_slice()[1..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ impl Packet {
|
||||||
match self
|
match self
|
||||||
{
|
{
|
||||||
&Packet::Raw(_, payload_len) => payload_len,
|
&Packet::Raw(_, payload_len) => payload_len,
|
||||||
&Packet::Payload(ref payload) => payload.len(),
|
Packet::Payload(payload) => payload.len(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ pub trait ReadPacketExt: ReadBytesExt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_uint32(&mut self) -> Result<u32> {
|
fn read_uint32(&mut self) -> Result<u32> {
|
||||||
Ok(self.read_u32::<BigEndian>()?)
|
self.read_u32::<BigEndian>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_bytes(&mut self, len: usize) -> Result<Vec<u8>> {
|
fn read_bytes(&mut self, len: usize) -> Result<Vec<u8>> {
|
||||||
|
|
@ -189,7 +189,7 @@ pub trait ReadPacketExt: ReadBytesExt {
|
||||||
Ok(
|
Ok(
|
||||||
string
|
string
|
||||||
.split(",")
|
.split(",")
|
||||||
.filter_map(|l| T::from_str(&l).ok())
|
.filter_map(|l| T::from_str(l).ok())
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -231,20 +231,20 @@ pub trait WritePacketExt: WriteBytesExt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_uint32(&mut self, value: u32) -> Result<()> {
|
fn write_uint32(&mut self, value: u32) -> Result<()> {
|
||||||
self.write_u32::<BigEndian>(value as u32)
|
self.write_u32::<BigEndian>(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_list<T: ToString>(&mut self, list: &[T]) -> Result<()> {
|
fn write_list<T: ToString>(&mut self, list: &[T]) -> Result<()> {
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
let mut iter = list.iter();
|
let iter = list.iter();
|
||||||
|
|
||||||
while let Some(item) = iter.next() {
|
for item in iter {
|
||||||
if !string.is_empty() {
|
if !string.is_empty() {
|
||||||
string += ",";
|
string += ",";
|
||||||
}
|
}
|
||||||
string += &*item.to_string();
|
string += &*item.to_string();
|
||||||
}
|
}
|
||||||
self.write_string(&*string)
|
self.write_string(&string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ impl Ed25519KeyPair {
|
||||||
r.read_exact(&mut private)?;
|
r.read_exact(&mut private)?;
|
||||||
|
|
||||||
Ok(Box::new(Ed25519KeyPair {
|
Ok(Box::new(Ed25519KeyPair {
|
||||||
public: public,
|
public,
|
||||||
private: Some(private),
|
private: Some(private),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ impl Ed25519KeyPair {
|
||||||
|
|
||||||
Ok(Box::new(Ed25519KeyPair {
|
Ok(Box::new(Ed25519KeyPair {
|
||||||
private: None,
|
private: None,
|
||||||
public: public,
|
public,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ impl KeyPair for Ed25519KeyPair {
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
let mut reader = Cursor::new(signature);
|
let mut reader = Cursor::new(signature);
|
||||||
let id = reader.read_string().unwrap_or(vec![]);
|
let id = reader.read_string().unwrap_or_default();
|
||||||
|
|
||||||
if id == b"ssh-ed25519" {
|
if id == b"ssh-ed25519" {
|
||||||
if let Ok(sig) = reader.read_string() {
|
if let Ok(sig) = reader.read_string() {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ extern crate rand;
|
||||||
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use rand::{Rng, RngCore};
|
use rand::RngCore;
|
||||||
use ssh::public_key::{self, CryptoSystem, KeyPair};
|
use ssh::public_key::{self, CryptoSystem, KeyPair};
|
||||||
|
|
||||||
fn test_export_import(keypair: &Box<dyn KeyPair>) -> Box<dyn KeyPair> {
|
fn test_export_import(keypair: &Box<dyn KeyPair>) -> Box<dyn KeyPair> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue