mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 22:32:18 +01:00
Run cargo fmt
This commit is contained in:
parent
16c57380d7
commit
a9fb733bea
10 changed files with 121 additions and 51 deletions
22
.travis.yml
22
.travis.yml
|
|
@ -1,5 +1,27 @@
|
||||||
|
sudo: false
|
||||||
language: rust
|
language: rust
|
||||||
rust:
|
rust:
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
cache: cargo
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- libcurl4-openssl-dev
|
||||||
|
- libelf-dev
|
||||||
|
- libdw-dev
|
||||||
|
before_script:
|
||||||
|
- |
|
||||||
|
pip install 'travis-cargo<0.2' --user &&
|
||||||
|
export PATH=$HOME/.local/bin:/usr/local/bin:$PATH
|
||||||
|
- export PATH="$PATH:$HOME/.cargo/bin"
|
||||||
|
- which rustfmt || cargo install rustfmt
|
||||||
|
script:
|
||||||
|
- cargo fmt -- --write-mode=diff
|
||||||
|
- travis-cargo build
|
||||||
|
- travis-cargo test
|
||||||
|
- travis-cargo --only stable doc
|
||||||
|
after_success:
|
||||||
|
- travis-cargo --only stable doc-upload
|
||||||
|
- travis-cargo coveralls --no-sudo --verify
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use std::str::FromStr;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// Slice of implemented key exchange algorithms, ordered by preference
|
/// Slice of implemented key exchange algorithms, ordered by preference
|
||||||
pub static KEY_EXCHANGE: &[KeyExchangeAlgorithm] = &[
|
pub static KEY_EXCHANGE: &[KeyExchangeAlgorithm] =
|
||||||
|
&[
|
||||||
KeyExchangeAlgorithm::CURVE25519_SHA256,
|
KeyExchangeAlgorithm::CURVE25519_SHA256,
|
||||||
// KeyExchangeAlgorithm::DH_GROUP_EXCHANGE_SHA1,
|
// KeyExchangeAlgorithm::DH_GROUP_EXCHANGE_SHA1,
|
||||||
];
|
];
|
||||||
|
|
@ -14,7 +15,8 @@ pub static HOST_KEY: &[PublicKeyAlgorithm] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Slice of implemented encryption algorithms, ordered by preference
|
/// Slice of implemented encryption algorithms, ordered by preference
|
||||||
pub static ENCRYPTION: &[EncryptionAlgorithm] = &[EncryptionAlgorithm::AES256_CTR];
|
pub static ENCRYPTION: &[EncryptionAlgorithm] =
|
||||||
|
&[EncryptionAlgorithm::AES256_CTR];
|
||||||
|
|
||||||
/// Slice of implemented MAC algorithms, ordered by preference
|
/// Slice of implemented MAC algorithms, ordered by preference
|
||||||
pub static MAC: &[MacAlgorithm] = &[MacAlgorithm::HMAC_SHA2_512];
|
pub static MAC: &[MacAlgorithm] = &[MacAlgorithm::HMAC_SHA2_512];
|
||||||
|
|
@ -54,12 +56,15 @@ impl FromStr for KeyExchangeAlgorithm {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<KeyExchangeAlgorithm, ()> {
|
fn from_str(s: &str) -> Result<KeyExchangeAlgorithm, ()> {
|
||||||
use self::KeyExchangeAlgorithm::*;
|
use self::KeyExchangeAlgorithm::*;
|
||||||
match s {
|
match s
|
||||||
|
{
|
||||||
"curve25519-sha256" => Ok(CURVE25519_SHA256),
|
"curve25519-sha256" => Ok(CURVE25519_SHA256),
|
||||||
"ecdh-sha2-nistp256" => Ok(ECDH_SHA2_NISTP256),
|
"ecdh-sha2-nistp256" => Ok(ECDH_SHA2_NISTP256),
|
||||||
"ecdh-sha2-nistp384" => Ok(ECDH_SHA2_NISTP384),
|
"ecdh-sha2-nistp384" => Ok(ECDH_SHA2_NISTP384),
|
||||||
"ecdh-sha2-nistp521" => Ok(ECDH_SHA2_NISTP521),
|
"ecdh-sha2-nistp521" => Ok(ECDH_SHA2_NISTP521),
|
||||||
"diffie-hellman-group-exchange-sha256" => Ok(DH_GROUP_EXCHANGE_SHA256),
|
"diffie-hellman-group-exchange-sha256" => Ok(
|
||||||
|
DH_GROUP_EXCHANGE_SHA256,
|
||||||
|
),
|
||||||
"diffie-hellman-group-exchange-sha1" => Ok(DH_GROUP_EXCHANGE_SHA1),
|
"diffie-hellman-group-exchange-sha1" => Ok(DH_GROUP_EXCHANGE_SHA1),
|
||||||
"diffie-hellman-group16-sha512" => Ok(DH_GROUP16_SHA512),
|
"diffie-hellman-group16-sha512" => Ok(DH_GROUP16_SHA512),
|
||||||
"diffie-hellman-group18-sha512" => Ok(DH_GROUP18_SHA512),
|
"diffie-hellman-group18-sha512" => Ok(DH_GROUP18_SHA512),
|
||||||
|
|
@ -77,7 +82,8 @@ impl FromStr for KeyExchangeAlgorithm {
|
||||||
impl fmt::Display for KeyExchangeAlgorithm {
|
impl fmt::Display for KeyExchangeAlgorithm {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::KeyExchangeAlgorithm::*;
|
use self::KeyExchangeAlgorithm::*;
|
||||||
f.write_str(match self {
|
f.write_str(match self
|
||||||
|
{
|
||||||
&CURVE25519_SHA256 => "curve25519-sha256",
|
&CURVE25519_SHA256 => "curve25519-sha256",
|
||||||
&ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256",
|
&ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256",
|
||||||
&ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384",
|
&ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384",
|
||||||
|
|
@ -109,7 +115,8 @@ impl FromStr for PublicKeyAlgorithm {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<PublicKeyAlgorithm, ()> {
|
fn from_str(s: &str) -> Result<PublicKeyAlgorithm, ()> {
|
||||||
use self::PublicKeyAlgorithm::*;
|
use self::PublicKeyAlgorithm::*;
|
||||||
match s {
|
match s
|
||||||
|
{
|
||||||
"ssh-rsa" => Ok(SSH_RSA),
|
"ssh-rsa" => Ok(SSH_RSA),
|
||||||
"rsa-sha2-256" => Ok(RSA_SHA2_256),
|
"rsa-sha2-256" => Ok(RSA_SHA2_256),
|
||||||
"rsa-sha2-512" => Ok(RSA_SHA2_512),
|
"rsa-sha2-512" => Ok(RSA_SHA2_512),
|
||||||
|
|
@ -128,7 +135,8 @@ impl FromStr for PublicKeyAlgorithm {
|
||||||
impl fmt::Display for PublicKeyAlgorithm {
|
impl fmt::Display for PublicKeyAlgorithm {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::PublicKeyAlgorithm::*;
|
use self::PublicKeyAlgorithm::*;
|
||||||
f.write_str(match self {
|
f.write_str(match self
|
||||||
|
{
|
||||||
&SSH_RSA => "ssh-rsa",
|
&SSH_RSA => "ssh-rsa",
|
||||||
&RSA_SHA2_256 => "rsa-sha2-256",
|
&RSA_SHA2_256 => "rsa-sha2-256",
|
||||||
&RSA_SHA2_512 => "rsa-sha2-512",
|
&RSA_SHA2_512 => "rsa-sha2-512",
|
||||||
|
|
@ -156,7 +164,8 @@ impl FromStr for EncryptionAlgorithm {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<EncryptionAlgorithm, ()> {
|
fn from_str(s: &str) -> Result<EncryptionAlgorithm, ()> {
|
||||||
use self::EncryptionAlgorithm::*;
|
use self::EncryptionAlgorithm::*;
|
||||||
match s {
|
match s
|
||||||
|
{
|
||||||
"aes128-ctr" => Ok(AES128_CTR),
|
"aes128-ctr" => Ok(AES128_CTR),
|
||||||
"aes128-cbc" => Ok(AES128_CBC),
|
"aes128-cbc" => Ok(AES128_CBC),
|
||||||
"aes192-ctr" => Ok(AES192_CTR),
|
"aes192-ctr" => Ok(AES192_CTR),
|
||||||
|
|
@ -175,7 +184,8 @@ impl FromStr for EncryptionAlgorithm {
|
||||||
impl fmt::Display for EncryptionAlgorithm {
|
impl fmt::Display for EncryptionAlgorithm {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::EncryptionAlgorithm::*;
|
use self::EncryptionAlgorithm::*;
|
||||||
f.write_str(match self {
|
f.write_str(match self
|
||||||
|
{
|
||||||
&AES128_CTR => "aes128-ctr",
|
&AES128_CTR => "aes128-ctr",
|
||||||
&AES128_CBC => "aes128-cbc",
|
&AES128_CBC => "aes128-cbc",
|
||||||
&AES192_CTR => "aes192-ctr",
|
&AES192_CTR => "aes192-ctr",
|
||||||
|
|
@ -200,7 +210,8 @@ impl FromStr for MacAlgorithm {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<MacAlgorithm, ()> {
|
fn from_str(s: &str) -> Result<MacAlgorithm, ()> {
|
||||||
use self::MacAlgorithm::*;
|
use self::MacAlgorithm::*;
|
||||||
match s {
|
match s
|
||||||
|
{
|
||||||
"hmac-sha1" => Ok(MacAlgorithm::HMAC_SHA1),
|
"hmac-sha1" => Ok(MacAlgorithm::HMAC_SHA1),
|
||||||
"hmac-sha2-256" => Ok(MacAlgorithm::HMAC_SHA2_256),
|
"hmac-sha2-256" => Ok(MacAlgorithm::HMAC_SHA2_256),
|
||||||
"hmac-sha2-512" => Ok(MacAlgorithm::HMAC_SHA2_512),
|
"hmac-sha2-512" => Ok(MacAlgorithm::HMAC_SHA2_512),
|
||||||
|
|
@ -215,7 +226,8 @@ impl FromStr for MacAlgorithm {
|
||||||
impl fmt::Display for MacAlgorithm {
|
impl fmt::Display for MacAlgorithm {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::MacAlgorithm::*;
|
use self::MacAlgorithm::*;
|
||||||
f.write_str(match self {
|
f.write_str(match self
|
||||||
|
{
|
||||||
&HMAC_SHA1 => "hmac-sha1",
|
&HMAC_SHA1 => "hmac-sha1",
|
||||||
&HMAC_SHA2_256 => "hmac-sha2-256",
|
&HMAC_SHA2_256 => "hmac-sha2-256",
|
||||||
&HMAC_SHA2_512 => "hmac-sha2-512",
|
&HMAC_SHA2_512 => "hmac-sha2-512",
|
||||||
|
|
@ -233,7 +245,8 @@ pub enum CompressionAlgorithm {
|
||||||
impl FromStr for CompressionAlgorithm {
|
impl FromStr for CompressionAlgorithm {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<CompressionAlgorithm, ()> {
|
fn from_str(s: &str) -> Result<CompressionAlgorithm, ()> {
|
||||||
match s {
|
match s
|
||||||
|
{
|
||||||
"zlib" => Ok(CompressionAlgorithm::Zlib),
|
"zlib" => Ok(CompressionAlgorithm::Zlib),
|
||||||
"none" => Ok(CompressionAlgorithm::None),
|
"none" => Ok(CompressionAlgorithm::None),
|
||||||
_ => {
|
_ => {
|
||||||
|
|
@ -246,7 +259,8 @@ impl FromStr for CompressionAlgorithm {
|
||||||
|
|
||||||
impl fmt::Display for CompressionAlgorithm {
|
impl fmt::Display for CompressionAlgorithm {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str(match self {
|
f.write_str(match self
|
||||||
|
{
|
||||||
&CompressionAlgorithm::Zlib => "zlib",
|
&CompressionAlgorithm::Zlib => "zlib",
|
||||||
&CompressionAlgorithm::None => "none",
|
&CompressionAlgorithm::None => "none",
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
extern crate ssh;
|
extern crate ssh;
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use ssh::public_key;
|
use ssh::public_key;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,15 @@ impl DhGroupSha1 {
|
||||||
DhGroupSha1 {
|
DhGroupSha1 {
|
||||||
g: None,
|
g: None,
|
||||||
p: None,
|
p: None,
|
||||||
e: None
|
e: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyExchange for DhGroupSha1 {
|
impl KeyExchange for DhGroupSha1 {
|
||||||
fn process(&mut self, packet: &Packet) -> KeyExchangeResult {
|
fn process(&mut self, packet: &Packet) -> KeyExchangeResult {
|
||||||
match packet.msg_type() {
|
match packet.msg_type()
|
||||||
|
{
|
||||||
MessageType::KeyExchange(DH_GEX_REQUEST) => {
|
MessageType::KeyExchange(DH_GEX_REQUEST) => {
|
||||||
let mut reader = packet.reader();
|
let mut reader = packet.reader();
|
||||||
let min = reader.read_uint32().unwrap();
|
let min = reader.read_uint32().unwrap();
|
||||||
|
|
@ -52,7 +53,8 @@ impl KeyExchange for DhGroupSha1 {
|
||||||
let g = rng.gen_biguint(opt as usize).to_bigint().unwrap();
|
let g = rng.gen_biguint(opt as usize).to_bigint().unwrap();
|
||||||
let p = rng.gen_biguint(opt as usize).to_bigint().unwrap();
|
let p = rng.gen_biguint(opt as usize).to_bigint().unwrap();
|
||||||
|
|
||||||
let mut packet = Packet::new(MessageType::KeyExchange(DH_GEX_GROUP));
|
let mut packet =
|
||||||
|
Packet::new(MessageType::KeyExchange(DH_GEX_GROUP));
|
||||||
packet.with_writer(&|w| {
|
packet.with_writer(&|w| {
|
||||||
w.write_mpint(g.clone())?;
|
w.write_mpint(g.clone())?;
|
||||||
w.write_mpint(p.clone())?;
|
w.write_mpint(p.clone())?;
|
||||||
|
|
@ -63,14 +65,15 @@ impl KeyExchange for DhGroupSha1 {
|
||||||
self.p = Some(p);
|
self.p = Some(p);
|
||||||
|
|
||||||
KeyExchangeResult::Ok(Some(packet))
|
KeyExchangeResult::Ok(Some(packet))
|
||||||
},
|
}
|
||||||
MessageType::KeyExchange(DH_GEX_INIT) => {
|
MessageType::KeyExchange(DH_GEX_INIT) => {
|
||||||
let mut reader = packet.reader();
|
let mut reader = packet.reader();
|
||||||
let e = reader.read_mpint().unwrap();
|
let e = reader.read_mpint().unwrap();
|
||||||
|
|
||||||
println!("Received e: {:?}", e);
|
println!("Received e: {:?}", e);
|
||||||
|
|
||||||
let mut packet = Packet::new(MessageType::KeyExchange(DH_GEX_REPLY));
|
let mut packet =
|
||||||
|
Packet::new(MessageType::KeyExchange(DH_GEX_REPLY));
|
||||||
packet.with_writer(&|w| {
|
packet.with_writer(&|w| {
|
||||||
w.write_string("HELLO WORLD")?;
|
w.write_string("HELLO WORLD")?;
|
||||||
w.write_mpint(e.clone())?;
|
w.write_mpint(e.clone())?;
|
||||||
|
|
@ -81,7 +84,7 @@ impl KeyExchange for DhGroupSha1 {
|
||||||
self.e = Some(e);
|
self.e = Some(e);
|
||||||
|
|
||||||
KeyExchangeResult::Ok(Some(packet))
|
KeyExchangeResult::Ok(Some(packet))
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
debug!("Unhandled key exchange packet: {:?}", packet);
|
debug!("Unhandled key exchange packet: {:?}", packet);
|
||||||
KeyExchangeResult::Error(None)
|
KeyExchangeResult::Error(None)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use packet::Packet;
|
||||||
pub enum KeyExchangeResult {
|
pub enum KeyExchangeResult {
|
||||||
Ok(Option<Packet>),
|
Ok(Option<Packet>),
|
||||||
Done(Option<Packet>),
|
Done(Option<Packet>),
|
||||||
Error(Option<Packet>)
|
Error(Option<Packet>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait KeyExchange {
|
pub trait KeyExchange {
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,14 @@ pub enum MessageType {
|
||||||
ChannelRequest,
|
ChannelRequest,
|
||||||
ChannelSuccess,
|
ChannelSuccess,
|
||||||
ChannelFailure,
|
ChannelFailure,
|
||||||
Unknown
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for MessageType {
|
impl From<u8> for MessageType {
|
||||||
fn from(id: u8) -> Self {
|
fn from(id: u8) -> Self {
|
||||||
use self::MessageType::*;
|
use self::MessageType::*;
|
||||||
match id {
|
match id
|
||||||
|
{
|
||||||
1 => Disconnect,
|
1 => Disconnect,
|
||||||
2 => Ignore,
|
2 => Ignore,
|
||||||
3 => Unimplemented,
|
3 => Unimplemented,
|
||||||
|
|
@ -65,7 +66,7 @@ impl From<u8> for MessageType {
|
||||||
98 => ChannelRequest,
|
98 => ChannelRequest,
|
||||||
99 => ChannelSuccess,
|
99 => ChannelSuccess,
|
||||||
100 => ChannelFailure,
|
100 => ChannelFailure,
|
||||||
_ => Unknown
|
_ => Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +74,8 @@ impl From<u8> for MessageType {
|
||||||
impl Into<u8> for MessageType {
|
impl Into<u8> for MessageType {
|
||||||
fn into(self) -> u8 {
|
fn into(self) -> u8 {
|
||||||
use self::MessageType::*;
|
use self::MessageType::*;
|
||||||
match self {
|
match self
|
||||||
|
{
|
||||||
Disconnect => 1,
|
Disconnect => 1,
|
||||||
Ignore => 2,
|
Ignore => 2,
|
||||||
Unimplemented => 3,
|
Unimplemented => 3,
|
||||||
|
|
@ -102,7 +104,7 @@ impl Into<u8> for MessageType {
|
||||||
ChannelRequest => 98,
|
ChannelRequest => 98,
|
||||||
ChannelSuccess => 99,
|
ChannelSuccess => 99,
|
||||||
ChannelFailure => 100,
|
ChannelFailure => 100,
|
||||||
Unknown => 255
|
Unknown => 255,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::io::{self, BufReader, Read, Result, Write};
|
||||||
use std::str::{self, FromStr};
|
use std::str::{self, FromStr};
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
use std::io::{self, BufReader, Write, Read, Result};
|
|
||||||
|
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||||
|
|
||||||
use message::MessageType;
|
use message::MessageType;
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
|
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
pub struct Packet {
|
pub struct Packet {
|
||||||
payload: Vec<u8>
|
payload: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packet {
|
impl Packet {
|
||||||
|
|
@ -30,14 +32,14 @@ impl Packet {
|
||||||
|
|
||||||
let mut payload = Vec::with_capacity(payload_len);
|
let mut payload = Vec::with_capacity(payload_len);
|
||||||
let mut padding = Vec::with_capacity(padding_len);
|
let mut padding = Vec::with_capacity(padding_len);
|
||||||
// let mut mac = Vec::with_capacity(mac_len);
|
// let mut mac = Vec::with_capacity(mac_len);
|
||||||
|
|
||||||
stream.take(payload_len as u64).read_to_end(&mut payload)?;
|
stream.take(payload_len as u64).read_to_end(&mut payload)?;
|
||||||
stream.take(padding_len as u64).read_to_end(&mut padding)?;
|
stream.take(padding_len as u64).read_to_end(&mut padding)?;
|
||||||
|
|
||||||
// if mac_len > 0 {
|
// if mac_len > 0 {
|
||||||
// stream.take(mac_len as u64).read_to_end(&mut mac);
|
// stream.take(mac_len as u64).read_to_end(&mut mac);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Ok(Packet { payload: payload })
|
Ok(Packet { payload: payload })
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +51,7 @@ impl Packet {
|
||||||
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(&self.payload)?;
|
stream.write(&self.payload)?;
|
||||||
stream.write(&[0u8;255][..padding_len])?;
|
stream.write(&[0u8; 255][..padding_len])?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +60,10 @@ impl Packet {
|
||||||
&mut self.payload
|
&mut self.payload
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_writer(&mut self, f: &Fn(&mut Write) -> Result<()>) -> Result<()> {
|
pub fn with_writer(
|
||||||
|
&mut self,
|
||||||
|
f: &Fn(&mut Write) -> Result<()>,
|
||||||
|
) -> Result<()> {
|
||||||
f(&mut self.payload)
|
f(&mut self.payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +76,12 @@ impl Packet {
|
||||||
let padding_len = 8 - ((self.payload.len() + 5) % 8);
|
let padding_len = 8 - ((self.payload.len() + 5) % 8);
|
||||||
|
|
||||||
// The padding has to be at least 4 bytes long
|
// The padding has to be at least 4 bytes long
|
||||||
if padding_len < 4 { padding_len + 8 }
|
if padding_len < 4 {
|
||||||
else { padding_len }
|
padding_len + 8
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
padding_len
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +108,11 @@ pub trait ReadPacketExt: ReadBytesExt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_utf8(&mut self) -> Result<String> {
|
fn read_utf8(&mut self) -> Result<String> {
|
||||||
Ok(str::from_utf8(self.read_string()?.as_slice()).unwrap_or("").to_owned())
|
Ok(
|
||||||
|
str::from_utf8(self.read_string()?.as_slice())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_bool(&mut self) -> Result<bool> {
|
fn read_bool(&mut self) -> Result<bool> {
|
||||||
|
|
@ -108,7 +121,12 @@ pub trait ReadPacketExt: ReadBytesExt {
|
||||||
|
|
||||||
fn read_enum_list<T: FromStr>(&mut self) -> Result<Vec<T>> {
|
fn read_enum_list<T: FromStr>(&mut self) -> Result<Vec<T>> {
|
||||||
let string = self.read_utf8()?;
|
let string = self.read_utf8()?;
|
||||||
Ok(string.split(",").filter_map(|l| T::from_str(&l).ok()).collect())
|
Ok(
|
||||||
|
string
|
||||||
|
.split(",")
|
||||||
|
.filter_map(|l| T::from_str(&l).ok())
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_name_list(&mut self) -> Result<Vec<String>> {
|
fn read_name_list(&mut self) -> Result<Vec<String>> {
|
||||||
|
|
@ -161,7 +179,7 @@ pub trait WritePacketExt: WriteBytesExt {
|
||||||
}
|
}
|
||||||
string += &*item.to_string();
|
string += &*item.to_string();
|
||||||
}
|
}
|
||||||
self.write_string(&*string)
|
self.write_string(&*string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,6 +187,11 @@ impl<R: WriteBytesExt + ?Sized> WritePacketExt for R {}
|
||||||
|
|
||||||
impl fmt::Debug for Packet {
|
impl fmt::Debug for Packet {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Packet({:?}, {} bytes)", self.msg_type(), self.payload.len())
|
write!(
|
||||||
|
f,
|
||||||
|
"Packet({:?}, {} bytes)",
|
||||||
|
self.msg_type(),
|
||||||
|
self.payload.len()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use public_key::{KeyPair, CryptoSystem};
|
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::io::ErrorKind::InvalidData;
|
use std::io::ErrorKind::InvalidData;
|
||||||
use rand::{self, Rng};
|
|
||||||
use crypto::ed25519;
|
use crypto::ed25519;
|
||||||
|
use public_key::{CryptoSystem, KeyPair};
|
||||||
|
use rand::{self, Rng};
|
||||||
|
|
||||||
pub static ED25519: CryptoSystem = CryptoSystem {
|
pub static ED25519: CryptoSystem = CryptoSystem {
|
||||||
id: "ed25519",
|
id: "ed25519",
|
||||||
|
|
@ -90,7 +91,8 @@ impl KeyPair for Ed25519KeyPair {
|
||||||
if let Some(private_key) = self.private {
|
if let Some(private_key) = self.private {
|
||||||
let signature = ed25519::signature(data, &private_key);
|
let signature = ed25519::signature(data, &private_key);
|
||||||
Ok(signature.to_vec())
|
Ok(signature.to_vec())
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
|
|
||||||
//mod rsa;
|
// mod rsa;
|
||||||
mod ed25519;
|
mod ed25519;
|
||||||
|
|
||||||
//pub use self::rsa::RSA;
|
// pub use self::rsa::RSA;
|
||||||
|
|
||||||
pub use self::ed25519::ED25519;
|
pub use self::ed25519::ED25519;
|
||||||
|
|
||||||
pub trait KeyPair {
|
pub trait KeyPair {
|
||||||
|
|
@ -22,5 +23,5 @@ pub struct CryptoSystem {
|
||||||
pub id: &'static str,
|
pub id: &'static str,
|
||||||
pub generate_key_pair: fn(bits: Option<u32>) -> Box<KeyPair>,
|
pub generate_key_pair: fn(bits: Option<u32>) -> Box<KeyPair>,
|
||||||
pub import: fn(r: &mut Read) -> io::Result<Box<KeyPair>>,
|
pub import: fn(r: &mut Read) -> io::Result<Box<KeyPair>>,
|
||||||
pub read_public: fn(r: &mut Read) -> io::Result<Box<KeyPair>>
|
pub read_public: fn(r: &mut Read) -> io::Result<Box<KeyPair>>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
extern crate ssh;
|
extern crate ssh;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
use rand::Rng;
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
use ssh::public_key::{self, CryptoSystem, KeyPair};
|
use ssh::public_key::{self, CryptoSystem, KeyPair};
|
||||||
|
|
||||||
fn test_export_import(keypair: &Box<KeyPair>) -> Box<KeyPair> {
|
fn test_export_import(keypair: &Box<KeyPair>) -> Box<KeyPair> {
|
||||||
|
|
@ -20,7 +21,7 @@ fn test_crypto_system(system: &CryptoSystem, key_size: Option<u32>) {
|
||||||
let keypair2 = test_export_import(&keypair);
|
let keypair2 = test_export_import(&keypair);
|
||||||
|
|
||||||
// Generate a random message
|
// Generate a random message
|
||||||
let mut buffer = [0;4096];
|
let mut buffer = [0; 4096];
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
rng.fill_bytes(&mut buffer);
|
rng.fill_bytes(&mut buffer);
|
||||||
|
|
||||||
|
|
@ -36,4 +37,6 @@ fn test_crypto_system(system: &CryptoSystem, key_size: Option<u32>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ed25519() { test_crypto_system(&public_key::ED25519, None); }
|
fn test_ed25519() {
|
||||||
|
test_crypto_system(&public_key::ED25519, None);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue