key-storage.proto 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. syntax = "proto3";
  2. package app;
  3. option java_package = "ch.threema.localcrypto.protobuf";
  4. option java_multiple_files = true;
  5. message InnerKeyStorage {
  6. enum Version {
  7. // Initial version
  8. V1_0 = 0;
  9. }
  10. }
  11. // Inner key storage V1, encoded in the following way:
  12. //
  13. // 1. Let `data` be the result of encoding this key storage to bytes.
  14. // 2. Let `version` be the selected `InnerKeyStorage.Version.V1_X` version.
  15. // 3. Return `u16-le(version) || data`.
  16. message InnerKeyStorageV1 {
  17. // Master key, used for the database, files, encrypted settings, etc.
  18. bytes master_key = 1;
  19. }
  20. message IntermediateKeyStorage {
  21. enum Version {
  22. // Initial version
  23. V1_0 = 0;
  24. }
  25. }
  26. // Intermediate key storage V1, encoded in the following way:
  27. //
  28. // 1. Let `data` be the result of encoding this key storage to bytes.
  29. // 2. Let `version` be the selected `IntermediateKeyStorage.Version.V1_X` version.
  30. // 3. Return `u16-le(version) || data`.
  31. message IntermediateKeyStorageV1 {
  32. message RemoteSecretProtected {
  33. // Associated remote secret authentication token
  34. bytes remote_secret_authentication_token = 1;
  35. // Associated remote secret hash
  36. bytes remote_secret_hash = 2;
  37. // Encapsulated compatible, version-prefixed inner key storage, encrypted
  38. // and encoded in the following way:
  39. //
  40. // 1. Let `RS` be the remote secret.
  41. // 2. Let `RSSK` be the result of
  42. // `BLAKE2b(key=RS, salt='rssk-a', personal='3ma-rs')`.
  43. // 3. Let `inner` be the plaintext `Inner`, encoded to bytes.
  44. // 4. Let `nonce` be a random nonce.
  45. // 5. Let `encrypted-inner` be the result of encrypting `inner` by
  46. // `XChaCha20-Poly1305(key=RSSK, nonce)`.
  47. // 6. Set this field to `nonce || encrypted-inner` (i.e. an
  48. // `extra.crypto.encrypted-data-with-nonce-ahead` struct).
  49. bytes encrypted_inner = 3;
  50. }
  51. oneof inner {
  52. // A compatible, version-prefixed inner key storage without any further
  53. // protection
  54. bytes plaintext_inner = 1;
  55. // Inner key storage protected by the Remote Secret protocol
  56. RemoteSecretProtected remote_secret_protected_inner = 2;
  57. }
  58. }
  59. message OuterKeyStorage {
  60. enum Version {
  61. // Initial version
  62. V1_0 = 0;
  63. }
  64. }
  65. // Outer key storage V1, encoded in the following way:
  66. //
  67. // 1. Let `data` be the result of encoding this key storage to bytes.
  68. // 2. Let `version` be the selected `OuterKeyStorage.Version.V1_X` version.
  69. // 3. Return `u16-le(version) || data`.
  70. message OuterKeyStorageV1 {
  71. message Argon2idProtected {
  72. // Version of Argon2
  73. enum Argon2Version {
  74. VERSION_1_3 = 0;
  75. }
  76. Argon2Version version = 1;
  77. // Random salt (16 bytes)
  78. bytes salt = 2;
  79. // Memory usage in bytes (≥ 128 MiB)
  80. uint32 memory_bytes = 3;
  81. // Number of iterations (≥ 3)
  82. uint32 iterations = 4;
  83. // Amount of parallelism (≥ 1, recommended to be 1)
  84. uint32 parallelism = 5;
  85. // Encapsulated compatible, version-prefixed intermediate key storage,
  86. // encrypted and encoded in the following way:
  87. //
  88. // 1. Let `SK` be a 32 byte secret key derived by running Argon2id with the
  89. // given parameters and the user-provided passphrase.
  90. // 2. Let `nonce` be a random nonce.
  91. // 3. Let `intermediate` be a compatible, version-prefixed intermediate key
  92. // storage encoded to bytes.
  93. // 4. Let `encrypted-intermediate` be the result of encrypting `intermediate`
  94. // by `XChaCha20-Poly1305(key=SK, nonce)`.
  95. // 5. Set this field to `nonce || encrypted-intermediate` (i.e. an
  96. // `extra.crypto.encrypted-data-with-nonce-ahead` struct).
  97. bytes encrypted_intermediate = 6;
  98. }
  99. oneof intermediate {
  100. // A compatible, version-prefixed intermediate key storage without any
  101. // further protection
  102. bytes plaintext_intermediate = 1;
  103. // Intermediate key storage protected by a passphrase, using Argon2id
  104. Argon2idProtected argon2id_protected_intermediate = 2;
  105. }
  106. }