Skip to content

Commit

Permalink
fix: make upload-client.py work with HMAC correctl
Browse files Browse the repository at this point in the history
  • Loading branch information
tuddman committed Apr 1, 2024
1 parent d3566c9 commit 5a486c8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
uploads/
myenv
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ A simple, asynchronous file server to support XMTP Message History transfers. Ru

Ensure you have the following installed:

- Rust and Cargo. You can install them from [https://rustup.rs/](https://rustup.rs/)
- Rust and Cargo. You can install them both from [https://rustup.rs](https://rustup.rs)
- To run the example uploader, ensure python is installed on your system.

Set the `SECRET_KEY` environment variable.

export SECRET_KEY=super-long-super-secret-unique-key-goes-here


### Installing

Expand Down Expand Up @@ -45,6 +51,22 @@ Example using curl:

curl http://0.0.0.0:5558/files/{id} --output retrieved_file.aes

### Example Client Uploader

Set up a virtual environment

python3 -m venv myenv
source myenv/bin/activate

Install the dependencies

pip3 install -r requirements.txt

Run the uploader script

python3 upload-client.py


## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0
35 changes: 24 additions & 11 deletions upload-client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@

import hmac
import hashlib
import requests
import os

file_path = "test_bundle.txt"

secret_key = os.environ.get("SECRET_KEY", "").encode()

# Ensure the secret key is not empty
if not secret_key:
print("SECRET_KEY environment variable is not set.")
exit(1)

# The shared secret key
secret_key = b"your-secret-key"
# The request payload consisting of a message history bundle
with open(file_path, 'rb') as file:
file_content = file.read()
print(file_content)

# The request payload
payload = b"your request payload"
# Compute the HMAC
hmac_instance = hmac.new(secret_key, file_content, hashlib.sha256)
hmac_hex = hmac_instance.hexdigest()
print(hmac_hex)

# Compute the HMAC
hmac_instance = hmac.new(secret_key, payload, hashlib.sha256)
hmac_hex = hmac_instance.hexdigest()
# Send the request with the HMAC header
headers = {'X-HMAC': hmac_hex}
response = requests.post('http://0.0.0.0:5558/upload', headers=headers, data=file_content)

# Send the request with the HMAC header
headers = {'X-HMAC': hmac_hex}
response = requests.post('http://0.0.0.0:5558/upload', headers=headers, data=payload)
# Log the response
print(f"Response Status Code: {response.status_code}")
print(f"Response Body: {response.text}")

0 comments on commit 5a486c8

Please sign in to comment.