Commit Graph

416 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 c21f61ddd8 db: fix change detection for symlinks
apk_fileinfo_get() special cases symlink digest calculation.
Convert apk_fsdir_ops.file_digest to .file_info to fix symlink
change detection.

fixes #10853
2022-08-17 21:13:40 +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
Timo Teräs 232067b3d1 db: fix atfd for access repository index
fixes #10834
2022-04-05 10:31:57 +03:00
Ariadne Conill feec480b34 keep APK_DEFAULT_ARCH as the define used in source code 2022-03-30 09:17:25 +00:00
Ariadne Conill 917698ec1d use arch_prefix for this feature instead 2022-03-30 09:17:25 +00:00
Ariadne Conill c29638cd81 use APK_DEFAULT_ABI_TAG everywhere APK_DEFAULT_ARCH was previously used 2022-03-30 09:17:25 +00:00
Timo Teräs bc2b5b69b7 db: make --no-cache disable the cache completely
Including using files found from the cache, or creating the cache
directories with --initdb.

Based on patch by Paul Spooren.
2022-03-29 10:01:34 +03:00
Daniel Kolesa 1be55db3d0 db: fix APK_OPENF_NO_STATE check
fixes #10821
2022-03-06 18:28:10 +02:00
Timo Teräs 00e397d564 db: honor APK_OPENF_NO_STATE again
Do not call apk_db_read_layer() or try to process the layer
if APK_OPENF_NO_STATE is specified. It might fail because of
non-existing database directory. Based on patch by Daniel.

fixes commit 9e4dd29f "db: prepare database reading for layers"

Fixes #10821

Reported-and-analyzed-by: Daniel Kolesa <daniel@octaforge.org>
2022-03-06 16:07:42 +02:00
Timo Teräs 86d75e10f5 db, uvol: commit regular files before uvol volumes
add priority to order fsdir commit sequence
2022-02-22 14:03:47 +02:00
Timo Teräs 3a194ea5d7 db: fix apkindex path generation
remove the left over apk_blob_push_fmt() call that corrupted uri and
trim the path end from trailing slashes to get original functionality.

fixes commit be4ce407 "support new index format without attaching arch"
2022-02-22 14:02:44 +02:00
Timo Teräs f69ae30272 db: sort world dependencies to layers 2022-02-21 10:24:05 +02:00
Timo Teräs 9089edcc44 db: prepare database writing for layers 2022-02-21 10:24:05 +02:00
Timo Teräs 9e4dd29f54 db: prepare database reading for layers 2022-02-21 10:24:05 +02:00
Paul Spooren be4ce40797 support new index format without attaching arch
By default the package architecture is attached to the repository url.
With this commit it is possible to define new indexes ending on `.adb`.
If such index file is detected the packages must be in the same folder
as the index.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2022-02-14 17:21:51 +00:00
Ariadne Conill 6315575af1 database: fix apk_db_cache_active returning true when cache not configured
this regression was caused by refactoring of the options handling into the
apk_ctx struct in 354713d2, presumably a little too much innovation with sed

fixes #10799
2022-02-03 22:26:57 +00: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 10b26851a4 database: refactor mounting and unmounting /proc 2021-12-29 20:37:28 +02:00
Ariadne Conill dfe2e141ca database: relocate find_mountpoint() 2021-12-29 20:37:28 +02:00
Ariadne Conill ae4008c4f2 database: refactor cache remounting 2021-12-29 20:37:28 +02:00
Ariadne Conill 4fa6a9fd73 database: refactor tmpfs root detection and cache setup 2021-12-29 20:37:25 +02:00
Ariadne Conill 6344a0eedb database: isolate linux-specific mountpoint headers 2021-12-29 20:14:41 +02:00
Ariadne Conill 8d5784aaf5 database: use SA_RESETHAND instead of SA_ONESHOT when registering a SIGALRM handler
SA_ONESHOT is a GNU-specific alias for POSIX SA_RESETHAND.
2021-12-29 10:36:59 +02:00
Ariadne Conill 2a9c0277c0 use fstatat, not fstatat64
the stat64 family of functions were provided as transitional functions,
but when building on glibc with _GNU_SOURCE, or any other supported system,
the stat functions are equivalent to their stat64 counterparts
2021-12-29 07:52:48 +00:00
Paul Spooren f2a5959139 apk: add --preserve-env option
This options is useful for (post)install scripts to run with the same
environment variables as apk is executed.

[TT: minor stylistic changes]

Signed-off-by: Paul Spooren <mail@aparcar.org>
2021-12-29 09:50:50 +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 845fa93814 db: synthesize symlink hashes for v3 packages
The v3 format will not require the hash, but synthesize it to the
DB so v3 packages can get installed properly.

fixes #10785
2021-11-22 13:41:22 +02:00
Timo Teräs cce6239074 db: fix regression in creating .apk-new files
The apk_fsdir_file_digest() servers dual purpose: to calculate
the checksum, but also to determine if the file exists. Move
it's error check where it originally was.

fixes #10791
2021-11-22 10:35:18 +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 16e0f6df7f fix fetching of depdencies only packages
Remove the APK_REPOSITORY_CACHED bit from dependencies only
packages (that is, installed_size == 0). For fetch, the problem
is that apk_db_select_repo() would return the cache repository,
but the package would not be there. Update also the locations
needed to handle these packages correctly without the cached
repository bit being set.
2021-11-15 13:35:59 +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 d441cf523c db: purge temporary files without explicit modification check
When extraction failed, the user has had no opportunity to edit
any files. Just clean up.
2021-11-03 16:06:04 +02:00
Timo Teräs 5c0c249b78 extract: move uvol extraction code to extract
fix also the progress callback on uvol extraction
2021-11-03 15:37:10 +02:00
Timo Teräs d821265865 db, extract: handle waitpid returning EINTR 2021-11-03 15:37:10 +02:00
Timo Teräs 6941aac4c6 db, audit: support sha256-160 hashes for v3 pkg compat 2021-11-03 15:37:10 +02:00
Timo Teräs 40f0866367 db, add: support adding v3 package files 2021-10-27 16:14:45 +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 33c1de8ea1 db: honor SOURCE_DATE_EPOCH for scriptdb
fixes #10762
2021-08-23 11:11:29 +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 083ea5a13b db: add some error checking to database state write
Make errors more observable. Unfortunately full rollback is
non-trivial to implement. This is something to be fixed with
the v3 database format.
2021-07-26 14:10:07 +03:00
Samanta Navarro d212aca070 db: fix installed db writing with long names
Packages containing files with path names longer than 1024 characters
cannot fit into the buffer which is used to write "installed" database.
This leads to bbuf being APK_BLOB_NULL in apk_db_write_fdb because
apk_blob_push_blob notices the condition and correctly handles it.

The problem occurs when arguments to apk_ostream_write are manually
calculated by pointer arithmetics. Since bbuf.ptr is NULL in such a
case, bbuf.ptr - buf leads to a huge size value while buf still points
into the stack.

fixes #10751

[TT: minor edit to commit and abbreviating the commit message]
2021-07-26 13:36:28 +03:00
Timo Teräs 3d203e8f5f db: allow read-only operations without cache
fixes #10748
2021-07-23 14:39:38 +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 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 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 0683b069ba db: check syscall errors in update_permissions() 2021-06-21 13:02:12 +03:00