Commit Graph

97 Commits

Author SHA1 Message Date
Thomas Waldmann 21d4407170
always implicitly require manifest TAMs
remove a lot of complexity from the code that was just there to
support legacy borg versions < 1.0.9 which did not TAM authenticate
the manifest.

since then, borg writes TAM authentication to the manifest,
even if the repo is unencrypted.
if the repo is unencrypted, it did not check the somehow pointless
authentication that was generated without any secret, but
if we add that fake TAM, we can also verify the fake TAM.

if somebody explicitly switches off all crypto, they can not
expect authentication.

for everybody else, borg now always generates the TAM and also
verifies it.
2023-09-03 22:01:46 +02:00
Thomas Waldmann 5cd2060345
rebuild_refcounts: keep archive ID, if possible
rebuild_refcounts verifies and recreates the TAM.
Now it re-uses the salt, so that the archive ID does not change
just because of a new salt if the archive has still the same data.
2023-08-30 01:13:52 +02:00
Thomas Waldmann 95b5604422
TAM msgs: be more specific: archives vs. manifest 2023-08-30 00:58:03 +02:00
Thomas Waldmann b23e6cb73d
list: support {tam} placeholder. check archive TAM.
list: shows either "verified" or "none", depending on
whether a TAM auth tag could be verified or was
missing (old archives from borg < 1.0.9).

when loading an archive, we now try to verify the archive
TAM, but we do not require it. people might still have
old archives in their repos and we want to be able to
list such repos without fatal exceptions.
2023-08-30 00:58:02 +02:00
Thomas Waldmann bfead4b288
fixup with msgpack data types related fixes 2023-08-29 22:32:30 +02:00
Thomas Waldmann a2ee13fd34
check: rebuild_manifest must verify archive TAM 2023-08-29 21:10:32 +02:00
Thomas Waldmann d5ffa59c91
bugfix: skip TAM check with BORG_WORKAROUNDS=authenticated_no_key
This is an emergency workaround for authenticated repos
if the user has lost the borg key.

We can't compute the TAM key without the borg key, so just
skip all the TAM stuff.
2023-07-20 17:54:33 +02:00
Thomas Waldmann 3051473168
BORG_WORKAROUNDS=authenticated_no_key to extract from authenticated repos without key, fixes #7700 2023-07-20 17:17:28 +02:00
Thomas Waldmann 58d3dbcec0
keyfile: improve key sanity check, fixes #7561
check key file structure, make sure the binary key
is not way too short (or zero) length.

if key file looks strange, emit warnings.
2023-06-29 23:13:29 +02:00
Thomas Waldmann 989b0a2847
use correct path for security dir when accessing legacy repos (v1)
while on macOS the new and old security dir location is the same path,
this is not the case on e.g. Linux, it could move from .config/borg/security to
.local/share/borg/security .

See #5760.
2023-05-19 21:12:59 +02:00
Thomas Waldmann e02d9edc34
remove nonce management, related repo methods
not needed for borg2 repos (we derive a new session key for each borg
invocation and start counting from 0).

also not needed for borg 1.x repos because we only read them (borg transfer)
and won't write new encrypted data to them.
2023-05-11 17:51:49 +02:00
Thomas Waldmann fea630027c
assert_id: better be paranoid, fixes #7362
This makes borg2's new crypto do the same check as borg1's old crypto
and makes sure that no chunks created by an evil borg client would
go unnoticed.
2023-02-19 21:14:20 +01:00
Thomas Waldmann 2705ccb59b
key storage: type hints / cleanup 2023-01-30 18:08:05 +01:00
Thomas Waldmann f9078ebfa9
FlexiKey: define STORAGE in base class
avoids some mypy warnings.
2023-01-30 15:54:52 +01:00
Thomas Waldmann a07c93d7f4 add assertion to key_factory, fail early with zero-len manifest data 2022-09-21 09:06:59 +02:00
Thomas Waldmann fa986a9f19 repoobj: add a layer to format/parse repo objects
borg < 2:

obj = encrypted(compressed(data))

borg 2:

obj = enc_meta_len32 + encrypted(msgpacked(meta)) + encrypted(compressed(data))

handle compr / decompr in repoobj

move the assert_id call from decrypt to RepoObj.parse

also:
- for AEADKeyBase, add a dummy assert_id (not needed here)
- only test assert_id for other if not AEADKeyBase instance
- remove test_getting_wrong_chunk. assert_id is called elsewhere
  and is not needed any more anyway with the new AEAD crypto.
- only give manifest (includes key, repo, repo_objs)
- only return manifest from Manifest.load (includes key, repo, repo_objs)
2022-09-04 00:49:38 +02:00
Thomas Waldmann 9beaced33c move manifest module from helpers to borg.manifest 2022-08-13 21:55:12 +02:00
Thomas Waldmann 4ec17d969c rename --copy-ae-key into --copy-crypt-key 2022-08-04 10:32:24 +02:00
Thomas Waldmann d5df53732d increase Key.version to 2
Old borg (< 2.0) can not read/process the new keys that have crypt_key instead of enc_key and enc_hmac_key.
2022-08-03 12:25:58 +02:00
Thomas Waldmann 3ee69bc7ba Key: crypt_key instead of enc_key + enc_hmac_key, fixes #6611 2022-08-03 12:04:23 +02:00
Thomas Waldmann 9878956140 rcreate --copy-ae-key: copy AE key from key of other repo, fixes #6710
default: create new, random authenticated encryption key.
2022-08-01 14:57:30 +02:00
Thomas Waldmann a8dda5cb0c transfer: check whether ID hash method and chunker secret are same, fixes #6893
also: add PlaintextKey and AuthenticatedKey support to uses_same_id_hash function.
2022-08-01 13:27:47 +02:00
Thomas Waldmann f82f123b56 new crypto does not need to call ._assert_id()
https://github.com/borgbackup/borg/pull/6463#discussion_r925436156
2022-07-20 14:13:25 +02:00
Thomas Waldmann b8e48c5036 mypy: fixes / annotations 2022-07-15 14:54:48 +02:00
Thomas Waldmann b07aeef498 add mypy checking
also added some .pyi files needed to check the cython code (taken from #5703 and updated).

fixed "syntax error" in key.py.

all mypy complaints not fixed yet.
2022-07-15 12:49:38 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann 350393c9fd remove unused imports 2022-07-05 00:05:07 +02:00
Thomas Waldmann eabad3e3b7 rcreate: always use argon2 kdf for new repos, fixes #6820
this way, we can remove the legacy pbkdf2 key code in next release.
2022-06-30 20:52:48 +02:00
Thomas Waldmann dc2f2f47a8 rcreate: remove legacy encryption modes for new repos, fixes #6490
These are legacy crypto modes based on AES-CTR mode:
(repokey|keyfile)[-blake2]

New crypto modes with session keys and AEAD ciphers:

(repokey|keyfile)[-blake2]-(aes-ocb|chacha20-poly1305)

Tests needed some changes:
- most used repokey/keyfile, changed to new modes
- some nonce tests removed, the new crypto code does not generate
  the repo side nonces any more (were only used for AES-CTR)
2022-06-30 20:52:48 +02:00
Thomas Waldmann dbae8e60eb remove borg upgrade 2022-06-26 00:25:44 +02:00
Thomas Waldmann 33444be926 more str vs bytes fixing 2022-06-09 17:57:28 +02:00
Thomas Waldmann 8e87f1111b cleanup msgpack related str/bytes mess, fixes #968
see ticket and borg.helpers.msgpack docstring.

this changeset implements the full migration to
msgpack 2.0 spec (use_bin_type=True, raw=False).

still needed compat to the past is done via want_bytes decoder in borg.item.
2022-06-09 17:57:28 +02:00
Thomas Waldmann af776ce7a6 refactor: borg.key.uses_same_id_hash(key_old, key_new) 2022-05-03 21:32:35 +02:00
Thomas Waldmann 3239836dce fix key id hash compat check: also support new->new
the check only considered old key -> new key changes, but
new key to new key is of course also fine.

e.g. repokey-aes-ocb -> repokey-aes-ocb (both use hmac-sha256
as id hash)
2022-05-03 21:25:44 +02:00
Thomas Waldmann 0e53dc040a api: enable giving already compressed data
the api already offered getting compressed data,
but not giving compressed data.

thus: cache.add_chunk and key.encrypt improved.
2022-05-03 04:15:01 +02:00
Thomas Waldmann 4b070040d6 init --other-location=OTHER_REPO: reuse key material from OTHER_REPO, fixes #6554
it potentially will ask for the passphrase for the key of OTHERREPO.
for the newly created repo, it will use the same passphrase.

it will copy: enc_key, enc_hmac_key, id_key, chunker_seed.

keeping the id_key (and id algorithm) and the chunker seed (and chunker
algorithm and parameters) is desirable for deduplication.
the id algorithm is usually either HMAC-SHA256 or BLAKE2b.

keeping the enc_key / enc_hmac_key must be implemented carefully:
A) AES-CTR -> AES-CTR is INSECURE due to nonce reuse, thus not allowed.
B) AES-CTR -> AEAD with session keys is secure.
C) AEAD with session keys -> AEAD with session keys is secure.

AEAD modes with session keys: AES-OCB and CHACHA20-POLY1305.
2022-05-02 18:50:27 +02:00
Thomas Waldmann ed59159649 argon2 key: use chacha20-poly1305 instead of aes256-ctr + hmac-sha256, fixes #6601
so we can completely get rid of aes-ctr some day.
2022-04-16 11:52:33 +02:00
Thomas Waldmann f5cddf0224 load_key: no key is same as empty key, fixes #6441
when migrating from repokey to keyfile, we just store an empty key into the repo config,
because we do not have a "delete key" RPC api. thus, empty key means "there is no key".

here we fix load_key, so that it does not behave differently for no key and empty key:
in both cases, it just returns an empty value.

additionally, we strip the value we get from the config, so whitespace does not matter.

All callers now check for the repokey not being empty, otherwise RepoKeyNotFoundError
is raised.
2022-04-10 20:58:59 +02:00
Andrey Bienkowski 6cf5ae4ca1 Give types for every argument 2022-04-10 15:36:46 +03:00
Andrey Bienkowski fc6d423052 Passphrase.argon2 -> FlexiKey.argon2 2022-04-10 15:06:26 +03:00
Andrey Bienkowski 0850a7c295 Passphrase.kdf -> FlexiKey.pbkdf2 2022-04-10 05:33:10 +03:00
Andrey Andreyevich Bienkowski 56c27a99d0
Argon2 the second part: implement key encryption / decryption (#6469)
Argon2 the second part: implement encryption/decryption of argon2 keys

borg init --key-algorithm=argon2 (new default, older pbkdf2 also still available)

borg key change-passphrase: keep key algorithm the same
borg key change-location: keep key algorithm the same

use env var BORG_TESTONLY_WEAKEN_KDF=1 to resource limit (cpu, memory, ...) the kdf when running the automated tests.
2022-04-07 16:22:34 +02:00
Thomas Waldmann 154e5d87e7 micro opt: callers shall provide a memoryview to .decompress()
if they would call with a bytes object, it would usually cause
1 object copy to remove the compression type bytes.
2022-04-01 21:22:31 +02:00
Thomas Waldmann 7083e6738f bugfix: correctly give manifest id
but do not verify chunk-id for it (does not match because the ID is
fixed at all-zero).
2022-03-26 20:07:52 +01:00
Thomas Waldmann fe7eb5702b use hmac.compare_digest instead of ==, fixes #6470 2022-03-26 18:51:36 +01:00
Thomas Waldmann dd2a054ac4 crypto: key: reduce class inheritance depth 2022-03-26 17:05:57 +01:00
Thomas Waldmann e4b65dea76 crypto: add IV overflow check
will never happen, but better play safe.
2022-03-26 17:05:57 +01:00
Thomas Waldmann c50e1124b5 also authenticate the chunkid when using the AEAD ciphers (AES-OCB/CHACHA-POLY) 2022-03-26 17:05:57 +01:00
Thomas Waldmann d3b78a6cf5 minor key.encrypt api change/cleanup
we already have .decrypt(id, data, ...).
i changed .encrypt(chunk) to .encrypt(id, data).

the old borg crypto won't really need or use the id,
but the new AEAD crypto will authenticate the id in future.
2022-03-26 17:05:57 +01:00
Thomas Waldmann 5c66fa4caa crypto: layout updates, low-level does not deal with IV
encrypt used to "patch" the IV into the header,
decrypt used to fetch it from there.

encrypt now takes the header just "as is" and
also decrypt expects that the IV is already set.
2022-03-26 17:05:57 +01:00