]> git.ipfire.org Git - pakfire.git/commitdiff
keys: Do not insist on reading the comment line first
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 20:28:21 +0000 (20:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 20:28:21 +0000 (20:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/key.c

index 8824a9f674d6dee6796a59bf19fdd195fdcab10e..db893e5f22d884120ea86935e209bab8e0eb0b9f 100644 (file)
@@ -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;
                }
        }