grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 15/19] appended signatures: parse PKCS#7 signedData and X.


From: Daniel Axtens
Subject: Re: [PATCH v3 15/19] appended signatures: parse PKCS#7 signedData and X.509 certificates
Date: Thu, 21 Apr 2022 21:32:41 +1000

Hi,

>> This code allows us to parse:
>> 
>>  - PKCS#7 signedData messages. Only a single signerInfo is supported,
>>    which is all that the Linux sign-file utility supports creating
>>    out-of-the-box. Only RSA, SHA-256 and SHA-512 are supported.
>>    Any certificate embedded in the PKCS#7 message will be ignored.
>> 
>>  - X.509 certificates: at least enough to verify the signatures on the
>>    PKCS#7 messages. We expect that the certificates embedded in grub will
>>    be leaf certificates, not CA certificates. The parser enforces this.
>
> Doesn't grub support CA certificates for EFI?
>
For EFI, the verification isn't done by grub, it's done by either the
shim or by firmware. They do - per the spec - support certificate
chaining. So you could validly put a CA cert into db or MokList and have
a signature on an Authenticode signature chain back to that.

> Why limit to leaf certificates here?

Conventionally, appended signatures don't include embedded certificates
whereas Authenticode signatures do. There's nothing stopping you putting
one into the PKCS#7 message for an appended signature - it's just not
the way they are used on kernel modules or kernel binaries. So if
there's not an embedded certificate that can chain back to a CA
certificate, grub has to have access to the leaf certificate.

> If this is technical limitation of the code in question could you fail
> the build when CA certificate is used rather than crashing the
> bootloader when it boots?

I guess. I think IBM has been reasonably open in saying that static key
secure boot is not the end of the road for Power, so we expect that
ultimately keys could be loaded from somewhere other than the binary
like firmware storage. So even if we added this check in grub-mkimage,
we'd still need to keep it at runtime as well.

>>  - X.509 certificates support the Extended Key Usage extension and handle
>>    it by verifying that the certificate has a single purpose, that is code
>                                                 ^^^^^^^^^^^^^^
> This should be updated I suppose.

So this is - surprisingly - still accurate! We still only support 1
_Extended_ Key Usage. The change that we made as a result of SUSE's bug
report was to support additional regular, non-extended key
usages. Here's the change broken out:

commit 6056d5fc59907c486309c401135757f00ebf7760
Author: Daniel Axtens <dja@axtens.net>
Date:   Tue Nov 30 15:00:57 2021 +1100

    x509: allow Digitial Signature plus other Key Usages
    
    Currently the x509 certificate parser for appended signature
    verification requires that the certificate have the Digitial Signature
    key usage and _only_ the Digitial Signature use. This is overly strict
    and becomes policy enforcement rather than a security property.
    
    Require that the Digitial Signature usage is present, but do not
    require that it is the only usage present.
    
    Reported-by: Michal Suchanek <msuchanek@suse.com>
    Signed-off-by: Daniel Axtens <dja@axtens.net>

diff --git a/grub-core/commands/appendedsig/x509.c 
b/grub-core/commands/appendedsig/x509.c
index 70480aa73c9d..6ae985b30ff8 100644
--- a/grub-core/commands/appendedsig/x509.c
+++ b/grub-core/commands/appendedsig/x509.c
@@ -547,7 +547,7 @@ cleanup:
 
 /*
  * Verify the Key Usage extension.
- * We only permit the Digital signature usage.
+ * We require the Digital signature usage.
  */
 static grub_err_t
 verify_key_usage (grub_uint8_t *value, int value_size)
@@ -586,10 +586,10 @@ verify_key_usage (grub_uint8_t *value, int value_size)
       goto cleanup;
     }
 
-  if (usage != digitalSignatureUsage)
+  if (!(usage & digitalSignatureUsage))
     {
       err =
-       grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unexpected Key Usage value: %x",
+       grub_error (GRUB_ERR_BAD_FILE_TYPE, "Key Usage (0x%x) missing Digital 
Signature usage",
                    usage);
       goto cleanup;
     }

Kind regards,
Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]