diff --git a/Cargo.lock b/Cargo.lock index 1defd8b..3220e7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1607,7 +1607,46 @@ dependencies = [ ] [[package]] -name = "ssh-cert-dist" +name = "ssh-cert-dist-client" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "axum-extra", + "chrono", + "clap", + "rand 0.8.5", + "reqwest", + "serde", + "ssh-cert-dist-common", + "ssh-key", + "tempfile", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "url", +] + +[[package]] +name = "ssh-cert-dist-common" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "axum", + "axum-extra", + "serde", + "ssh-key", + "tempfile", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "ssh-cert-dist-server" version = "0.1.0" dependencies = [ "anyhow", @@ -1618,8 +1657,8 @@ dependencies = [ "clap", "jwt-compact", "rand 0.8.5", - "reqwest", "serde", + "ssh-cert-dist-common", "ssh-key", "tempfile", "thiserror", @@ -1628,13 +1667,13 @@ dependencies = [ "tower-http", "tracing", "tracing-subscriber", - "url", ] [[package]] name = "ssh-encoding" version = "0.1.0" -source = "git+https://github.com/a-dma/SSH.git?branch=u2f_signatures#ce0c34c935acd2caf7174d33039ec1c4557119de" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19cfdc32e0199062113edf41f344fbf784b8205a94600233c84eb838f45191e1" dependencies = [ "base64ct", "pem-rfc7468", @@ -1644,7 +1683,8 @@ dependencies = [ [[package]] name = "ssh-key" version = "0.5.1" -source = "git+https://github.com/a-dma/SSH.git?branch=u2f_signatures#ce0c34c935acd2caf7174d33039ec1c4557119de" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "288d8f5562af5a3be4bda308dd374b2c807b940ac370b5efa1c99311da91d9a1" dependencies = [ "ed25519-dalek", "num-bigint-dig", diff --git a/Cargo.toml b/Cargo.toml index 014bc21..67dca87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,43 +1,8 @@ -[package] -name = "ssh-cert-dist" -version = "0.1.0" -authors = ["shimun "] -edition = "2021" +[workspace] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -default = [ "client", "reload", "info", "authorized" ] -reload = [] -authorized =[ "dep:jwt-compact" ] -index = [] -info = [ "axum/json", "ssh-key/serde" ] -client = [ "dep:url", "dep:reqwest" ] - - -[dependencies] -anyhow = "1.0.66" -async-trait = "0.1.59" -axum = { version = "0.6.1", features = ["http2"] } -axum-extra = { version = "0.4.1", features = ["typed-routing"] } -chrono = "0.4.23" -clap = { version = "4.0.29", features = ["env", "derive"] } -jwt-compact = { version = "0.6.0", features = ["serde_cbor", "std", "clock"], optional = true } -rand = "0.8.5" -reqwest = { version = "0.11.13", optional = true } -serde = { version = "1.0.148", features = ["derive"] } -ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] } -thiserror = "1.0.37" -tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] } -tower = { version = "0.4.13", features = ["util"] } -tower-http = { version = "0.3.4", features = ["map-request-body", "trace"] } -tracing = { version = "0.1.37", features = ["release_max_level_debug"] } -tracing-subscriber = "0.3.16" -url = { version = "2.3.1", optional = true } - -[patch.crates-io] -ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" } - -[dev-dependencies] -tempfile = "3.3.0" +members = [ + "common", + "server", + "client", +] diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..52690d4 --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "ssh-cert-dist-client" +version = "0.1.0" +authors = ["shimun "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.66" +async-trait = "0.1.59" +axum-extra = { version = "0.4.1", features = ["typed-routing"] } +chrono = "0.4.23" +clap = { version = "4.0.29", features = ["env", "derive"] } +rand = "0.8.5" +reqwest = { version = "0.11.13", optional = true } +serde = { version = "1.0.148", features = ["derive"] } +ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] } +thiserror = "1.0.37" +tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] } +tracing = { version = "0.1.37", features = ["release_max_level_debug"] } +tracing-subscriber = "0.3.16" +url = { version = "2.3.1" } +ssh-cert-dist-common = { path = "../common" } + +[patch.crates-io] +ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" } + +[dev-dependencies] +tempfile = "3.3.0" + diff --git a/src/client.rs b/client/src/client.rs similarity index 97% rename from src/client.rs rename to client/src/client.rs index 26064ef..07a83f2 100644 --- a/src/client.rs +++ b/client/src/client.rs @@ -3,7 +3,7 @@ use axum_extra::routing::TypedPath; use clap::{Args, Parser, Subcommand}; use reqwest::{Client, StatusCode}; use ssh_key::Certificate; -use std::io::{stdin}; +use std::io::stdin; use std::path::PathBuf; use std::time::{Duration, SystemTime}; use tokio::fs; @@ -11,10 +11,7 @@ use tracing::{debug, error, info, instrument, trace}; use url::Url; -use crate::certs::load_cert; -use crate::certs::read_dir; -use crate::env_key; -use crate::routes::*; +use ssh_cert_dist_common::*; #[derive(Parser)] pub struct ClientArgs { @@ -46,7 +43,7 @@ pub struct UploadArgs { files: Vec, } -#[derive(Args)] +#[derive(Parser)] pub struct ClientCommand { #[clap(subcommand)] cmd: ClientCommands, diff --git a/client/src/main.rs b/client/src/main.rs new file mode 100644 index 0000000..e187af3 --- /dev/null +++ b/client/src/main.rs @@ -0,0 +1,10 @@ +use clap::Parser; + +mod client; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + + client::run(client::ClientCommand::parse()).await +} diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..8d3b228 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "ssh-cert-dist-common" +version = "0.1.0" +authors = ["shimun "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.66" +async-trait = "0.1.59" +axum = { version = "0.6.1" } +axum-extra = { version = "0.4.1", features = ["typed-routing"] } +serde = { version = "1.0.148", features = ["derive"] } +ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] } +thiserror = "1.0.37" +tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] } +tracing = { version = "0.1.37", features = ["release_max_level_debug"] } +tracing-subscriber = "0.3.16" + +[patch.crates-io] +ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" } + +[dev-dependencies] +tempfile = "3.3.0" + diff --git a/src/certs.rs b/common/src/certs.rs similarity index 100% rename from src/certs.rs rename to common/src/certs.rs diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..af4e7dc --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,6 @@ +mod certs; +mod routes; +mod util; + +pub use certs::*; +pub use routes::*; diff --git a/src/routes.rs b/common/src/routes.rs similarity index 95% rename from src/routes.rs rename to common/src/routes.rs index 3b4599e..294dadf 100644 --- a/src/routes.rs +++ b/common/src/routes.rs @@ -1,3 +1,4 @@ +use async_trait::async_trait; use axum_extra::routing::TypedPath; use serde::Deserialize; diff --git a/common/src/util.rs b/common/src/util.rs new file mode 100644 index 0000000..0a73400 --- /dev/null +++ b/common/src/util.rs @@ -0,0 +1,6 @@ +#[macro_export] +macro_rules! env_key { + ( $var:expr ) => { + concat!("SSH_CD_", $var) + }; +} diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 0000000..5414f9c --- /dev/null +++ b/server/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "ssh-cert-dist-server" +version = "0.1.0" +authors = ["shimun "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = [ "reload", "info", "authorized" ] +reload = [] +authorized =[ "dep:jwt-compact" ] +index = [] +info = [ "axum/json", "ssh-key/serde" ] + + +[dependencies] +anyhow = "1.0.66" +async-trait = "0.1.59" +axum = { version = "0.6.1", features = ["http2"] } +axum-extra = { version = "0.4.1", features = ["typed-routing"] } +chrono = "0.4.23" +clap = { version = "4.0.29", features = ["env", "derive"] } +jwt-compact = { version = "0.6.0", features = ["serde_cbor", "std", "clock"], optional = true } +rand = "0.8.5" +serde = { version = "1.0.148", features = ["derive"] } +ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] } +thiserror = "1.0.37" +tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] } +tower = { version = "0.4.13", features = ["util"] } +tower-http = { version = "0.3.4", features = ["map-request-body", "trace"] } +tracing = { version = "0.1.37", features = ["release_max_level_debug"] } +tracing-subscriber = "0.3.16" +ssh-cert-dist-common = { path = "../common" } + +[patch.crates-io] +ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" } + +[dev-dependencies] +tempfile = "3.3.0" + diff --git a/src/api.rs b/server/src/api.rs similarity index 99% rename from src/api.rs rename to server/src/api.rs index e146c2a..6ab1269 100644 --- a/src/api.rs +++ b/server/src/api.rs @@ -6,12 +6,10 @@ use std::path::{self, PathBuf}; use std::sync::Arc; use std::time::{Duration, SystemTime}; -use crate::certs::{load_cert_by_id, read_certs, read_pubkey, store_cert}; -use crate::env_key; -use crate::routes::*; use anyhow::Context; use axum::body; use axum::extract::{Query, State}; +use ssh_cert_dist_common::*; use axum::{http::StatusCode, response::IntoResponse, Json, Router}; use axum_extra::routing::RouterExt; diff --git a/src/api/extract.rs b/server/src/api/extract.rs similarity index 94% rename from src/api/extract.rs rename to server/src/api/extract.rs index 4db8d7a..37a4eee 100644 --- a/src/api/extract.rs +++ b/server/src/api/extract.rs @@ -1,8 +1,6 @@ use super::ApiError; use anyhow::Context; -use axum::{ - async_trait, body::BoxBody, extract::FromRequest, http::Request, -}; +use axum::{async_trait, body::BoxBody, extract::FromRequest, http::Request}; use ssh_key::{Certificate, SshSig}; use tracing::trace; diff --git a/server/src/main.rs b/server/src/main.rs new file mode 100644 index 0000000..dbaeb77 --- /dev/null +++ b/server/src/main.rs @@ -0,0 +1,10 @@ +use clap::Parser; + +mod api; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + + api::run(api::ApiArgs::parse()).await +} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index f54af37..0000000 --- a/src/main.rs +++ /dev/null @@ -1,36 +0,0 @@ -use api::ApiArgs; -use clap::Parser; -#[cfg(feature = "client")] -use client::ClientCommand; - -mod api; -mod certs; -#[cfg(feature = "client")] -mod client; -mod routes; - -#[macro_export] -macro_rules! env_key { - ( $var:expr ) => { - concat!("SSH_CD_", $var) - }; -} - -#[derive(Parser)] -enum Command { - Server(ApiArgs), - #[cfg(feature = "client")] - Client(ClientCommand), -} - -#[tokio::main(flavor = "current_thread")] -async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt::init(); - - match Command::parse() { - Command::Server(args) => api::run(args).await?, - #[cfg(feature = "client")] - Command::Client(args) => client::run(args).await?, - } - Ok(()) -}