Spaces:
Sleeping
Sleeping
Igor commited on
Debug: Print traceback on 500 error in server
Browse files
server.py
CHANGED
|
@@ -59,11 +59,11 @@ def encrypt_message(req: EncryptRequest):
|
|
| 59 |
if len(recipient_pub_bytes) != 32:
|
| 60 |
raise HTTPException(status_code=400, detail="Invalid Public Signal (must be 32 bytes)")
|
| 61 |
|
| 62 |
-
# Derive Secret
|
| 63 |
-
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
encrypted_payload = CRYPTO.encrypt_message(
|
| 67 |
|
| 68 |
# Steganography
|
| 69 |
raw_words = [WORDLIST[b] for b in encrypted_payload]
|
|
@@ -76,6 +76,8 @@ def encrypt_message(req: EncryptRequest):
|
|
| 76 |
return {"shitpost": output}
|
| 77 |
|
| 78 |
except Exception as e:
|
|
|
|
|
|
|
| 79 |
raise HTTPException(status_code=500, detail=str(e))
|
| 80 |
|
| 81 |
@app.post("/decrypt")
|
|
@@ -88,15 +90,20 @@ def decrypt_message(req: DecryptRequest):
|
|
| 88 |
|
| 89 |
sender_pub_bytes = decode_string(req.sender_public_signal)
|
| 90 |
|
| 91 |
-
# Derive Secret
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Parse Shitpost
|
| 95 |
# Note: decode_string handles the stealth/punctuation stripping now
|
| 96 |
payload = decode_string(req.ciphertext_shitpost)
|
| 97 |
|
| 98 |
-
# Decrypt
|
| 99 |
-
plaintext = CRYPTO.decrypt_message(
|
| 100 |
|
| 101 |
return {"message": plaintext}
|
| 102 |
|
|
|
|
| 59 |
if len(recipient_pub_bytes) != 32:
|
| 60 |
raise HTTPException(status_code=400, detail="Invalid Public Signal (must be 32 bytes)")
|
| 61 |
|
| 62 |
+
# Derive Secret (Returns {'tx': bytes, 'rx': bytes})
|
| 63 |
+
keys = CRYPTO.derive_shared_secret(sender_priv, recipient_pub_bytes)
|
| 64 |
|
| 65 |
+
# Use TX key for encryption
|
| 66 |
+
encrypted_payload = CRYPTO.encrypt_message(keys['tx'], req.message)
|
| 67 |
|
| 68 |
# Steganography
|
| 69 |
raw_words = [WORDLIST[b] for b in encrypted_payload]
|
|
|
|
| 76 |
return {"shitpost": output}
|
| 77 |
|
| 78 |
except Exception as e:
|
| 79 |
+
import traceback
|
| 80 |
+
traceback.print_exc()
|
| 81 |
raise HTTPException(status_code=500, detail=str(e))
|
| 82 |
|
| 83 |
@app.post("/decrypt")
|
|
|
|
| 90 |
|
| 91 |
sender_pub_bytes = decode_string(req.sender_public_signal)
|
| 92 |
|
| 93 |
+
# Derive Secret (Returns {'tx': bytes, 'rx': bytes})
|
| 94 |
+
# Note: derive_shared_secret handles the sort order internally.
|
| 95 |
+
# If I am Recipient (Alice), and Sender is Bob:
|
| 96 |
+
# derive(AlicePriv, BobPub) -> returns Alice's View.
|
| 97 |
+
# Alice's View: 'rx' is the key Bob used to encrypt.
|
| 98 |
+
|
| 99 |
+
keys = CRYPTO.derive_shared_secret(recipient_priv, sender_pub_bytes)
|
| 100 |
|
| 101 |
# Parse Shitpost
|
| 102 |
# Note: decode_string handles the stealth/punctuation stripping now
|
| 103 |
payload = decode_string(req.ciphertext_shitpost)
|
| 104 |
|
| 105 |
+
# Decrypt using RX key
|
| 106 |
+
plaintext = CRYPTO.decrypt_message(keys['rx'], payload)
|
| 107 |
|
| 108 |
return {"message": plaintext}
|
| 109 |
|