Skip to content

Commit

Permalink
Merge pull request #18 from wiktor-k/wiktor/more-cleanup
Browse files Browse the repository at this point in the history
Clean up a bit the project
  • Loading branch information
wiktor-k authored Feb 27, 2024
2 parents 2f84bdf + cb82e17 commit 175d054
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
skip = .cargo,.git,target
ignore-words-list = crate,ser
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
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

tests:
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

lints:
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
10 changes: 10 additions & 0 deletions .github/workflows/dco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: DCO

on: pull_request

jobs:
check:
name: Developer Certificate of Origin
runs-on: ubuntu-latest
steps:
- uses: tisonkun/[email protected]
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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<Message, AgentError> {
match message {
Expand All @@ -35,22 +35,34 @@ impl Session for MyAgent {
}
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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<dyn std::error::Error>> {
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 [email protected]
```

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.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pub mod error;

#[cfg(feature = "agent")]
pub use self::agent::Agent;

#[cfg(feature = "agent")]
pub use async_trait::async_trait;

0 comments on commit 175d054

Please sign in to comment.