All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] verify: search keyid in hashed signature subpackets
@ 2016-03-29 19:02 Ignat Korchagin
  2016-03-30  4:44 ` Andrei Borzenkov
  0 siblings, 1 reply; 14+ messages in thread
From: Ignat Korchagin @ 2016-03-29 19:02 UTC (permalink / raw)
  To: grub-devel

Currently GRUB2 verify logic searches PGP keyid only in unhashed subpackets of PGP signature packet. As a result, signatures generated with GoLang openpgp package (https://godoc.org/golang.org/x/crypto/openpgp) could not be verified, because this package puts keyid in hashed subpackets and GRUB code never initializes the keyid variable, therefore is not able to find "verification key" with id 0x0.

diff --git a/grub-core/commands/verify.c b/grub-core/commands/verify.c
index 166d0aa..dde37c4 100644
--- a/grub-core/commands/verify.c
+++ b/grub-core/commands/verify.c
@@ -532,33 +532,15 @@
 
     hash->write (context, &v, sizeof (v));
     hash->write (context, &v4, sizeof (v4));
-    while (rem)
-      {
-	r = grub_file_read (sig, readbuf,
-			    rem < READBUF_SIZE ? rem : READBUF_SIZE);
-	if (r < 0)
-	  goto fail;
-	if (r == 0)
-	  break;
-	hash->write (context, readbuf, r);
-	rem -= r;
-      }
-    hash->write (context, &v, sizeof (v));
-    s = 0xff;
-    hash->write (context, &s, sizeof (s));
-    hash->write (context, &headlen, sizeof (headlen));
-    r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
-    if (r != sizeof (unhashed_sub))
+    if (rem > READBUF_SIZE)
+      goto fail;
+    r = grub_file_read (sig, readbuf, rem);
+    if (r != rem)
       goto fail;
     {
       grub_uint8_t *ptr;
       grub_uint32_t l;
-      rem = grub_be_to_cpu16 (unhashed_sub);
-      if (rem > READBUF_SIZE)
-	goto fail;
-      r = grub_file_read (sig, readbuf, rem);
-      if (r != rem)
-	goto fail;
+
       for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
 	{
 	  if (*ptr < 192)
@@ -581,6 +563,46 @@
 	    keyid = grub_get_unaligned64 (ptr + 1);
 	}
     }
+    hash->write (context, readbuf, r);
+    hash->write (context, &v, sizeof (v));
+    s = 0xff;
+    hash->write (context, &s, sizeof (s));
+    hash->write (context, &headlen, sizeof (headlen));
+    r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
+    if (r != sizeof (unhashed_sub))
+      goto fail;
+    if (keyid == 0)
+      {
+        grub_uint8_t *ptr;
+        grub_uint32_t l;
+        rem = grub_be_to_cpu16 (unhashed_sub);
+        if (rem > READBUF_SIZE)
+	  goto fail;
+        r = grub_file_read (sig, readbuf, rem);
+        if (r != rem)
+	  goto fail;
+        for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
+	  {
+	    if (*ptr < 192)
+	      l = *ptr++;
+	    else if (*ptr < 255)
+	      {
+	        if (ptr + 1 >= readbuf + rem)
+		  break;
+	        l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
+	        ptr += 2;
+	      }
+	    else
+	      {
+	        if (ptr + 5 >= readbuf + rem)
+		  break;
+	        l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
+	        ptr += 5;
+	      }
+	    if (*ptr == 0x10 && l >= 8)
+	      keyid = grub_get_unaligned64 (ptr + 1);
+	  }
+      }
 
     hash->final (context);
 



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-11-15 12:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-29 19:02 [PATCH] verify: search keyid in hashed signature subpackets Ignat Korchagin
2016-03-30  4:44 ` Andrei Borzenkov
2016-03-30  8:47   ` Ignat Korchagin
2016-03-30  9:38     ` Andrei Borzenkov
2016-03-30 14:09       ` Ignat Korchagin
2016-04-09  4:27         ` Andrei Borzenkov
2016-04-10 18:34           ` Ignat Korchagin
2016-04-19 14:28             ` Ignat Korchagin
2016-04-21 16:54               ` Ignat Korchagin
2016-04-28 21:32                 ` Ignat Korchagin
2016-11-10 13:50                   ` Daniel Kiper
2016-11-13  9:18                     ` Andrei Borzenkov
2016-11-15 12:42                       ` Daniel Kiper
2016-11-15 12:43                         ` Ignat Korchagin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.