Diary and Photos keep their photos as records of the account's entity data (Daochi docs/entity-data.md): entity.photos.<sha256>, synced as private.entity.v1.photos in Inbe's own signed v6 sync and sealed in Daochi's record profile with the account's photos key, the same bytes libsodium writes. A photo's bytes travel as sealed chunks of at most 8 MiB at /api/v1/blobs/entity/, so the same picture is stored once per node for every app of the account. Photos released versions kept move there by themselves: library photos once their bytes are on the device, and Diary files that an entry includes, named and dated as before. An old copy goes only after the sync node confirmed the photo's record and chunks and they came back whole; then the old records name the photo and keep every field for released versions, which read them through 2027-10-24, the Diary file leaves the device, hex chunks shrink, and the old copies are deleted from each node. Any failure keeps the old copy for a later pass, and a delegate device moves nothing.
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Print the known-answer entity record of tests/storage_sync_behavior.zi.
|
|
|
|
The record is sealed with libsodium (PyNaCl), as other apps of the account
|
|
seal theirs, in Daochi's record profile (docs/entity-data.md): the record
|
|
key of kind photos from the test account's private key, XChaCha20-Poly1305
|
|
with a fixed nonce, and the profile's sorted-key envelope, base64url without
|
|
padding. Run it to reproduce the constants the test embeds.
|
|
"""
|
|
|
|
import base64
|
|
import hashlib
|
|
import hmac
|
|
import json
|
|
|
|
import nacl.bindings
|
|
|
|
# set_account() stores the private key as the hex digits "42" repeated.
|
|
PRIVATE_KEY = bytes([0x42]) * 2560
|
|
ACCOUNT = "7e1d" * 16
|
|
HASH = "1f2e3d4c5b6a7988" * 4
|
|
COLLECTION = "private.entity.v1.photos"
|
|
SCHEMA = "entity.photo.v1"
|
|
NONCE = bytes(range(24))
|
|
|
|
|
|
def base64url(data: bytes) -> str:
|
|
return base64.urlsafe_b64encode(data).rstrip(b"=").decode()
|
|
|
|
|
|
def main() -> None:
|
|
key = hmac.new(PRIVATE_KEY, b"daochi-entity-v1/records/photos", hashlib.sha256).digest()
|
|
plain = json.dumps({"hash": HASH, "size": 6000, "type": "image/jpeg", "taken_at": 1792224900,
|
|
"width": 4032, "height": 3024, "added_at": 1792224960,
|
|
"name": "IMG_2041.jpg", "caption": "Written by another app"},
|
|
separators=(",", ":"), sort_keys=True)
|
|
aad = ('{"account_id":"%s","app_id":"entity","collection":"%s","id":"%s","schema":"%s"}'
|
|
% (ACCOUNT, COLLECTION, HASH, SCHEMA))
|
|
sealed = nacl.bindings.crypto_aead_xchacha20poly1305_ietf_encrypt(
|
|
plain.encode(), aad.encode(), NONCE, key)
|
|
envelope = ('{"aad":%s,"alg":"xchacha20poly1305","ciphertext":"%s","key_id":"entity-v1",'
|
|
'"nonce":"%s","profile":"daochi-record-v1"}' % (aad, base64url(sealed), base64url(NONCE)))
|
|
print("record key:", key.hex())
|
|
print("plain:", plain)
|
|
print("nonce:", base64url(NONCE))
|
|
print("ciphertext:", base64url(envelope.encode()))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|