diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..e55647b --- /dev/null +++ b/.codespellrc @@ -0,0 +1,3 @@ +[codespell] +skip = .cargo,.git,target +ignore-words-list = crate,ser diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e7c53c..1db68de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,26 +1,30 @@ name: CI -on: [push, pull_request] +on: + pull_request: + push: + tags: + - 'v*' + branches: [ main ] + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true jobs: - # Use the following command to fix words locally: - # codespell --ignore-words-list "ser,crate,daa,keypair" --skip "*/target,*-sys" --write-changes check-spelling: name: Check spelling runs-on: ubuntu-latest steps: - name: Check spelling uses: codespell-project/actions-codespell@master - with: - ignore_words_list: "ser,crate,daa,keypair" - path: tss-esapi - skip: "*/target,*-sys" formatting: name: Check formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Check formatting run: cargo fmt --all -- --check @@ -28,7 +32,7 @@ jobs: name: Unit tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build and test run: cargo build --verbose --all && cargo test --verbose --all @@ -36,6 +40,6 @@ jobs: name: Clippy lints runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Check for lints run: cargo clippy -- -D warnings diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.yml new file mode 100644 index 0000000..cddcee1 --- /dev/null +++ b/.github/workflows/dco.yml @@ -0,0 +1,10 @@ +name: DCO + +on: pull_request + +jobs: + check: + name: Developer Certificate of Origin + runs-on: ubuntu-latest + steps: + - uses: tisonkun/actions-dco@v1.1 diff --git a/Cargo.lock b/Cargo.lock index 7f55430..c54b994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -278,6 +278,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "hermit-abi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" + [[package]] name = "humantime" version = "2.1.0" @@ -322,6 +328,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.32.2" @@ -521,6 +537,7 @@ dependencies = [ "backtrace", "libc", "mio", + "num_cpus", "pin-project-lite", "socket2", "tokio-macros", diff --git a/Cargo.toml b/Cargo.toml index e8c4d68..75fd5cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,4 @@ required-features = ["agent"] [dev-dependencies] env_logger = "0.11.0" openssl = "0.10.16" -tokio = { version = "1", features = ["macros"] } +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/README.md b/README.md index 10d1453..451707c 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ # ssh-agent-lib +[![CI](https://github.com/wiktor-k/ssh-agent-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/wiktor-k/ssh-agent-lib/actions/workflows/ci.yml) +[![Crates.io](https://img.shields.io/crates/v/ssh-agent-lib)](https://crates.io/crates/ssh-agent-lib) + A collection of types for writing custom SSH agents. -This makes it possible to utilize remote keys not supported by the -default OpenSSH agent. +This makes it possible to utilize remote keys not supported by the default OpenSSH agent. ## Example -This example starts listening on a Unix socket `connect.sock` and -processes requests. +This example starts listening on a Unix socket `ssh-agent.sock` and processes requests. ```rust,no_run -use async_trait::async_trait; use tokio::net::UnixListener; use ssh_agent_lib::agent::{Session, Agent}; use ssh_agent_lib::error::AgentError; -use ssh_agent_lib::proto::message::{Message, SignRequest}; +use ssh_agent_lib::proto::message::Message; #[derive(Default)] struct MyAgent; -#[async_trait] +#[ssh_agent_lib::async_trait] impl Session for MyAgent { async fn handle(&mut self, message: Message) -> Result { match message { @@ -35,22 +35,34 @@ impl Session for MyAgent { } } -#[tokio::main(flavor = "current_thread")] -async fn main() -> Result<(), Box> { - let agent = MyAgent; - let socket = "connect.sock"; - let _ = std::fs::remove_file(socket); - let socket = UnixListener::bind(socket)?; +#[tokio::main] +async fn main() -> Result<(), Box> { + let socket = "ssh-agent.sock"; + let _ = std::fs::remove_file(socket); // remove the socket if exists - agent.listen(socket).await?; + MyAgent.listen(UnixListener::bind(socket)?).await?; Ok(()) } ``` -For more elaborate example see `examples` directory. +Now, point your OpenSSH client to this socket using `SSH_AUTH_SOCK` environment variable and it will transparently use the agent: + +```sh +SSH_AUTH_SOCK=ssh-agent.sock ssh user@example.com +``` + +For more elaborate example see the `examples` directory or [crates using `ssh-agent-lib`](https://crates.io/crates/ssh-agent-lib/reverse_dependencies). ## Note This library has been forked from [sekey/ssh-agent.rs](https://github.com/sekey/ssh-agent.rs) as the upstream seems not be maintained (at least as of 2022). + +# License + +This project is licensed under the [MIT license](https://opensource.org/licenses/MIT). + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you shall be licensed as above, without any additional terms or conditions. diff --git a/src/lib.rs b/src/lib.rs index 5774b0c..c9b22bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,3 +9,6 @@ pub mod error; #[cfg(feature = "agent")] pub use self::agent::Agent; + +#[cfg(feature = "agent")] +pub use async_trait::async_trait;