Commit Graph

189 Commits

Author SHA1 Message Date
Thomas Waldmann cbeef56454 pyupgrade --py38-plus ./**/*.py 2022-02-27 20:11:56 +01:00
Björn Ketelaars 73c426497f Fix build with LibreSSL
#6338 introduces regression when building with LibreSSL (3.5.0).

```
cc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -g -fPIC -O2 -pipe -g -O2 -pipe -g -O2 -pipe -fPIC -Isrc/borg/crypto -I/usr/local/include/python3.9 -c src/borg/crypto/low_level.c -o /tmp/ports/pobj/borgbackup-1.2.1/borg-eec359cf228caf00d9c72bde07bf939872e9d3fa/temp.openbsd-7.1-amd64-3.9/src/borg/crypto/low_level.o
src/borg/crypto/low_level.c:12439:48: error: use of undeclared identifier 'EVP_chacha20_poly1305'; did you mean 'EVP_aead_chacha20_poly1305'?
  __pyx_v_self->__pyx_base.__pyx_base.cipher = EVP_chacha20_poly1305;
                                               ^~~~~~~~~~~~~~~~~~~~~
                                               EVP_aead_chacha20_poly1305
/usr/include/openssl/evp.h:1161:17: note: 'EVP_aead_chacha20_poly1305' declared here
const EVP_AEAD *EVP_aead_chacha20_poly1305(void);
                ^
1 error generated.
```

Unfortunately `EVP_aead_chacha20_poly1305`, offered by LibreSSL, is not
a drop in replacement for `EVP_chacha20_poly1305`. More info on the
first can be found at https://man.openbsd.org/EVP_AEAD_CTX_init.3.
2022-02-26 22:03:00 +01:00
Thomas Waldmann 0f2a45b474 crypto: get rid of deprecated HMAC_* functions
These were deprecated in OpenSSL 3.0.
2022-02-26 20:20:11 +01:00
TW 8f945ea252
Merge pull request #6338 from ThomasWaldmann/drop-openssl10
drop openssl 1.0.x support
2022-02-26 20:18:56 +01:00
Thomas Waldmann d1d3d1dfa4 crypto: remove support for: OpenSSL < 1.1.1, LibreSSL < 2.7.0
All these are unsupported since long.

Newer versions of LibreSSL have gained chacha20-poly1305 support,
but still lack aes256-ocb support.
Also they have the HMAC_CTX_new/free api now.

docs: openssl >= 1.1.1 is required now
anything older is out of support anyway.
2022-02-26 00:55:19 +01:00
James Buren 0d2fae6e7b 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 16:42:24 -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
Thomas Waldmann 7136e2c93c fix crash with relative BORG_KEY_FILE, fixes #3197 2017-10-20 21:13:11 +02:00
Marian Beermann b00179ff78 init: fix wrong encryption choices in command line parser 2017-10-08 12:29:03 +02:00
Thomas Waldmann 6a6fd31804 use prepared env for calling BORG_PASSCOMMAND, fixes #3050 2017-09-25 04:36:06 +02:00
Marian Beermann b8793d9577 keymanager: don't depend on optional readline module 2017-08-28 10:15:38 +02:00
Marian Beermann e57dd4bc9e crypto: avoid bad prototype codegen from cython
(-Wstrict-prototypes, Cyton forgets a "void")
2017-07-29 12:28:33 +02:00
Marian Beermann 630e45b742 crypto: fix wrong use of const 2017-07-29 12:28:06 +02:00
Marian Beermann d5ee16d676 crypto: remove AES-GCM 2017-07-29 12:22:11 +02:00
Thomas Waldmann dc4abffbc0 remove unused bytes16 conversions 2017-07-27 23:48:30 +02:00
Thomas Waldmann 63ebfc140b remove unused extract_nonce method 2017-07-27 23:48:30 +02:00
Thomas Waldmann e7228fa3a4 cosmetic: move some lines 2017-07-27 23:48:30 +02:00
Thomas Waldmann 68ef5e8a4b allow different MACs, implement blake2b MAC 2017-07-27 23:48:30 +02:00
Thomas Waldmann 945b5e25e2 dispatch to dummy blake2b ciphersuite 2017-07-27 23:48:30 +02:00
Thomas Waldmann 1e23291b7f post-merge: re-enabled AuthenticatedKey and tests 2017-07-27 23:48:30 +02:00
Thomas Waldmann 6090fdeef3 move the cipher internal counter overflow check to encrypt()/decrypt() 2017-07-27 23:48:30 +02:00
Thomas Waldmann 8f1678e2ba set_iv / next iv with integers 2017-07-27 23:48:30 +02:00
Thomas Waldmann 58c2dafbe0 nonce manager: remove get/set iv, make it integer based 2017-07-27 23:48:30 +02:00
Thomas Waldmann f34092e567 move openssl version checks to staticmethod requirements_check 2017-07-27 23:48:30 +02:00
Thomas Waldmann 23959eb5bf borg.key: include chunk id in exception msgs 2017-07-27 23:48:30 +02:00
Thomas Waldmann 37cf3ef469 init ciphersuites with header_len and aad_offset
it's needed for extract_iv already, so it should be given to init, not encrypt/decrypt
2017-07-27 23:48:30 +02:00
Thomas Waldmann e9bbf9307d refactor to cipher.extract_iv
position and length of iv depends on cipher
2017-07-27 23:48:29 +02:00
Thomas Waldmann 2d79f19263 refactor / generalize to num_cipher_blocks 2017-07-27 23:48:29 +02:00
Thomas Waldmann 310b4b7775 UNENCRYPTED (and unauthenticated) "ciphersuite"
it can be used to integrate the plaintext mode with the AEAD modes, both use same api now.
2017-07-27 23:48:29 +02:00
Thomas Waldmann f76f42c2a0 use cipher.block_count()
there are some more places where it is used.
2017-07-27 23:48:29 +02:00
Thomas Waldmann de0707d3dd refactor AES class to new api 2017-07-27 23:48:29 +02:00
Thomas Waldmann fbc740427d cosmetic: s/enc_cipher/cipher/, remove comment 2017-07-27 23:48:08 +02:00
Thomas Waldmann 8752039bec integrate new crypto code 2017-07-27 23:33:15 +02:00
Thomas Waldmann 4effe40415 re-add legacy AES() crypto class
we need it to encrypt/decrypt key files / config keys.
2017-07-27 23:22:32 +02:00
Thomas Waldmann ef880de64c add iv as optional encrypt() param 2017-07-27 23:22:32 +02:00
Thomas Waldmann 5287531130 make sure set_iv is called before each encrypt() call 2017-07-27 23:22:32 +02:00
Thomas Waldmann d88c0765e7 make sure sizes are in sync 2017-07-27 23:22:32 +02:00
Thomas Waldmann fb85d6abdc generalize intermediate classes' init 2017-07-27 23:22:32 +02:00
Thomas Waldmann 11349d1699 move IV type check to set_iv method 2017-07-27 23:22:32 +02:00
Thomas Waldmann 71b8d7fc18 generalize block count computation
also: use block_count method for legacy ciphersuites
2017-07-27 23:22:32 +02:00
Thomas Waldmann ca4fc2a222 generalize next_iv comment 2017-07-27 23:22:31 +02:00
Thomas Waldmann ce5c5781aa replace literals for iv_len/mac_len 2017-07-27 23:22:31 +02:00
Thomas Waldmann 741ab8ba05 use PyMem_Malloc / Free
Hopefully it is better dealing with a lot of small-object allocations than malloc/free is.
Small allocs happen if the input file is small, so it results only in 1 small chunk.
2017-07-27 23:22:31 +02:00
Thomas Waldmann 15490d520d add support for AES-OCB and chacha20-poly1305
also: use AEAD base class
2017-07-27 23:22:31 +02:00
Thomas Waldmann 92080f9572 crypto: add functions missing in openssl 1.0.x 2017-07-27 23:22:31 +02:00
Thomas Waldmann ee604ab390 crypto: use OpenSSL 1.1 HMAC API
This breaks it on OpenSSL 1.0.x as there is no HMAC_CTX_new/free() yet.

OTOH, this change is consistent with the previous change done for
EVP_CIPHER_CTX (which works on 1.0 and 1.1).
2017-07-27 23:22:31 +02:00
Thomas Waldmann 67567fc432 new crypto api, blackbox/AEAD. also adds AES256-GCM.
includes:

- aes256-ctr-hmac-sha256 (attic/borg legacy, optional aad support)

- aes256-gcm (new, optional aad support)
  uses 96bits for iv, 128bit for auth tag.

- header support
  the caller-provided header will be just copied in front of the rest -
  this avoids expensive operations (memcpy, garbage collection) in Python.
  the first bytes in the header may be non-authenticated data if aad_offset > 0.
  this is to support legacy attic/borg envelope layout, where the type byte
  is not authenticated.

- aad support
  additional authenticated data - it just contributes to the computed mac,
  but is not encrypted). the current api assumes that aad starts at some
  aad_offset inside the given header and extends to the end of it.

- iv handling helpers, compute next iv based on amount of processed data

- unit tests

Note: the changes are intentionally kept isolated / not integrated into the
      rest of the code, so this has to be done later.
2017-07-27 23:22:19 +02:00
enkore 6ffa797bde Merge pull request #2791 from ThomasWaldmann/dash_open
WIP dash_open
2017-07-05 10:02:34 +02:00
Thomas Waldmann a96dede632 dash_open: generalized and renamed open_file_or_stdin 2017-07-05 01:58:31 +02:00
TW 9ca666907b use limited unpacker for outer key, fixes #2174 (#2790)
* use limited unpacker for outer key, fixes #2174

* fixup: higher inner key data size limit
2017-07-04 22:51:31 +02:00
Marian Beermann 9a856533ba fuse: versions view, linear numbering by archive time 2017-07-03 12:38:10 +02:00
Marian Beermann 336d0426db crypto low_level: don't mutate local bytes()
CPython kind-of permits this (even by the docs),
other implementations don't. Allocate the result on the stack,
then copy to fresh bytes.
2017-07-02 15:19:50 +02:00
Marian Beermann 29646d5b5e key import: allow reading from stdin 2017-06-27 16:18:21 +02:00
Marian Beermann 78f0e5d473 archiver: add test for paperkey import, fix bug 2017-06-27 12:22:33 +02:00
Thomas Waldmann 89f3cab6cd move get_limited_unpacker to helpers
also: move some constants to borg.constants
2017-06-25 23:36:28 +02:00
Thomas Waldmann 6c2c51939d Manifest: use limited unpacker 2017-06-25 23:36:28 +02:00
Marian Beermann 221dc1c4c7 normalize authenticated key modes
rename authenticated to authenticated-blake2, consistent with the other
blake2 key modes

add authenticated mode that fills the blank and is consistent with the
other "unqualified" key modes
2017-06-11 18:07:09 +02:00
Andrea Gelmini e4247cc0d2 Fix typos 2017-06-09 16:49:30 +02:00
Marian Beermann 6c91a750d1 algorithms: rename crc32 to checksums 2017-06-01 21:26:42 +02:00
Marian Beermann 0221e31058 file_integrity: use xxh64 2017-06-01 21:26:42 +02:00
Marian Beermann 4e6a771ee7 BORG_PASSCOMMAND: use same cmd-string splitting as BORG_RSH 2017-05-31 19:41:17 +02:00
enkore 349a4ade7c Merge pull request #2568 from enkore/issue/1101.integration.cache
1101.integration.cache
2017-05-31 19:34:43 +02:00
TuXicc 578b76af3a Added BORG_PASSCOMMAND environment variable (#2573) 2017-05-31 19:25:21 +02:00
Marian Beermann 9032aa062b testsuite: simplify ArchiverCorruptionTestCase 2017-05-31 18:08:20 +02:00
Marian Beermann 83bca02a4e file_integrity: hash_part: mix length into state 2017-05-25 17:44:01 +02:00
Marian Beermann 1dfe693003 cache: integrity checking in archive.chunks.d 2017-05-25 16:28:46 +02:00
Marian Beermann 39051ac5f1 file_integrity: split in IntegrityCheckedFile + Detached variant 2017-05-25 14:04:41 +02:00
enkore 820066da5d Implement IntegrityCheckedFile (#2502)
Implement IntegrityCheckedFile

This is based on much earlier work from October 2016 by me, but is
overall simplified and changed terminology (from "signing" to
hashing and integrity checking).

See #1688 for the full history.
2017-05-12 21:38:31 +02:00
Marian Beermann a16d81271a key: add round-trip test 2017-05-12 20:49:17 +02:00
Marian Beermann 848df38d08 Rename Key.passphrase_protected -> logically_encrypted & document 2017-05-12 20:36:23 +02:00
Marian Beermann cad49b844e key: authenticated mode = not passphrase protected 2017-05-12 20:35:18 +02:00
Marian Beermann d964101eb5 consider repokey w/o passphrase == unencrypted 2017-05-07 22:13:49 +02:00
Marian Beermann a976e11a63 create crypto package with key, keymanager, low_level 2017-05-02 20:49:27 +02:00