feat: adopt smolmail protocol 1.1 with accept tokens and leave-mail-on-server
This commit is contained in:
parent
eef7bf9b1d
commit
d6fa097626
11 changed files with 911 additions and 232 deletions
|
|
@ -23,6 +23,7 @@ import nacl.bindings as sodium
|
|||
from noise.connection import Keypair, NoiseConnection
|
||||
|
||||
LABEL_SEAL, LABEL_MSG, LABEL_ID = b"smolmail/1 seal", b"smolmail/1 msg", b"smolmail/1 id"
|
||||
LABEL_IDENTITY, LABEL_ACCEPT, LABEL_MAC = b"smolmail/1 identity", b"smolmail/1 accept", b"smolmail/1 mac"
|
||||
TIME = 1730000000 # fixed so the envelope vector is reproducible
|
||||
|
||||
|
||||
|
|
@ -139,9 +140,26 @@ def main() -> int:
|
|||
"sender_seed": sender_seed.hex(), "recipient_seed": recipient_seed.hex(),
|
||||
"esk": esk.hex(), "body": body.hex(), "time": TIME,
|
||||
"envelope": envelope.hex(),
|
||||
"id": hashlib.sha256(LABEL_ID + envelope).digest()[:16].hex(),
|
||||
"id": hashlib.sha256(LABEL_ID + envelope).digest().hex(),
|
||||
"unpadded_plaintext_len": len(plaintext)}
|
||||
|
||||
# --- §2/§5.8: master-derived rotation seeds and accept tokens
|
||||
master = seed("master")
|
||||
correspondent = seed("correspondent identity")
|
||||
accept_key = hkdf_sha256(master, b"", LABEL_ACCEPT, 32)
|
||||
token = hmac.new(accept_key, correspondent, hashlib.sha256).digest()
|
||||
mid = seed("token message id")
|
||||
out["tokens"] = {
|
||||
"master": master.hex(),
|
||||
"identity_seed_0": hkdf_sha256(master, b"", LABEL_IDENTITY + struct.pack(">I", 0), 32).hex(),
|
||||
"identity_seed_1": hkdf_sha256(master, b"", LABEL_IDENTITY + struct.pack(">I", 1), 32).hex(),
|
||||
"accept_key": accept_key.hex(),
|
||||
"correspondent": correspondent.hex(),
|
||||
"token": token.hex(),
|
||||
"message_id": mid.hex(),
|
||||
"accept_mac": hmac.new(token, LABEL_MAC + mid, hashlib.sha256).digest().hex(),
|
||||
}
|
||||
|
||||
# --- Noise NX transcript with every key fixed
|
||||
i_e, r_e, s_priv = seed("nx initiator eph"), seed("nx responder eph"), seed("nx server static")
|
||||
s_pub = sodium.crypto_scalarmult_base(s_priv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue