Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 137 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,78 @@

## Introduction

This project establishes the necessary infrastructure for auditing
cryptographic operations executed by system crypto libraries. This is
achieved by deploying BPF USDT probes. These probes intercept specific
entry points within the crypto libraries, capturing data as they are
utilized by user-space processes across the system, thereby enabling
subsequent analysis.

The primary use-case of this project is to facilitate the migration of
organizations to post-quantum cryptography. Since post-quantum
algorithms are relatively new and not all applications are immediately
compatible, a mandatory switch from classical cryptography is
impractical. To enable a smoother transition, crypto-auditing can be
employed at run time to identify any instances where classical
cryptography is still in use.

The crypto-auditing design prioritizes privacy, system efficiency, and
ease of maintainability, ensuring that user activity remains
confidential, performance is minimally impacted, and collection rules
are easily managed.

More detailed design documents are available from the following links:
This project provides the infrastructure needed to audit
cryptographic operations performed by system crypto libraries. It
does so with BPF USDT probes placed at specific entry points in those
libraries, which capture data as the libraries are used by user-space
processes across the system, for later analysis.

The primary use case of this project is to help organizations migrate
to post-quantum cryptography. Since post-quantum algorithms are
relatively new and not every application supports them yet, a forced
switch away from classical cryptography is impractical. To make the
transition smoother, crypto-auditing can be used at run time to
identify where classical cryptography is still in use.

The design of crypto-auditing prioritizes privacy, efficiency, and
maintainability: user activity remains confidential, the impact on
performance is minimal, and collection rules are easy to manage.

More detailed design documents are available at the following links:

- [Objectives and high-level design](docs/objectives.md)
- [Architecture](docs/architecture.md)
- [Logging format for primary event logs](docs/logging-format.md)
- [Event keys registry](docs/registry.md)
- [Event schema](docs/schema.md)
- [USDT probe points](docs/probe-points.md)
- [Measuring performance impact](docs/performance.md)

## Installation

1. Install the latest Rust toolchain
2. Install the dependencies (note that libbpf 1.1.1 or later is required)
2. Install the dependencies (libbpf 1.1.1 or later is required)
```console
$ sudo dnf install bpftool make libbpf-devel llvm-devel rustfmt
```
3. Build the programs with `make`
3. Build the programs
```console
$ make
```
4. Install the programs with `make install`
4. Install the programs
```console
$ sudo make install
```

## Running

1. Create dedicated user and group (e.g., crypto-auditing:crypto-auditing)
1. Create a dedicated user and group (e.g., crypto-auditing:crypto-auditing)
```console
$ sudo groupadd crypto-auditing
$ sudo useradd -g crypto-auditing
$ sudo useradd -g crypto-auditing crypto-auditing
```
2. Modify systemd configuration for agent in `/lib/systemd/system/crau-agent.service`:
2. Set the user and group in the agent's systemd unit, `/lib/systemd/system/crau-agent.service`:
```ini
User=crypto-auditing
Group=crypto-auditing
```
3. Modify agent configuration in `/etc/crypto-auditing/agent.conf`:
3. Configure the agent in `/etc/crypto-auditing/agent.conf`:
```toml
library = ["/path/to/installation/lib64/libgnutls.so.30"]
user = "crypto-auditing:crypto-auditing"
```
4. Enable agent
4. Start the agent
```console
$ sudo systemctl daemon-reload
$ sudo systemctl start crau-agent.service
```
5. Run monitor
5. Run the monitor
```console
$ crau-monitor
```
6. On another terminal, run any commands using the instrumented library, such as GnuTLS in Fedora Linux 43 or later
6. In another terminal, run any program that uses an instrumented
library, such as GnuTLS in Fedora Linux 43 or later (the
credentials below are from the GnuTLS source tree)
```console
$ gnutls-serv --x509certfile=doc/credentials/x509/cert-rsa-pss.pem --x509keyfile=doc/credentials/x509/key-rsa-pss.pem &
$ gnutls-cli --x509cafile=doc/credentials/x509/ca.pem localhost -p 5556
Expand All @@ -84,25 +85,43 @@ $ gnutls-cli --x509cafile=doc/credentials/x509/ca.pem localhost -p 5556 --priori

## Inspecting logs

In the above example, client stores events in a log file on the system, which can be parsed and printed with the `crau-query` executable:
In the above example, the agent writes the events to a log file on
the system (`/var/log/crypto-auditing/audit.cborseq` by default),
which can be parsed and printed with `crau-query`:

```console
$ crau-query
[
{
"context": "33acb8e6ccc65bb285bd2f84cac3bf80",
"start": 49431626623324,
"end": 49431626623324,
"context": "88b7dd7bb10fc0cb92fba1b1d29845b5",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699631.408859,
"end": 1795699631.410625,
"events": {
"name": "tls::handshake_client",
"name": "tls::handshake",
"tls::ciphersuite": 4866,
"tls::protocol_version": 772
"tls::protocol_version": 772,
"tls::role": "client"
},
"spans": [
{
"context": "cdbaebffb957deffec8664b52ab8290d",
"start": 49431631956782,
"end": 49431631963209,
"context": "8ffbea6903587c06f75ec75616e949fe",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699631.409042,
"end": 1795699631.409454,
"events": {
"name": "tls::key_exchange",
"tls::group": 4588
}
},
{
"context": "683ae04c31deba23437c6f22ca5a4a5d",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699631.410405,
"end": 1795699631.410411,
"events": {
"name": "tls::verify",
"tls::signature_algorithm": 2057
Expand All @@ -111,40 +130,72 @@ $ crau-query
]
},
{
"context": "c8e0a865bab48563e70780234c3de1c0",
"start": 49431626833778,
"end": 49431627033707,
"context": "0d185bb96a48985821682ea9e6d5bf99",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699631.41073,
"end": 1795699631.412496,
"events": {
"name": "tls::handshake_server",
"name": "tls::handshake",
"tls::ciphersuite": 4866,
"tls::protocol_version": 772
"tls::protocol_version": 772,
"tls::role": "server"
},
"spans": [
{
"context": "3c062a160cc8bc8113d05eff4ffc5da5",
"start": 49431628203429,
"end": 49431628207396,
"context": "5a6da95cde5576570659f87e46d02495",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699631.410913,
"end": 1795699631.411325,
"events": {
"name": "tls::verify",
"name": "tls::key_exchange",
"tls::group": 4588
}
},
{
"context": "bd41d878bfa7a9112af639fbd56dc8de",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699631.412276,
"end": 1795699631.412282,
"events": {
"name": "tls::sign",
"tls::signature_algorithm": 2057
}
}
]
},
{
"context": "953c66fdd64be71bf99ccc4b91298c95",
"start": 49434502888728,
"end": 49434502888728,
"context": "a1eb974b9a488489f9c735085092b38a",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699634.288516,
"end": 1795699634.290282,
"events": {
"name": "tls::handshake_client",
"name": "tls::handshake",
"tls::ciphersuite": 49200,
"tls::protocol_version": 771
"tls::protocol_version": 771,
"tls::role": "client"
},
"spans": [
{
"context": "d5ba85329440a679aece93ef63322753",
"start": 49434509684783,
"end": 49434509694813,
"context": "0ae36c5a2d6b48e6e23579999f9b6058",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699634.288699,
"end": 1795699634.289111,
"events": {
"name": "tls::key_exchange",
"tls::group": 29
}
},
{
"context": "b2a86f9a405af0121673ebf9198344df",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-cli",
"start": 1795699634.290062,
"end": 1795699634.290068,
"events": {
"name": "tls::verify",
"tls::signature_algorithm": 2057
Expand All @@ -153,21 +204,37 @@ $ crau-query
]
},
{
"context": "c8e0a865bab48563e70780234c3de1c0",
"start": 49434503007039,
"end": 49434503047270,
"context": "31720ee831cbddff777b5834b3218053",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699634.2904,
"end": 1795699634.292166,
"events": {
"name": "tls::handshake_server",
"name": "tls::handshake",
"tls::ciphersuite": 49200,
"tls::protocol_version": 771
"tls::protocol_version": 771,
"tls::role": "server"
},
"spans": [
{
"context": "983d47ffeaf4b50691c80f2431c6b539",
"start": 49434503929186,
"end": 49434503940540,
"context": "2e447e8567b59af193a5171aacb14ab9",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699634.290583,
"end": 1795699634.290995,
"events": {
"name": "tls::verify",
"name": "tls::key_exchange",
"tls::group": 29
}
},
{
"context": "dd44b7c754d9648e5a095679bd6539a6",
"origin": "5e2f1c8a9b7d4e3f60a1b2c3d4e5f60718293a4b",
"executable": "gnutls-serv",
"start": 1795699634.291946,
"end": 1795699634.291952,
"events": {
"name": "tls::sign",
"tls::signature_algorithm": 2057
}
}
Expand All @@ -176,15 +243,15 @@ $ crau-query
]
```

From this output, a flamegraph can be produced with the
From this output, a flamegraph can be generated with
`scripts/flamegraph.py`:

```console
$ crau-query | python scripts/flamegraph.py -
dumping data to flamegraph.html
```

You can open the generated `flamegraph.html` with your browser.
You can then open the generated `flamegraph.html` in your browser.

## License

Expand All @@ -195,5 +262,5 @@ You can open the generated `flamegraph.html` with your browser.

## Credits

- [libbpf-async](https://github.com/fujita/libbpf-async) for asynchronous BPF ringbuf implementation over libbpf-rs
- [rust-keylime](https://github.com/keylime/rust-keylime/) for permissions management code
- [libbpf-async](https://github.com/fujita/libbpf-async) for the asynchronous BPF ring buffer implementation on top of libbpf-rs
- [rust-keylime](https://github.com/keylime/rust-keylime/) for the permission management code
70 changes: 70 additions & 0 deletions agent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
0.4.0
-----
- Added `--ringbuf-size` option and `ringbuf_size` configuration to
specify the size of the BPF ring buffer
- Bumped default BPF ring buffer size from 4 KB to 256 KB
- Added support for `release_context` probe
- Prohibited all-zero library context, so events with a `NULL` context
are ignored
- Stopped obfuscating context IDs
- Switched to `bpf_copy_from_user*` from `bpf_probe_read_user*`, so
memory in unmapped pages can be read
- Switched to `figment` for merging options from command-line and
configuration file
- Switched to `AsyncFd::register_with_interest` to address
RUSTSEC-2026-0386, and updated `tokio` dependency to `1.53.3`
- Updated `sysinfo` dependency to `0.39`


0.3.2
-----
- Moved test fixtures into the crate
- Added `repository` and `homepage` to the package manifest


0.3.1
-----
- Added executable filename of the application to the logs
- Added system boot time to the primary log as metadata
- Dropped Linux capabilities other than `CAP_BPF` and `CAP_PERFMON`
after startup
- Worked around `bpf_stream_vprintk` compatibility issue with libbpf
1.6
- Removed unused direct dependency on `nix`


0.3.0
-----
- Renamed the executable from `crypto-auditing-agent` to `crau-agent`,
as well as the systemd unit
- Renamed `ContextID` to `ContextId`
- Suppressed compilation warning


0.2.4
-----
- Switched to using synchronous version of BPF ring buffer
- Spawned event sender in a worker thread
- Used unbounded channel for communicating with internal threads
- Updated edition to Rust 2024


0.2.3
-----
- Updated `libbpf-rs` and `libbpf-cargo` dependencies to `0.24`


0.2.2
-----
- Added support for composite events


0.2.1
-----
- Added `README.md`
- Clarified copyright and licensing


0.2.0
-----
- Initial release
Loading