From: Michael Tremer Date: Thu, 1 Jun 2023 20:28:21 +0000 (+0000) Subject: keys: Do not insist on reading the comment line first X-Git-Tag: 0.9.29~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd5d0981ff427786acca9d47c81b5734650d4aab;p=pakfire.git keys: Do not insist on reading the comment line first Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/key.c b/src/libpakfire/key.c index 8824a9f67..db893e5f2 100644 --- a/src/libpakfire/key.c +++ b/src/libpakfire/key.c @@ -383,57 +383,35 @@ PAKFIRE_EXPORT int pakfire_key_import(struct pakfire_key** key, if (bytes_read < 0) break; - // Increment the line counter - lineno++; + // Decode the key + r = pakfire_b64decode(pakfire, &buffer, &buffer_length, line); + if (r) { + ERROR(pakfire, "Could not decode the key: %m\n"); + errno = EINVAL; + r = 1; + goto ERROR; + } - switch (lineno) { - // The first line must start with "untrusted comment:" - case 1: - if (!pakfire_string_startswith(line, "untrusted comment:")) { - ERROR(pakfire, "The first line must start with 'untrusted comment:'\n"); - errno = EINVAL; - r = 1; - goto ERROR; - } + // What kind of key do we have? + switch (buffer_length) { + // Public Key + case sizeof(struct pakfire_key_public_key): + r = pakfire_key_import_public_key(key, pakfire, + (struct pakfire_key_public_key*)buffer); break; - // The second line should hold the key - case 2: - // Decode the key - r = pakfire_b64decode(pakfire, &buffer, &buffer_length, line); - if (r) { - ERROR(pakfire, "Could not decode the key: %m\n"); - errno = EINVAL; - r = 1; - goto ERROR; - } - - // What kind of key do we have? - switch (buffer_length) { - // Public Key - case sizeof(struct pakfire_key_public_key): - r = pakfire_key_import_public_key(key, pakfire, - (struct pakfire_key_public_key*)buffer); - break; - - // Private Key - case sizeof(struct pakfire_key_private_key): - r = pakfire_key_import_secret_key(key, pakfire, - (struct pakfire_key_private_key*)buffer); - break; - - // Unknown key - default: - ERROR(pakfire, "Unsupported key type\n"); - errno = ENOTSUP; - r = 1; - goto ERROR; - } + // Private Key + case sizeof(struct pakfire_key_private_key): + r = pakfire_key_import_secret_key(key, pakfire, + (struct pakfire_key_private_key*)buffer); break; - // Ignore any further data + // Unknown key default: - break; + ERROR(pakfire, "Unsupported key type\n"); + errno = ENOTSUP; + r = 1; + goto ERROR; } }