forked from secure-systems-lab/securesystemslib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very bare bones Signer for Google Cloud KMS: Private keys live in KMS, signing happens in KMS (although payloading hash happens in Signer). This is not super usable without issue secure-systems-lab#447 but demonstrates the simplicity. With 447, the usage pattern nwould be signer = Signer( "gcpkms://projects/openssf/locations/global/keyRings/securesystemslib-test-keyring/cryptoKeys/securesystemslib-test-key/cryptoKeyVersions/1", pubkey ) so all GCP specific details are in the private key URI. Key creation is not supported at this point.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
name: Test GCP KMS | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-20.04 | ||
permissions: | ||
id-token: 'write' | ||
steps: | ||
- uses: 'actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8' | ||
- name: 'Authenticate to Google Cloud' | ||
id: 'auth' | ||
uses: 'google-github-actions/auth@c4799db9111fba4461e9f9da8732e5057b394f72' | ||
with: | ||
token_format: 'access_token' | ||
workload_identity_provider: 'projects/367732848534/locations/global/workloadIdentityPools/securesystemslib-test-pool/providers/securesystemslib-test-provider' | ||
service_account: '[email protected]' | ||
|
||
- name: 'Install google-cloud-kms' | ||
run: pip install google-cloud-kms | ||
|
||
- name: 'Sign with KMSSigner' | ||
run: | | ||
python3 test-signer.py | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from securesystemslib import keys | ||
from securesystemslib.signer import GCPSigner | ||
|
||
data = "data".encode("utf-8") | ||
|
||
pubkey = { | ||
"keyid": "abcd", | ||
"keytype": "ecdsa", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyval": { | ||
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEDJchWswdXOBpMqXkekAzwuWjL+Hx\ncw2ZonDbixh/wTf1FkpxmT8Aq6/WN6NNXOW4Rw9Lua2aKLZo2ZeNrk2VLA==\n-----END PUBLIC KEY-----\n" | ||
}, | ||
} | ||
|
||
|
||
gcp_id = "projects/openssf/locations/global/keyRings/securesystemslib-test-keyring/cryptoKeys/securesystemslib-test-key/cryptoKeyVersions/1" | ||
# This should be parsed from pubkey | ||
hash_algo = "sha256" | ||
|
||
signer = GCPSigner(gcp_id, hash_algo, pubkey["keyid"]) | ||
sig = signer.sign(data) | ||
|
||
if not keys.verify_signature(pubkey, sig.to_dict(), data): | ||
raise RuntimeError( | ||
f"Failed to verify signature by {pubkey['keyid']}: sig was {sig.to_dict()}" | ||
) | ||
print("OK") |