Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Kernel:tools
qemu
0013-appended-signature-Support-two-certificate...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0013-appended-signature-Support-two-certificates.patch of Package qemu
From 63eb79772de45f7e3a07039eb248b8c8384a6b85 Mon Sep 17 00:00:00 2001 From: Michal Suchanek <msuchanek@suse.de> Date: Wed, 5 Jan 2022 17:10:06 +0100 Subject: [PATCH] appended signature: Support two certificates. Signed-off-by: Michal Suchanek <msuchanek@suse.de> --- lib/libcrypto/appended_sig.c | 72 +++++++++++++--------- lib/libcrypto/certificate.h | 112 +++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 28 deletions(-) diff --git a/roms/SLOF/lib/libcrypto/appended_sig.c b/roms/SLOF/lib/libcrypto/appended_sig.c index 6b7c0cd..f3d6de5 100644 --- a/roms/SLOF/lib/libcrypto/appended_sig.c +++ b/roms/SLOF/lib/libcrypto/appended_sig.c @@ -32,10 +32,43 @@ int is_secureboot() { return 1; } +static int verify_one_cert(mbedtls_pkcs7 *pkcs7, const void *blob, size_t bloblen, const void *cert, size_t certlen, const char *certdesc) +{ + mbedtls_x509_crt *x509 = malloc(sizeof(mbedtls_x509_crt)); + int rc = 0; + + mbedtls_x509_crt_init(x509); + printf("%d\n", __LINE__); + rc = mbedtls_x509_crt_parse_der(x509, cert, certlen); + if (rc) { + printf("%d\n", __LINE__); + + printf("Appended signature: internal error parsing %s x509 certificate.\n", certdesc); + rc = 0; + goto exit_x509; + } + printf("%d\n", __LINE__); + + rc = mbedtls_pkcs7_signed_data_verify(pkcs7, x509, blob, bloblen); + printf("Appended signature: %sverified by %s x509 certificate.\n", rc ? "NOT " : "" , certdesc); + if (rc) { + printf("%d\n", __LINE__); + rc = 0; + goto exit_x509; + } + + rc = 1; + +exit_x509: + mbedtls_x509_crt_free(x509); + free(x509); + + return rc; +} + int verify_appended_signature(void *blob, size_t len) { void *ptr; mbedtls_pkcs7 *pkcs7; - mbedtls_x509_crt *x509; int rc = 0; struct module_signature *modsig; @@ -69,48 +102,31 @@ int verify_appended_signature(void *blob, size_t len) { // point at the pkcs7 data itself: ptr -= modsig->sig_len; + printf("%d\n", __LINE__); + printf("ptr at %p, blob at %p, computed len %lu ? %lu\n", ptr, blob, len-(ptr-blob), (unsigned long)(ptr-blob)); + // load into the pkcs7 code pkcs7 = malloc(sizeof(mbedtls_pkcs7)); mbedtls_pkcs7_init(pkcs7); - rc = mbedtls_pkcs7_parse_der(ptr, modsig->sig_len, pkcs7); if (rc != MBEDTLS_PKCS7_SIGNED_DATA) { printf("Appended signature: error parsing PKCS#7 data: %d. Aborting.\n", rc); rc = 0; goto exit; } - - x509 = malloc(sizeof(mbedtls_x509_crt)); - mbedtls_x509_crt_init(x509); - printf("%d\n", __LINE__); - rc = mbedtls_x509_crt_parse_der(x509, certificate_der, certificate_der_len); - if (rc) { printf("%d\n", __LINE__); - printf("Appended signature: internal error parsing builtin x509 certificate. Aborting.\n"); - rc = 0; - goto exit_x509; - } - printf("%d\n", __LINE__); + rc = verify_one_cert(pkcs7, blob, (ptr-blob), certificate_SLE_crt, certificate_SLE_crt_len, "SLE"); + if (rc) + goto exit; - printf("ptr at %p, blob at %p, computed len %lu ? %lu\n", ptr, blob, len-(ptr-blob), (unsigned long)(ptr-blob)); + rc = verify_one_cert(pkcs7, blob, (ptr-blob), certificate_der, certificate_der_len, "project"); + if (rc) + goto exit; - rc = mbedtls_pkcs7_signed_data_verify(pkcs7, x509, blob, (ptr - blob)); - if (rc) { - printf("%d\n", __LINE__); - printf("Appended signature: verification failed. Refusing to proceed.\n"); - rc = 0; - goto exit_x509; - } printf("%d\n", __LINE__); - - rc = 1; - -exit_x509: - mbedtls_x509_crt_free(x509); - free(x509); - + printf("Appended signature: verification failed. Refusing to proceed.\n"); exit: mbedtls_pkcs7_free(pkcs7); free(pkcs7); diff --git a/roms/SLOF/lib/libcrypto/certificate.h b/roms/SLOF/lib/libcrypto/certificate.h index b48f1ee..88d2e4b 100644 --- a/roms/SLOF/lib/libcrypto/certificate.h +++ b/roms/SLOF/lib/libcrypto/certificate.h @@ -116,3 +116,115 @@ unsigned char certificate_der[] = { 0x61 }; unsigned int certificate_der_len = 1369; + +unsigned char certificate_SLE_crt[] = { + 0x30, 0x82, 0x05, 0x04, 0x30, 0x82, 0x03, 0xec, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x09, 0x00, 0xed, 0x87, 0x85, 0xb7, 0x8f, 0xfc, 0x12, 0x7e, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, + 0x0b, 0x05, 0x00, 0x30, 0x81, 0xa6, 0x31, 0x2d, 0x30, 0x2b, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0c, 0x24, 0x53, 0x55, 0x53, 0x45, 0x20, 0x4c, 0x69, + 0x6e, 0x75, 0x78, 0x20, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x69, + 0x73, 0x65, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, + 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, + 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, + 0x55, 0x04, 0x07, 0x0c, 0x09, 0x4e, 0x75, 0x72, 0x65, 0x6d, 0x62, 0x65, + 0x72, 0x67, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, + 0x18, 0x53, 0x55, 0x53, 0x45, 0x20, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20, + 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x20, 0x47, 0x6d, 0x62, + 0x48, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0a, + 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, + 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, + 0x01, 0x16, 0x0d, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x40, 0x73, 0x75, 0x73, + 0x65, 0x2e, 0x64, 0x65, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x33, + 0x30, 0x38, 0x31, 0x30, 0x31, 0x35, 0x30, 0x38, 0x5a, 0x17, 0x0d, 0x33, + 0x30, 0x31, 0x32, 0x33, 0x31, 0x31, 0x30, 0x31, 0x35, 0x30, 0x38, 0x5a, + 0x30, 0x81, 0xab, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x0c, 0x29, 0x53, 0x55, 0x53, 0x45, 0x20, 0x4c, 0x69, 0x6e, 0x75, 0x78, + 0x20, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x20, + 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, + 0x53, 0x69, 0x67, 0x6e, 0x6b, 0x65, 0x79, 0x31, 0x0b, 0x30, 0x09, 0x06, + 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x09, 0x4e, 0x75, 0x72, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x67, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, + 0x0a, 0x0c, 0x18, 0x53, 0x55, 0x53, 0x45, 0x20, 0x4c, 0x69, 0x6e, 0x75, + 0x78, 0x20, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x20, 0x47, + 0x6d, 0x62, 0x48, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x0a, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x54, 0x65, 0x61, 0x6d, + 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, + 0x01, 0x09, 0x01, 0x16, 0x0d, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x40, 0x73, + 0x75, 0x73, 0x65, 0x2e, 0x64, 0x65, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, + 0x01, 0x01, 0x00, 0xb6, 0xf0, 0x29, 0x43, 0x8a, 0xa0, 0xc4, 0x38, 0x9b, + 0x3a, 0x96, 0x2e, 0x7c, 0x5c, 0x90, 0x1b, 0x71, 0xc3, 0xb1, 0x0b, 0xf0, + 0x8c, 0xf7, 0xeb, 0x40, 0x77, 0x58, 0xaa, 0x47, 0x0a, 0x0d, 0x9b, 0xf3, + 0x84, 0xa1, 0x49, 0x4a, 0x90, 0x2e, 0xe2, 0x0b, 0xa5, 0x92, 0xe2, 0xa7, + 0x39, 0xe3, 0x0e, 0xd7, 0xe7, 0x9c, 0xa4, 0xe0, 0xbd, 0x7f, 0x41, 0xba, + 0x99, 0xb2, 0x30, 0x60, 0x2b, 0x0c, 0xfc, 0x62, 0x81, 0x09, 0x42, 0x91, + 0x41, 0x93, 0xce, 0x07, 0x97, 0x92, 0x78, 0x65, 0x3e, 0x34, 0x96, 0x88, + 0x5d, 0x5e, 0x88, 0x8a, 0x68, 0x5f, 0x62, 0x2d, 0xcc, 0x5e, 0x68, 0x5e, + 0x56, 0xb3, 0xfa, 0xe1, 0x77, 0x7a, 0xa6, 0xf7, 0x27, 0xfe, 0x2a, 0x65, + 0x93, 0x62, 0x0f, 0x2d, 0xb6, 0xdd, 0x8c, 0x87, 0xa2, 0x48, 0x89, 0xa0, + 0xd7, 0x1b, 0x5f, 0x9e, 0xb7, 0x1a, 0x59, 0xaf, 0xad, 0xcc, 0xe3, 0x2e, + 0x30, 0x04, 0x1f, 0x17, 0x8c, 0x14, 0x95, 0x59, 0xc5, 0x17, 0x83, 0xe7, + 0x87, 0x48, 0x28, 0x4b, 0x6b, 0x2f, 0xd8, 0xb8, 0xf7, 0x7d, 0x54, 0x38, + 0x5d, 0x5e, 0xdd, 0xf1, 0xbb, 0x01, 0xf6, 0x0c, 0x1d, 0x59, 0x24, 0x10, + 0x33, 0x06, 0xd2, 0x6f, 0x94, 0x97, 0xa2, 0x22, 0xd9, 0x38, 0x8a, 0xd9, + 0x88, 0x8f, 0xe7, 0xe8, 0x30, 0xf9, 0x50, 0xbf, 0x18, 0x6a, 0x9f, 0xb6, + 0x7f, 0x9b, 0x01, 0x5c, 0x0d, 0x4c, 0xb6, 0x89, 0xd7, 0xf7, 0x53, 0x12, + 0x52, 0xee, 0xbc, 0x56, 0x1e, 0xe5, 0xff, 0xd5, 0x17, 0x12, 0x7b, 0x64, + 0xc7, 0x96, 0xf2, 0x39, 0xd4, 0x40, 0x2b, 0x19, 0xdd, 0x22, 0x99, 0xcf, + 0x41, 0x06, 0xb3, 0x85, 0x7b, 0x50, 0xa0, 0x5b, 0x24, 0x3e, 0xd5, 0x73, + 0x2a, 0xcf, 0xbc, 0x8c, 0x87, 0xa6, 0x0c, 0xea, 0x2c, 0x9f, 0xb7, 0x13, + 0x90, 0x18, 0x0e, 0x10, 0xfe, 0x3d, 0x89, 0x02, 0x03, 0x01, 0x00, 0x01, + 0xa3, 0x82, 0x01, 0x2c, 0x30, 0x82, 0x01, 0x28, 0x30, 0x0c, 0x06, 0x03, + 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, + 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x5a, 0x24, 0x04, + 0x49, 0xd2, 0x9f, 0xd0, 0xd8, 0xa7, 0xa1, 0x87, 0xe6, 0xfc, 0x0e, 0x26, + 0xb9, 0x5d, 0x1a, 0xa8, 0x7b, 0x30, 0x81, 0xd3, 0x06, 0x03, 0x55, 0x1d, + 0x23, 0x04, 0x81, 0xcb, 0x30, 0x81, 0xc8, 0x80, 0x14, 0xec, 0xab, 0x0d, + 0x42, 0xc4, 0x56, 0xcf, 0x77, 0x04, 0x36, 0xb9, 0x73, 0x99, 0x38, 0x62, + 0x96, 0x5e, 0x87, 0x26, 0x2f, 0xa1, 0x81, 0xac, 0xa4, 0x81, 0xa9, 0x30, + 0x81, 0xa6, 0x31, 0x2d, 0x30, 0x2b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, + 0x24, 0x53, 0x55, 0x53, 0x45, 0x20, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20, + 0x45, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x20, 0x53, + 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x44, 0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, + 0x09, 0x4e, 0x75, 0x72, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x67, 0x31, 0x21, + 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x53, 0x55, 0x53, + 0x45, 0x20, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x73, 0x20, 0x47, 0x6d, 0x62, 0x48, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0a, 0x42, 0x75, 0x69, 0x6c, + 0x64, 0x20, 0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0d, 0x62, + 0x75, 0x69, 0x6c, 0x64, 0x40, 0x73, 0x75, 0x73, 0x65, 0x2e, 0x64, 0x65, + 0x82, 0x01, 0x01, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, + 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x13, 0x06, 0x03, 0x55, + 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, + 0x05, 0x07, 0x03, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, + 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, + 0xa8, 0x52, 0x38, 0x95, 0x54, 0x1f, 0xde, 0x17, 0xa1, 0xd1, 0x35, 0xab, + 0x67, 0x07, 0x34, 0x7a, 0x3d, 0xf4, 0xa7, 0x51, 0x21, 0x54, 0x99, 0xac, + 0x37, 0x10, 0xb2, 0xfe, 0x6b, 0x67, 0xe8, 0x80, 0xe4, 0x47, 0x39, 0xb3, + 0x01, 0xef, 0x45, 0xfd, 0x3c, 0x79, 0x07, 0xa2, 0xb2, 0xb6, 0x3b, 0x63, + 0xd9, 0x6b, 0xd4, 0xda, 0x63, 0xa1, 0x8c, 0x35, 0xba, 0xd5, 0x37, 0x6f, + 0x93, 0x65, 0x01, 0xaa, 0x56, 0xa9, 0x4d, 0xb4, 0xf4, 0x5f, 0x6a, 0x05, + 0x0a, 0x8e, 0x30, 0xc3, 0xc8, 0x26, 0xda, 0xe0, 0xf2, 0x63, 0x79, 0xc2, + 0x10, 0xcd, 0x23, 0x74, 0xf8, 0xfc, 0x5e, 0x70, 0x3e, 0x4f, 0xea, 0xda, + 0xc7, 0x07, 0x30, 0xe8, 0xda, 0x2c, 0x2b, 0x72, 0x7a, 0x83, 0xe6, 0xc4, + 0x5a, 0x39, 0x17, 0xd2, 0x55, 0xab, 0xca, 0x5d, 0x63, 0x83, 0x1b, 0x80, + 0xab, 0x7c, 0xee, 0xa7, 0x8b, 0x76, 0xae, 0x5e, 0xfd, 0xdb, 0x3f, 0xa7, + 0x01, 0x40, 0x26, 0x09, 0x2a, 0xec, 0x61, 0xe4, 0x10, 0xc6, 0x72, 0x88, + 0x78, 0x2b, 0xd9, 0x09, 0x83, 0x06, 0x82, 0x2c, 0x52, 0xa1, 0x8a, 0xef, + 0xd9, 0x2c, 0x43, 0xf2, 0x14, 0xc5, 0x0b, 0xc5, 0xd6, 0xeb, 0x4e, 0xaf, + 0x21, 0x35, 0x5b, 0xf5, 0xfc, 0x5a, 0x60, 0x5d, 0x5c, 0x0a, 0x30, 0x8b, + 0x8e, 0x19, 0x10, 0xa6, 0x77, 0xa0, 0x56, 0x24, 0xf4, 0x99, 0x5e, 0x50, + 0x70, 0xf5, 0xbf, 0x20, 0x88, 0xea, 0x2a, 0x56, 0xb5, 0x37, 0xdb, 0x07, + 0xdb, 0xa6, 0xee, 0x17, 0x07, 0x09, 0x20, 0x75, 0xd0, 0x44, 0x1e, 0x21, + 0xd5, 0xba, 0x15, 0xb4, 0x8a, 0xa2, 0x41, 0x93, 0x9e, 0xe0, 0x18, 0xc6, + 0x45, 0x3b, 0xd1, 0x20, 0xb1, 0x8e, 0x6b, 0xf5, 0x97, 0x9f, 0xc5, 0x21, + 0x42, 0xf3, 0x1c, 0xdf, 0xd6, 0xc2, 0xaf, 0x54, 0xb1, 0x31, 0x1b, 0xe9, + 0x09, 0x5e, 0xf3, 0x2b +}; +unsigned int certificate_SLE_crt_len = 1288; -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor