Skip to content

Commit

Permalink
Add also check for Public Key URI
Browse files Browse the repository at this point in the history
Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Feb 6, 2025
1 parent 50cf7d7 commit 5b4ef96
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/tpkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/store.h>
Expand Down Expand Up @@ -77,6 +79,41 @@ static void verify_op(EVP_PKEY *key, const char *data, size_t len,
EVP_MD_CTX_free(ver_md);
}

static void check_public_info(EVP_PKEY *key)
{
BIO *membio = BIO_new(BIO_s_mem());
BUF_MEM *memdata = NULL;
const char *type = "type=public";
void *found = NULL;
int ret;

if (!membio) {
PRINTERROSSL("Failed to instantiate Memory BIO\n");
exit(EXIT_FAILURE);
}

ret = EVP_PKEY_print_public(membio, key, 0, NULL);
if (ret != 1) {
PRINTERROSSL("Failed to print public key info\n");
exit(EXIT_FAILURE);
}

BIO_get_mem_ptr(membio, &memdata);
if (!memdata) {
PRINTERROSSL("Failed to fetch BIO memory pointer\n");
exit(EXIT_FAILURE);
}

found = memmem(memdata->data, memdata->length, type, sizeof(type) - 1);
if (!found) {
PRINTERR("%.*s\n", (int)memdata->length, memdata->data);
PRINTERROSSL("Public type indicator not found in printout!\n");
exit(EXIT_FAILURE);
}

BIO_free(membio);
}

int main(int argc, char *argv[])
{
const char *data = "Sign Me!";
Expand All @@ -91,6 +128,8 @@ int main(int argc, char *argv[])

verify_op(key, data, sizeof(data), sig, siglen);

check_public_info(key);

PRINTERR("ALL A-OK!\n");
exit(EXIT_SUCCESS);
}

0 comments on commit 5b4ef96

Please sign in to comment.