Commit e90a86e89e for strongswan.org
commit e90a86e89e0ec776a1106ae3b076ca857b6d648d
Author: Tobias Brunner <tobias@strongswan.org>
Date: Thu Mar 12 17:51:17 2026 +0100
certificate-printer: Expose function to print details about public keys
diff --git a/src/libstrongswan/credentials/certificates/certificate_printer.c b/src/libstrongswan/credentials/certificates/certificate_printer.c
index 920031617a..ac0e7ac9d0 100644
--- a/src/libstrongswan/credentials/certificates/certificate_printer.c
+++ b/src/libstrongswan/credentials/certificates/certificate_printer.c
@@ -590,17 +590,16 @@ static void print_ocsp_response(private_certificate_printer_t *this,
}
}
-/**
- * Print public key information
+/*
+ * Described in header
*/
-static void print_pubkey(private_certificate_printer_t *this, public_key_t *key,
- bool has_privkey)
+void certificate_printer_print_pubkey(FILE *f, char *prefix, public_key_t *key,
+ bool has_privkey)
{
key_type_t type = key->get_type(key);
chunk_t chunk;
- FILE *f = this->f;
- fprintf(f, " pubkey: %N %d bits", key_type_names, type,
+ fprintf(f, "%-12s %N %d bits", prefix, key_type_names, type,
key->get_keysize(key));
if (has_privkey)
{
@@ -734,7 +733,7 @@ METHOD(certificate_printer_t, print, void,
key = cert->get_public_key(cert);
if (key)
{
- print_pubkey(this, key, has_privkey);
+ certificate_printer_print_pubkey(this->f, " pubkey:", key, has_privkey);
key->destroy(key);
}
}
diff --git a/src/libstrongswan/credentials/certificates/certificate_printer.h b/src/libstrongswan/credentials/certificates/certificate_printer.h
index 9e0ebd6d84..6c6ced8cb1 100644
--- a/src/libstrongswan/credentials/certificates/certificate_printer.h
+++ b/src/libstrongswan/credentials/certificates/certificate_printer.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2026 Tobias Brunner
* Copyright (C) 2015 Andreas Steffen
*
* Copyright (C) secunet Security Networks AG
@@ -68,4 +69,16 @@ struct certificate_printer_t {
certificate_printer_t* certificate_printer_create(FILE *f, bool detailed,
bool utc);
+/**
+ * Print the given public key with the given prefix to a file stream.
+ *
+ * @param f file where print output is directed to (usually stdout)
+ * @param prefix prefix (e.g. " pubkey:"), max. 12 chars
+ * @param key public key to print details about
+ * @param has_privkey whether to add a hint indicating that a matching private
+ * key is available
+ */
+void certificate_printer_print_pubkey(FILE *f, char *prefix, public_key_t *key,
+ bool has_privkey);
+
#endif /** CERTIFICATE_PRINTER_H_ @}*/