Commit Graph

33 Commits (0b7d6dfbf2c7e54171719f4a427789962d365642)

Author SHA1 Message Date
Aydin Mercan 0b7d6dfbf2
crypto: start seperating public/private key usage
Digests now use bearssl + libsodium instead of openssl + libsodium.
It fits better with the API looking more similar and I don't think it
will be that much of a bottleneck.

Instead of a apk_pkey that mimicks the EVP_PKEY semantics, have seperate
public and private key structures. However, apk is broken because of it
and needs fixing. The rest of the code might compile but won't work
as I haven't handled the cases where pkey corressponds to public/private
keys in codebase properly. Also, DSA signatures are removed.

Public and private keys impls' now use a static array of vtables
internally. The indicies correspond to the signature scheme version and
checking `< APK_*_MAX` should be enough? I tried to make so that higher
values correspond to more desirable constructs, this might come in handy.

Signing/verifying start is free from keys as it isn't used though it
might be brought back for domain seperated hashes, ability to get
timestamps involved with epheremal keys in the future etc.

`apk_crypto.h` is free from openssl includes although some headers still
use them for now.
2022-08-24 10:15:14 +03:00
Timo Teräs 1d473e004c adb: use qsort_r 2022-03-21 14:09:06 +02:00
Timo Teräs c6b9297bcb mkndx, adb: fix index searching
Additioal logic is needed to search objects on array: the object
comparer needs separate modes to match index, template or exact
object template. This should fix mkndx to be able to use old index.

fixes #10828
2022-03-21 14:09:06 +02:00
Timo Teräs 950972a56b mkndx: fix index generation for v2 and v3 packages
For v2 packages, the identity was never set.
For v3 packages, the file size was never set.

This fixes both issues.
2022-03-21 14:09:06 +02:00
Timo Teräs 6df225eac3 mkpkg, adb: validate version and dependency format
Fail if the package or dependency version format is not valid.

fixes #10807
2022-02-01 14:47:27 +02:00
Ariadne Conill 6941f8bd61 adb: use sys/uio.h for iovec operations
readv/writev and struct iovec are declared in sys/uio.h per POSIX.
using it without sys/uio.h is a GNU extension.

ref #10794
2021-12-14 13:06:26 -06:00
Ariadne Conill f4f7796ccc everywhere: use stdlib.h for malloc(3) definition, not GNU-specific malloc.h
musl implements support for malloc.h, but it is only a stub.  we do not use
any of the GNU-specific malloc interfaces, so just use POSIX stdlib.h instead.

ref #10794
2021-12-14 16:23:29 +00:00
Timo Teräs 40f0866367 db, add: support adding v3 package files 2021-10-27 16:14:45 +03:00
Timo Teräs 9bd1e95e5b mkpkg: make unique-id field a blob 2021-10-25 15:48:59 +03:00
Timo Teräs 9f07a3447e adb: fix --allow-untrusted to work again
and fix the error code if untrusted adb is seen
2021-09-13 13:18:17 +03:00
Timo Teräs 99fa1fb797 trust: always use have valid struct apk_trust *
Make sure we always have valid struct apk_trust * for code using it.

Load the signing keys directly when being specified to produce
sane error message if loading them fails.
2021-08-23 17:02:50 +03:00
Timo Teräs 72d8cb8937 remove IS_ERR_OR_NULL
In most places where pointer can be an 'error' it cannot be null
pointer. Further, in those cases just calling PTR_ERR() is not enough
to handle the null case. Simplify code by removing this case.

If NULL case needs to be handled, it's better to add separate check
and return fixed error code in that case.
2021-08-23 17:02:50 +03:00
Timo Teräs f61eba0627 extract: use extraction api, and implement it for v3 packages
The extract applet now works with both v2 and v3 packages.
2021-07-30 17:54:25 +03:00
Timo Teräs 003e713502 adb: fix some error handling paths 2021-07-26 14:23:49 +03:00
Timo Teräs c1405f9311 adb: fix error handling of non-adb files 2021-07-25 08:52:43 +03:00
Timo Teräs e6b7fa49ce adb: add a small adb blob header with versions and root object 2021-07-22 16:14:49 +03:00
Timo Teräs e2ebd761a5 adb: refactor struct adb_header to adb_file_header
In struct adb, do not keep the whole header, just the schema
in host byte order.
2021-07-22 16:14:49 +03:00
Timo Teräs 2f1186aa40 adb: make adb mmap/stream parser more united, add ADB_BLOCK_DATAX
Harden the error checking of expected block types and their order.
Add ADB_BLOCK_DATAX as reserved for >1GB blocks.
2021-07-22 16:14:49 +03:00
Timo Teräs 05364528bb adb, convndx: check istream_close result 2021-07-22 15:30:08 +03:00
Timo Teräs 7e585512f4 io: make apk_istream_get/read() fail on incomplete read 2021-07-22 15:30:08 +03:00
Timo Teräs 796d298313 rework apk_istream_splice and apk_istream_tee
- apk_istream_splice usage is converted to apk_stream_copy which
  is the newer variant. With caching enabled by default, this
  makes more sense mmapping or using separate buffers.

- apk_istream_tee is reworked to write to apk_ostream, which simplifies
  quite a bit of various things
2021-07-22 15:30:08 +03:00
Timo Teräs 94c5e01038 adb: remove the now unused get_default_int() hook
It is no longer needed, and can be later reintroduced if needed.
2021-07-22 15:30:08 +03:00
Timo Teräs 3b00c0dc80 adb: unify various interfaces to adb_m_process
Removes code duplication, and puts important checks in one place.
Support seamless decompression in adbdump.
2021-07-22 15:30:08 +03:00
Timo Teräs 2a25a595ce check trust in adb_trust_write_signatures()
Based on patch from Daniel Golle <daniel@makrotopia.org>
2021-07-16 10:16:32 +03:00
Timo Teräs d89c219173 reduce misuse of error codes from errno.h 2021-06-19 16:10:13 +03:00
Timo Teräs 91cb2514e4 extract: new applet to extract v2 packages 2021-06-11 13:35:32 +03:00
Timo Teräs 7ce4cc4b73 add basic abstraction for cryptographic operations
- basic digesting and signing apis (subject still to fine tuning)
- update digest code, and adb signing for the thin wrapping layer
- old v1 package and database handling not updated
- default mkpkg file hash to sha256

ref #10744
2021-06-11 13:35:32 +03:00
Timo Teräs 7c9f001cda mkpkg: new applet to create v2 packages with basic functionality 2021-06-11 13:35:32 +03:00
Timo Teräs 1456296b43 add adbgen applet to generate databases from it's text dump 2021-06-02 22:35:58 +03:00
Timo Teräs 209201bc5d add abstraction to adb "walking" - a sax like API to enumerate whole db
This converts 'adbdump' applet to generate adb_walk api callbacks,
and implement gentext backend to generate the yaml-like text output.
2021-05-26 12:47:48 +03:00
Timo Teräs 705e002bb0 rename adb_trust to apk_trust, and use it as package signature keystore too 2020-10-09 16:09:19 +03:00
Timo Teräs f9f8594069 adb: improve sorting features, sort installed-db package listing 2020-10-09 16:09:19 +03:00
Timo Teräs efe0c4afec adb: introduce apk-tools database format, and few applets
This is a flat buffers inspired format that allows fast
mmaped access to the data with low overhead, signature support
and relatively good forward support.
2020-10-09 16:09:19 +03:00