internals.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .. include:: global.rst.inc
  2. .. _internals:
  3. Internals
  4. =========
  5. Key files
  6. ---------
  7. When initialized with the ``init -e keyfile`` command, |project_name|
  8. needs an associated file in ``$HOME/.attic/keys`` to read and write
  9. the repository. As with most crypto code in |project_name|, the format
  10. of those files is defined in `attic/key.py`_. The format is based on
  11. msgpack_, base64 encoding and PBKDF2_ SHA256 encryption, which is
  12. then encoded again in a msgpack_.
  13. The internal data structure is as follows:
  14. version
  15. currently always an integer, 1
  16. repository_id
  17. the ``id`` field in the ``config`` ``INI`` file of the repository.
  18. enc_key
  19. the AES encryption key
  20. enc_hmac_key
  21. the HMAC key (32 bytes)
  22. id_key
  23. another HMAC key? unclear.
  24. chunk_seed
  25. unknown
  26. Those fields are encoded using msgpack_. The utf-8-encoded phassphrase
  27. is encrypted with a PBKDF2_ and SHA256_ using 100000 iterations and a
  28. random 32 bytes salt to give us a derived key. The derived key is 32
  29. bytes long. A HMAC_ SHA256_ checksum of the above fields is generated
  30. with the derived key, then the derived key is also used to encrypt the
  31. above pack of fields. Then the result is stored in a another msgpack_
  32. formatted as follows:
  33. version
  34. currently always an integer, 1
  35. salt
  36. random 32 bytes salt used to encrypt the passphrase
  37. iterations
  38. number of iterations used to encrypt the passphrase
  39. algorithm
  40. the hashing algorithm used to encrypt the passphrase and do the HMAC
  41. checksum
  42. hash
  43. the HMAC checksum of the encrypted passphrase key
  44. data
  45. the passphrase key, encrypted with AES over a PBKDF2_ SHA256 hash
  46. described above
  47. The resulting msgpack_ is then encoded using base64 and written to the
  48. key file, wrapped using the textwrap_ module with a header. The header
  49. is a single line with the string ``ATTIC_KEY``, a space and a
  50. hexadecimal representation of the repository id.