trust: add draft seperate public/secret loading

It isn't clear where secret keys will be located at but this should at
least allow for cleaner seperation in lists.
cute-signatures
Aydin Mercan 2022-08-10 16:54:51 +03:00
parent 5b020ec9ef
commit 1c54a3fbb4
Signed by: jaiden
SSH Key Fingerprint: SHA256:vy6hjzotbn/MWZAbjzURNk3NL62EPkjoHsJ5xr/s7nk
3 changed files with 23 additions and 4 deletions

View File

@ -1180,7 +1180,7 @@ int adb_trust_write_signatures(struct apk_trust *trust, struct adb *db, struct a
struct adb_sign_v0 v0;
unsigned char buf[ADB_MAX_SIGNATURE_LEN];
} sig;
struct apk_trust_key *tkey;
struct apk_trust_secret_key *tkey;
apk_blob_t md;
size_t siglen;
int r;

View File

@ -18,7 +18,7 @@ struct apk_trust_key {
char *filename;
};
struct apk_trust_secret {
struct apk_trust_secret_key {
struct list_head key_node;
struct apk_secret_key key;
char *filename;

View File

@ -21,6 +21,25 @@ static struct apk_trust_key *apk_trust_load_public(int dirfd, const char *filena
return key;
}
static struct apk_trust_secret_key *apk_trust_load_secret(int dirfd, const char *filename)
{
struct apk_trust_secret_key *key;
int r;
key = calloc(1, sizeof *key);
if (!key) return ERR_PTR(-ENOMEM);
r = apk_secret_key_load(&key->key, dirfd, filename);
if (r != 0) {
free(key);
return ERR_PTR(r);
}
list_init(&key->key_node);
key->filename = strdup(filename);
return key;
}
static int __apk_trust_load_pubkey(void *pctx, int dirfd, const char *filename)
{
struct apk_trust *trust = pctx;
@ -93,11 +112,11 @@ static int option_parse_signing(void *ctx, struct apk_ctx *ac, int optch, const
{
struct apk_trust *trust = &ac->trust;
struct apk_out *out = &ac->out;
struct apk_trust_key *key;
struct apk_trust_secret_key *key;
switch (optch) {
case OPT_SIGN_sign_key:
key = apk_trust_load_public(AT_FDCWD, optarg);
key = apk_trust_load_secret(AT_FDCWD, optarg);
if (IS_ERR(key)) {
apk_err(out, "Failed to load signing key: %s: %s",
optarg, apk_error_str(PTR_ERR(key)));