Commit graph

116 commits

Author SHA1 Message Date
Thomas Waldmann
ed80bf2c37
do a late lookup on helpers.workarounds
so we can modify it within borg code elsewhere and it
will get the updated value when it accesses the attribute.
2024-03-28 14:44:38 +01:00
TW
319441e75d
Merge pull request #8051 from ThomasWaldmann/corrupted-key-errmsg-1.4
better error msg for corrupted key data, fixes #8016
2024-01-19 00:45:59 +01:00
Thomas Waldmann
dbbccf9451
better error msg for corrupted key data, fixes #8016 2024-01-18 23:59:35 +01:00
Thomas Waldmann
98fa922904
bump api version to 1.4 2024-01-18 20:09:49 +01:00
Thomas Waldmann
742bd0c097
refactor: use less binascii
our own hex_to_bin / bin_to_hex is more comfortable to use.

also: optimize remaining binascii usage / imports.
2024-01-18 18:13:40 +01:00
Thomas Waldmann
d9132a34d4
give clean error msg for invalid nonce file, see #7967
That rather long traceback was not pretty.

Of course users should usually have valid nonce files,
but multiple users managed to corrupt the file contents somehow.

Also:
- add Error / ErrorWithTraceback exception classes to RPC layer.
- add hex_to_bin helper
- also call hex_to_bin for the local nonce file (security dir)
2024-01-17 15:31:03 +01:00
Thomas Waldmann
f6279eac9d
shorten TAMRequiredError error msg
Users using recently created repos (after borg 1.0.9) or
who followed the upgrade procedure of 1.0.9 or >1.2.4 will
never see this error msg.

So, have it as short as and similar to the ArchiveTAMRequiredError.
2023-12-27 13:46:13 +01:00
Thomas Waldmann
62ad0369ef
update "modern" error RCs (docs and code) 2023-12-27 13:45:48 +01:00
Thomas Waldmann
8d2fd2a30e
ran pyupgrade --py39-plus ./**/*.py 2023-12-25 02:34:44 +01:00
Thomas Waldmann
c813f9ba59
crypto: get rid of deprecated HMAC_* functions
These were deprecated in OpenSSL 3.0.
Instead, use hmac.digest from Python stdlib.
2023-12-23 22:20:50 +01:00
Thomas Waldmann
6dbfbd6a19
activate tracebacks for TAM exceptions 2023-09-25 11:01:38 +02:00
Thomas Waldmann
d05d02f238
implement BORG_WORKAROUNDS=ignore_invalid_archive_tam, see #7791 2023-08-31 00:36:04 +02:00
Thomas Waldmann
d78ed697ae
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 02:52:27 +02:00
Thomas Waldmann
85b173d3d1
TAM msgs: be more specific: archives vs. manifest 2023-08-30 02:52:23 +02:00
Thomas Waldmann
75518d945c
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 02:52:15 +02:00
Thomas Waldmann
1fd94bd38f
check: rebuild_manifest must verify archive TAM 2023-08-29 21:59:04 +02:00
Thomas Waldmann
104cc196fc
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 18:02:58 +02:00
Thomas Waldmann
8ac7178ab9
BORG_WORKAROUNDS=authenticated_no_key to extract from authenticated repos without key, fixes #7700 2023-07-03 15:38:21 +02:00
Thomas Waldmann
a5801b9971
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-27 21:39:43 +02:00
Rayyan Ansari
82f6adf8e0
file_integrity.py: make sure file_fd is always closed on exit 2022-11-19 14:30:16 +01:00
Thomas Waldmann
25390de2c7 give a more helpful error msg for unsupported key format, fixes #6561 2022-04-24 22:03:28 +02:00
Thomas Waldmann
05d7ee9ed8 give a more helpful error msg for unsupported encrypted key format, fixes #6561 2022-04-24 21:55:41 +02:00
Thomas Waldmann
7fc1d75cd3 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-12 19:43:48 +02:00
TW
b5443da6cb
Merge pull request #6493 from ThomasWaldmann/use-compare_digest-1.2
use hmac.compare_digest instead of ==, fixes #6470
2022-03-26 19:48:05 +01:00
Thomas Waldmann
b75079c0f8 use hmac.compare_digest instead of ==, fixes #6470 2022-03-26 18:52:41 +01:00
Thomas Waldmann
3e91694a0a avoid losing the key (old crypto)
if we just have a pointer to a bytes object which might go out of scope, we can lose it.

also: cython can directly assign a bytes object into a same-size char array.
2022-03-26 18:32:44 +01:00
Björn Ketelaars
71fa056c47 1.2 - Remove unused code
#6473 Removed AEAD ciphers AES-OCB and CHACHA20-POLY1305 from 1.2. As a
result some additional code can be removed.

Passes regression tests.
2022-03-21 18:54:50 +01:00
Thomas Waldmann
aa57a3cb57 remove AEAD ciphers AES-OCB and CHACHA20-POLY1305, fixes #6472
not used in 1.2.x, we'll start using them in 1.3.
2022-03-20 23:05:30 +01:00
Thomas Waldmann
dc811bda6f fix "'HMAC_CTX' already defined" cython warning 2022-03-08 21:47:14 +01:00
Thomas Waldmann
72ccafb4b8 hmac.digest: some more minor optimizations
also some cosmetic changes:
- import hmac module
- use hmac.compare_digest
2022-03-06 11:26:04 +03:00
Thomas Waldmann
bcd1d49d3b hmac_sha256: replace own cython wrapper code by hmac.digest python stdlib (since py38)
i measured performance of both: pretty much the same.
2022-03-06 11:26:04 +03:00
Thomas Waldmann
c4ed840c7b pyupgrade --py38-plus ./**/*.py 2022-02-27 21:12:44 +01:00
James Buren
067dd10027 src/borg/crypto/low_level.pyx: fix compiler warning
The generated source code was producing a compiler warning due to
the pointers differing in constness. The called function expects
a non-const pointer while the generated code produces a const pointer
via a cast. This changes the cast to drop 'const' to make the compiler
happy.
2022-02-25 17:36:48 -06:00
Thomas Waldmann
7edba854b2 use create=True when creating new keys, fixes #6036 2022-02-04 19:33:45 +01:00
Thomas Waldmann
d299b8bc9c KeyfileKeyBase: add create=False param to save method
If we create a new repo (and a new keyfile key, create=True),
there must not already exist a keyfile at the path/filename
where we want to write the new one.

In other use cases (e.g. if we overwrite a keyfile due
to the user changing their passphrase, create=False),
of course overwriting at the same path/fname is desired.
2022-02-04 19:33:45 +01:00
Graham Stockton
0724d4be4e
key export: print key if path is '-' or not given, fixes #6092 (#6093)
key export: print key if path is '-' or not given, fixes #6092

"borg key export [REPOSITORY]" now displays the key.
2022-01-20 02:55:52 +01:00
Thomas Waldmann
1dbe86a14e use blake2b from hashlib 2021-01-28 18:00:00 +01:00
Matthew Glazar
5a32de918e allow key-import+BORG_KEY_FILE to create key files
Running 'borg key import' on a keyfile repository with the BORG_KEY_FILE
environment variable set works correctly if the BORG_KEY_FILE file
already exists. However, the command crashes if the BORG_KEY_FILE file
does not exist:

    $ BORG_KEY_FILE=newborgkey borg key import /home/strager/borg-backups/straglum borgkey
    Local Exception
    Traceback (most recent call last):
      [snip]
      File "[snip]/borg/crypto/key.py", line 713, in sanity_check
        with open(filename, 'rb') as fd:
    FileNotFoundError: [Errno 2] No such file or directory: '[snip]/newborgkey'

    Platform: Linux straglum 5.0.0-25-generic #26~18.04.1-Ubuntu SMP Thu Aug 1 13:51:02 UTC 2019 x86_64
    Linux: debian buster/sid
    Borg: 1.1.11  Python: CPython 3.7.7 msgpack: 0.5.6
    PID: 15306  CWD: /home/strager/Projects/borg
    sys.argv: ['[snip]/borg', 'key', 'import', '/home/strager/borg-backups/straglum', 'borgkey']
    SSH_ORIGINAL_COMMAND: None

Make 'borg key import' not require the BORG_KEY_FILE file to already
exist.

This commit does not change the behavior of 'borg key import' without
BORG_KEY_FILE. This commit also does not change the behavior of 'borg
key import' on a repokey repository.
2020-06-04 19:29:15 -07:00
Matthew Glazar
538d3245cd refactor key file searching functions
I want to change the key lookup logic for the 'borg key import' command.
Extract methods out of the KeyfileKey.find_key and
KeyfileKey.get_new_target to make this future change possible without
duplicating code.

This commit should not change behavior.
2020-06-03 19:02:33 -07:00
Björn Ketelaars
a87f38e35f crypto: LibreSSL has HMAC_CTX_free and *HMAC_CTX_new
While here improve indentation (use 4 spaces instead of 3).
2019-02-28 07:06:45 +01:00
Björn Ketelaars
9278920bd5 1.2.0a: fix LibreSSL support, see #4403 2019-02-26 21:24:28 +01:00
Thomas Waldmann
a65cefb7bb bump API_VERSIONs to 1.2_xx 2019-02-24 19:45:41 +01:00
motwok
6fde90b7f8
Merge pull request #1 from borgbackup/master
Update form upstream to fork
2018-10-29 21:39:01 +01:00
Thomas Waldmann
10cdadb2f8 flake8: fix F841 2018-10-29 12:36:03 +01:00
Emmo Emminghaus
f8ef6af454 hashindex: clean void* arithmetic up #2677
lowlevel: clean void* arithmetic up
unpack: repalce nonstandard false with 0
2018-10-24 21:40:05 +02:00
Łukasz Stelmach
548355125e read a passphrase from a file descriptor
Read a passpharase from a file descriptor specified in the
BORG_PASSPHRASE_FD environment variable.
2018-09-21 09:11:39 +02:00
Thomas Waldmann
3c173cc03b wrap msgpack, fixes #3632, fixes #2738
wrap msgpack to avoid future upstream api changes making troubles
or that we would have to globally spoil our code with extra params.

make sure the packing is always with use_bin_type=False,
thus generating "old" msgpack format (as borg always did) from
bytes objects.

make sure the unpacking is always with raw=True,
thus generating bytes objects.

note:

safe unicode encoding/decoding for some kinds of data types is done in Item
class (see item.pyx), so it is enough if we care for bytes objects on the
msgpack level.

also wrap exception handling, so borg code can catch msgpack specific
exceptions even if the upstream msgpack code raises way too generic
exceptions typed Exception, TypeError or ValueError.
We use own Exception classes for this, upstream classes are deprecated
2018-08-06 17:32:55 +02:00
Thomas Waldmann
dc78fcf193 improve getpass user experience, see #3689
if interactive passphrase query fails and the env vars are not set,
show a clear error message about this.

users often do 'BORG_PASSPHRASE=secret', forgetting the 'export'.
or they use sudo (and not sudo -E).
in both cases, the env vars won't be available for the borg process.
2018-03-20 21:21:23 +01:00
Thomas Waldmann
b2ffb8bd65 make the C compiler happy, fixes #3490
fix a false positive compiler warning about olen being referenced
before assignment (which is not true, see comments in #3490).
2018-03-03 04:07:25 +01:00
Niels Ole Salscheider
cb3b38ee7f Fix build with LibreSSL 2017-11-05 16:29:37 +01:00