mirror of
https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
synced 2026-04-08 22:15:47 +03:00
Compare commits
64 Commits
f38378bbc8
...
python-jos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
137f682f74 | ||
|
|
ff3e258f13 | ||
|
|
cad7658e8e | ||
|
|
eb120fb8dd | ||
|
|
7346cf6d7a | ||
|
|
9f80dadeba | ||
|
|
f7d9b3574e | ||
|
|
4786a345a8 | ||
|
|
c7186f46a1 | ||
|
|
3314d6b95e | ||
|
|
0c5368b863 | ||
|
|
5c54f5171f | ||
|
|
2afd3a4eb3 | ||
|
|
b5e186a58e | ||
|
|
3ebf87f01a | ||
|
|
b8ec5e11e2 | ||
|
|
2065a33571 | ||
|
|
608ec9fb6c | ||
|
|
c0d23e78cd | ||
|
|
fd89cd0785 | ||
|
|
f58e54cf28 | ||
|
|
26a5bdb320 | ||
|
|
6b2c8d512a | ||
|
|
bffa357225 | ||
|
|
656d568cbe | ||
|
|
82c8e89d8f | ||
|
|
2ee92b6f81 | ||
|
|
52a1834817 | ||
|
|
dd0042b850 | ||
|
|
eded286c89 | ||
|
|
764e012fb7 | ||
|
|
52e9f2cae9 | ||
|
|
09fe2a605c | ||
|
|
8ec87a8859 | ||
|
|
18f577b4f6 | ||
|
|
eab3b21d60 | ||
|
|
2157394dfa | ||
|
|
b577edcf67 | ||
|
|
8e3e49fc36 | ||
|
|
2638f67cd9 | ||
|
|
60a6c83a3d | ||
|
|
ae03867502 | ||
|
|
295e3c9482 | ||
|
|
3961acf231 | ||
|
|
04914740a4 | ||
|
|
6af9cd04c9 | ||
|
|
29268b1658 | ||
|
|
938a112b8a | ||
|
|
16870e9d67 | ||
|
|
55b7437fe7 | ||
|
|
e7e007a45f | ||
|
|
161a1430cf | ||
|
|
1ccb203b25 | ||
|
|
6c1a8d42dc | ||
|
|
d248496f34 | ||
|
|
fd1babaca5 | ||
|
|
cd9c655d65 | ||
|
|
6ed4bdfe6f | ||
|
|
e1ae757a50 | ||
|
|
b0ca5d7ab5 | ||
|
|
14f8b54752 | ||
|
|
dc783e6518 | ||
|
|
3666e22707 | ||
|
|
6b54d4794b |
@@ -2,7 +2,7 @@ Package: fastapi-dls
|
|||||||
Version: 0.0
|
Version: 0.0
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Maintainer: Oscar Krause oscar.krause@collinwebdesigns.de
|
Maintainer: Oscar Krause oscar.krause@collinwebdesigns.de
|
||||||
Depends: python3, python3-fastapi, python3-uvicorn, python3-dotenv, python3-dateutil, python3-josepy, python3-sqlalchemy, python3-cryptography, python3-markdown, uvicorn, openssl
|
Depends: python3, python3-fastapi, python3-uvicorn, python3-dotenv, python3-dateutil, python3-jwt, python3-sqlalchemy, python3-cryptography, python3-markdown, uvicorn, openssl
|
||||||
Recommends: curl
|
Recommends: curl
|
||||||
Installed-Size: 10240
|
Installed-Size: 10240
|
||||||
Homepage: https://git.collinwebdesigns.de/oscar.krause/fastapi-dls
|
Homepage: https://git.collinwebdesigns.de/oscar.krause/fastapi-dls
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# Toggle debug mode
|
# Toggle debug mode
|
||||||
#DEBUG=false
|
#DEBUG=false
|
||||||
|
|
||||||
|
# Cert Path
|
||||||
|
CERT_PATH="/etc/fastapi-dls/cert"
|
||||||
|
|
||||||
# Where the client can find the DLS server
|
# Where the client can find the DLS server
|
||||||
DLS_URL=127.0.0.1
|
DLS_URL=127.0.0.1
|
||||||
DLS_PORT=443
|
DLS_PORT=443
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
WORKING_DIR=/usr/share/fastapi-dls
|
WORKING_DIR=/usr/share/fastapi-dls
|
||||||
CONFIG_DIR=/etc/fastapi-dls
|
CONFIG_DIR=/etc/fastapi-dls
|
||||||
|
|
||||||
|
source $CONFIG_DIR/env
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
[ -f $CONFIG_DIR/webserver.key ] && default_answer="N" || default_answer="Y"
|
[ -f $CONFIG_DIR/webserver.key ] && default_answer="N" || default_answer="Y"
|
||||||
[ $default_answer == "Y" ] && V="Y/n" || V="y/N"
|
[ $default_answer == "Y" ] && V="Y/n" || V="y/N"
|
||||||
@@ -25,27 +27,32 @@ if [ -f $CONFIG_DIR/webserver.key ]; then
|
|||||||
|
|
||||||
if [ -x "$(command -v curl)" ]; then
|
if [ -x "$(command -v curl)" ]; then
|
||||||
echo "> Testing API ..."
|
echo "> Testing API ..."
|
||||||
source $CONFIG_DIR/env
|
|
||||||
curl --insecure -X GET https://$DLS_URL:$DLS_PORT/-/health
|
curl --insecure -X GET https://$DLS_URL:$DLS_PORT/-/health
|
||||||
else
|
else
|
||||||
echo "> Testing API failed, curl not available. Please test manually!"
|
echo "> Testing API failed, curl not available. Please test manually!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "> Create Certificate-Chain folder ..."
|
||||||
|
mkdir -p $CERT_PATH
|
||||||
|
|
||||||
|
echo "> Set permissions ..."
|
||||||
chown -R www-data:www-data $CONFIG_DIR
|
chown -R www-data:www-data $CONFIG_DIR
|
||||||
chown -R www-data:www-data $WORKING_DIR
|
chown -R www-data:www-data $WORKING_DIR
|
||||||
|
|
||||||
|
echo "> Done."
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
# #
|
# #
|
||||||
# fastapi-dls is now installed. #
|
# fastapi-dls is now installed. #
|
||||||
# #
|
# #
|
||||||
# Service should be up and running. #
|
# Service should be up and running (if you choose to auto-generate #
|
||||||
# Webservice is listen to https://localhost #
|
# self-signed webserver certificate). #
|
||||||
# #
|
|
||||||
# Configuration is stored in /etc/fastapi-dls/env. #
|
|
||||||
# #
|
# #
|
||||||
|
# - Webservice is listen to https://localhost # #
|
||||||
|
# - Configuration is stored in /etc/fastapi-dls/env #
|
||||||
# #
|
# #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# https://packages.debian.org/hu/
|
# https://packages.debian.org/hu/
|
||||||
fastapi==0.92.0
|
fastapi==0.92.0
|
||||||
uvicorn[standard]==0.17.6
|
uvicorn[standard]==0.17.6
|
||||||
python-jose[cryptography]==3.3.0
|
pyjwt==2.10.1
|
||||||
cryptography==38.0.4
|
cryptography==38.0.4
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
sqlalchemy==1.4.46
|
sqlalchemy==1.4.46
|
||||||
|
|||||||
11
.DEBIAN/requirements-trixie-13.txt
Normal file
11
.DEBIAN/requirements-trixie-13.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://packages.debian.org/hu/
|
||||||
|
fastapi==0.115.11
|
||||||
|
uvicorn[standard]==0.32.0
|
||||||
|
pyjwt==2.10.1
|
||||||
|
cryptography==43.0.0
|
||||||
|
python-dateutil==2.9.0
|
||||||
|
sqlalchemy==2.0.40
|
||||||
|
markdown==3.7
|
||||||
|
python-dotenv==1.0.1
|
||||||
|
jinja2==3.1.6
|
||||||
|
httpx==0.28.1
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# https://packages.ubuntu.com
|
# https://packages.ubuntu.com
|
||||||
fastapi==0.101.0
|
fastapi==0.101.0
|
||||||
uvicorn[standard]==0.27.1
|
uvicorn[standard]==0.27.1
|
||||||
python-jose[cryptography]==3.3.0
|
pyjwt==2.10.1
|
||||||
cryptography==41.0.7
|
cryptography==41.0.7
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
sqlalchemy==1.4.50
|
sqlalchemy==1.4.50
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# https://packages.ubuntu.com
|
# https://packages.ubuntu.com
|
||||||
fastapi==0.110.3
|
fastapi==0.110.3
|
||||||
uvicorn[standard]==0.30.3
|
uvicorn[standard]==0.30.3
|
||||||
python-jose[cryptography]==3.3.0
|
pyjwt==2.10.1
|
||||||
cryptography==42.0.5
|
cryptography==42.0.5
|
||||||
python-dateutil==2.9.0
|
python-dateutil==2.9.0
|
||||||
sqlalchemy==2.0.32
|
sqlalchemy==2.0.32
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pkgdesc='NVIDIA DLS server implementation with FastAPI'
|
|||||||
arch=('any')
|
arch=('any')
|
||||||
url='https://git.collinwebdesigns.de/oscar.krause/fastapi-dls'
|
url='https://git.collinwebdesigns.de/oscar.krause/fastapi-dls'
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
depends=('python' 'python-jose' 'python-starlette' 'python-httpx' 'python-fastapi' 'python-dotenv' 'python-dateutil' 'python-sqlalchemy' 'python-cryptography' 'uvicorn' 'python-markdown' 'openssl')
|
depends=('python' 'python-pyjwt' 'python-starlette' 'python-httpx' 'python-fastapi' 'python-dotenv' 'python-dateutil' 'python-sqlalchemy' 'python-cryptography' 'uvicorn' 'python-markdown' 'openssl')
|
||||||
provider=("$pkgname")
|
provider=("$pkgname")
|
||||||
install="$pkgname.install"
|
install="$pkgname.install"
|
||||||
backup=('etc/default/fastapi-dls')
|
backup=('etc/default/fastapi-dls')
|
||||||
|
|||||||
@@ -162,20 +162,22 @@ test:apt:
|
|||||||
image: $IMAGE
|
image: $IMAGE
|
||||||
stage: test
|
stage: test
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
- if: ($CI_PIPELINE_SOURCE == 'merge_request_event') || ($CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH)
|
||||||
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
|
||||||
changes:
|
changes:
|
||||||
- app/**/*
|
- app/**/*
|
||||||
- .DEBIAN/**/*
|
- .DEBIAN/**/*
|
||||||
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
- .gitlab-ci.yml
|
||||||
|
variables:
|
||||||
|
VERSION: "0.0.1"
|
||||||
parallel:
|
parallel:
|
||||||
matrix:
|
matrix:
|
||||||
- IMAGE:
|
- IMAGE:
|
||||||
- debian:trixie-slim # EOL: t.b.a.
|
- debian:trixie-slim # EOL: t.b.a.; "python3-jose" not available, but "python3-josepy" or "python3-jwt"
|
||||||
- debian:bookworm-slim # EOL: June 06, 2026
|
- debian:bookworm-slim # EOL: June 06, 2026
|
||||||
- debian:bookworm-slim # EOL: June 06, 2026
|
- debian:bullseye-slim # EOL: June 06, 2026
|
||||||
- ubuntu:24.04 # EOL: April 2036
|
- ubuntu:24.04 # EOL: April 2036 (Noble Numbat)
|
||||||
- ubuntu:24.10
|
- ubuntu:25.04 # EOL: January 2026 (Plucky Puffin); "python3-jose" not available, but "python3-josepy" or "python3-jwt"
|
||||||
|
- ubuntu:25.10 # EOL: July 2026 (Questing Quokka);
|
||||||
needs:
|
needs:
|
||||||
- job: build:apt
|
- job: build:apt
|
||||||
artifacts: true
|
artifacts: true
|
||||||
@@ -210,8 +212,7 @@ test:apt:
|
|||||||
test:pacman:archlinux:
|
test:pacman:archlinux:
|
||||||
image: archlinux:base
|
image: archlinux:base
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
- if: ($CI_PIPELINE_SOURCE == 'merge_request_event') || ($CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH)
|
||||||
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
|
||||||
changes:
|
changes:
|
||||||
- app/**/*
|
- app/**/*
|
||||||
- .PKGBUILD/**/*
|
- .PKGBUILD/**/*
|
||||||
@@ -249,7 +250,7 @@ semgrep-sast:
|
|||||||
|
|
||||||
test_coverage:
|
test_coverage:
|
||||||
# extends: test
|
# extends: test
|
||||||
image: python:3.12-slim-bookworm
|
image: python:3.13-slim-trixie
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
stage: test
|
stage: test
|
||||||
rules:
|
rules:
|
||||||
@@ -376,7 +377,7 @@ deploy:pacman:
|
|||||||
release:
|
release:
|
||||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||||
stage: .post
|
stage: .post
|
||||||
needs: [ build:docker, build:apt, build:pacman ]
|
needs: [ deploy:docker, deploy:apt, deploy:pacman ]
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_TAG
|
- if: $CI_COMMIT_TAG
|
||||||
script:
|
script:
|
||||||
@@ -391,4 +392,4 @@ release:
|
|||||||
- name: 'Package Registry'
|
- name: 'Package Registry'
|
||||||
url: 'https://git.collinwebdesigns.de/oscar.krause/fastapi-dls/-/packages'
|
url: 'https://git.collinwebdesigns.de/oscar.krause/fastapi-dls/-/packages'
|
||||||
- name: 'Container Registry'
|
- name: 'Container Registry'
|
||||||
url: 'https://git.collinwebdesigns.de/oscar.krause/fastapi-dls/container_registry/40'
|
url: 'https://git.collinwebdesigns.de/oscar.krause/fastapi-dls/container_registry/70'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.12-alpine
|
FROM python:3.13-alpine
|
||||||
|
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ARG COMMIT=""
|
ARG COMMIT=""
|
||||||
|
|||||||
178
README.md
178
README.md
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
Minimal Delegated License Service (DLS).
|
Minimal Delegated License Service (DLS).
|
||||||
|
|
||||||
> [!warning] Branch support \
|
> [!warning] Branch support
|
||||||
> FastAPI-DLS Version 1.x supports up to **`17.x`** releases. \
|
> FastAPI-DLS Version 1.x supports up to **`17.x`** releases. \
|
||||||
> FastAPI-DLS Version 2.x is backwards compatible to `17.x` and supports **`18.x`** releases in combination
|
> FastAPI-DLS Version 2.x is backwards compatible to `17.x` and supports **`18.x`**, **`19.x`**, releases in combination
|
||||||
> with [gridd-unlock-patcher](https://git.collinwebdesigns.de/oscar.krause/gridd-unlock-patcher).
|
> with [gridd-unlock-patcher](https://git.collinwebdesigns.de/vgpu/gridd-unlock-patcher).
|
||||||
> Other combinations of FastAPI-DLS and Driver-Branches may work but are not tested.
|
> Other combinations of FastAPI-DLS and Driver-Branches may work but are not tested.
|
||||||
|
|
||||||
> [!note] Compatibility
|
> [!note] Compatibility
|
||||||
> Compatibility tested with official NLS 2.0.1, 2.1.0, 3.1.0, 3.3.1, 3.4.0. For Driver compatibility
|
> Compatibility tested with official NLS 2.0.1, 2.1.0, 3.1.0, 3.3.1, 3.4.0. **For Driver compatibility
|
||||||
> see [compatibility matrix](#vgpu-software-compatibility-matrix).
|
> see [compatibility matrix](#vgpu-software-compatibility-matrix)**.
|
||||||
|
|
||||||
This service can be used without internet connection.
|
This service can be used without internet connection.
|
||||||
Only the clients need a connection to this service on configured port.
|
Only the clients need a connection to this service on configured port.
|
||||||
@@ -18,7 +18,6 @@ Only the clients need a connection to this service on configured port.
|
|||||||
**Official Links**
|
**Official Links**
|
||||||
|
|
||||||
* https://git.collinwebdesigns.de/oscar.krause/fastapi-dls (Private Git)
|
* https://git.collinwebdesigns.de/oscar.krause/fastapi-dls (Private Git)
|
||||||
* https://gitea.publichub.eu/oscar.krause/fastapi-dls (Public Git)
|
|
||||||
* https://hub.docker.com/r/collinwebdesigns/fastapi-dls (Docker-Hub `collinwebdesigns/fastapi-dls:latest`)
|
* https://hub.docker.com/r/collinwebdesigns/fastapi-dls (Docker-Hub `collinwebdesigns/fastapi-dls:latest`)
|
||||||
|
|
||||||
*All other repositories are forks! (which is no bad - just for information and bug reports)*
|
*All other repositories are forks! (which is no bad - just for information and bug reports)*
|
||||||
@@ -329,16 +328,15 @@ Packages are available here:
|
|||||||
|
|
||||||
Successful tested with (**LTS Version**):
|
Successful tested with (**LTS Version**):
|
||||||
|
|
||||||
|
- **Debian 13 (Trixie)** (EOL: June 30, 2028)
|
||||||
- **Debian 12 (Bookworm)** (EOL: June 06, 2026)
|
- **Debian 12 (Bookworm)** (EOL: June 06, 2026)
|
||||||
- *Ubuntu 22.10 (Kinetic Kudu)* (EOL: July 20, 2023)
|
- *Ubuntu 22.10 (Kinetic Kudu)* (EOL: July 20, 2023)
|
||||||
- *Ubuntu 23.04 (Lunar Lobster)* (EOL: January 2024)
|
- *Ubuntu 23.04 (Lunar Lobster)* (EOL: January 2024)
|
||||||
- *Ubuntu 23.10 (Mantic Minotaur)* (EOL: July 2024)
|
- *Ubuntu 23.10 (Mantic Minotaur)* (EOL: July 2024)
|
||||||
- **Ubuntu 24.04 (Noble Numbat)** (EOL: Apr 2029)
|
- **Ubuntu 24.04 (Noble Numbat)** (EOL: Apr 2029)
|
||||||
- *Ubuntu 24.10 (Oracular Oriole)* (EOL: Jul 2025)
|
|
||||||
|
|
||||||
Not working with:
|
Not working with:
|
||||||
|
|
||||||
- Debian 11 (Bullseye) and lower (missing `python-jose` dependency)
|
|
||||||
- Ubuntu 22.04 (Jammy Jellyfish) (not supported as for 15.01.2023 due to [fastapi - uvicorn version missmatch](https://bugs.launchpad.net/ubuntu/+source/fastapi/+bug/1970557))
|
- Ubuntu 22.04 (Jammy Jellyfish) (not supported as for 15.01.2023 due to [fastapi - uvicorn version missmatch](https://bugs.launchpad.net/ubuntu/+source/fastapi/+bug/1970557))
|
||||||
|
|
||||||
**Run this on your server instance**
|
**Run this on your server instance**
|
||||||
@@ -415,13 +413,148 @@ acme.sh --issue -d example.com \
|
|||||||
|
|
||||||
After first success you have to replace `--issue` with `--renew`.
|
After first success you have to replace `--issue` with `--renew`.
|
||||||
|
|
||||||
# Configuration
|
## Nginx Reverse Proxy (experimental)
|
||||||
|
|
||||||
|
- This guide is written for Debian/Ubuntu systems, other may work, but you have to do your setup on your own
|
||||||
|
- Uvicorn does no longer serve requests directly
|
||||||
|
- NGINX is used as HTTP & HTTPS entrypoint
|
||||||
|
- Assumes you already have set up webserver certificate and private-key
|
||||||
|
|
||||||
|
**Install Nginx Webserver**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
apt-get install nginx-light
|
||||||
|
```
|
||||||
|
|
||||||
|
**Remove default vhost**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
rm /etc/nginx/sites-enabled/default
|
||||||
|
```
|
||||||
|
|
||||||
|
**Create fastapi-dls vhost**
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>`/etc/nginx/sites-available/fastapi-dls`</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
upstream dls-backend {
|
||||||
|
server 127.0.0.1:8000; # must match dls listen port
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2 default_server;
|
||||||
|
listen [::]:443 ssl http2 default_server;
|
||||||
|
|
||||||
|
root /var/www/html;
|
||||||
|
index index.html;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
ssl_certificate "/etc/fastapi-dls/cert/webserver.crt";
|
||||||
|
ssl_certificate_key "/etc/fastapi-dls/cert/webserver.key";
|
||||||
|
ssl_session_cache shared:SSL:1m;
|
||||||
|
ssl_session_timeout 10m;
|
||||||
|
ssl_protocols TLSv1.3 TLSv1.2;
|
||||||
|
# ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305";
|
||||||
|
# ssl_ciphers PROFILE=SYSTEM;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
# https://www.uvicorn.org/deployment/
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection $connection_upgrade;
|
||||||
|
proxy_redirect off;
|
||||||
|
proxy_buffering off;
|
||||||
|
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|
||||||
|
proxy_pass http://dls-backend$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /-/health {
|
||||||
|
access_log off;
|
||||||
|
add_header 'Content-Type' 'application/json';
|
||||||
|
return 200 '{\"status\":\"up\",\"service\":\"nginx\"}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
|
||||||
|
root /var/www/html;
|
||||||
|
index index.html;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location /leasing/v1/lessor/shutdown {
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_pass http://dls-backend/leasing/v1/lessor/shutdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
**Enable and test vhost**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
ln -s /etc/nginx/sites-available/fastapi-dls /etc/nginx/sites-enabled/fastapi-dls
|
||||||
|
|
||||||
|
nginx -t
|
||||||
|
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
|
||||||
|
# nginx: configuration file /etc/nginx/nginx.conf test is successful
|
||||||
|
```
|
||||||
|
|
||||||
|
**Override default fastapi-dls systemd service**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mkdir /etc/systemd/system/fastapi-dls.service.d
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>`/etc/systemd/system/fastapi-dls.service.d/override.conf`</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
[Service]
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=uvicorn main:app \
|
||||||
|
--env-file /etc/fastapi-dls/env \
|
||||||
|
--host 127.0.0.1 --port 8000 \
|
||||||
|
--app-dir /usr/share/fastapi-dls/app \
|
||||||
|
--proxy-headers
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
**Run**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
systemctl daemon-reload
|
||||||
|
service nginx start
|
||||||
|
service fastapi-dls start
|
||||||
|
```
|
||||||
|
|
||||||
|
# Configuration (Service)
|
||||||
|
|
||||||
| Variable | Default | Usage |
|
| Variable | Default | Usage |
|
||||||
|--------------------------|----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
|
|------------------------|----------------------------------------|------------------------------------------------------------------------------------------------------|
|
||||||
| `DEBUG` | `false` | Toggles `fastapi` debug mode |
|
| `DEBUG` | `false` | Toggles `fastapi` debug mode |
|
||||||
| `DLS_URL` | `localhost` | Used in client-token to tell guest driver where dls instance is reachable |
|
| `DLS_URL` | `localhost` | Used in client-token to tell guest driver where dls instance is reachable |
|
||||||
| `DLS_PORT` | `443` | Used in client-token to tell guest driver where dls instance is reachable |
|
| `DLS_PORT` | `443` | Used in client-token to tell guest driver where dls instance is reachable |
|
||||||
|
| `CERT_PATH` | `None` | Path to a Directory where generated Certificates are stored. Defaults to `/<app-dir>/cert`. |
|
||||||
| `TOKEN_EXPIRE_DAYS` | `1` | Client auth-token validity (used for authenticate client against api, **not `.tok` file!**) |
|
| `TOKEN_EXPIRE_DAYS` | `1` | Client auth-token validity (used for authenticate client against api, **not `.tok` file!**) |
|
||||||
| `LEASE_EXPIRE_DAYS` | `90` | Lease time in days |
|
| `LEASE_EXPIRE_DAYS` | `90` | Lease time in days |
|
||||||
| `LEASE_RENEWAL_PERIOD` | `0.15` | The percentage of the lease period that must elapse before a licensed client can renew a license \*1 |
|
| `LEASE_RENEWAL_PERIOD` | `0.15` | The percentage of the lease period that must elapse before a licensed client can renew a license \*1 |
|
||||||
@@ -429,7 +562,7 @@ After first success you have to replace `--issue` with `--renew`.
|
|||||||
| `CORS_ORIGINS` | `https://{DLS_URL}` | Sets `Access-Control-Allow-Origin` header (comma separated string) \*2 |
|
| `CORS_ORIGINS` | `https://{DLS_URL}` | Sets `Access-Control-Allow-Origin` header (comma separated string) \*2 |
|
||||||
| `SITE_KEY_XID` | `00000000-0000-0000-0000-000000000000` | Site identification uuid |
|
| `SITE_KEY_XID` | `00000000-0000-0000-0000-000000000000` | Site identification uuid |
|
||||||
| `INSTANCE_REF` | `10000000-0000-0000-0000-000000000001` | Instance identification uuid |
|
| `INSTANCE_REF` | `10000000-0000-0000-0000-000000000001` | Instance identification uuid |
|
||||||
| `ALLOTMENT_REF` | `20000000-0000-0000-0000-000000000001` | Allotment identification uuid | |
|
| `ALLOTMENT_REF` | `20000000-0000-0000-0000-000000000001` | Allotment identification uuid |
|
||||||
|
|
||||||
\*1 For example, if the lease period is one day and the renewal period is 20%, the client attempts to renew its license
|
\*1 For example, if the lease period is one day and the renewal period is 20%, the client attempts to renew its license
|
||||||
every 4.8 hours. If network connectivity is lost, the loss of connectivity is detected during license renewal and the
|
every 4.8 hours. If network connectivity is lost, the loss of connectivity is detected during license renewal and the
|
||||||
@@ -535,9 +668,10 @@ Status endpoint, used for *healthcheck*.
|
|||||||
|
|
||||||
Shows current runtime environment variables and their values.
|
Shows current runtime environment variables and their values.
|
||||||
|
|
||||||
**`GET /-/config/root-ca`**
|
**`GET /-/config/root-certificate`**
|
||||||
|
|
||||||
Returns the Root-CA Certificate which is used. This is required for patching `nvidia-gridd` on 18.x releases.
|
Returns the Root-Certificate Certificate which is used.
|
||||||
|
This is required for patching `nvidia-gridd` on `18.x`, `19.x` releases.
|
||||||
|
|
||||||
**`GET /-/readme`**
|
**`GET /-/readme`**
|
||||||
|
|
||||||
@@ -748,20 +882,24 @@ The error message can safely be ignored (since we have no license limitation :P)
|
|||||||
# vGPU Software Compatibility Matrix
|
# vGPU Software Compatibility Matrix
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Show Table</summary>
|
<summary>Successfully tested with this package versions: Show Table</summary>
|
||||||
|
|
||||||
Successfully tested with this package versions.
|
|
||||||
|
|
||||||
| FastAPI-DLS Version | vGPU Suftware | Driver Branch | Linux vGPU Manager | Linux Driver | Windows Driver | Release Date | EOL Date |
|
| FastAPI-DLS Version | vGPU Suftware | Driver Branch | Linux vGPU Manager | Linux Driver | Windows Driver | Release Date | EOL Date |
|
||||||
|---------------------|:-------------:|:-------------:|--------------------|--------------|----------------|--------------:|--------------:|
|
|---------------------|:-------------:|:-------------:|--------------------|--------------|----------------|--------------:|--------------:|
|
||||||
| `2.x` | `18.0` | **R570** | `570.124.03` | `570.124.06` | `572.60` | March 2025 | March 2026 |
|
| `2.x` | `19.0` | **R580** | `580.65.05` | `580.65.06` | `580.88` | August 2025 | July 2028 |
|
||||||
| `1.x` & `2.x` | `17.5` | | `550.144.02` | `550.144.03` | `553.62` | January 2025 | June 2025 |
|
| `2.x` | `18.4` | **R570** | `570.172.07` | `570.172.08` | `573.48` | July 2025 | March 2026 |
|
||||||
|
| | `18.3` | **R570** | `570.158.02` | `570.158.01` | `573.36` | June 2025 | |
|
||||||
|
| | `18.2` | **R570** | `570.148.06` | `570.148.08` | `573.07` | May 2025 | |
|
||||||
|
| | `18.1` | **R570** | `570.133.08` | `570.133.07` | `572.83` | April 2025 | |
|
||||||
|
| | `18.0` | **R570** | `570.124.03` | `570.124.06` | `572.60` | March 2025 | |
|
||||||
|
| `1.x` & `2.x` | `17.6` | **R550** | `550.163.02` | `550.63.01` | `553.74` | April 2025 | June 2025 |
|
||||||
|
| | `17.5` | | `550.144.02` | `550.144.03` | `553.62` | January 2025 | |
|
||||||
| | `17.4` | | `550.127.06` | `550.127.05` | `553.24` | October 2024 | |
|
| | `17.4` | | `550.127.06` | `550.127.05` | `553.24` | October 2024 | |
|
||||||
| | `17.3` | | `550.90.05` | `550.90.07` | `552.74` | July 2024 | |
|
| | `17.3` | | `550.90.05` | `550.90.07` | `552.74` | July 2024 | |
|
||||||
| | `17.2` | | `550.90.05` | `550.90.07` | `552.55` | June 2024 | |
|
| | `17.2` | | `550.90.05` | `550.90.07` | `552.55` | June 2024 | |
|
||||||
| | `17.1` | | `550.54.16` | `550.54.15` | `551.78` | March 2024 | |
|
| | `17.1` | | `550.54.16` | `550.54.15` | `551.78` | March 2024 | |
|
||||||
| | `17.0` | **R550** | `550.54.10` | `550.54.14` | `551.61` | February 2024 | |
|
| | `17.0` | **R550** | `550.54.10` | `550.54.14` | `551.61` | February 2024 | |
|
||||||
| `1.x` | `16.9` | **R535** | `535.230.02` | `535.216.01` | `539.19` | October 2024 | July 2026 |
|
| `1.x` | `16.11` | **R535** | `535.261.04` | `535.261.03` | `539.41` | July 2025 | July 2026 |
|
||||||
| `1.x` | `15.4` | **R525** | `525.147.01` | `525.147.05` | `529.19` | June 2023 | December 2023 |
|
| `1.x` | `15.4` | **R525** | `525.147.01` | `525.147.05` | `529.19` | June 2023 | December 2023 |
|
||||||
| `1.x` | `14.4` | **R510** | `510.108.03` | `510.108.03` | `514.08` | December 2022 | February 2023 |
|
| `1.x` | `14.4` | **R510** | `510.108.03` | `510.108.03` | `514.08` | December 2022 | February 2023 |
|
||||||
|
|
||||||
@@ -787,6 +925,6 @@ Special thanks to:
|
|||||||
- `Krutav Shah` who wrote the [vGPU_Unlock Wiki](https://docs.google.com/document/d/1pzrWJ9h-zANCtyqRgS7Vzla0Y8Ea2-5z2HEi4X75d2Q/)
|
- `Krutav Shah` who wrote the [vGPU_Unlock Wiki](https://docs.google.com/document/d/1pzrWJ9h-zANCtyqRgS7Vzla0Y8Ea2-5z2HEi4X75d2Q/)
|
||||||
- `Wim van 't Hoog` for the [Proxmox All-In-One Installer Script](https://wvthoog.nl/proxmox-vgpu-v3/)
|
- `Wim van 't Hoog` for the [Proxmox All-In-One Installer Script](https://wvthoog.nl/proxmox-vgpu-v3/)
|
||||||
- `mrzenc` who wrote [fastapi-dls-nixos](https://github.com/mrzenc/fastapi-dls-nixos)
|
- `mrzenc` who wrote [fastapi-dls-nixos](https://github.com/mrzenc/fastapi-dls-nixos)
|
||||||
- `electricsheep49` who wrote [gridd-unlock-patcher](https://git.collinwebdesigns.de/oscar.krause/gridd-unlock-patcher)
|
- `electricsheep49` who wrote [gridd-unlock-patcher](https://git.collinwebdesigns.de/vgpu/gridd-unlock-patcher)
|
||||||
|
|
||||||
And thanks to all people who contributed to all these libraries!
|
And thanks to all people who contributed to all these libraries!
|
||||||
|
|||||||
11
ROADMAP.md
11
ROADMAP.md
@@ -2,6 +2,17 @@
|
|||||||
|
|
||||||
I am planning to implement the following features in the future.
|
I am planning to implement the following features in the future.
|
||||||
|
|
||||||
|
## Patching Endpoint
|
||||||
|
|
||||||
|
A (optional) Path-Variable to `gridd-unlock-patcher` which enables an additional endpoint.
|
||||||
|
Here you can upload your `nvidia-gridd` binary or `nvxdapix.dll` which then will be patched and responded.
|
||||||
|
|
||||||
|
## All-In-One Installer Script Endpoint
|
||||||
|
|
||||||
|
A new all-in-one installer endpoint
|
||||||
|
(here a script is returned for linux or windows which then could be called like
|
||||||
|
curl https://<fastapi-dls>/-/install/deb | sh which then
|
||||||
|
download and place a client-token in the right directory, patch your girdd / dll and restart nvidia-gridd service)
|
||||||
|
|
||||||
## HA - High Availability
|
## HA - High Availability
|
||||||
|
|
||||||
|
|||||||
109
app/main.py
109
app/main.py
@@ -5,17 +5,18 @@ from contextlib import asynccontextmanager
|
|||||||
from datetime import datetime, timedelta, UTC
|
from datetime import datetime, timedelta, UTC
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from json import loads as json_loads, dumps as json_dumps
|
from json import loads as json_loads, dumps as json_dumps
|
||||||
from os import getenv as env
|
from os import getenv as env, listdir
|
||||||
from os.path import join, dirname
|
from os.path import join, dirname, isfile, isdir, exists
|
||||||
|
from textwrap import wrap
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.requests import Request
|
from fastapi.requests import Request
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.responses import Response, RedirectResponse, StreamingResponse
|
from fastapi.responses import Response, RedirectResponse, StreamingResponse
|
||||||
from jose import jws, jwk, jwt, JWTError
|
import jwt
|
||||||
from jose.constants import ALGORITHMS
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
@@ -39,6 +40,7 @@ db_init(db), migrate(db)
|
|||||||
# Load DLS variables (all prefixed with "INSTANCE_*" is used as "SERVICE_INSTANCE_*" or "SI_*" in official dls service)
|
# Load DLS variables (all prefixed with "INSTANCE_*" is used as "SERVICE_INSTANCE_*" or "SI_*" in official dls service)
|
||||||
DLS_URL = str(env('DLS_URL', 'localhost'))
|
DLS_URL = str(env('DLS_URL', 'localhost'))
|
||||||
DLS_PORT = int(env('DLS_PORT', '443'))
|
DLS_PORT = int(env('DLS_PORT', '443'))
|
||||||
|
CERT_PATH = str(env('CERT_PATH', None))
|
||||||
SITE_KEY_XID = str(env('SITE_KEY_XID', '00000000-0000-0000-0000-000000000000'))
|
SITE_KEY_XID = str(env('SITE_KEY_XID', '00000000-0000-0000-0000-000000000000'))
|
||||||
INSTANCE_REF = str(env('INSTANCE_REF', '10000000-0000-0000-0000-000000000001'))
|
INSTANCE_REF = str(env('INSTANCE_REF', '10000000-0000-0000-0000-000000000001'))
|
||||||
ALLOTMENT_REF = str(env('ALLOTMENT_REF', '20000000-0000-0000-0000-000000000001'))
|
ALLOTMENT_REF = str(env('ALLOTMENT_REF', '20000000-0000-0000-0000-000000000001'))
|
||||||
@@ -48,19 +50,22 @@ LEASE_RENEWAL_PERIOD = float(env('LEASE_RENEWAL_PERIOD', 0.15))
|
|||||||
LEASE_RENEWAL_DELTA = timedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0)))
|
LEASE_RENEWAL_DELTA = timedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0)))
|
||||||
CLIENT_TOKEN_EXPIRE_DELTA = relativedelta(years=12)
|
CLIENT_TOKEN_EXPIRE_DELTA = relativedelta(years=12)
|
||||||
CORS_ORIGINS = str(env('CORS_ORIGINS', '')).split(',') if (env('CORS_ORIGINS')) else [f'https://{DLS_URL}']
|
CORS_ORIGINS = str(env('CORS_ORIGINS', '')).split(',') if (env('CORS_ORIGINS')) else [f'https://{DLS_URL}']
|
||||||
|
DRIVERS_DIR = env('DRIVERS_DIR', None)
|
||||||
DT_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
DT_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
||||||
PRODUCT_MAPPING = ProductMapping(filename=join(dirname(__file__), 'static/product_mapping.json'))
|
PRODUCT_MAPPING = ProductMapping(filename=join(dirname(__file__), 'static/product_mapping.json'))
|
||||||
|
|
||||||
# Create certificate chain and signing keys
|
# Create certificate chain and signing keys
|
||||||
ca_setup = CASetup(service_instance_ref=INSTANCE_REF)
|
ca_setup = CASetup(service_instance_ref=INSTANCE_REF, cert_path=CERT_PATH)
|
||||||
|
my_root_private_key = PrivateKey.from_file(ca_setup.root_private_key_filename)
|
||||||
|
my_root_public_key = my_root_private_key.public_key()
|
||||||
my_root_certificate = Cert.from_file(ca_setup.root_certificate_filename)
|
my_root_certificate = Cert.from_file(ca_setup.root_certificate_filename)
|
||||||
my_ca_certificate = Cert.from_file(ca_setup.ca_certificate_filename)
|
my_ca_certificate = Cert.from_file(ca_setup.ca_certificate_filename)
|
||||||
my_si_certificate = Cert.from_file(ca_setup.si_certificate_filename)
|
my_si_certificate = Cert.from_file(ca_setup.si_certificate_filename)
|
||||||
my_si_private_key = PrivateKey.from_file(ca_setup.si_private_key_filename)
|
my_si_private_key = PrivateKey.from_file(ca_setup.si_private_key_filename)
|
||||||
my_si_public_key = my_si_private_key.public_key()
|
my_si_public_key = my_si_private_key.public_key()
|
||||||
|
|
||||||
jwt_encode_key = jwk.construct(my_si_private_key.pem(), algorithm=ALGORITHMS.RS256)
|
jwt_encode_key = my_si_private_key.pem() # todo: replace directly in code
|
||||||
jwt_decode_key = jwk.construct(my_si_private_key.public_key().pem(), algorithm=ALGORITHMS.RS256)
|
jwt_decode_key = my_si_private_key.public_key().pem() # todo: replace directly in code
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO
|
LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO
|
||||||
@@ -96,6 +101,9 @@ async def lifespan(_: FastAPI):
|
|||||||
config = dict(openapi_url=None, docs_url=None, redoc_url=None) # dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc')
|
config = dict(openapi_url=None, docs_url=None, redoc_url=None) # dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc')
|
||||||
app = FastAPI(title='FastAPI-DLS', description='Minimal Delegated License Service (DLS).', version=VERSION, lifespan=lifespan, **config)
|
app = FastAPI(title='FastAPI-DLS', description='Minimal Delegated License Service (DLS).', version=VERSION, lifespan=lifespan, **config)
|
||||||
|
|
||||||
|
if DRIVERS_DIR is not None:
|
||||||
|
app.mount('/-/static-drivers', StaticFiles(directory=str(DRIVERS_DIR), html=False), name='drivers')
|
||||||
|
|
||||||
app.debug = DEBUG
|
app.debug = DEBUG
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
@@ -110,7 +118,9 @@ app.add_middleware(
|
|||||||
def __get_token(request: Request) -> dict:
|
def __get_token(request: Request) -> dict:
|
||||||
authorization_header = request.headers.get('authorization')
|
authorization_header = request.headers.get('authorization')
|
||||||
token = authorization_header.split(' ')[1]
|
token = authorization_header.split(' ')[1]
|
||||||
return jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False})
|
|
||||||
|
# return jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False})
|
||||||
|
return jwt.decode(jwt=token, key=jwt_decode_key, algorithms=['RS256'], options={'verify_aud': False})
|
||||||
|
|
||||||
|
|
||||||
# Endpoints
|
# Endpoints
|
||||||
@@ -151,10 +161,9 @@ async def _config():
|
|||||||
return Response(content=json_dumps(response), media_type='application/json', status_code=200)
|
return Response(content=json_dumps(response), media_type='application/json', status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get('/-/config/root-certificate', summary='* Root Certificate', description='returns Root--Certificate needed for patching nvidia-gridd')
|
||||||
@app.get('/-/config/root-ca', summary='* Root CA', description='returns Root-CA needed for patching nvidia-gridd')
|
|
||||||
async def _config():
|
async def _config():
|
||||||
return Response(content=my_root_certificate.pem().decode('utf-8'), media_type='text/plain')
|
return Response(content=my_root_certificate.pem().decode('utf-8').strip(), media_type='text/plain')
|
||||||
|
|
||||||
|
|
||||||
@app.get('/-/readme', summary='* Readme')
|
@app.get('/-/readme', summary='* Readme')
|
||||||
@@ -203,6 +212,25 @@ async def _manage(request: Request):
|
|||||||
return Response(response, media_type='text/html', status_code=200)
|
return Response(response, media_type='text/html', status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get('/-/drivers/{directory:path}', summary='* List drivers directory')
|
||||||
|
async def _drivers(request: Request, directory: str | None):
|
||||||
|
if DRIVERS_DIR is None:
|
||||||
|
return Response(status_code=404, content=f'Variable "DRIVERS_DIR" not set.')
|
||||||
|
|
||||||
|
path = join(DRIVERS_DIR, directory)
|
||||||
|
|
||||||
|
if not exists(path) and not isfile(path):
|
||||||
|
return Response(status_code=404, content=f'Resource "{path}" not found!')
|
||||||
|
|
||||||
|
content = [{
|
||||||
|
"type": "file" if isfile(f'{path}/{_}') else "folder" if isdir(f'{path}/{_}') else "unknown",
|
||||||
|
"name": _,
|
||||||
|
"link": f'/-/static-drivers/{directory}{_}',
|
||||||
|
} for _ in listdir(path)]
|
||||||
|
|
||||||
|
return Response(content=json_dumps({"directory": path, "content": content}), media_type='application/json', status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@app.get('/-/origins', summary='* Origins')
|
@app.get('/-/origins', summary='* Origins')
|
||||||
async def _origins(request: Request, leases: bool = False):
|
async def _origins(request: Request, leases: bool = False):
|
||||||
session = sessionmaker(bind=db)()
|
session = sessionmaker(bind=db)()
|
||||||
@@ -287,14 +315,16 @@ async def _client_token():
|
|||||||
"mod": my_si_public_key.mod(),
|
"mod": my_si_public_key.mod(),
|
||||||
"exp": my_si_public_key.exp(),
|
"exp": my_si_public_key.exp(),
|
||||||
},
|
},
|
||||||
"service_instance_public_key_pem": my_si_private_key.public_key().pem().decode('utf-8'),
|
"service_instance_public_key_pem": my_si_public_key.pem().decode('utf-8').strip(),
|
||||||
"key_retention_mode": "LATEST_ONLY"
|
"key_retention_mode": "LATEST_ONLY"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
content = jws.sign(payload, key=jwt_encode_key, headers=None, algorithm=ALGORITHMS.RS256)
|
# content = jws.sign(payload, key=jwt_encode_key, headers=None, algorithm=ALGORITHMS.RS256)
|
||||||
|
content = jwt.encode(payload=payload, key=jwt_encode_key, headers=None, algorithm='RS256')
|
||||||
|
|
||||||
response = StreamingResponse(iter([content]), media_type="text/plain")
|
# response = StreamingResponse(iter([content]), media_type="text/plain")
|
||||||
|
response = StreamingResponse(iter(content), media_type="text/plain")
|
||||||
filename = f'client_configuration_token_{datetime.now().strftime("%d-%m-%y-%H-%M-%S")}.tok'
|
filename = f'client_configuration_token_{datetime.now().strftime("%d-%m-%y-%H-%M-%S")}.tok'
|
||||||
response.headers["Content-Disposition"] = f'attachment; filename={filename}'
|
response.headers["Content-Disposition"] = f'attachment; filename={filename}'
|
||||||
|
|
||||||
@@ -383,7 +413,8 @@ async def auth_v1_code(request: Request):
|
|||||||
'kid': SITE_KEY_XID
|
'kid': SITE_KEY_XID
|
||||||
}
|
}
|
||||||
|
|
||||||
auth_code = jws.sign(payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm=ALGORITHMS.RS256)
|
# auth_code = jws.sign(payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm=ALGORITHMS.RS256)
|
||||||
|
auth_code = jwt.encode(payload=payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm='RS256')
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"auth_code": auth_code,
|
"auth_code": auth_code,
|
||||||
@@ -401,8 +432,9 @@ async def auth_v1_token(request: Request):
|
|||||||
j, cur_time = json_loads((await request.body()).decode('utf-8')), datetime.now(UTC)
|
j, cur_time = json_loads((await request.body()).decode('utf-8')), datetime.now(UTC)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(token=j.get('auth_code'), key=jwt_decode_key, algorithms=ALGORITHMS.RS256)
|
#payload = jwt.decode(token=j.get('auth_code'), key=jwt_decode_key, algorithms=ALGORITHMS.RS256)
|
||||||
except JWTError as e:
|
payload = jwt.decode(jwt=j.get('auth_code'), key=jwt_decode_key, algorithms=['RS256'])
|
||||||
|
except jwt.PyJWTError as e:
|
||||||
response = {'status': 400, 'title': 'invalid token', 'detail': str(e)}
|
response = {'status': 400, 'title': 'invalid token', 'detail': str(e)}
|
||||||
return Response(content=json_dumps(response), media_type='application/json', status_code=400)
|
return Response(content=json_dumps(response), media_type='application/json', status_code=400)
|
||||||
|
|
||||||
@@ -428,7 +460,7 @@ async def auth_v1_token(request: Request):
|
|||||||
'origin_ref': origin_ref,
|
'origin_ref': origin_ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
auth_token = jwt.encode(new_payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm=ALGORITHMS.RS256)
|
auth_token = jwt.encode(payload=new_payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm='RS256')
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"auth_token": auth_token,
|
"auth_token": auth_token,
|
||||||
@@ -462,27 +494,46 @@ async def leasing_v1_config_token(request: Request):
|
|||||||
"mod": my_si_public_key.mod(),
|
"mod": my_si_public_key.mod(),
|
||||||
"exp": my_si_public_key.exp(),
|
"exp": my_si_public_key.exp(),
|
||||||
},
|
},
|
||||||
# 64 chars per line (pem default)
|
"service_instance_public_key_pem": my_si_public_key.pem().decode('utf-8').strip(),
|
||||||
"service_instance_public_key_pem": my_si_private_key.public_key().pem().decode('utf-8').strip(),
|
|
||||||
"key_retention_mode": "LATEST_ONLY"
|
"key_retention_mode": "LATEST_ONLY"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
my_jwt_encode_key = jwk.construct(my_si_private_key.pem().decode('utf-8'), algorithm=ALGORITHMS.RS256)
|
# my_jwt_encode_key = jwk.construct(my_si_private_key.pem().decode('utf-8'), algorithm=ALGORITHMS.RS256)
|
||||||
config_token = jws.sign(payload, key=my_jwt_encode_key, headers=None, algorithm=ALGORITHMS.RS256)
|
# config_token = jws.sign(payload, key=my_jwt_encode_key, headers=None, algorithm=ALGORITHMS.RS256)
|
||||||
|
config_token = jwt.encode(payload=payload, key=jwt_encode_key, headers=None, algorithm='RS256')
|
||||||
|
|
||||||
response_ca_chain = my_ca_certificate.pem().decode('utf-8')
|
response_ca_chain = my_ca_certificate.pem().decode('utf-8').strip()
|
||||||
response_si_certificate = my_si_certificate.pem().decode('utf-8')
|
|
||||||
|
# 76 chars per line on original response with "\r\n"
|
||||||
|
"""
|
||||||
|
response_ca_chain = my_ca_certificate.pem().decode('utf-8').strip()
|
||||||
|
response_ca_chain = response_ca_chain.replace('-----BEGIN CERTIFICATE-----', '')
|
||||||
|
response_ca_chain = response_ca_chain.replace('-----END CERTIFICATE-----', '')
|
||||||
|
response_ca_chain = response_ca_chain.replace('\n', '')
|
||||||
|
response_ca_chain = wrap(response_ca_chain, 76)
|
||||||
|
response_ca_chain = '\r\n'.join(response_ca_chain)
|
||||||
|
response_ca_chain = f'-----BEGIN CERTIFICATE-----\r\n{response_ca_chain}\r\n-----END CERTIFICATE-----'
|
||||||
|
"""
|
||||||
|
response_si_certificate = my_si_certificate.pem().decode('utf-8').strip()
|
||||||
|
|
||||||
|
# 76 chars per line on original response with "\r\n"
|
||||||
|
"""
|
||||||
|
response_si_certificate = my_si_certificate.pem().decode('utf-8').strip()
|
||||||
|
response_si_certificate = response_si_certificate.replace('-----BEGIN CERTIFICATE-----', '')
|
||||||
|
response_si_certificate = response_si_certificate.replace('-----END CERTIFICATE-----', '')
|
||||||
|
response_si_certificate = response_si_certificate.replace('\n', '')
|
||||||
|
response_si_certificate = wrap(response_si_certificate, 76)
|
||||||
|
response_si_certificate = '\r\n'.join(response_si_certificate)
|
||||||
|
"""
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"certificateConfiguration": {
|
"certificateConfiguration": {
|
||||||
# 76 chars per line
|
|
||||||
"caChain": [response_ca_chain],
|
"caChain": [response_ca_chain],
|
||||||
# 76 chars per line
|
|
||||||
"publicCert": response_si_certificate,
|
"publicCert": response_si_certificate,
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"exp": int(my_si_certificate.raw().public_key().public_numbers().e),
|
"exp": my_si_certificate.public_key().exp(),
|
||||||
"mod": [hex(my_si_certificate.raw().public_key().public_numbers().n)[2:]],
|
"mod": [my_si_certificate.public_key().mod()],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"configToken": config_token,
|
"configToken": config_token,
|
||||||
@@ -681,7 +732,7 @@ async def leasing_v1_lessor_shutdown(request: Request):
|
|||||||
j, cur_time = json_loads((await request.body()).decode('utf-8')), datetime.now(UTC)
|
j, cur_time = json_loads((await request.body()).decode('utf-8')), datetime.now(UTC)
|
||||||
|
|
||||||
token = j.get('token')
|
token = j.get('token')
|
||||||
token = jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False})
|
token = jwt.decode(jwt=token, key=jwt_decode_key, algorithms='RS256', options={'verify_aud': False})
|
||||||
origin_ref = token.get('origin_ref')
|
origin_ref = token.get('origin_ref')
|
||||||
|
|
||||||
released_lease_list = list(map(lambda x: x.lease_ref, Lease.find_by_origin_ref(db, origin_ref)))
|
released_lease_list = list(map(lambda x: x.lease_ref, Lease.find_by_origin_ref(db, origin_ref)))
|
||||||
|
|||||||
52
app/util.py
52
app/util.py
@@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime, UTC, timedelta
|
from datetime import datetime, UTC, timedelta
|
||||||
from json import loads as json_loads
|
from json import loads as json_loads
|
||||||
from os.path import join, dirname, isfile
|
from os.path import join, dirname, isfile, isdir
|
||||||
|
|
||||||
from cryptography import x509
|
from cryptography import x509
|
||||||
from cryptography.hazmat._oid import NameOID
|
from cryptography.hazmat._oid import NameOID
|
||||||
@@ -38,14 +38,18 @@ class CASetup:
|
|||||||
SI_PRIVATE_KEY_FILENAME = 'si_private_key.pem'
|
SI_PRIVATE_KEY_FILENAME = 'si_private_key.pem'
|
||||||
SI_CERTIFICATE_FILENAME = 'si_certificate.pem'
|
SI_CERTIFICATE_FILENAME = 'si_certificate.pem'
|
||||||
|
|
||||||
def __init__(self, service_instance_ref: str):
|
def __init__(self, service_instance_ref: str, cert_path: str = None):
|
||||||
|
cert_path_prefix = join(dirname(__file__), 'cert')
|
||||||
|
if cert_path is not None and len(cert_path) > 0 and isdir(cert_path):
|
||||||
|
cert_path_prefix = cert_path
|
||||||
|
|
||||||
self.service_instance_ref = service_instance_ref
|
self.service_instance_ref = service_instance_ref
|
||||||
self.root_private_key_filename = join(dirname(__file__), 'cert', CASetup.ROOT_PRIVATE_KEY_FILENAME)
|
self.root_private_key_filename = join(cert_path_prefix, CASetup.ROOT_PRIVATE_KEY_FILENAME)
|
||||||
self.root_certificate_filename = join(dirname(__file__), 'cert', CASetup.ROOT_CERTIFICATE_FILENAME)
|
self.root_certificate_filename = join(cert_path_prefix, CASetup.ROOT_CERTIFICATE_FILENAME)
|
||||||
self.ca_private_key_filename = join(dirname(__file__), 'cert', CASetup.CA_PRIVATE_KEY_FILENAME)
|
self.ca_private_key_filename = join(cert_path_prefix, CASetup.CA_PRIVATE_KEY_FILENAME)
|
||||||
self.ca_certificate_filename = join(dirname(__file__), 'cert', CASetup.CA_CERTIFICATE_FILENAME)
|
self.ca_certificate_filename = join(cert_path_prefix, CASetup.CA_CERTIFICATE_FILENAME)
|
||||||
self.si_private_key_filename = join(dirname(__file__), 'cert', CASetup.SI_PRIVATE_KEY_FILENAME)
|
self.si_private_key_filename = join(cert_path_prefix, CASetup.SI_PRIVATE_KEY_FILENAME)
|
||||||
self.si_certificate_filename = join(dirname(__file__), 'cert', CASetup.SI_CERTIFICATE_FILENAME)
|
self.si_certificate_filename = join(cert_path_prefix, CASetup.SI_CERTIFICATE_FILENAME)
|
||||||
|
|
||||||
if not (isfile(self.root_private_key_filename)
|
if not (isfile(self.root_private_key_filename)
|
||||||
and isfile(self.root_certificate_filename)
|
and isfile(self.root_certificate_filename)
|
||||||
@@ -81,7 +85,20 @@ class CASetup:
|
|||||||
.not_valid_before(datetime.now(tz=UTC) - timedelta(days=1))
|
.not_valid_before(datetime.now(tz=UTC) - timedelta(days=1))
|
||||||
.not_valid_after(datetime.now(tz=UTC) + timedelta(days=365 * 10))
|
.not_valid_after(datetime.now(tz=UTC) + timedelta(days=365 * 10))
|
||||||
.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True)
|
.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True)
|
||||||
|
.add_extension(x509.KeyUsage(
|
||||||
|
digital_signature=False,
|
||||||
|
key_encipherment=False,
|
||||||
|
key_cert_sign=True,
|
||||||
|
key_agreement=False,
|
||||||
|
content_commitment=False,
|
||||||
|
data_encipherment=False,
|
||||||
|
crl_sign=True,
|
||||||
|
encipher_only=False,
|
||||||
|
decipher_only=False),
|
||||||
|
critical=True
|
||||||
|
)
|
||||||
.add_extension(x509.SubjectKeyIdentifier.from_public_key(my_root_public_key), critical=False)
|
.add_extension(x509.SubjectKeyIdentifier.from_public_key(my_root_public_key), critical=False)
|
||||||
|
.add_extension(x509.AuthorityKeyIdentifier.from_issuer_public_key(my_root_public_key), critical=False)
|
||||||
.sign(my_root_private_key, hashes.SHA256()))
|
.sign(my_root_private_key, hashes.SHA256()))
|
||||||
|
|
||||||
my_root_private_key_as_pem = my_root_private_key.private_bytes(
|
my_root_private_key_as_pem = my_root_private_key.private_bytes(
|
||||||
@@ -134,7 +151,6 @@ class CASetup:
|
|||||||
critical=True
|
critical=True
|
||||||
)
|
)
|
||||||
.add_extension(x509.SubjectKeyIdentifier.from_public_key(my_ca_public_key), critical=False)
|
.add_extension(x509.SubjectKeyIdentifier.from_public_key(my_ca_public_key), critical=False)
|
||||||
# .add_extension(x509.AuthorityKeyIdentifier.from_issuer_public_key(my_root_public_key), critical=False)
|
|
||||||
.add_extension(x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(
|
.add_extension(x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(
|
||||||
my_root_certificate.extensions.get_extension_for_class(x509.SubjectKeyIdentifier).value
|
my_root_certificate.extensions.get_extension_for_class(x509.SubjectKeyIdentifier).value
|
||||||
), critical=False)
|
), critical=False)
|
||||||
@@ -314,16 +330,22 @@ class Cert:
|
|||||||
def pem(self) -> bytes:
|
def pem(self) -> bytes:
|
||||||
return self.__cert.public_bytes(encoding=serialization.Encoding.PEM)
|
return self.__cert.public_bytes(encoding=serialization.Encoding.PEM)
|
||||||
|
|
||||||
|
def public_key(self) -> "PublicKey":
|
||||||
|
data = self.__cert.public_key().public_bytes(
|
||||||
|
encoding=serialization.Encoding.PEM,
|
||||||
|
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||||
|
)
|
||||||
|
return PublicKey(data=data)
|
||||||
|
|
||||||
def signature(self) -> bytes:
|
def signature(self) -> bytes:
|
||||||
return self.__cert.signature
|
return self.__cert.signature
|
||||||
|
|
||||||
|
def subject_key_identifier(self):
|
||||||
|
return self.__cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier).value.key_identifier
|
||||||
|
|
||||||
|
def authority_key_identifier(self):
|
||||||
|
return self.__cert.extensions.get_extension_for_class(x509.AuthorityKeyIdentifier).value.key_identifier
|
||||||
|
|
||||||
def load_file(filename: str) -> bytes:
|
|
||||||
log = logging.getLogger(f'{__name__}')
|
|
||||||
log.debug(f'Loading contents of file "{filename}')
|
|
||||||
with open(filename, 'rb') as file:
|
|
||||||
content = file.read()
|
|
||||||
return content
|
|
||||||
|
|
||||||
class DriverMatrix:
|
class DriverMatrix:
|
||||||
__DRIVER_MATRIX_FILENAME = 'static/driver_matrix.json'
|
__DRIVER_MATRIX_FILENAME = 'static/driver_matrix.json'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
fastapi==0.115.12
|
fastapi==0.116.1
|
||||||
uvicorn[standard]==0.34.1
|
uvicorn[standard]==0.35.0
|
||||||
python-jose[cryptography]==3.4.0
|
pyjwt==2.10.1
|
||||||
cryptography==44.0.2
|
cryptography==45.0.6
|
||||||
python-dateutil==2.9.0
|
python-dateutil==2.9.0
|
||||||
sqlalchemy==2.0.40
|
sqlalchemy==2.0.43
|
||||||
markdown==3.8
|
markdown==3.8.2
|
||||||
python-dotenv==1.1.0
|
python-dotenv==1.1.1
|
||||||
|
|||||||
73
test/main.py
73
test/main.py
@@ -4,11 +4,13 @@ from base64 import b64encode as b64enc
|
|||||||
from calendar import timegm
|
from calendar import timegm
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
from json import loads as json_loads, dumps as json_dumps
|
||||||
from uuid import uuid4, UUID
|
from uuid import uuid4, UUID
|
||||||
|
|
||||||
|
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
|
||||||
|
from cryptography.hazmat.primitives.hashes import SHA256
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from jose import jwt, jwk, jws
|
import jwt
|
||||||
from jose.constants import ALGORITHMS
|
|
||||||
from starlette.testclient import TestClient
|
from starlette.testclient import TestClient
|
||||||
|
|
||||||
# add relative path to use packages as they were in the app/ dir
|
# add relative path to use packages as they were in the app/ dir
|
||||||
@@ -26,18 +28,22 @@ ORIGIN_REF, ALLOTMENT_REF, SECRET = str(uuid4()), '20000000-0000-0000-0000-00000
|
|||||||
|
|
||||||
# CA & Signing
|
# CA & Signing
|
||||||
ca_setup = CASetup(service_instance_ref=INSTANCE_REF)
|
ca_setup = CASetup(service_instance_ref=INSTANCE_REF)
|
||||||
|
my_root_private_key = PrivateKey.from_file(ca_setup.root_private_key_filename)
|
||||||
my_root_certificate = Cert.from_file(ca_setup.root_certificate_filename)
|
my_root_certificate = Cert.from_file(ca_setup.root_certificate_filename)
|
||||||
|
my_ca_certificate = Cert.from_file(ca_setup.ca_certificate_filename)
|
||||||
|
my_ca_private_key = PrivateKey.from_file(ca_setup.ca_private_key_filename)
|
||||||
my_si_private_key = PrivateKey.from_file(ca_setup.si_private_key_filename)
|
my_si_private_key = PrivateKey.from_file(ca_setup.si_private_key_filename)
|
||||||
my_si_private_key_as_pem = my_si_private_key.pem()
|
my_si_private_key_as_pem = my_si_private_key.pem()
|
||||||
my_si_public_key = my_si_private_key.public_key()
|
my_si_public_key = my_si_private_key.public_key()
|
||||||
my_si_public_key_as_pem = my_si_private_key.public_key().pem()
|
my_si_public_key_as_pem = my_si_private_key.public_key().pem()
|
||||||
|
my_si_certificate = Cert.from_file(ca_setup.si_certificate_filename)
|
||||||
|
|
||||||
jwt_encode_key = jwk.construct(my_si_private_key_as_pem, algorithm=ALGORITHMS.RS256)
|
jwt_encode_key = my_si_private_key.pem()
|
||||||
jwt_decode_key = jwk.construct(my_si_public_key_as_pem, algorithm=ALGORITHMS.RS256)
|
jwt_decode_key = my_si_private_key.public_key().pem()
|
||||||
|
|
||||||
|
|
||||||
def __bearer_token(origin_ref: str) -> str:
|
def __bearer_token(origin_ref: str) -> str:
|
||||||
token = jwt.encode({"origin_ref": origin_ref}, key=jwt_encode_key, algorithm=ALGORITHMS.RS256)
|
# token = jwt.encode({"origin_ref": origin_ref}, key=jwt_encode_key, algorithm=ALGORITHMS.RS256)
|
||||||
|
token = jwt.encode(payload={"origin_ref": origin_ref}, key=jwt_encode_key, algorithm='RS256')
|
||||||
token = f'Bearer {token}'
|
token = f'Bearer {token}'
|
||||||
return token
|
return token
|
||||||
|
|
||||||
@@ -59,6 +65,31 @@ def test_signing():
|
|||||||
my_si_public_key.verify_signature(signature_get_header, b'Hello')
|
my_si_public_key.verify_signature(signature_get_header, b'Hello')
|
||||||
|
|
||||||
|
|
||||||
|
def test_keypair_and_certificates():
|
||||||
|
assert my_root_certificate.public_key().mod() == my_root_private_key.public_key().mod()
|
||||||
|
assert my_ca_certificate.public_key().mod() == my_ca_private_key.public_key().mod()
|
||||||
|
assert my_si_certificate.public_key().mod() == my_si_public_key.mod()
|
||||||
|
|
||||||
|
assert len(my_root_certificate.public_key().mod()) == 1024
|
||||||
|
assert len(my_ca_certificate.public_key().mod()) == 1024
|
||||||
|
assert len(my_si_certificate.public_key().mod()) == 512
|
||||||
|
|
||||||
|
#assert my_si_certificate.public_key().mod() != my_si_public_key.mod()
|
||||||
|
|
||||||
|
my_root_certificate.public_key().raw().verify(
|
||||||
|
my_ca_certificate.raw().signature,
|
||||||
|
my_ca_certificate.raw().tbs_certificate_bytes,
|
||||||
|
PKCS1v15(),
|
||||||
|
SHA256(),
|
||||||
|
)
|
||||||
|
my_ca_certificate.public_key().raw().verify(
|
||||||
|
my_si_certificate.raw().signature,
|
||||||
|
my_si_certificate.raw().tbs_certificate_bytes,
|
||||||
|
PKCS1v15(),
|
||||||
|
SHA256(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_index():
|
def test_index():
|
||||||
response = client.get('/')
|
response = client.get('/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
@@ -76,9 +107,9 @@ def test_config():
|
|||||||
|
|
||||||
|
|
||||||
def test_config_root_ca():
|
def test_config_root_ca():
|
||||||
response = client.get('/-/config/root-ca')
|
response = client.get('/-/config/root-certificate')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.content.decode('utf-8') == my_root_certificate.pem().decode('utf-8')
|
assert response.content.decode('utf-8').strip() == my_root_certificate.pem().decode('utf-8').strip()
|
||||||
|
|
||||||
|
|
||||||
def test_readme():
|
def test_readme():
|
||||||
@@ -103,21 +134,31 @@ def test_config_token():
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
nv_response_certificate_configuration = response.json().get('certificateConfiguration')
|
nv_response_certificate_configuration = response.json().get('certificateConfiguration')
|
||||||
|
|
||||||
|
nv_ca_chain = nv_response_certificate_configuration.get('caChain')[0].encode('utf-8')
|
||||||
|
nv_ca_chain = Cert(nv_ca_chain)
|
||||||
|
|
||||||
nv_response_public_cert = nv_response_certificate_configuration.get('publicCert').encode('utf-8')
|
nv_response_public_cert = nv_response_certificate_configuration.get('publicCert').encode('utf-8')
|
||||||
nv_jwt_decode_key = jwk.construct(nv_response_public_cert, algorithm=ALGORITHMS.RS256)
|
nv_response_public_key = nv_response_certificate_configuration.get('publicKey')
|
||||||
|
|
||||||
|
nv_si_certificate = Cert(nv_response_public_cert)
|
||||||
|
assert nv_si_certificate.public_key().mod() == nv_response_public_key.get('mod')[0]
|
||||||
|
assert nv_si_certificate.authority_key_identifier() == nv_ca_chain.subject_key_identifier()
|
||||||
|
|
||||||
|
# nv_jwt_decode_key = jwk.construct(nv_response_public_cert, algorithm=ALGORITHMS.RS256)
|
||||||
|
|
||||||
nv_response_config_token = response.json().get('configToken')
|
nv_response_config_token = response.json().get('configToken')
|
||||||
|
|
||||||
payload = jws.verify(nv_response_config_token, key=nv_jwt_decode_key, algorithms=ALGORITHMS.RS256)
|
#payload = jws.verify(nv_response_config_token, key=nv_jwt_decode_key, algorithms=ALGORITHMS.RS256)
|
||||||
payload = json.loads(payload)
|
payload = jwt.decode(jwt=nv_response_config_token, key=nv_si_certificate.public_key().pem(), algorithms=['RS256'], options={'verify_signature': False})
|
||||||
assert payload.get('iss') == 'NLS Service Instance'
|
assert payload.get('iss') == 'NLS Service Instance'
|
||||||
assert payload.get('aud') == 'NLS Licensed Client'
|
assert payload.get('aud') == 'NLS Licensed Client'
|
||||||
assert payload.get('service_instance_ref') == INSTANCE_REF
|
assert payload.get('service_instance_ref') == INSTANCE_REF
|
||||||
|
|
||||||
nv_si_public_key_configuration = payload.get('service_instance_public_key_configuration')
|
nv_si_public_key_configuration = payload.get('service_instance_public_key_configuration')
|
||||||
nv_si_public_key_me = nv_si_public_key_configuration.get('service_instance_public_key_me')
|
nv_si_public_key_me = nv_si_public_key_configuration.get('service_instance_public_key_me')
|
||||||
# assert nv_si_public_key_me.get('mod') == 1 #nv_si_public_key_mod
|
|
||||||
assert len(nv_si_public_key_me.get('mod')) == 512
|
assert len(nv_si_public_key_me.get('mod')) == 512 # nv_si_public_key_mod
|
||||||
assert nv_si_public_key_me.get('exp') == 65537 # nv_si_public_key_exp
|
assert nv_si_public_key_me.get('exp') == 65537 # nv_si_public_key_exp
|
||||||
|
|
||||||
|
|
||||||
@@ -189,7 +230,7 @@ def test_auth_v1_code():
|
|||||||
response = client.post('/auth/v1/code', json=payload)
|
response = client.post('/auth/v1/code', json=payload)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
payload = jwt.get_unverified_claims(token=response.json().get('auth_code'))
|
payload = jwt.decode(response.json().get('auth_code'), key=my_si_public_key_as_pem, algorithms=['RS256'])
|
||||||
assert payload.get('origin_ref') == ORIGIN_REF
|
assert payload.get('origin_ref') == ORIGIN_REF
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +247,7 @@ def test_auth_v1_token():
|
|||||||
"kid": "00000000-0000-0000-0000-000000000000"
|
"kid": "00000000-0000-0000-0000-000000000000"
|
||||||
}
|
}
|
||||||
payload = {
|
payload = {
|
||||||
"auth_code": jwt.encode(payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm=ALGORITHMS.RS256),
|
"auth_code": jwt.encode(payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm='RS256'),
|
||||||
"code_verifier": SECRET,
|
"code_verifier": SECRET,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +255,7 @@ def test_auth_v1_token():
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
token = response.json().get('auth_token')
|
token = response.json().get('auth_token')
|
||||||
payload = jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False})
|
payload = jwt.decode(token, key=jwt_decode_key, algorithms=['RS256'], options={'verify_signature': False})
|
||||||
assert payload.get('origin_ref') == ORIGIN_REF
|
assert payload.get('origin_ref') == ORIGIN_REF
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user