-
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.
feat: complete the verification part
- Loading branch information
1 parent
68580c5
commit 2c05210
Showing
11 changed files
with
546 additions
and
47 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
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 |
---|---|---|
|
@@ -11,4 +11,5 @@ demo/input/.DS_Store | |
.env | ||
temp/ | ||
venv | ||
input/ | ||
input/ | ||
temp.txt |
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 |
---|---|---|
|
@@ -66,7 +66,7 @@ docker build -t my-proof . | |
``` | ||
|
||
``` | ||
docker run --rm --volume $(pwd)/demo/sealed:/sealed --volume $(pwd)/demo/input:/input --volume $(pwd)/demo/output:/output --env [email protected] my-proof | ||
docker run --rm --volume $(pwd)/demo/sealed:/sealed --volume $(pwd)/demo/input:/input --volume $(pwd)/demo/output:/output -e AWS_ACCESS_KEY_ID=<your-access-key-id> -e AWS_SECRET_ACCESS_KEY=<your-secret-access-key> my-proof | ||
``` | ||
|
||
## Building and Releasing | ||
|
@@ -119,7 +119,7 @@ curl -L https://address/of/gsc-my-proof.tar.gz | docker load | |
To run the image: | ||
|
||
``` | ||
docker run --rm --volume /gsc-my-proof/input:/input --volume /gsc-my-proof/output:/output --device /dev/sgx_enclave:/dev/sgx_enclave --volume /var/run/aesmd:/var/run/aesmd --volume /mnt/gsc-my-proof/sealed:/sealed --env [email protected] gsc-my-proof | ||
docker run --rm --volume /gsc-my-proof/input:/input --volume /gsc-my-proof/output:/output --device /dev/sgx_enclave:/dev/sgx_enclave --volume /var/run/aesmd:/var/run/aesmd --volume /mnt/gsc-my-proof/sealed:/sealed gsc-my-proof | ||
``` | ||
|
||
Remember to populate the `/input` directory with the files you want to process. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import boto3 | ||
import json | ||
import os | ||
from datetime import datetime | ||
|
||
def download_json_from_s3(bucket_name, file_key, aws_access_key_id, aws_secret_access_key): | ||
|
||
# Initialize S3 client | ||
s3 = boto3.client( | ||
's3', | ||
aws_access_key_id=aws_access_key_id, | ||
aws_secret_access_key=aws_secret_access_key | ||
) | ||
|
||
try: | ||
# Download the file from S3 | ||
response = s3.get_object(Bucket=bucket_name, Key=file_key) | ||
|
||
# Read the content and parse it as JSON | ||
content = response['Body'].read().decode('utf-8') | ||
json_data = json.loads(content) | ||
|
||
return json_data | ||
except Exception as e: | ||
print(f"Error downloading or parsing JSON from S3: {str(e)}") | ||
return None | ||
|
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,96 @@ | ||
import boto3 | ||
import json | ||
from datetime import datetime | ||
import logging | ||
import hashlib | ||
|
||
class HashManager: | ||
def __init__(self, bucket_name, remote_file_key, aws_access_key_id, aws_secret_access_key): | ||
# Initialize S3 client with credentials | ||
self.s3_client = boto3.client( | ||
's3', | ||
aws_access_key_id=aws_access_key_id, | ||
aws_secret_access_key=aws_secret_access_key | ||
) | ||
self.bucket_name = bucket_name | ||
self.remote_file_key = remote_file_key | ||
|
||
def _initialize_empty_hash_file(self): | ||
"""Initialize an empty hash file in S3""" | ||
data = { | ||
'hashes': [], | ||
'lastUpdated': datetime.utcnow().isoformat() + 'Z' | ||
} | ||
self.s3_client.put_object( | ||
Bucket=self.bucket_name, | ||
Key=self.remote_file_key, | ||
Body=json.dumps(data, indent=2), | ||
ContentType='application/json' | ||
) | ||
return [] | ||
|
||
def get_remote_hashes(self): | ||
"""Fetch hashes from remote S3 JSON file""" | ||
try: | ||
response = self.s3_client.get_object( | ||
Bucket=self.bucket_name, | ||
Key=self.remote_file_key | ||
) | ||
data = json.loads(response['Body'].read().decode('utf-8')) | ||
return data.get('hashes', []) | ||
except self.s3_client.exceptions.NoSuchKey: | ||
# If file doesn't exist, create it and return empty list | ||
return self._initialize_empty_hash_file() | ||
except Exception as e: | ||
logging.error(f"Error fetching remote hashes: {str(e)}") | ||
raise | ||
|
||
def update_remote_hashes(self, new_hashes): | ||
"""Update remote JSON file with new hashes""" | ||
try: | ||
data = { | ||
'hashes': new_hashes, | ||
'lastUpdated': datetime.utcnow().isoformat() + 'Z' | ||
} | ||
|
||
self.s3_client.put_object( | ||
Bucket=self.bucket_name, | ||
Key=self.remote_file_key, | ||
Body=json.dumps(data, indent=2), | ||
ContentType='application/json' | ||
) | ||
return True | ||
except Exception as e: | ||
logging.error(f"Error updating remote hashes: {str(e)}") | ||
raise | ||
|
||
def add_hash(self, new_hash): | ||
"""Add a single hash to the remote file""" | ||
current_hashes = self.get_remote_hashes() | ||
if new_hash not in current_hashes: | ||
current_hashes.append(new_hash) | ||
self.update_remote_hashes(current_hashes) | ||
return True | ||
return False | ||
|
||
def remove_hash(self, hash_to_remove): | ||
"""Remove a hash from the remote file""" | ||
current_hashes = self.get_remote_hashes() | ||
if hash_to_remove in current_hashes: | ||
current_hashes.remove(hash_to_remove) | ||
self.update_remote_hashes(current_hashes) | ||
return True | ||
return False | ||
|
||
def generate_hash(self, input_string): | ||
"""Generate a SHA-256 hash from an input string | ||
Args: | ||
input_string (str): The string to hash | ||
Returns: | ||
str: The hexadecimal representation of the hash | ||
""" | ||
# Encode the string to bytes and generate hash | ||
hash_object = hashlib.sha256(str(input_string).encode()) | ||
return hash_object.hexdigest() |
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.