|
| 1 | +# SCITT API emulator |
| 2 | + |
| 3 | +This repository contains the source code for the SCITT API emulator. It is meant to allow experimenting with [SCITT](https://datatracker.ietf.org/wg/scitt/about/) APIs and formats. It is not meant to be used in production code. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +The emulator assumes a Linux environment with Python 3.8 or higher. |
| 8 | +On Ubuntu, run the following to install Python: |
| 9 | + |
| 10 | +```sh |
| 11 | +sudo apt install python3.8 python3.8-venv |
| 12 | +``` |
| 13 | + |
| 14 | +## Clone the emulator |
| 15 | + |
| 16 | +Clone the scitt-api-emulator repository and change into the scitt-api-emulator folder: |
| 17 | + |
| 18 | +```sh |
| 19 | +git clone https://github.com/microsoft/scitt-api-emulator |
| 20 | +cd scitt-api-emulator |
| 21 | +``` |
| 22 | + |
| 23 | +## Use the emulator |
| 24 | + |
| 25 | +### Start a fake SCITT service |
| 26 | + |
| 27 | +```sh |
| 28 | +./scitt-emulator.sh server --workspace workspace/ --tree-alg CCF |
| 29 | +``` |
| 30 | + |
| 31 | +`--tree-alg` is currently `CCF` only. |
| 32 | + |
| 33 | +The default port is 8000 but can be changed with the `--port` argument. |
| 34 | + |
| 35 | +Now the server is running at http://localhost:8000/ and uses `workspace/` to store the service parameters and service state. |
| 36 | + |
| 37 | +The service has the following REST API: |
| 38 | + |
| 39 | +- `POST /entries` - submit a COSE_Sign1 claim to the emulator and return an entry id |
| 40 | +- `GET /entries/<entry_id>` - retrieve the COSE_Sign1 claim for the corresponding entry id |
| 41 | +- `GET /entries/<entry_id>/receipt` - retrieve the SCITT receipt for corresponding entry id |
| 42 | + |
| 43 | +The following steps should be done from a different terminal, leaving the service running in the background. |
| 44 | + |
| 45 | +### Create claims |
| 46 | + |
| 47 | +```sh |
| 48 | +./scitt-emulator.sh client create-claim --issuer did:web:example.com --content-type application/json --payload '{"sun": "yellow"}' --out claim.cose |
| 49 | +``` |
| 50 | + |
| 51 | +Note: The emulator does not verify claim signatures and generates an ad-hoc key pair to sign the claim. |
| 52 | + |
| 53 | +### Submit claims and retrieve receipts |
| 54 | + |
| 55 | +```sh |
| 56 | +./scitt-emulator.sh client submit-claim --claim claim.cose --out claim.receipt.cbor |
| 57 | +``` |
| 58 | + |
| 59 | +The `submit-claim` command uses the default service URL `http://127.0.0.1:8000` which can be changed with the `--url` argument. It can be used with the built-in server or an external service implementation. |
| 60 | + |
| 61 | +This command sends the following two requests: |
| 62 | + |
| 63 | +1. `POST /entries` with the claim file as HTTP body. The response is JSON containing `"entry_id"`. |
| 64 | +2. `GET /entries/<entry_id>/receipt` to retrieve the SCITT receipt. |
| 65 | + |
| 66 | +### Retrieve claims |
| 67 | + |
| 68 | +```sh |
| 69 | +./scitt-emulator.sh client retrieve-claim --entry-id 123 --out claim.cose |
| 70 | +``` |
| 71 | + |
| 72 | +The `retrieve-claim` command uses the default service URL `http://127.0.0.1:8000` which can be changed with the `--url` argument. It can be used with the built-in server or an external service implementation. |
| 73 | + |
| 74 | +This command sends the following request: |
| 75 | + |
| 76 | +- `GET /entries/<entry_id>` to retrieve the claim. |
| 77 | + |
| 78 | +### Retrieve receipts |
| 79 | + |
| 80 | +```sh |
| 81 | +./scitt-emulator.sh client retrieve-receipt --entry-id 123 --out receipt.cbor |
| 82 | +``` |
| 83 | + |
| 84 | +The `retrieve-receipt` command uses the default service URL `http://127.0.0.1:8000` which can be changed with the `--url` argument. It can be used with the built-in server or an external service implementation. |
| 85 | + |
| 86 | +This command sends the following request: |
| 87 | + |
| 88 | +- `GET /entries/<entry_id>/receipt` to retrieve the receipt. |
| 89 | + |
| 90 | +### Validate receipts |
| 91 | + |
| 92 | +```sh |
| 93 | +./scitt-emulator.sh client verify-receipt --claim claim.cose --receipt claim.receipt.cbor --service-parameters workspace/service_parameters.json |
| 94 | +``` |
| 95 | + |
| 96 | +The `verify-receipt` command verifies a SCITT receipt given a SCITT claim and a service parameters file. This command can be used to verify receipts generated by other implementations. |
| 97 | + |
| 98 | +The `service_parameters.json` file gets created when starting a service using `./scitt-emulator.sh server`. The format of this file is not standardized and is currently: |
| 99 | + |
| 100 | +```json |
| 101 | +{ |
| 102 | + "serviceId": "emulator", |
| 103 | + "treeAlgorithm": "CCF", |
| 104 | + "signatureAlgorithm": "ES256", |
| 105 | + "serviceCertificate": "-----BEGIN CERTIFICATE-----..." |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +`"signatureAlgorithm"` and `"serviceCertificate"` are additional parameters specific to the [`CCF` tree algorithm](https://ietf-scitt.github.io/draft-birkholz-scitt-receipts/draft-birkholz-scitt-receipts.html#name-additional-parameters). |
| 110 | + |
| 111 | +### COSE and CBOR debugging |
| 112 | + |
| 113 | +The following websites can be used to inspect COSE and CBOR files: |
| 114 | + |
| 115 | +- https://gluecose.github.io/cose-viewer/ |
| 116 | +- https://cbor.me/ |
| 117 | + |
| 118 | +## Code structure |
| 119 | + |
| 120 | +`scitt_emulator/scitt.py` contains the core SCITT algorithms that are agnostic of a specific tree algorithm. |
| 121 | + |
| 122 | +`scitt_emulator/ccf.py` is the implementation of the [CCF tree algorithm](https://ietf-scitt.github.io/draft-birkholz-scitt-receipts/draft-birkholz-scitt-receipts.html#name-ccf-tree-algorithm). For each claim, a receipt is generated using a fake but valid Merkle tree that is independent of other submitted claims. A real CCF service would maintain a single Merkle tree covering all submitted claims and auxiliarly entries. |
| 123 | + |
| 124 | +`scitt_emulator/server.py` is a simple Flask server that acts as a SCITT transparency service. |
| 125 | + |
| 126 | +`scitt_emulator/client.py` is a CLI that supports creating claims, submitting claims to and retrieving receipts from the server, and verifying receipts. |
| 127 | + |
| 128 | +In order to add a new tree algorithm, a file like `scitt_emulator/ccf.py` must be created and the containing class be added in `scitt_emulator/tree_algs.py`. |
| 129 | + |
| 130 | +## Run tests |
| 131 | + |
| 132 | +``` |
| 133 | +./run-tests.sh |
| 134 | +``` |
| 135 | + |
| 136 | +## Contributing |
| 137 | + |
| 138 | +This project welcomes contributions and suggestions. Please see the [Contribution guidelines](CONTRIBUTING.md). |
0 commit comments