Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jTzpo-0001KB-Ng for mharc-grub-devel@gnu.org; Wed, 29 Apr 2020 23:26:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44948) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTzpm-0001JQ-RC for grub-devel@gnu.org; Wed, 29 Apr 2020 23:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTznB-00050o-R0 for grub-devel@gnu.org; Wed, 29 Apr 2020 23:25:58 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:40790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTznB-0004zn-Cc for grub-devel@gnu.org; Wed, 29 Apr 2020 23:23:17 -0400 Received: by mail-pj1-x102a.google.com with SMTP id fu13so131819pjb.5 for ; Wed, 29 Apr 2020 20:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:subject:date:message-id:mime-version; bh=4PnGo5oTv1gq2+ETUiETj2Zt2q0b62SQFD3eQPzQXYM=; b=fv5orH65v6Gye8aL9OB7doxX1WH0eH0ow80eXhQq/j8WmT3JuT1MQwosBye6xgvHAr g2Vn0ieeJsJFzpsJqZ4PO8QiOjKTSdscBJNqwqyqP+ND71WNc4I/3+OYPCrcIoSUD2Yy g2hCc+H7d6ia6pOK7Hu5eBiYvGD1JE3b/MA5Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=4PnGo5oTv1gq2+ETUiETj2Zt2q0b62SQFD3eQPzQXYM=; b=Y95ZishD1b3HXxVgNT4BVKt6vLzPz1Y1E+CYmqOo5Mxmpe0msmacy5ZVDEU2GJMPvT NrluX0Bg7iYA5rXY0acNYxTqPt8rKjHqBpVzZdHSCcoxwnsp1QNEDQuMLvnZOdp+q6Xc IHKqx0p0/0qYO9K/PoFL6QxoUWItko/dVq10yco4NNzwlDiAmXXr5v8C2UPi73DT901h VbMebhWv/okmElhTvvuUjRZNkYMJcl3eShobzOSXV1RBnYxCB7A3KL8umy/5yp8jtV1c rkyESl51kWHeAE6WLzV9b0bWTkRG8txllrBADzQ4NMIZJ+Wl3rEUnXJDrX0HEL9osWn8 fo9Q== X-Gm-Message-State: AGi0PuZeO2jMXoqeXQ8QgJyQhY9RlYmRzmWaXa4/Tk0OcXnKSs80MRWV 5q88aG3IW/YEHVL2gy981R7qY6A6JIc= X-Google-Smtp-Source: APiQypKa4zoFZsPhvDX9asbsCHUcuslXP5E2u5gTRYg9yy60mbCM1k5bctTNm6gERHBbqjDqc2MFLQ== X-Received: by 2002:a17:902:7003:: with SMTP id y3mr1691458plk.18.1588216994924; Wed, 29 Apr 2020 20:23:14 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-2de2-77fd-5fca-2438.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:2de2:77fd:5fca:2438]) by smtp.gmail.com with ESMTPSA id g25sm2131672pfo.150.2020.04.29.20.23.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 20:23:14 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Subject: ASN.1 parsing for verifying appended signatures Date: Thu, 30 Apr 2020 13:23:10 +1000 Message-ID: <87tv11sllt.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=dja@axtens.net; helo=mail-pj1-x102a.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2607:f8b0:4864:20::102a X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 03:25:59 -0000 Hi, I'd like to teach grub how to verify appended signatures. Appended signatures are a format used by the Linux kernel to cryptographically sign binaries. They're used to verify kernel modules on all platforms [1], and they're also used on some platforms (such as PowerPC) for signing the kernel itself [2]. The cryptographic content of an appended signature is a PKCS#7 message, which is in ASN.1 DER format. I have a proof-of-concept that adds a verifier much like the existing detached signature verifier. It uses libtasn1 to parse the appended signature and an x509 signing certificate and then uses the existing libgcrypt functionality to perform the cryptographic verification. I'd like to gradually upstream this verifier. As part of that, rather than writing a bespoke ASN.1 parser for grub, I'm hoping to include libtasn1 in grub. libtasn1 is LGPLv2.1+ licensed, which is the same as libgcrypt, so I believe it's a compatible license already. I have a couple of questions I was hoping to get some input on: 1) Would including libtasn1 into grub be acceptable? It has the advantage of being extensively tried and tested, so I think it's likely to be more reliable than a hand-rolled solution. 2) If so, would it be better to write a script like import_gcry.py, or to perform the import once manually? I think the idea of import_gcry.py was to ease future upgrades of libgcrypt, but it no longer works and we've taken to applying patches directly [3]. My preference would be to import it manually in two commits - one which brings in the unmodified libtasn1 source, and then one that adapts it to grub. That way, we should be able to use git rebase to help us apply future updates. But I'm happy to do whatever would be most acceptable. Regards, Daniel [1]: https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html [2]: These signatures are verified by the kernel's Integrity Measurement Architecture (IMA) when kexec()ing into a new kernel. Ubuntu already ships powerpc kernels signed in this way, and the OpenPower host bootloader (Petitboot) uses this for secure boot. [3]: See e.g. commit e5ba6b26181b ("libgcrypt: Import replacement CRC operations"), which reads in part: The ideal solution would be to update to a new version of libgcrypt, and I spent some time trying to do that. However, util/import_gcry.py requires complex modifications to cope with the new version, and I stalled part-way through; furthermore, GRUB's libgcrypt tree already contains some backports of upstream changes. Rather than allowing the perfect to be the enemy of the good, I think it's best to backport this single change to at least sort out the licensing situation. Doing so won't make things any harder for a future wholesale upgrade.