summaryrefslogtreecommitdiff
path: root/src/context.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-08-23 15:17:11 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-08-23 17:02:50 +0300
commit99fa1fb797995fb5857f7604f90033b08ebf430c (patch)
tree726ae7a26b57ca44a1806c025335a31d8667103d /src/context.c
parent72d8cb8937c5ffa7016ef3fdfeb17c5abae97b61 (diff)
downloadapk-tools-99fa1fb797995fb5857f7604f90033b08ebf430c.tar.gz
apk-tools-99fa1fb797995fb5857f7604f90033b08ebf430c.tar.bz2
apk-tools-99fa1fb797995fb5857f7604f90033b08ebf430c.tar.xz
apk-tools-99fa1fb797995fb5857f7604f90033b08ebf430c.zip
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.
Diffstat (limited to 'src/context.c')
-rw-r--r--src/context.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/context.c b/src/context.c
index 7020b25..9298a5a 100644
--- a/src/context.c
+++ b/src/context.c
@@ -16,7 +16,7 @@ void apk_ctx_init(struct apk_ctx *ac)
{
memset(ac, 0, sizeof *ac);
apk_string_array_init(&ac->repository_list);
- apk_string_array_init(&ac->private_keys);
+ apk_trust_init(&ac->trust);
apk_out_reset(&ac->out);
ac->out.out = stdout;
ac->out.err = stderr;
@@ -28,7 +28,6 @@ void apk_ctx_free(struct apk_ctx *ac)
apk_id_cache_free(&ac->id_cache);
apk_trust_free(&ac->trust);
apk_string_array_free(&ac->repository_list);
- apk_string_array_free(&ac->private_keys);
if (ac->out.log) fclose(ac->out.log);
}
@@ -75,12 +74,10 @@ int apk_ctx_prepare(struct apk_ctx *ac)
struct apk_trust *apk_ctx_get_trust(struct apk_ctx *ac)
{
- if (!ac->trust.initialized) {
- int r = apk_trust_init(&ac->trust,
- openat(ac->root_fd, ac->keys_dir, O_RDONLY | O_CLOEXEC),
- ac->private_keys);
- if (r) return ERR_PTR(r);
- ac->trust.allow_untrusted = !!(ac->flags & APK_ALLOW_UNTRUSTED);
+ if (!ac->trust.keys_loaded) {
+ int r = apk_trust_load_keys(&ac->trust,
+ openat(ac->root_fd, ac->keys_dir, O_RDONLY | O_CLOEXEC));
+ if (r != 0) apk_err(&ac->out, "Unable to load trust keys: %s", apk_error_str(r));
}
return &ac->trust;
}