Skip to content

Commit

Permalink
Add signing and verification methods based on in-toto statements (sig…
Browse files Browse the repository at this point in the history
…store#193)

* signing and verification

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>

* changed behavior to raise an exception on failure
license
gitignore newline
add dependencies

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>

deps

* gitignore;requirements

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>

* dependencies

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>

* Bump frozen dependencies

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* import paths

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>

---------

Signed-off-by: Martin Sablotny <msablotny@nvidia.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Martin Sablotny <susperius@gmail.com>
Co-authored-by: susperius <1203928+susperius@users.noreply.github.com>
  • Loading branch information
susperius and susperius authored Jul 9, 2024
1 parent 373cc53 commit 99480e3
Show file tree
Hide file tree
Showing 19 changed files with 783 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__pycache__/
.venv/
.pytest_cache/
test_material/
7 changes: 7 additions & 0 deletions model_signing/install/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
absl-py
betterproto
cryptography
in-toto-attestation
pyOpenSSL
protobuf
psutil
sigstore
sigstore-protobuf-specs
36 changes: 33 additions & 3 deletions model_signing/install/requirements_Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
#
# pip-compile --generate-hashes --output-file=model_signing/install/requirements_Darwin.txt --strip-extras model_signing/install/requirements.in
#
absl-py==2.1.0 \
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
# via -r model_signing/install/requirements.in
annotated-types==0.7.0 \
--hash=sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 \
--hash=sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89
# via pydantic
betterproto==2.0.0b6 \
--hash=sha256:720ae92697000f6fcf049c69267d957f0871654c8b0d7458906607685daee784 \
--hash=sha256:a0839ec165d110a69d0d116f4d0e2bec8d186af4db826257931f0831dab73fcf
# via sigstore-protobuf-specs
# via
# -r model_signing/install/requirements.in
# sigstore-protobuf-specs
certifi==2024.7.4 \
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
Expand Down Expand Up @@ -196,6 +202,7 @@ cryptography==42.0.8 \
--hash=sha256:fa76fbb7596cc5839320000cdd5d0955313696d9511debab7ee7278fc8b5c84a \
--hash=sha256:fff12c88a672ab9c9c1cf7b0c80e3ad9e2ebd9d828d955c126be4fd3e5578c9e
# via
# -r model_signing/install/requirements.in
# pyopenssl
# sigstore
dnspython==2.6.1 \
Expand Down Expand Up @@ -231,6 +238,10 @@ idna==3.7 \
# via
# email-validator
# requests
in-toto-attestation==0.9.3 \
--hash=sha256:1f44d3f3bded1ed551e260c5e9f834ee05de03f1d2f360bada5a172c11d748ff \
--hash=sha256:cc0cf97417d94953b9fee6e9d415a11c59b4d47cee4f13746ffe935b28e3e8c4
# via -r model_signing/install/requirements.in
markdown-it-py==3.0.0 \
--hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \
--hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb
Expand Down Expand Up @@ -335,6 +346,21 @@ platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
# via sigstore
protobuf==5.27.2 \
--hash=sha256:0e341109c609749d501986b835f667c6e1e24531096cff9d34ae411595e26505 \
--hash=sha256:176c12b1f1c880bf7a76d9f7c75822b6a2bc3db2d28baa4d300e8ce4cde7409b \
--hash=sha256:354d84fac2b0d76062e9b3221f4abbbacdfd2a4d8af36bab0474f3a0bb30ab38 \
--hash=sha256:4fadd8d83e1992eed0248bc50a4a6361dc31bcccc84388c54c86e530b7f58863 \
--hash=sha256:54330f07e4949d09614707c48b06d1a22f8ffb5763c159efd5c0928326a91470 \
--hash=sha256:610e700f02469c4a997e58e328cac6f305f649826853813177e6290416e846c6 \
--hash=sha256:7fc3add9e6003e026da5fc9e59b131b8f22b428b991ccd53e2af8071687b4fce \
--hash=sha256:9e8f199bf7f97bd7ecebffcae45ebf9527603549b2b562df0fbc6d4d688f14ca \
--hash=sha256:a109916aaac42bff84702fb5187f3edadbc7c97fc2c99c5ff81dd15dcce0d1e5 \
--hash=sha256:b848dbe1d57ed7c191dfc4ea64b8b004a3f9ece4bf4d0d80a367b76df20bf36e \
--hash=sha256:f3ecdef226b9af856075f28227ff2c90ce3a594d092c39bee5513573f25e2714
# via
# -r model_signing/install/requirements.in
# in-toto-attestation
psutil==6.0.0 \
--hash=sha256:02b69001f44cc73c1c5279d02b30a817e339ceb258ad75997325e0e6169d8b35 \
--hash=sha256:1287c2b95f1c0a364d23bc6f2ea2365a8d4d9b726a3be7294296ff7ba97c17f0 \
Expand Down Expand Up @@ -471,7 +497,9 @@ pyjwt==2.8.0 \
pyopenssl==24.1.0 \
--hash=sha256:17ed5be5936449c5418d1cd269a1a9e9081bc54c17aed272b45856a3d3dc86ad \
--hash=sha256:cabed4bfaa5df9f1a16c0ef64a0cb65318b5cd077a7eda7d6970131ca2f41a6f
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
python-dateutil==2.9.0.post0 \
--hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
Expand Down Expand Up @@ -502,7 +530,9 @@ sigstore==3.0.0 \
sigstore-protobuf-specs==0.3.2 \
--hash=sha256:50c99fa6747a3a9c5c562a43602cf76df0b199af28f0e9d4319b6775630425ea \
--hash=sha256:cae041b40502600b8a633f43c257695d0222a94efa1e5110a7ec7ada78c39d99
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
sigstore-rekor-types==0.0.13 \
--hash=sha256:377fee942d5fc66437a4f54599472157149affaece9bbc7deb05e5b42f34ceba \
--hash=sha256:63e9306a26931ed74411911948c250da7c5adc51c53507227738170424e6ae2d
Expand Down
36 changes: 33 additions & 3 deletions model_signing/install/requirements_Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
#
# pip-compile --generate-hashes --output-file=model_signing/install/requirements_Linux.txt --strip-extras model_signing/install/requirements.in
#
absl-py==2.1.0 \
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
# via -r model_signing/install/requirements.in
annotated-types==0.7.0 \
--hash=sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 \
--hash=sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89
# via pydantic
betterproto==2.0.0b6 \
--hash=sha256:720ae92697000f6fcf049c69267d957f0871654c8b0d7458906607685daee784 \
--hash=sha256:a0839ec165d110a69d0d116f4d0e2bec8d186af4db826257931f0831dab73fcf
# via sigstore-protobuf-specs
# via
# -r model_signing/install/requirements.in
# sigstore-protobuf-specs
certifi==2024.7.4 \
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
Expand Down Expand Up @@ -196,6 +202,7 @@ cryptography==42.0.8 \
--hash=sha256:fa76fbb7596cc5839320000cdd5d0955313696d9511debab7ee7278fc8b5c84a \
--hash=sha256:fff12c88a672ab9c9c1cf7b0c80e3ad9e2ebd9d828d955c126be4fd3e5578c9e
# via
# -r model_signing/install/requirements.in
# pyopenssl
# sigstore
dnspython==2.6.1 \
Expand Down Expand Up @@ -231,6 +238,10 @@ idna==3.7 \
# via
# email-validator
# requests
in-toto-attestation==0.9.3 \
--hash=sha256:1f44d3f3bded1ed551e260c5e9f834ee05de03f1d2f360bada5a172c11d748ff \
--hash=sha256:cc0cf97417d94953b9fee6e9d415a11c59b4d47cee4f13746ffe935b28e3e8c4
# via -r model_signing/install/requirements.in
markdown-it-py==3.0.0 \
--hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \
--hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb
Expand Down Expand Up @@ -335,6 +346,21 @@ platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
# via sigstore
protobuf==5.27.2 \
--hash=sha256:0e341109c609749d501986b835f667c6e1e24531096cff9d34ae411595e26505 \
--hash=sha256:176c12b1f1c880bf7a76d9f7c75822b6a2bc3db2d28baa4d300e8ce4cde7409b \
--hash=sha256:354d84fac2b0d76062e9b3221f4abbbacdfd2a4d8af36bab0474f3a0bb30ab38 \
--hash=sha256:4fadd8d83e1992eed0248bc50a4a6361dc31bcccc84388c54c86e530b7f58863 \
--hash=sha256:54330f07e4949d09614707c48b06d1a22f8ffb5763c159efd5c0928326a91470 \
--hash=sha256:610e700f02469c4a997e58e328cac6f305f649826853813177e6290416e846c6 \
--hash=sha256:7fc3add9e6003e026da5fc9e59b131b8f22b428b991ccd53e2af8071687b4fce \
--hash=sha256:9e8f199bf7f97bd7ecebffcae45ebf9527603549b2b562df0fbc6d4d688f14ca \
--hash=sha256:a109916aaac42bff84702fb5187f3edadbc7c97fc2c99c5ff81dd15dcce0d1e5 \
--hash=sha256:b848dbe1d57ed7c191dfc4ea64b8b004a3f9ece4bf4d0d80a367b76df20bf36e \
--hash=sha256:f3ecdef226b9af856075f28227ff2c90ce3a594d092c39bee5513573f25e2714
# via
# -r model_signing/install/requirements.in
# in-toto-attestation
psutil==6.0.0 \
--hash=sha256:02b69001f44cc73c1c5279d02b30a817e339ceb258ad75997325e0e6169d8b35 \
--hash=sha256:1287c2b95f1c0a364d23bc6f2ea2365a8d4d9b726a3be7294296ff7ba97c17f0 \
Expand Down Expand Up @@ -471,7 +497,9 @@ pyjwt==2.8.0 \
pyopenssl==24.1.0 \
--hash=sha256:17ed5be5936449c5418d1cd269a1a9e9081bc54c17aed272b45856a3d3dc86ad \
--hash=sha256:cabed4bfaa5df9f1a16c0ef64a0cb65318b5cd077a7eda7d6970131ca2f41a6f
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
python-dateutil==2.9.0.post0 \
--hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
Expand Down Expand Up @@ -502,7 +530,9 @@ sigstore==3.0.0 \
sigstore-protobuf-specs==0.3.2 \
--hash=sha256:50c99fa6747a3a9c5c562a43602cf76df0b199af28f0e9d4319b6775630425ea \
--hash=sha256:cae041b40502600b8a633f43c257695d0222a94efa1e5110a7ec7ada78c39d99
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
sigstore-rekor-types==0.0.13 \
--hash=sha256:377fee942d5fc66437a4f54599472157149affaece9bbc7deb05e5b42f34ceba \
--hash=sha256:63e9306a26931ed74411911948c250da7c5adc51c53507227738170424e6ae2d
Expand Down
36 changes: 33 additions & 3 deletions model_signing/install/requirements_Windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
#
# pip-compile --generate-hashes --output-file=model_signing/install/requirements_Windows.txt --strip-extras model_signing/install/requirements.in
#
absl-py==2.1.0 \
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
# via -r model_signing/install/requirements.in
annotated-types==0.7.0 \
--hash=sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 \
--hash=sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89
# via pydantic
betterproto==2.0.0b6 \
--hash=sha256:720ae92697000f6fcf049c69267d957f0871654c8b0d7458906607685daee784 \
--hash=sha256:a0839ec165d110a69d0d116f4d0e2bec8d186af4db826257931f0831dab73fcf
# via sigstore-protobuf-specs
# via
# -r model_signing/install/requirements.in
# sigstore-protobuf-specs
certifi==2024.7.4 \
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
Expand Down Expand Up @@ -196,6 +202,7 @@ cryptography==42.0.8 \
--hash=sha256:fa76fbb7596cc5839320000cdd5d0955313696d9511debab7ee7278fc8b5c84a \
--hash=sha256:fff12c88a672ab9c9c1cf7b0c80e3ad9e2ebd9d828d955c126be4fd3e5578c9e
# via
# -r model_signing/install/requirements.in
# pyopenssl
# sigstore
dnspython==2.6.1 \
Expand Down Expand Up @@ -231,6 +238,10 @@ idna==3.7 \
# via
# email-validator
# requests
in-toto-attestation==0.9.3 \
--hash=sha256:1f44d3f3bded1ed551e260c5e9f834ee05de03f1d2f360bada5a172c11d748ff \
--hash=sha256:cc0cf97417d94953b9fee6e9d415a11c59b4d47cee4f13746ffe935b28e3e8c4
# via -r model_signing/install/requirements.in
markdown-it-py==3.0.0 \
--hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \
--hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb
Expand Down Expand Up @@ -335,6 +346,21 @@ platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
# via sigstore
protobuf==5.27.2 \
--hash=sha256:0e341109c609749d501986b835f667c6e1e24531096cff9d34ae411595e26505 \
--hash=sha256:176c12b1f1c880bf7a76d9f7c75822b6a2bc3db2d28baa4d300e8ce4cde7409b \
--hash=sha256:354d84fac2b0d76062e9b3221f4abbbacdfd2a4d8af36bab0474f3a0bb30ab38 \
--hash=sha256:4fadd8d83e1992eed0248bc50a4a6361dc31bcccc84388c54c86e530b7f58863 \
--hash=sha256:54330f07e4949d09614707c48b06d1a22f8ffb5763c159efd5c0928326a91470 \
--hash=sha256:610e700f02469c4a997e58e328cac6f305f649826853813177e6290416e846c6 \
--hash=sha256:7fc3add9e6003e026da5fc9e59b131b8f22b428b991ccd53e2af8071687b4fce \
--hash=sha256:9e8f199bf7f97bd7ecebffcae45ebf9527603549b2b562df0fbc6d4d688f14ca \
--hash=sha256:a109916aaac42bff84702fb5187f3edadbc7c97fc2c99c5ff81dd15dcce0d1e5 \
--hash=sha256:b848dbe1d57ed7c191dfc4ea64b8b004a3f9ece4bf4d0d80a367b76df20bf36e \
--hash=sha256:f3ecdef226b9af856075f28227ff2c90ce3a594d092c39bee5513573f25e2714
# via
# -r model_signing/install/requirements.in
# in-toto-attestation
psutil==6.0.0 \
--hash=sha256:02b69001f44cc73c1c5279d02b30a817e339ceb258ad75997325e0e6169d8b35 \
--hash=sha256:1287c2b95f1c0a364d23bc6f2ea2365a8d4d9b726a3be7294296ff7ba97c17f0 \
Expand Down Expand Up @@ -471,7 +497,9 @@ pyjwt==2.8.0 \
pyopenssl==24.1.0 \
--hash=sha256:17ed5be5936449c5418d1cd269a1a9e9081bc54c17aed272b45856a3d3dc86ad \
--hash=sha256:cabed4bfaa5df9f1a16c0ef64a0cb65318b5cd077a7eda7d6970131ca2f41a6f
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
python-dateutil==2.9.0.post0 \
--hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
Expand Down Expand Up @@ -502,7 +530,9 @@ sigstore==3.0.0 \
sigstore-protobuf-specs==0.3.2 \
--hash=sha256:50c99fa6747a3a9c5c562a43602cf76df0b199af28f0e9d4319b6775630425ea \
--hash=sha256:cae041b40502600b8a633f43c257695d0222a94efa1e5110a7ec7ada78c39d99
# via sigstore
# via
# -r model_signing/install/requirements.in
# sigstore
sigstore-rekor-types==0.0.13 \
--hash=sha256:377fee942d5fc66437a4f54599472157149affaece9bbc7deb05e5b42f34ceba \
--hash=sha256:63e9306a26931ed74411911948c250da7c5adc51c53507227738170424e6ae2d
Expand Down
6 changes: 3 additions & 3 deletions model_signing/install/requirements_dev_Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ ninja==1.11.1.1 \
--hash=sha256:ecf80cf5afd09f14dcceff28cb3f11dc90fb97c999c89307aea435889cb66877 \
--hash=sha256:fa2ba9d74acfdfbfbcf06fad1b8282de8a7a8c481d9dee45c859a8c93fcc1082
# via pytype
pycnite==2024.7.9 \
--hash=sha256:aece401e70e8b6bf369b3b33867c79a1b8bf584e68da9790de2f821503cebcf8 \
--hash=sha256:f07bea393ee4d5820013fae66db6cc091e8dc01fd3f6b367595108752f264872
platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
# via pylint
pycnite==2024.6.28 \
--hash=sha256:228b2cfae86fecc82e1bddb2b44b4890b337e0a778c1521a56546642dd28bfe4 \
--hash=sha256:e3f1f9697b49af8d4edc0e0d228b23fdfc56acc7878bc64378e46ddf8150d3a8
# via pytype
pydot==2.0.0 \
--hash=sha256:408a47913ea7bd5d2d34b274144880c1310c4aee901f353cf21fe2e526a4ea28 \
Expand Down
7 changes: 3 additions & 4 deletions model_signing/install/requirements_dev_Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,13 @@ ninja==1.11.1.1 \
--hash=sha256:ecf80cf5afd09f14dcceff28cb3f11dc90fb97c999c89307aea435889cb66877 \
--hash=sha256:fa2ba9d74acfdfbfbcf06fad1b8282de8a7a8c481d9dee45c859a8c93fcc1082
# via pytype
pycnite==2024.7.9 \
--hash=sha256:aece401e70e8b6bf369b3b33867c79a1b8bf584e68da9790de2f821503cebcf8 \
--hash=sha256:f07bea393ee4d5820013fae66db6cc091e8dc01fd3f6b367595108752f264872
platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
--hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
# via pylint
pycnite==2024.6.28 \
--hash=sha256:228b2cfae86fecc82e1bddb2b44b4890b337e0a778c1521a56546642dd28bfe4 \
--hash=sha256:e3f1f9697b49af8d4edc0e0d228b23fdfc56acc7878bc64378e46ddf8150d3a8
# via pytype
pydot==2.0.0 \
--hash=sha256:408a47913ea7bd5d2d34b274144880c1310c4aee901f353cf21fe2e526a4ea28 \
--hash=sha256:60246af215123fa062f21cd791be67dda23a6f280df09f68919e637a1e4f3235
Expand Down
13 changes: 13 additions & 0 deletions model_signing/signature/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
38 changes: 38 additions & 0 deletions model_signing/signature/encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from google.protobuf import json_format
from in_toto_attestation.v1 import statement_pb2 as statement_pb

PAYLOAD_TYPE = "application/vnd.in-toto+json"


def pae(statement: statement_pb.Statement) -> bytes:
"""Generates the PAE encoding of the statement.
See https://github.com/secure-systems-lab/dsse/blob/v1.0.0/protocol.md
for details.
Args:
statement (statement_pb.Statement): the statement to be encoded.
Returns:
bytes: the encoded statement as bytes.
"""
enc_payload = json_format.MessageToJson(statement).encode()
payload_len = len(enc_payload)
pae = ('DSSEV1'
f' {len(PAYLOAD_TYPE)} {PAYLOAD_TYPE}'
f' {payload_len} {enc_payload}')
pae = pae.encode()
return pae
Loading

0 comments on commit 99480e3

Please sign in to comment.