summaryrefslogtreecommitdiffstats
path: root/cmake/Modules/findopensslfeatures.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules/findopensslfeatures.c')
-rw-r--r--cmake/Modules/findopensslfeatures.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/cmake/Modules/findopensslfeatures.c b/cmake/Modules/findopensslfeatures.c
index 390f1d2..ed7eb8e 100644
--- a/cmake/Modules/findopensslfeatures.c
+++ b/cmake/Modules/findopensslfeatures.c
@@ -4,6 +4,9 @@
#include <openssl/ec.h>
#include <openssl/objects.h>
#include <openssl/evp.h>
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include <openssl/provider.h>
+#endif
int
list_curves()
@@ -65,15 +68,57 @@ list_ciphers()
return 0;
}
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+static void
+print_km_name(const char *name, void *param)
+{
+ /* Do not print OIDs for better clarity */
+ if (!name || ((name[0] <= '9') && (name[0] >= '0'))) {
+ return;
+ }
+ printf("%s\n", name);
+}
+
+static void
+print_km(EVP_KEYMGMT *km, void *param)
+{
+ EVP_KEYMGMT_names_do_all(km, print_km_name, NULL);
+}
+#endif
+
int
list_publickey()
{
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
for (size_t i = 0; i < EVP_PKEY_meth_get_count(); i++) {
const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
int id = 0;
EVP_PKEY_meth_get0_info(&id, NULL, pmeth);
printf("%s\n", OBJ_nid2ln(id));
}
+#else
+ EVP_KEYMGMT_do_all_provided(NULL, print_km, NULL);
+#endif
+ return 0;
+}
+
+int
+list_providers()
+{
+ printf("default\n");
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+ const char *known_names[] = {"legacy", "fips"};
+ for (size_t i = 0; i < sizeof(known_names) / sizeof(known_names[0]); i++) {
+ OSSL_PROVIDER *prov = OSSL_PROVIDER_load(NULL, known_names[i]);
+ if (prov) {
+ printf("%s\n", known_names[i]);
+ OSSL_PROVIDER_unload(prov);
+ }
+ }
+#else
+ /* OpenSSL < 3.0 includes all legacy algorithms in the default provider */
+ printf("legacy\n");
+#endif
return 0;
}
@@ -81,7 +126,8 @@ int
main(int argc, char *argv[])
{
if (argc != 2) {
- fprintf(stderr, "Usage: opensslfeatures [curves|hashes|ciphers|publickey]\n");
+ fprintf(stderr,
+ "Usage: opensslfeatures [curves|hashes|ciphers|publickey|providers]\n");
return 1;
}
if (!strcmp(argv[1], "hashes")) {
@@ -96,6 +142,9 @@ main(int argc, char *argv[])
if (!strcmp(argv[1], "publickey")) {
return list_publickey();
}
+ if (!strcmp(argv[1], "providers")) {
+ return list_providers();
+ }
fprintf(stderr, "Unknown command: %s\n", argv[1]);
return 1;
}