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
101 changes: 57 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,97 @@
A command-line tool for managing Credential Engine platform resources.

## Requirements

- Python 3.11 or later
- `pip`
## Installation

> **Recommended:** install inside a virtual environment. This avoids file-permission errors, PATH conflicts, and "invalid distribution" warnings from previous installs.

### Option 1: Install from source with a virtual environment (recommended)

**macOS / Linux:**

```bash
git clone https://github.com/CredentialEngine/ce-cli.git
cd ce-cli

python3 -m venv .venv
source .venv/bin/activate

pip install -e .
```

**Windows (PowerShell):**

```powershell
git clone https://github.com/CredentialEngine/ce-cli.git
cd ce-cli

python -m venv .venv
.venv\Scripts\activate

pip install -e .
```

When the venv is active you'll see `(.venv)` in your prompt, and `ce` is automatically on `PATH`. To leave the venv, run `deactivate`. To re-enter it next time, run the activate command above from the project folder.

### Option 2: Install from a release

1. Download the `.whl` from the [Releases page](https://github.com/CredentialEngine/ce-cli/releases).
2. Install it (inside a venv is still recommended):
```bash
pip install ce_cli-<version>-py3-none-any.whl
```

### Upgrading

From a release `.whl`:

```bash
pip install --upgrade ce_cli-<version>-py3-none-any.whl
```

From source: `git pull` and re-run `pip install -e .` inside your venv.

### Option 3: Install from source without a venv

```bash
git clone https://github.com/CredentialEngine/ce-cli.git
cd ce-cli
pip install -e .
```

This puts the `ce` command on your `$PATH`. On Windows, see the [Windows PATH note](#windows-path-note) below if `ce` isn't found.

### Verify the installation

```bash
ce --help
```

You should see the top-level command list.

### Windows PATH note

When you install on Windows without a venv, pip often drops ce.exe into your user Scripts folder, which Windows doesn't put on PATH by default:

```
C:\Users\<you>\AppData\Roaming\Python\Python310\Scripts
```

If `ce --help` fails after install, either use a venv (recommended) or add that folder to your User PATH:

```powershell
[Environment]::SetEnvironmentVariable(
"Path",
$env:Path + ";C:\Users\$env:USERNAME\AppData\Roaming\Python\Python310\Scripts",
"User"
)
```

Then **close and reopen PowerShell** existing windows won't pick up the new PATH.



## Quick start
Expand Down Expand Up @@ -153,21 +153,30 @@ IIR commands are grouped by the noun they operate on:

#### Sign a single challenge (`ce iir challenge sign`)

Signs a CE-generated challenge JSON file with an Ed25519 private key (alg `EdDSA`) and verifies the resulting JWT against the public key resolved from the DID in the payload. No login required — offline for `did:key`, single HTTPS fetch for `did:web`.
Signs a CE-generated challenge JSON file and verifies the resulting JWT against the public key resolved from the DID in the payload. `--algorithm` picks the key type. No login required: offline for `did:key`, a single HTTPS fetch for `did:web`.

```bash
ce iir challenge sign \
--private-key z3u2en... \
--challenge-file challenge.json \
--output signed-challenge.jwt
| `--algorithm` | JWT `alg` | Key in the DID | DIDs |
| ------------- | --------- | ---------------------------------------- | -------------------------- |
| `Ed25519` | `EdDSA` | `Multikey` (`publicKeyMultibase`, `z...`) | `did:key`, `did:web` |
| `RS256` | `RS256` | `JsonWebKey2020` (`publicKeyJwk`, `kty: RSA`) | `did:web` only for now |

```powershell
ce iir challenge sign --algorithm Ed25519 --private-key z3u2en... --challenge-file challenge.json --output signed-challenge.jwt

ce iir challenge sign --algorithm RS256 --private-key rsa-private-key.pem --challenge-file challenge.json --output signed-challenge.jwt
```

| Flag | Required | Description |
| ------------------ | -------- | -------------------------------------------------------------------- |
| `--private-key` | Yes | Ed25519 private seed, multibase base58btc (starts with `z`) |
| `--algorithm` | Yes | `Ed25519` or `RS256` (exact spelling) |
| `--private-key` | Yes | Ed25519: private seed, multibase base58btc (starts with `z`). RS256: path to an unencrypted PEM key file (`BEGIN PRIVATE KEY` or `BEGIN RSA PRIVATE KEY`), the PEM text, or the bare base64 key |
| `--challenge-file` | Yes | Path to the challenge JSON produced by CE |
| `--output`, `-o` | No | Write the JWT to this file. If omitted, the JWT is printed to stdout |

RSA keys must be at least 2048 bits. For RS256 the DID document must list the key under `authentication`. RSA `did:key`
is not supported yet: use a `did:web` with a `JsonWebKey2020` key. Giving an RSA key with `--algorithm Ed25519`, or an
Ed25519 seed with `--algorithm RS256`, fails with a hint to use the other algorithm.

The challenge JSON must include `did`, `challenge`, `aud`, `iat`, and `exp`. The `did` field is used as the JWT header `kid` and to resolve the public key for verification (`did:key` resolves offline; `did:web` is fetched over HTTPS using the OS trust store).

Example challenge file:
Expand Down Expand Up @@ -199,15 +208,15 @@ Register DIDs for multiple organizations in one go. The process has two phases.
ce iir challenge bulk-sign --csv input.csv --output output.csv
```

Validates each row (membership, registry lookup, DID resolution), creates challenges, signs JWTs with the provided private keys, and writes the results to an output CSV. If `--output` is omitted, defaults to `Output-<stem>-<UTC>.csv`. Failed rows are written to `Errors-<stem>-<UTC>.csv` (override with `--errors`).
Validates each row (algorithm, membership, registry lookup, DID resolution), creates challenges, signs JWTs with the provided private keys using each row's `Algorithm`, verifies them against the DID, and writes the results to an output CSV. If `--output` is omitted, defaults to `Output-<stem>-<UTC>.csv`. Failed rows are written to `Errors-<stem>-<UTC>.csv` (override with `--errors`).

**Phase 2 — Publish to the IIR registry (`ce iir issuer-did publish`):**

```bash
ce iir issuer-did publish --input output.csv
```

Verifies the JWT signatures and publishes each issuer to the IIR. Pass `--yes`/`-y` to skip the confirmation prompt. Failed publishes are written to `PublishErrors-<stem>-<UTC>.csv` (override with `--publish-errors`).
Verifies the JWT signatures and publishes each issuer to the IIR. Ed25519 and RS256 rows are handled the same way: the API reads the algorithm from the JWT. Pass `--yes`/`-y` to skip the confirmation prompt. Failed publishes are written to `PublishErrors-<stem>-<UTC>.csv` (override with `--publish-errors`).

#### Input CSV format

Expand All @@ -216,8 +225,8 @@ Verifies the JWT signatures and publishes each issuer to the IIR. Pass `--yes`/`
| `CTID` | Yes | The organization's CTID (must be published in the registry) |
| `DID` | Yes | `did:key:...` or `did:web:...` |
| `VerificationMethod` | Yes | Full verification method ID (e.g., `did:key:z6Mk...#z6Mk...`) |
| `Algorithm` | For did:key | `Ed25519`, `secp256k1`, `P-256`, or `X25519` |
| `PrivateKey` | Yes | Multibase-encoded private key for signing |
| `Algorithm` | Yes | `Ed25519` or `RS256`, on every row (did:web included) |
| `PrivateKey` | Yes | Ed25519: multibase seed (`z...`). RS256: PEM key file path, PEM text with literal `\n` line breaks, or bare base64 |
| `ValidFrom` | No | Date when the issuer becomes valid (MM/DD/YYYY) |
| `ValidUntil` | No | Date when the issuer expires (MM/DD/YYYY) |

Expand All @@ -226,7 +235,8 @@ Example:
```csv
CTID,DID,VerificationMethod,Algorithm,PrivateKey,ValidFrom,ValidUntil
ce-12345678-...,did:key:z6MkhaX...,did:key:z6MkhaX...#z6MkhaX...,Ed25519,z3u2en...,01/01/2024,12/31/2025
ce-87654321-...,did:web:example.com,did:web:example.com#key-1,,z3u2en...,,
ce-87654321-...,did:web:example.com,did:web:example.com#key-1,Ed25519,z3u2en...,,
ce-87654321-...,did:web:example.com,did:web:example.com#key-2,RS256,keys\rsa-private-key.pem,,
```

`ValidFrom` and `ValidUntil` are optional.
Expand Down Expand Up @@ -307,15 +317,18 @@ ce-cli/
│ ├── env.py # ce env list / use / show
│ ├── config.py # ce config set / get / list / reset
│ ├── iir.py # ce iir challenge bulk-sign, ce iir issuer-did publish
│ ├── iir_sign_challenge.py # ce iir challenge sign
│ └── resource.py # ce resource list / show / create / delete
├── config/
│ ├── settings.py # OIDCSettings, token I/O, paths
│ └── context.py # Environment model, active-env helpers
├── iir/
│ ├── challenge/
│ │ └── sign.py # ce iir challenge sign (--algorithm Ed25519 | RS256)
│ ├── csv_processor.py # Bulk DID upload (bulk-sign + publish)
│ └── did_ops.py # DID validation, challenges, JWT signing
│ └── did_ops.py # DID validation, challenges, IIR API calls
├── implementations/
│ ├── iir_challenge_sign_ed25519.py # Ed25519 (EdDSA) signing and verification
│ ├── iir_challenge_sign_rs256.py # RS256 signing and verification
│ └── publisher/ # Behind ce publisher: client.py, service.py, cli.py (shared options and errors)
├── publisher/ # ce publisher: a noun is a folder, a verb is a file that exposes `main`
│ └── project/
Expand Down
29 changes: 20 additions & 9 deletions ce/commands/iir.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def issuer_did_group() -> None:
"csv_path",
required=True,
type=click.Path(exists=True, dir_okay=False, readable=True),
help="Input CSV file (columns: CTID, DID, VerificationMethod, Algorithm, PrivateKey, ValidFrom, ValidUntil).",
help=(
"Input CSV file (columns: CTID, DID, VerificationMethod, Algorithm, "
"PrivateKey, ValidFrom, ValidUntil). Algorithm is Ed25519 or RS256."
),
)
@click.option(
"--output",
Expand All @@ -82,19 +85,27 @@ def bulk_sign(csv_path: str, output_path: str | None, errors_path: str | None) -
Checks per row:
1. CTID format
2. Date format validation (ValidFrom, ValidUntil if provided)
3. Membership check - Is user a member of the org
4. Registry check - Is CTID published to the registry
5. DID classification
6. DID validation via API
7. Verification method
8. Create challenge
9. Sign JWT
10. Local JWT verification
3. Algorithm - Ed25519 or RS256
4. Membership check - Is user a member of the org
5. Registry check - Is CTID published to the registry
6. DID classification (did:key key type must match Algorithm)
7. DID validation via API
8. Verification method
9. Create challenge
10. Sign JWT with the row's Algorithm and verify it against the DID

\b
Input CSV columns (required):
CTID, DID, VerificationMethod, Algorithm, PrivateKey

\b
Algorithm and PrivateKey (required on every row, did:web included):
Ed25519 PrivateKey is the multibase seed (z...)
RS256 PrivateKey is a PEM key file path (relative paths are read
from the CSV's folder), PEM text with literal \\n line
breaks, or bare base64
A did:web with two keys needs one row per key, each with its own Algorithm.

\b
Input CSV columns (optional):
ValidFrom, ValidUntil (format: MM/DD/YYYY)
Expand Down
5 changes: 5 additions & 0 deletions ce/iir/challenge/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

Signs one CE challenge and produces a Proof JWT, then verifies it against the
public key resolved from the DID (did:key or did:web). No login required.
RS256 is supported for did:web only for now.
--algorithm picks the implementation:

Ed25519 alg=EdDSA, --private-key is a multibase seed (z...).
Expand All @@ -24,6 +25,7 @@
import click
from rich.console import Console

from ce.iir import did_ops
from ce.implementations import iir_challenge_sign_ed25519 as _ed25519
from ce.implementations import iir_challenge_sign_rs256 as _rs256

Expand Down Expand Up @@ -120,6 +122,7 @@ def main(
\b
--algorithm Ed25519 : --private-key is the multibase seed (z...).
--algorithm RS256 : --private-key is a PEM file path or the PEM text.
did:web only for now (RSA did:key is not supported yet).
The challenge JSON must include: did, challenge, aud, iat, exp.
Signature verification uses did:key (offline) or did:web (HTTPS).

Expand All @@ -140,6 +143,8 @@ def main(
kid = payload_obj["did"].strip()

if algorithm == ALGORITHM_RS256:
if kid.startswith("did:key:") and not did_ops.RSA_DID_KEY_ENABLED:
raise click.ClickException(did_ops.RSA_DID_KEY_HIDDEN_MESSAGE)
token = _rs256.sign_and_verify(private_key, kid, payload_obj)
else:
if looks_like_rsa_key(private_key):
Expand Down
Loading
Loading