Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chayleaf/mitm-cache

MITM caching proxy
https://github.com/chayleaf/mitm-cache

Last synced: 5 days ago
JSON representation

MITM caching proxy

Awesome Lists containing this project

README

        

# MITM cache

This is a caching MITM proxy for fetching the dependencies of poorly
designed build systems. To use it, first create a root CA cert using
`./generate.sh`, and then run the proxy:

```
Usage: mitm-cache [OPTIONS]

Commands:
record
replay
help Print this message or the help of the given subcommand(s)

Options:
-l, --listen Proxy listen address
-k, --ca-key Path to the ca.key file
-c, --ca-cert Path to the ca.cer file
-o, --out Write MITM cache description to this file
-h, --help Print help
```

```
Usage: mitm-cache record [OPTIONS]

Options:
-r, --record-text
Record text from URLs matching this regex
-x, --reject
Reject requests to URLs matching this regex
-f, --forget-redirects-from
Forget redirects from URLs matching this regex
-t, --forget-redirects-to
Forget redirects to URLs matching this regex
-h, --help
Print help
```

While the cache is running, you can send `SIGUSR1` to write the current
cache into `tmp.json`. At the end, you should send `SIGINT` to make the
proxy write the final cache into `out.json`, and then
use [fetch.nix](./fetch.nix) for fetching the dependencies
([default.nix](./default.nix) provides it at `mitm-cache.fetch`), and
finally pass the resulting derivation output to `mitm-cache replay`:

```
Usage: mitm-cache replay

Arguments:
Path to the cache fetched using fetch.nix

Options:
-h, --help Print help
```

## Lockfile Format

```json
{
"!version": 1,
"https://example.org/a": {
"hash": "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
},
"https://example.org/b": {
"text": "example"
},
"https://example.org/c": {
"redirect": "https://example.org/d"
}
}
```

`!version` specifies the lockfile version. `fetch.nix` is maintained to support
all lockfile versions, but mitm-cache only supports creating the
latest lockfile version.

Per-URL value is a JSON object containing one of the following keys:

- `hash` - specifies the response body's [SRI hash](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#using_subresource_integrity)
- `text` - specifies the response body as text. Only written if the
`--record-text` regex matches this URL.
- `redirect` - specifies the URL this page redirects to. If
any of the `--forget-redirects-*` rules apply, the target page's
value will be written as the page's value instead.