Skip to content

Commit

Permalink
re-export russh_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jul 17, 2024
1 parent 512c441 commit 9c2265e
Show file tree
Hide file tree
Showing 34 changed files with 65 additions and 71 deletions.
4 changes: 3 additions & 1 deletion russh-keys/src/format/pkcs8.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::convert::{TryFrom, TryInto};

use crate::{ec, key, key::SignatureHash, protocol, Error};
use pkcs8::{EncodePrivateKey, PrivateKeyInfo, SecretDocument};

use crate::key::SignatureHash;
use crate::{ec, key, protocol, Error};

/// Decode a PKCS#8-encoded private key.
pub fn decode_pkcs8(ciphertext: &[u8], password: Option<&[u8]>) -> Result<key::KeyPair, Error> {
let doc = SecretDocument::try_from(ciphertext)?;
Expand Down
1 change: 1 addition & 0 deletions russh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version = "1.65"
default = ["flate2"]
openssl = ["russh-keys/openssl", "dep:openssl"]
vendored-openssl = ["openssl/vendored", "russh-keys/vendored-openssl"]
legacy-ed25519-pkcs8-parser = ["russh-keys/legacy-ed25519-pkcs8-parser"]

[dependencies]
aes = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/client_exec_interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use log::info;
use russh::keys::*;
use russh::*;
use russh_keys::*;
use termion::raw::IntoRawMode;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::ToSocketAddrs;
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/client_exec_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use log::info;
use russh::keys::*;
use russh::*;
use russh_keys::*;
use tokio::io::AsyncWriteExt;
use tokio::net::ToSocketAddrs;

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/echoserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use russh::keys::*;
use russh::server::{Msg, Server as _, Session};
use russh::*;
use russh_keys::*;
use tokio::sync::Mutex;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/ratatui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use ratatui::layout::Rect;
use ratatui::style::{Color, Style};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::Terminal;
use russh::keys::key::PublicKey;
use russh::server::*;
use russh::{Channel, ChannelId};
use russh_keys::key::PublicKey;
use tokio::sync::Mutex;

type SshTerminal = Terminal<CrosstermBackend<TerminalHandle>>;
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/ratatui_shared_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use ratatui::layout::Rect;
use ratatui::style::{Color, Style};
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use ratatui::Terminal;
use russh::keys::key::PublicKey;
use russh::server::*;
use russh::{Channel, ChannelId};
use russh_keys::key::PublicKey;
use tokio::sync::Mutex;

type SshTerminal = Terminal<CrosstermBackend<TerminalHandle>>;
Expand Down
2 changes: 1 addition & 1 deletion russh/examples/sftp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;

use async_trait::async_trait;
use log::{error, info, LevelFilter};
use russh::keys::*;
use russh::*;
use russh_keys::*;
use russh_sftp::client::SftpSession;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/sftp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::time::Duration;

use async_trait::async_trait;
use log::{error, info, LevelFilter};
use russh::keys::key::KeyPair;
use russh::server::{Auth, Msg, Server as _, Session};
use russh::{Channel, ChannelId};
use russh_keys::key::KeyPair;
use russh_sftp::protocol::{File, FileAttributes, Handle, Name, Status, StatusCode, Version};
use tokio::sync::Mutex;

Expand Down
2 changes: 1 addition & 1 deletion russh/examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::sync::{Arc, Mutex};

use async_trait::async_trait;
use log::debug;
use russh::keys::*;
use russh::server::{Auth, Msg, Server as _, Session};
use russh::*;
use russh_keys::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
5 changes: 3 additions & 2 deletions russh/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
use std::sync::Arc;

use bitflags::bitflags;
use russh_cryptovec::CryptoVec;
use russh_keys::{encoding, key};
use ssh_key::Certificate;
use thiserror::Error;
use tokio::io::{AsyncRead, AsyncWrite};

use crate::keys::{encoding, key};
use crate::CryptoVec;

bitflags! {
/// Set of authentication methods, represented by bit flags.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions russh/src/cert.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;
use ssh_encoding::Encode;
use ssh_key::{Algorithm, Certificate, EcdsaCurve};

use crate::key::PubKey;
use crate::keys::encoding::Encoding;
use crate::negotiation::Named;
use crate::CryptoVec;

/// OpenSSH certificate for DSA public key
const CERT_DSA: &str = "[email protected]";
Expand Down
3 changes: 1 addition & 2 deletions russh/src/channels/io/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::sync::Arc;
use std::task::{ready, Context, Poll};

use futures::FutureExt;
use russh_cryptovec::CryptoVec;
use tokio::io::AsyncWrite;
use tokio::sync::mpsc::error::SendError;
use tokio::sync::mpsc::{self, OwnedPermit};
use tokio::sync::{Mutex, OwnedMutexGuard};

use super::ChannelMsg;
use crate::ChannelId;
use crate::{ChannelId, CryptoVec};

type BoxedThreadsafeFuture<T> = Pin<Box<dyn Sync + Send + std::future::Future<Output = T>>>;
type OwnedPermitFuture<S> =
Expand Down
3 changes: 1 addition & 2 deletions russh/src/channels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::sync::Arc;

use russh_cryptovec::CryptoVec;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::sync::mpsc::{Sender, UnboundedReceiver};
use tokio::sync::Mutex;

use crate::{ChannelId, ChannelOpenFailure, Error, Pty, Sig};
use crate::{ChannelId, ChannelOpenFailure, CryptoVec, Error, Pty, Sig};

pub mod io;

Expand Down
7 changes: 3 additions & 4 deletions russh/src/client/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ use std::convert::TryInto;
use std::num::Wrapping;

use log::{debug, error, info, trace, warn};
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::{Encoding, Reader};
use russh_keys::key::parse_public_key;

use crate::client::{Handler, Msg, Prompt, Reply, Session};
use crate::key::PubKey;
use crate::keys::encoding::{Encoding, Reader};
use crate::keys::key::parse_public_key;
use crate::negotiation::{Named, Select};
use crate::parsing::{ChannelOpenConfirmation, ChannelType, OpenChannelMessage};
use crate::session::{Encrypted, EncryptedState, GlobalRequestResponse, Kex, KexInit};
use crate::{
auth, msg, negotiation, strict_kex_violation, Channel, ChannelId, ChannelMsg,
ChannelOpenFailure, ChannelParams, Sig,
ChannelOpenFailure, ChannelParams, CryptoVec, Sig,
};

thread_local! {
Expand Down
11 changes: 5 additions & 6 deletions russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ use async_trait::async_trait;
use futures::task::{Context, Poll};
use futures::Future;
use log::{debug, error, info, trace};
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Reader;
use russh_keys::key::{self, parse_public_key, PublicKey, SignatureHash};
use ssh_key::Certificate;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadHalf, WriteHalf};
use tokio::net::{TcpStream, ToSocketAddrs};
Expand All @@ -60,15 +57,17 @@ use tokio::sync::{oneshot, Mutex};
use crate::channels::{Channel, ChannelMsg, ChannelRef};
use crate::cipher::{self, clear, CipherPair, OpeningKey};
use crate::key::PubKey;
use crate::keys::encoding::Reader;
use crate::keys::key::{self, parse_public_key, PublicKey, SignatureHash};
use crate::session::{
CommonSession, EncryptedState, Exchange, GlobalRequestResponse, Kex, KexDhDone, KexInit,
NewKeys,
};
use crate::ssh_read::SshRead;
use crate::sshbuffer::{SSHBuffer, SshId};
use crate::{
auth, msg, negotiation, strict_kex_violation, ChannelId, ChannelOpenFailure, Disconnect,
Limits, Sig,
auth, msg, negotiation, strict_kex_violation, ChannelId, ChannelOpenFailure, CryptoVec,
Disconnect, Limits, Sig,
};

mod encrypted;
Expand Down Expand Up @@ -1265,7 +1264,7 @@ impl KexDhDone {
debug!("sig_type: {:?}", sig_type);
sig_reader.read_string().map_err(crate::Error::from)?
};
use russh_keys::key::Verify;
use crate::keys::key::Verify;
debug!("signature: {:?}", signature);
if !pubkey.verify_server_auth(hash.as_ref(), signature) {
debug!("wrong server sig");
Expand Down
5 changes: 2 additions & 3 deletions russh/src/client/session.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use log::error;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;
use tokio::sync::oneshot;

use crate::client::Session;
use crate::keys::encoding::Encoding;
use crate::session::EncryptedState;
use crate::{msg, ChannelId, Disconnect, Pty, Sig};
use crate::{msg, ChannelId, CryptoVec, Disconnect, Pty, Sig};

impl Session {
fn channel_open_generic<F>(
Expand Down
5 changes: 2 additions & 3 deletions russh/src/kex/curve25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use curve25519_dalek::constants::ED25519_BASEPOINT_TABLE;
use curve25519_dalek::montgomery::MontgomeryPoint;
use curve25519_dalek::scalar::Scalar;
use log::debug;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;

use super::{compute_keys, KexAlgorithm, KexType};
use crate::keys::encoding::Encoding;
use crate::mac::{self};
use crate::session::Exchange;
use crate::{cipher, msg};
use crate::{cipher, msg, CryptoVec};

pub struct Curve25519KexType {}

Expand Down
5 changes: 2 additions & 3 deletions russh/src/kex/dh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ use digest::Digest;
use groups::DH;
use log::debug;
use num_bigint::BigUint;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;
use sha1::Sha1;
use sha2::{Sha256, Sha512};

use self::groups::{DhGroup, DH_GROUP1, DH_GROUP14, DH_GROUP16};
use super::{compute_keys, KexAlgorithm, KexType};
use crate::keys::encoding::Encoding;
use crate::session::Exchange;
use crate::{cipher, mac, msg};
use crate::{cipher, mac, msg, CryptoVec};

pub struct DhGroup1Sha1KexType {}

Expand Down
5 changes: 2 additions & 3 deletions russh/src/kex/ecdh_nistp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use log::debug;
use p256::NistP256;
use p384::NistP384;
use p521::NistP521;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;
use sha2::{Digest, Sha256, Sha384, Sha512};

use crate::kex::{compute_keys, KexAlgorithm, KexType};
use crate::keys::encoding::Encoding;
use crate::mac::{self};
use crate::session::Exchange;
use crate::{cipher, msg};
use crate::{cipher, msg, CryptoVec};

pub struct EcdhNistP256KexType {}

Expand Down
5 changes: 2 additions & 3 deletions russh/src/kex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ use dh::{
use digest::Digest;
use ecdh_nistp::{EcdhNistP256KexType, EcdhNistP384KexType, EcdhNistP521KexType};
use once_cell::sync::Lazy;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::Encoding;

use crate::cipher;
use crate::cipher::CIPHERS;
use crate::keys::encoding::Encoding;
use crate::mac::{self, MACS};
use crate::session::Exchange;
use crate::{cipher, CryptoVec};

pub(crate) trait KexType {
fn make(&self) -> Box<dyn KexAlgorithm + Send>;
Expand Down
3 changes: 1 addition & 2 deletions russh/src/kex/none.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use russh_cryptovec::CryptoVec;

use super::{KexAlgorithm, KexType};
use crate::CryptoVec;

pub struct NoneKexType {}

Expand Down
8 changes: 4 additions & 4 deletions russh/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::*;
use russh_keys::key::*;
use russh_keys::{ec, protocol};
use crate::keys::encoding::*;
use crate::keys::key::*;
use crate::keys::{ec, protocol};
use crate::CryptoVec;

#[doc(hidden)]
pub trait PubKey {
Expand Down
3 changes: 3 additions & 0 deletions russh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pub mod kex;
/// MAC algorithm names
pub mod mac;

/// Re-export of the `russh-keys` crate.
pub use russh_keys as keys;

mod cert;
mod key;
mod msg;
Expand Down
11 changes: 5 additions & 6 deletions russh/src/negotiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ use std::str::from_utf8;

use log::debug;
use rand::RngCore;
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::{Encoding, Reader};
use russh_keys::key;
use russh_keys::key::{KeyPair, PublicKey};

use crate::cipher::CIPHERS;
use crate::kex::{EXTENSION_OPENSSH_STRICT_KEX_AS_CLIENT, EXTENSION_OPENSSH_STRICT_KEX_AS_SERVER};
use crate::keys::encoding::{Encoding, Reader};
use crate::keys::key;
use crate::keys::key::{KeyPair, PublicKey};
use crate::server::Config;
use crate::{cipher, compression, kex, mac, msg, Error};
use crate::{cipher, compression, kex, mac, msg, CryptoVec, Error};

#[derive(Debug, Clone)]
pub struct Names {
Expand Down Expand Up @@ -146,7 +145,7 @@ impl Named for () {
}
}

use russh_keys::key::ED25519;
use crate::keys::key::ED25519;

impl Named for PublicKey {
fn name(&self) -> &'static str {
Expand Down
6 changes: 2 additions & 4 deletions russh/src/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use russh_cryptovec::CryptoVec;
use russh_keys::encoding::{Encoding, Position};

use crate::msg;
use crate::keys::encoding::{Encoding, Position};
use crate::{msg, CryptoVec};

#[derive(Debug)]
pub struct OpenChannelMessage {
Expand Down
6 changes: 3 additions & 3 deletions russh/src/server/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use auth::*;
use byteorder::{BigEndian, ByteOrder};
use log::{debug, error, info, trace, warn};
use negotiation::Select;
use russh_keys::encoding::{Encoding, Position, Reader};
use russh_keys::key;
use russh_keys::key::Verify;
use tokio::time::Instant;
use {msg, negotiation};

use super::super::*;
use super::*;
use crate::keys::encoding::{Encoding, Position, Reader};
use crate::keys::key;
use crate::keys::key::Verify;
use crate::msg::SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
use crate::parsing::{ChannelOpenConfirmation, ChannelType, OpenChannelMessage};

Expand Down
Loading

0 comments on commit 9c2265e

Please sign in to comment.