mailcycle 0.4.2__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mailcycle-0.4.2 → mailcycle-0.5.0}/PKG-INFO +1 -1
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/_version.py +1 -1
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/identity.py +51 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_vectors.py +27 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/.gitignore +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/LICENSE +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/README.md +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/live/README.md +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/pyproject.toml +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/__init__.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/_encoding.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/client.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/__init__.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/asymmetric.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/authproof.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/cipher.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/mnemonic.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/primitives.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/sealedbox.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/crypto/wordlist.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/errors.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/events.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/http.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/keys.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/mail.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/models.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/pairing.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/py.typed +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/trackers.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/src/mailcycle/webhooks.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/conftest.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_client.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_cross_implementation.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_events.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_pairing.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_pairing_reference.py +0 -0
- {mailcycle-0.4.2 → mailcycle-0.5.0}/tests/test_trackers.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mailcycle
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Python client for the Mailcycle API. Create addresses that receive mail, read and decrypt it on your machine, send, and listen for events.
|
|
5
5
|
Project-URL: Homepage, https://mailcycle.email/
|
|
6
6
|
Project-URL: Documentation, https://docs.mailcycle.email/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# The one place the version is written. pyproject.toml reads it from here.
|
|
2
|
-
__version__ = "0.
|
|
2
|
+
__version__ = "0.5.0"
|
|
@@ -24,11 +24,16 @@ from __future__ import annotations
|
|
|
24
24
|
import re
|
|
25
25
|
from dataclasses import dataclass
|
|
26
26
|
|
|
27
|
+
from cryptography.hazmat.primitives import hashes
|
|
28
|
+
from cryptography.hazmat.primitives.kdf.hkdf import HKDFExpand
|
|
29
|
+
|
|
27
30
|
from .._encoding import to_b64u
|
|
28
31
|
from .mnemonic import phrase_to_seed
|
|
29
32
|
from .primitives import hmac_sha256, public_key_from, sha256
|
|
30
33
|
|
|
31
34
|
_LABEL_PREFIX = "mailcycle/v1/"
|
|
35
|
+
_LABEL_PREFIX_V2 = "mailcycle/v2/"
|
|
36
|
+
_MAX_EPOCH = 2**31 - 1
|
|
32
37
|
_SAFE_LABEL = re.compile(r"^[A-Za-z0-9_-]{1,64}$")
|
|
33
38
|
|
|
34
39
|
|
|
@@ -41,6 +46,27 @@ def subkey(seed: bytes, label: str, length: int) -> bytes:
|
|
|
41
46
|
return (first + second)[:length]
|
|
42
47
|
|
|
43
48
|
|
|
49
|
+
def subkey_v2(key: bytes, label: str, length: int) -> bytes:
|
|
50
|
+
"""A labelled subkey under the version 2 derivation.
|
|
51
|
+
|
|
52
|
+
HKDF-Expand-SHA256 (RFC 5869) with the key as the PRK and
|
|
53
|
+
`mailcycle/v2/<label>` as the info. `subkey` concatenates its label and
|
|
54
|
+
makes its second block by appending `/2`, so one label's second block can
|
|
55
|
+
be another label's first; here the counter sits outside the label, so two
|
|
56
|
+
labels share output only if they are the same label. Only new kinds of key
|
|
57
|
+
use it, so no account id or existing key changes.
|
|
58
|
+
"""
|
|
59
|
+
if not 1 <= length <= 255 * 32:
|
|
60
|
+
raise ValueError("A subkey is 1 to 8160 bytes.")
|
|
61
|
+
info = f"{_LABEL_PREFIX_V2}{label}".encode()
|
|
62
|
+
return HKDFExpand(algorithm=hashes.SHA256(), length=length, info=info).derive(key)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _assert_epoch(epoch: int) -> None:
|
|
66
|
+
if isinstance(epoch, bool) or not isinstance(epoch, int) or not 0 <= epoch <= _MAX_EPOCH:
|
|
67
|
+
raise ValueError("A key epoch is a whole number from 0 to 2147483647.")
|
|
68
|
+
|
|
69
|
+
|
|
44
70
|
def _assert_safe_label(identifier: str) -> None:
|
|
45
71
|
"""Refuses an identifier that could reshape the derivation label around it.
|
|
46
72
|
|
|
@@ -116,6 +142,31 @@ def address_key_pair(vault_key: bytes, address_id: str) -> tuple[bytes, bytes]:
|
|
|
116
142
|
return private_key, public_key_from(private_key)
|
|
117
143
|
|
|
118
144
|
|
|
145
|
+
def address_key_at(vault_key: bytes, address_id: str, epoch: int) -> bytes:
|
|
146
|
+
"""The address's symmetric key at a key epoch.
|
|
147
|
+
|
|
148
|
+
Epoch 0 is `address_key`, the key every address has had from the start.
|
|
149
|
+
Later epochs come from `subkey_v2`: under `subkey`, `inbox/<id>/2` would be
|
|
150
|
+
the second half of epoch 0's key. Old epochs stay derivable, so mail sealed
|
|
151
|
+
under them still opens.
|
|
152
|
+
"""
|
|
153
|
+
_assert_epoch(epoch)
|
|
154
|
+
if epoch == 0:
|
|
155
|
+
return address_key(vault_key, address_id)
|
|
156
|
+
_assert_safe_label(address_id)
|
|
157
|
+
return subkey_v2(vault_key, f"inbox/{address_id}/{epoch}", 64)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def address_key_pair_at(vault_key: bytes, address_id: str, epoch: int) -> tuple[bytes, bytes]:
|
|
161
|
+
"""The address's X25519 (private, public) pair at a key epoch. Epoch 0 is `address_key_pair`."""
|
|
162
|
+
_assert_epoch(epoch)
|
|
163
|
+
if epoch == 0:
|
|
164
|
+
return address_key_pair(vault_key, address_id)
|
|
165
|
+
_assert_safe_label(address_id)
|
|
166
|
+
private_key = subkey_v2(vault_key, f"inbox-sealing/{address_id}/{epoch}", 32)
|
|
167
|
+
return private_key, public_key_from(private_key)
|
|
168
|
+
|
|
169
|
+
|
|
119
170
|
def fingerprint(account_id: str) -> str:
|
|
120
171
|
"""Short, human-comparable fingerprint, as the app shows when pairing."""
|
|
121
172
|
digest = sha256(account_id.encode("utf-8")).hex()[:12].upper()
|
|
@@ -31,10 +31,13 @@ from mailcycle.crypto.authproof import prove_account
|
|
|
31
31
|
from mailcycle.crypto.cipher import open_box, open_json, seal, seal_json
|
|
32
32
|
from mailcycle.crypto.identity import (
|
|
33
33
|
address_key,
|
|
34
|
+
address_key_at,
|
|
34
35
|
address_key_pair,
|
|
36
|
+
address_key_pair_at,
|
|
35
37
|
auth_verifier,
|
|
36
38
|
identity_from_seed,
|
|
37
39
|
subkey,
|
|
40
|
+
subkey_v2,
|
|
38
41
|
)
|
|
39
42
|
from mailcycle.crypto.mnemonic import phrase_to_seed, validate_phrase
|
|
40
43
|
from mailcycle.errors import DecryptionError, MailcycleError
|
|
@@ -107,6 +110,30 @@ def test_an_id_that_could_reshape_a_derivation_label_is_refused():
|
|
|
107
110
|
address_key_pair(VAULT_KEY, identifier)
|
|
108
111
|
|
|
109
112
|
|
|
113
|
+
# -- the version 2 derivation and key epochs ---------------------------
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@pytest.mark.parametrize("entry", VECTORS["subkeysV2"], ids=_ids(VECTORS["subkeysV2"], "label"))
|
|
117
|
+
def test_subkeys_v2(entry):
|
|
118
|
+
assert to_b64u(subkey_v2(from_b64u(entry["key"]), entry["label"], entry["length"])) == entry["out"]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@pytest.mark.parametrize("entry", VECTORS["epochs"], ids=_ids(VECTORS["epochs"], "epoch"))
|
|
122
|
+
def test_address_keys_at_an_epoch(entry):
|
|
123
|
+
assert to_b64u(address_key_at(VAULT_KEY, entry["inboxId"], entry["epoch"])) == entry["inboxKey"]
|
|
124
|
+
private_key, public_key = address_key_pair_at(VAULT_KEY, entry["inboxId"], entry["epoch"])
|
|
125
|
+
assert to_b64u(private_key) == entry["sealingPrivateKey"]
|
|
126
|
+
assert to_b64u(public_key) == entry["sealingPublicKey"]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_an_epoch_outside_the_range_is_refused():
|
|
130
|
+
for epoch in (-1, 2**31, True):
|
|
131
|
+
with pytest.raises(ValueError):
|
|
132
|
+
address_key_at(VAULT_KEY, "ibx_one", epoch)
|
|
133
|
+
with pytest.raises(ValueError):
|
|
134
|
+
address_key_pair_at(VAULT_KEY, "ibx_one/2", 1)
|
|
135
|
+
|
|
136
|
+
|
|
110
137
|
# -- symmetric boxes: what a device seals ------------------------------
|
|
111
138
|
|
|
112
139
|
SYMMETRIC = VECTORS["symmetricBoxes"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|