Commit Graph

185 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 191e2d412d io: move make_dirs as apk_make_dirs and use it 2022-04-05 10:53:52 +03:00
Daniel Kolesa d06a99128f package: respect version fuzziness when creating dep from adb 2022-03-31 01:59:50 +02:00
Timo Teräs d0821b6d42 pkg: recursive create exec dir
fixes #10825
2022-03-29 09:59:59 +03:00
Daniel Kolesa 386cadd0d4 package: fix error message when script fails to execute
Related: https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10825
2022-03-21 12:10:54 +00:00
Daniel Kolesa c5d9aaa1ee adb: fix handling of conflicts
Ensure not to mask away previously set APK_VERSION_CONFLICT when
serializing.

When deserializing, make sure to actually write out the conflict
flag when no version part is set.

When creating apk_dependency, ensure to set the conflict bit
correctly and mask it off result_mask.

Fixes https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10824
2022-03-07 08:26:07 +00:00
Timo Teräs 62bc43d2a4 pkg: use lib/apk/exec as the package script execution directory
var/cache is also reported to be mounted noexec on hardened
systems. Document some of the issues, and use lib/apk/exec
for the time being. Keep the scripts still in separate directory
from lib/apk so we can just delete directory if needed.

fixes #6591
2022-02-24 14:29:38 +02:00
Timo Teräs 21519221c2 adb: add layer to pkginfo 2022-02-21 10:24:05 +02:00
Timo Teräs f69ae30272 db: sort world dependencies to layers 2022-02-21 10:24:05 +02:00
Timo Teräs a2cd188039 package: fail on invalid control data
Handle meta data error to produce hard failure.

fixes #10806
2022-01-17 10:55:37 +02:00
Ariadne Conill 3d41d1c90a package: factor out /dev initialization to linux-specific helper function 2021-12-29 20:38:40 +02: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 1ab81fdd4c db: convert v3 scripts to ipkg on install
fixes #10796
2021-12-03 14:53:30 +02:00
Timo Teräs 83b71f0baf db: lazy create directories with --initdb
fixes #10778
2021-11-15 15:56:48 +02:00
Timo Teräs 3e6261392f pkg: fix reading of v3 package meta data
The adb object for apk_pkg_from_adb() was changed in commit 7d6de220
"database: support loading v3 indexes" which also addressed the broken
site in question but omitted updating the argument.

fixes #10783
2021-11-11 11:41:29 +02:00
Timo Teräs 7d6de2203e database: support loading v3 indexes 2021-11-09 21:50:11 +02:00
Timo Teräs a673653200 database: implement uvol support
by adding an abstraction layer to the file system
2021-11-09 21:50:11 +02:00
Timo Teräs 40f0866367 db, add: support adding v3 package files 2021-10-27 16:14:45 +03:00
Timo Teräs 5843daf7a1 Further refactor extract API to have separate ops vtable
This splits the callbacks by type, and further prepares the API
to be usable for v3 files too.
2021-07-27 16:28:22 +03:00
Timo Teräs 9c843e4ecd Refactor .apk extraction code
This moves and isolates the tar code to tar.c. And the actual
file extraction to disk is moved to extract.c.

A new API is introduced and used for v2 file extraction. This
essentially moves and isolates the apk_sign_ctx_* beast into
extract_v2.c and offers a saner interface to handling packages.

A place holder is added for v3 extraction.
2021-07-27 14:09:38 +03:00
Timo Teräs aca77e8410 Use __attribute__ ((format)) where possible and fix issues found by it 2021-07-26 10:25:23 +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 395e92b66e io: formalize apk_ostream_write() always writing full data 2021-07-22 15:30:08 +03:00
Timo Teräs b559a81694 io: rework apk_istream_get_* to not return erros in blob value
The interface was slightly cumbersome, so replace these functions
to return explicit error, and make the return blob a pointer arg.
2021-07-22 15:30:08 +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 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 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 a627ab8eb8 make apk_database optional for applets that don't need it
The new v3 applets don't use it, and eventually all applets will
use the new formats only.

This prepares the code for this, and moves trust, id_cache, and
root_fd to apk_ctx which is enough for v3 applets at this time.

The generic code is made to not initialize apk_database if it's
not needed.
2020-10-09 16:09:19 +03:00
Timo Teräs 354713d2f7 rename apk_db_options to apk_ctx, rework logging
makes apk_verbosity non-global

fixes #10682
2020-10-09 16:09:19 +03:00
Timo Teräs 7a7eca8670 make apk_flags non-global, make progress printing state non-global
ref #10682
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
Timo Teräs 5f66b618ef various changes to make clang not give warnings 2020-10-07 21:16:35 +03:00
Timo Teräs d0edeec8fb make the atom functions not use global state
This greatly helps with memory management on applications that
may want to daemonize and open/close database several times.

Also the lifetime and "owner" of memory for all data is now
explicitly bound to owning struct apk_database, which might
be helpful when writing language bindings. As side effect, the
interned "atoms" are unique only within what apk_database, so
comparing packages from different apk_database may not work
as expected.

Fixes #10697
2020-05-19 12:02:56 +03:00
TBK 5d796b5678 use SPDX-License-Identifier in source files 2020-05-07 10:45:42 +03:00
Reid Rankin d25e5e3879 Harden signature verification process
This mostly boils down to making sure control_started and
data_started are consistently used to gate actions, instead of
relying whether on file names start with a '.'.

None of the weaknesses this fixes are exploitable, but they
might have become so after changes to seemingly-unrelated code,
so it's good to clean them up.
2020-01-24 09:28:48 +02:00
Reid Rankin 093c4b8077 Improve documentation of signature verification process 2020-01-24 09:28:00 +02:00
Timo Teräs f123d77e0b archive: make apk_tar_parse check and close input stream
simplifies other code quite a bit
2020-01-11 11:32:51 +02:00
Timo Teräs 7caa217731 convert remaining locations to use istream instead of bstream 2020-01-11 11:20:48 +02:00
Timo Teräs 6da3e8eb15 istream, archive, db: convert db and tar function to use istream 2020-01-11 11:20:45 +02:00
Timo Teräs 9dda2d3c21 archive: remove support for old packages without xattr checksums 2020-01-11 03:43:38 +02:00
Timo Teräs 90fc52e2b8 del: report non-matching names and install-if rule non-deletion 2019-12-29 19:40:24 +02:00
Timo Teräs beab8545eb add support for openssl 1.1 2018-10-26 08:22:08 +03:00
Timo Teräs 6484ed9849 rework unpacking of packages and harden package file format requirements
A crafted .apk file could to trick apk writing unverified data to
an unexpected file during temporary file creation due to bugs in handling
long link target name and the way a regular file is extracted.

Several hardening steps are implemented to avoid this:
 - the temporary file is now always first unlinked (apk thus reserved
   all filenames .apk.* to be it's working files)
 - the temporary file is after that created with O_EXCL to avoid races
 - the temporary file is no longer directly the archive entry name
   and thus directly controlled by potentially untrusted data
 - long file names and link target names are now rejected
 - hard link targets are now more rigorously checked
 - various additional checks added for the extraction process to
   error out early in case of malformed (or old legacy) file

Reported-by: Max Justicz <max@justi.cz>
2018-09-10 10:59:39 +03:00
Jussi Kukkonen d609ef3c6c Invalidate id cache after script execution
It's common for a pre-install script to do something like
    addgroup -S group 2>/dev/null
When apk installs files after this, it sets the owner/group based on id cache
but currently the id cache is stale and doesn't contain the new group at that
point: instead the file will be installed with gid that the build host
happened to have for that group -- on target this might mean a non-existing
group or a completely different group.

We can't know if the script really did modify id cache contents so make sure
to reset the id cache on every script execution.
2018-07-02 10:06:53 -05:00
William Pitcock f18c708183 solver: implement support for choosing default virtuals
By introducing a new package metadata field, `provider_priority`
(index letter `k`), we can specify default packages to satisfy a
virtual.

If a user wishes to select an alternative provider for the virtual,
a changeset swapping the default provider for the selected provider
will be generated by the dependency resolver.
2017-11-02 03:08:24 +00:00
Timo Teräs 8f0938a056 package: remove package script after use (fixes #7974)
this is a regression introduced in commit 349c61c9
("add support for pre and post commit hooks")
2017-10-04 16:56:07 +03:00
Timo Teräs 4d9c0c39b0 io: make io vtables const struct, and add accessors for them
This reduces function pointers in heap, and unifies how the
io functions are called.
2017-06-23 10:07:44 +03:00
William Pitcock 693b4bcdb0 version: add support for fuzzy version matching
This is useful for requirements such as: python3=~3.6, which would match python3-3.6.[0-9].
This implementation should in theory be backwards compatible with the implementation in Adelie.
2017-05-27 21:49:53 +00:00
Timo Teräs 697c50524a package: add more secure signature methods 2017-02-28 10:47:15 +02:00
Henrik Riomar 349c61c961 add support for pre and post commit hooks
This allows for instance integration of etckeeper

[TT: Reorganized code a bit, and modified to use single
directory commit_hooks.d with argument for script of stage.]
2017-02-15 13:44:04 +02:00