From 5f99a195e8603eb522efb1f04039a91bf6c31a05 Mon Sep 17 00:00:00 2001 From: Andrew Lukoshko Date: Sat, 29 Mar 2025 23:35:42 +0000 Subject: [PATCH] appended signatures: add support for printableString in x509 Original patch by Daniel Axtens Signed-off-by: Andrew Lukoshko --- grub-core/commands/appendedsig/x509.c | 44 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/grub-core/commands/appendedsig/x509.c b/grub-core/commands/appendedsig/x509.c index 42ec65c..c2cfe5f 100644 --- a/grub-core/commands/appendedsig/x509.c +++ b/grub-core/commands/appendedsig/x509.c @@ -310,22 +310,36 @@ decode_string (char *der, int der_size, char **string, goto cleanup; } - if (grub_strncmp ("utf8String", choice, choice_size)) + if (grub_strncmp ("utf8String", choice, choice_size) == 0) { - err = - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "Only UTF-8 DirectoryStrings are supported, got %s", - choice); - goto cleanup_choice; + result = asn1_read_value (strasn, "utf8String", NULL, &tmp_size); + if (result != ASN1_MEM_ERROR) + { + err = + grub_error (GRUB_ERR_BAD_FILE_TYPE, + "Error reading size of UTF-8 string: %s", + asn1_strerror (result)); + goto cleanup_choice; + } } - - result = asn1_read_value (strasn, "utf8String", NULL, &tmp_size); - if (result != ASN1_MEM_ERROR) + else if (grub_strncmp("printableString", choice, choice_size) == 0) + { + result = asn1_read_value (strasn, "printableString", NULL, &tmp_size); + if (result != ASN1_MEM_ERROR) + { + err = + grub_error (GRUB_ERR_BAD_FILE_TYPE, + "Error reading size of printable string: %s", + asn1_strerror (result)); + goto cleanup_choice; + } + } + else { err = - grub_error (GRUB_ERR_BAD_FILE_TYPE, - "Error reading size of UTF-8 string: %s", - asn1_strerror (result)); + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Only UTF-8 and printable DirectoryStrings are supported, got %s", + choice); goto cleanup_choice; } @@ -341,13 +355,13 @@ decode_string (char *der, int der_size, char **string, goto cleanup_choice; } - result = asn1_read_value (strasn, "utf8String", *string, &tmp_size); + result = asn1_read_value (strasn, choice, *string, &tmp_size); if (result != ASN1_SUCCESS) { err = grub_error (GRUB_ERR_BAD_FILE_TYPE, - "Error reading out UTF-8 string in DirectoryString: %s", - asn1_strerror (result)); + "Error reading out %s in DirectoryString: %s", + choice, asn1_strerror (result)); grub_free (*string); goto cleanup_choice; } -- 2.43.5