Commit Graph

189 Commits

Author SHA1 Message Date
Thomas Waldmann 83c069ce5a
better error msg for corrupted key data, fixes #8016 2024-02-19 19:23:48 +01:00
Thomas Waldmann 334fbab897
refactor: use less binascii
our own hex_to_bin / bin_to_hex is more comfortable to use.

also: optimize remaining binascii usage / imports.
2024-02-19 02:16:19 +01:00
Thomas Waldmann 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22:58:02 +01:00
Thomas Waldmann a4602c6f61
remove unused hkdf_hmac_sha512 and related tests 2023-12-02 20:35:14 +01:00
Thomas Waldmann 64ce6d5923
crypto: use a one-step kdf for session keys, fixes #7953
also:
- fixes, simplifies, speeds up _get_session_key
- convert sessionid memoryview to bytes before calling _get_cipher,
to avoid TypeError in (crypt_key + sessionid + domain) operation.
- add docstring and comments
2023-12-02 20:33:07 +01:00
Thomas Waldmann cb4676048a
remove remainders of TAM support 2023-09-24 20:10:54 +02:00
Thomas Waldmann 1cf62d8fc7
remove manifest TAMs 2023-09-24 20:10:53 +02:00
Thomas Waldmann 6a68ad5cd6
remove archive TAMs 2023-09-24 20:10:51 +02:00
Thomas Waldmann 2d78fa89a5
always implicitly require archive TAMs
they must be there since the upgrade to borg 1.2.6 (or other
borg versions that also have a fix for CVE-2023-36811).
2023-09-03 22:02:35 +02:00
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 35ac39b751
fix F401 2023-07-26 01:23:37 +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
TW b70cefa474
Merge pull request #7556 from ThomasWaldmann/kill-nonce-manager
remove nonce management, related repo methods
2023-05-12 00:00:29 +02:00
Thomas Waldmann f970679b62
low_level crypto: fix borg version in comments 2023-05-11 20:10:55 +02:00
Thomas Waldmann 44f58b0870
low_level crypto: minor cleanup
HMAC is not used, we use hmac from py stdlib.
2023-05-11 20:09:47 +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 e772d70e05
cleaner FileLikeWrapper with own __init__ 2023-01-30 15:54:56 +01:00
Thomas Waldmann f9078ebfa9
FlexiKey: define STORAGE in base class
avoids some mypy warnings.
2023-01-30 15:54:52 +01:00
Rayyan Ansari c209daec63 file_integrity.py: make sure file_fd is always closed on exit 2022-11-15 18:46:08 +00: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 ef24dafb15 tests: use less RepoKey/KeyfileKey 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