2020-02-14 11:49:41 +00:00
|
|
|
/* app_verify.c - Alpine Package Keeper (APK)
|
2009-07-17 10:07:52 +00:00
|
|
|
*
|
2011-09-13 08:53:01 +00:00
|
|
|
* Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
|
2009-07-17 10:07:52 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2020-04-22 13:33:41 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
2009-07-17 10:07:52 +00:00
|
|
|
*/
|
|
|
|
|
2009-07-30 14:29:20 +00:00
|
|
|
#include <errno.h>
|
2009-07-17 10:07:52 +00:00
|
|
|
#include <stdio.h>
|
2009-07-31 13:08:09 +00:00
|
|
|
#include <fcntl.h>
|
2009-07-17 10:07:52 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "apk_applet.h"
|
|
|
|
#include "apk_database.h"
|
2010-03-05 08:13:25 +00:00
|
|
|
#include "apk_print.h"
|
2009-07-17 10:07:52 +00:00
|
|
|
|
2020-10-09 09:44:32 +00:00
|
|
|
static int verify_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
|
2009-07-17 10:07:52 +00:00
|
|
|
{
|
2020-10-09 09:44:32 +00:00
|
|
|
struct apk_out *out = &ac->out;
|
2009-07-17 10:07:52 +00:00
|
|
|
struct apk_sign_ctx sctx;
|
2020-10-09 09:44:32 +00:00
|
|
|
struct apk_id_cache *idc = apk_ctx_get_id_cache(ac);
|
2020-10-09 10:40:14 +00:00
|
|
|
struct apk_trust *trust = apk_ctx_get_trust(ac);
|
2013-06-18 10:01:51 +00:00
|
|
|
char **parg;
|
|
|
|
int r, ok, rc = 0;
|
2009-07-17 10:07:52 +00:00
|
|
|
|
2020-10-09 10:40:14 +00:00
|
|
|
trust->allow_untrusted = 1;
|
|
|
|
|
2013-06-18 10:01:51 +00:00
|
|
|
foreach_array_item(parg, args) {
|
2020-10-09 10:40:14 +00:00
|
|
|
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, trust);
|
2020-01-11 07:56:42 +00:00
|
|
|
r = apk_tar_parse(
|
|
|
|
apk_istream_gunzip_mpart(apk_istream_from_file(AT_FDCWD, *parg),
|
|
|
|
apk_sign_ctx_mpart_cb, &sctx),
|
2020-10-09 09:44:32 +00:00
|
|
|
apk_sign_ctx_verify_tar, &sctx, idc);
|
2009-07-17 10:07:52 +00:00
|
|
|
ok = sctx.control_verified && sctx.data_verified;
|
2020-10-05 15:52:51 +00:00
|
|
|
if (apk_out_verbosity(out) >= 1)
|
|
|
|
apk_msg(out, "%s: %d - %s", *parg, r,
|
2020-01-11 07:56:42 +00:00
|
|
|
r < 0 ? apk_error_str(r) :
|
2009-07-17 10:07:52 +00:00
|
|
|
ok ? "OK" :
|
2012-02-24 07:00:27 +00:00
|
|
|
!sctx.control_verified ? "UNTRUSTED" : "FAILED");
|
|
|
|
else if (!ok)
|
2020-10-05 15:52:51 +00:00
|
|
|
apk_out(out, "%s", *parg);
|
2009-07-17 10:07:52 +00:00
|
|
|
if (!ok)
|
|
|
|
rc++;
|
2020-01-11 07:56:42 +00:00
|
|
|
|
2009-07-17 10:07:52 +00:00
|
|
|
apk_sign_ctx_free(&sctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct apk_applet apk_verify = {
|
|
|
|
.name = "verify",
|
|
|
|
.main = verify_main,
|
|
|
|
};
|
|
|
|
|
|
|
|
APK_DEFINE_APPLET(apk_verify);
|
|
|
|
|