-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New version of Attestation SDK and Local Verifier. (#23)
* 1. Added new version of Attestation SDK and Local GPU Verifier 2. Updated RIM documentation * 1. Patched Local verifier's logic in comparing vBIOS version numbers 2. Added 1.2.0 packages for Attestation SDK * Removed vBIOS RIMs from rims directory
- Loading branch information
1 parent
6296b7a
commit 8db7fb5
Showing
45 changed files
with
358 additions
and
3,200 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
Binary file not shown.
Binary file added
BIN
+13.9 KB
guest_tools/attestation_sdk/dist/nv_attestation_sdk-1.2.0-py3-none-any.whl
Binary file not shown.
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
59 changes: 59 additions & 0 deletions
59
guest_tools/attestation_sdk/src/nv_attestation_sdk/gpu/attest_gpu_local.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# | ||
# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
import json | ||
import jwt | ||
import requests | ||
import base64 | ||
from cryptography.hazmat.primitives import serialization | ||
from cryptography.x509 import load_der_x509_certificate | ||
from cryptography.hazmat.backends import default_backend | ||
from nv_attestation_sdk import attestation | ||
from urllib.parse import urlparse | ||
from nv_attestation_sdk.gpu import gpu_utils | ||
|
||
def validate_gpu_token(verifier, gpu_token: str, policy: str): | ||
if policy == "" or gpu_token == "": | ||
return False | ||
decoded_token = jwt.decode(gpu_token, algorithms='HS256', verify=False, key="secret") | ||
auth_rules = gpu_utils.get_auth_rules(policy) | ||
return gpu_utils.validate_gpu_token_with_policy(decoded_token, auth_rules) | ||
|
||
def attest(nonce): | ||
attestation_result = False | ||
from verifier import cc_admin | ||
jwt_token = "" | ||
try: | ||
params = {"verbose": False, | ||
"test_no_gpu": False, | ||
"driver_rim": None, | ||
"vbios_rim": None, | ||
"user_mode": True, | ||
'rim_root_cert': None, | ||
'rim_service_url': None, | ||
'allow_hold_cert': True, | ||
'nonce': nonce} | ||
attestation_result, jwt_token = cc_admin.attest(params) | ||
except Exception as e: | ||
print("\tException: ", e) | ||
jwt_token = get_err_eat_token() | ||
return attestation_result, jwt_token | ||
|
||
def get_err_eat_token(errCode=1, errMsg="GPU_ATTESTATION_ERR"): | ||
errJson = {'x-nv-err-message': errMsg, 'x-nv-err-code': errCode} | ||
return jwt.encode(errJson, | ||
'secret', | ||
"HS256") | ||
|
||
def build_payload(nonce, evidence, cert_chain): | ||
data = dict() | ||
data['nonce'] = nonce | ||
encoded_evidence_bytes = evidence.encode("ascii") | ||
encoded_evidence = base64.b64encode(encoded_evidence_bytes) | ||
encoded_evidence = encoded_evidence.decode('utf-8') | ||
data['evidence'] = encoded_evidence | ||
data['arch'] = 'HOPPER' | ||
data['certificate'] = str(cert_chain) | ||
payload = json.dumps(data) | ||
return payload | ||
|
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
21 changes: 21 additions & 0 deletions
21
guest_tools/attestation_sdk/src/nv_attestation_sdk/gpu/gpu_utils.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
|
||
def validate_gpu_token_with_policy(token: str, auth_rules: str): | ||
for key in auth_rules: | ||
if key in token: | ||
if type(auth_rules[key]) is dict: | ||
return validate_gpu_token_with_policy(token[key], auth_rules[key]) | ||
else: | ||
if token[key] != auth_rules[key]: | ||
print("\t[ERROR] Invalid token. Authorized claims does not match the appraisal policy: ", key) | ||
return False | ||
else: | ||
print("\t[ERROR] Invalid token. Authorized claims does not match the appraisal policy: ", key) | ||
return False | ||
return True | ||
|
||
def get_auth_rules(policy: str): | ||
if policy == "": | ||
return None | ||
policy_obj = json.loads(policy) | ||
return policy_obj['authorization-rules'] |
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,15 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
from nv_attestation_sdk.gpu import attest_gpu_remote | ||
import secrets | ||
nonce = secrets.token_bytes(32).hex() | ||
|
||
evidence = attest_gpu_remote.generate_evidence(nonce) | ||
print(evidence) | ||
|
||
verify_result = attest_gpu_remote.verify_evidence(nonce,evidence, "https://nras.attestation.nvidia.com/v1/attest/gpu") | ||
|
||
print(verify_result) |
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
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
Oops, something went wrong.