Skip to content

Commit 160fb0b

Browse files
authored
Merge pull request #76 from wiktor-k/wiktor/better-readmes
Add client example to README.md
2 parents 082fa3b + 3ae4dc2 commit 160fb0b

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

.github/workflows/misc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# If the example doesn't compile the integration test will
3333
# be stuck. Check for compilation issues earlier to abort the job
3434
- name: Check if the example compiles
35-
run: cargo check --example key_storage
35+
run: cargo check --example key-storage
3636
- name: Run integration tests
3737
run: ./tests/sign-and-verify.sh
3838
if: ${{ ! matrix.windows }}

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ default = ["agent"]
3939
codec = ["tokio-util"]
4040
agent = ["futures", "log", "tokio", "async-trait", "codec"]
4141

42-
[[example]]
43-
name = "key_storage"
44-
required-features = ["agent"]
45-
4642
[dev-dependencies]
4743
env_logger = "0.11.0"
4844
rand = "0.8.5"

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
[![CI](https://github.com/wiktor-k/ssh-agent-lib/actions/workflows/rust.yml/badge.svg)](https://github.com/wiktor-k/ssh-agent-lib/actions/workflows/rust.yml)
44
[![Crates.io](https://img.shields.io/crates/v/ssh-agent-lib)](https://crates.io/crates/ssh-agent-lib)
55

6-
A collection of types for writing custom SSH agents as specified by the [SSH Agent Protocol Internet Draft](https://datatracker.ietf.org/doc/html/draft-miller-ssh-agent).
6+
A collection of types for writing custom SSH agents and connecting to existing ones.
77

8-
This makes it possible to utilize remote keys not supported by the default OpenSSH agent.
8+
The types in this crate closely follow the [SSH Agent Protocol Internet Draft](https://datatracker.ietf.org/doc/html/draft-miller-ssh-agent) specification and can be used to utilize remote keys not supported by the default OpenSSH agent.
99

10-
## Example
10+
## Examples
11+
12+
The following examples show a sample agent and a sample client.
13+
For more elaborate example see the `examples` directory or [crates using `ssh-agent-lib`](https://crates.io/crates/ssh-agent-lib/reverse_dependencies).
14+
15+
### Agent
1116

1217
The following example starts listening on a socket and processing requests.
1318
On Unix it uses `ssh-agent.sock` Unix domain socket while on Windows it uses a named pipe `\\.\pipe\agent`.
@@ -67,7 +72,32 @@ On Windows the path of the pipe has to be used:
6772
SSH_AUTH_SOCK=\\.\pipe\agent ssh [email protected]
6873
```
6974

70-
For more elaborate example see the `examples` directory or [crates using `ssh-agent-lib`](https://crates.io/crates/ssh-agent-lib/reverse_dependencies).
75+
### Client
76+
77+
The following example connects to the agent pointed to by the `SSH_AUTH_SOCK` environment variable and prints identities (public keys) that the agent knows of:
78+
79+
```rust,no_run
80+
use service_binding::Binding;
81+
use ssh_agent_lib::client::connect;
82+
83+
#[tokio::main]
84+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
85+
#[cfg(unix)]
86+
let mut client =
87+
connect(Binding::FilePath(std::env::var("SSH_AUTH_SOCK")?.into()).try_into()?)?;
88+
89+
#[cfg(windows)]
90+
let mut client =
91+
connect(Binding::NamedPipe(std::env::var("SSH_AUTH_SOCK")?.into()).try_into()?)?;
92+
93+
eprintln!(
94+
"Identities that this agent knows of: {:#?}",
95+
client.request_identities().await?
96+
);
97+
98+
Ok(())
99+
}
100+
```
71101

72102
## License
73103

examples/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Agent examples
2+
3+
The examples in this directory show slightly more elaborate use-cases that can be implemented using this crate.
4+
5+
## Agents
6+
7+
### `key-storage`
8+
9+
Implements a simple agent which remembers RSA private keys (added via `ssh-add`) and allows fetching their public keys and signing using three different signing mechanisms.
10+
11+
This example additionally shows how to extract extensions from messages and works on all major OSes.
12+
13+
It is used in integration tests that run as part of the CI.
14+
15+
### `openpgp-card-agent`
16+
17+
Allows using OpenPGP Card devices to sign SSH requests.
18+
The PIN is stored in memory and can be time-constrained using SSH constraints.
19+
For the sake of simplicity this agent supports only `ed25519` subkeys.
20+
21+
This example additionally shows how to create custom protocol based on SSH extensions (in this case decrypt/derive feature).
22+
23+
### `agent-socket-info`
24+
25+
Shows how to extract information about the underlying connection.
26+
For example under Unix systems this displays connecting process PID.
27+
To keep the example brief the data is printed as part of a fake public key comment.
28+
29+
## Clients
30+
31+
### `pgp-wrapper`
32+
33+
Wraps SSH keys in OpenPGP data thus allowing OpenPGP applications (such as GnuPG) to read and work with SSH keys.
34+
This makes it possible to create OpenPGP signatures utilizing SSH keys.
35+
36+
If the connecting agent supports derive/decrypt extension this example additionally creates a decryption subkey and can be used to decrypt OpenPGP data.
37+
38+
### `proto-dumper`
39+
40+
A simple forwarding example which works as an agent and client at the same time dumping all messages and forwarding them to the next agent.
41+
42+
### `ssh-agent-client`
43+
44+
Dumps identities stored by the agent.
45+
Additionally invokes an extension and reads the result.
File renamed without changes.

tests/sign-and-verify-win.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rem del /F /Q Cargo.toml.sig id_rsa id_rsa.pub agent.pub
22

3-
cmd /c "START /b cargo run --example key_storage"
3+
cmd /c "START /b cargo run --example key-storage"
44

55
@echo off
66
:waitloop

tests/sign-and-verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euxo pipefail
44

55
rm -rf ssh-agent.sock Cargo.toml.sig id_rsa id_rsa.pub agent.pub ca_user_key ca_user_key.pub id_rsa-cert.pub
6-
RUST_LOG=info cargo run --example key_storage &
6+
RUST_LOG=info cargo run --example key-storage &
77

88
while [ ! -e ssh-agent.sock ]; do
99
echo "Waiting for ssh-agent.sock"

0 commit comments

Comments
 (0)