# PantherX Device Identity Service

- Provides signed response from `px-device-identity` via REST API
- runs on `127.0.0.1:8000`

## Setup

### Setup on PantherX

- (1) Setup, and register your device with `px-device-identity`
- (2) Add service to system configuration

```scheme
(service px-device-identity-service-type)
```

### Install with pip package manager

_Install these packages as root; Minimum python version: v3.8_.

```bash
pip3 install https://source-git-pantherx-org.s3.eu-central-1.amazonaws.com/px-device-identity-service_latest.tgz
```

## Run

```bash
px-device-identity-service
```

Params:

```bash
-p, --port: Port to run the service on
-ho, --host: Host to run the service on
-kd, --key-dir: Directory to store keys
-cd, --config-dir: Directory to store config
-d, --debug: Run in debug mode
```

For development against Docker, roughly like this:

```bash
px-device-identity-service -kd /home/franz/git/ones-idp/.identity-service/keys -cd /home/franz/git/ones-idp/.identity-service/config
```

### Run as Service

- PantherX OS: `herd start px-device-identity`
- systemd based distributions like Debian, Centos, use the service from [here](docs/systemd-service.md)

## Use Rest API

To sign a string, do:

_The service automatically determines required key security from config._

```bash
$ curl --request POST \
     --header "Content-Type: application/json" \
     --data '{"deviceId":"2ed6a969-96a8-4bee-b865-1c9a5388ed40","message":"abc"}' \
     http://127.0.0.1:8000/sign

HTTP/1.0 202 Accepted
Date: Tue, 07 Jul 2020 06:54:06 GMT
Server: WSGIServer/0.2 CPython/3.8.3
access-control-allow-origin: *
content-length: 359
content-type: application/json

{
    "signature": "U0SkgjtuiMHgnnzkedTEoBUbDMKzVqrWFE8XV2VGoeVQL0B5ao1WbGSkB6WsefdSIDxrhs9A4c0iMRA2WHqqBwwT9JtWjYGzDPa4B3gxLTrKVAw33Msa6BS47VAQ41I4sOb0zjCNe_MqB_-0pcmqAKTVqX0B63cf6NVL0b274h95PjZ7DacoIx7zXL1geCHqi61k0u0qyKJxWZyO9bB_eicatgKN6Ycxn9RHBLMkkB2fxeE-tsxS66dN9s8UQutWn0GZHehDv7VCpdLsvhpMHsPfOzAe4XovFeR5c-gOF_9UKNeCIRU6kIaslwwwM7ygf8Eez3WQEwTbM_w0Xsptfw"
}
```

## Troubleshooting

Find logs at `/var/log/`

## Development

Create a guix environment like so:

```bash
# system dependencies
guix shell --pure --check python tpm2-tss tpm2-tss-engine

# python dependencies
python3 -m venv venv
source venv/bin/activate
pip3 install .
```
