]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Skip unavailable digests and ciphers in -*-commands
authorDmitry Belyavskiy <beldmit@gmail.com>
Fri, 11 Dec 2020 02:15:09 +0000 (03:15 +0100)
committerDmitry Belyavskiy <beldmit@gmail.com>
Tue, 15 Dec 2020 03:39:58 +0000 (04:39 +0100)
Fixes #13594

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13669)

apps/include/apps.h
apps/lib/engine.c
apps/list.c

index ddfa3c8383522bb2ba6cc85e0eac1f36785ccc0a..0a8d6f4060761989a573c71e63f8e8dd65631e52 100644 (file)
@@ -159,6 +159,8 @@ int finish_engine(ENGINE *e);
 char *make_engine_uri(ENGINE *e, const char *key_id, const char *desc);
 
 int get_legacy_pkey_id(OSSL_LIB_CTX *libctx, const char *algname, ENGINE *e);
+const EVP_MD *get_digest_from_engine(const char *name);
+const EVP_CIPHER *get_cipher_from_engine(const char *name);
 
 # ifndef OPENSSL_NO_OCSP
 OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
index e4a65b04e2c0ae905d33fbeb34e076c49d3a516b..209c4b6b03c269e9b8e23eacfcc6e2bf8adf0dbd 100644 (file)
@@ -163,3 +163,31 @@ int get_legacy_pkey_id(OSSL_LIB_CTX *libctx, const char *algname, ENGINE *e)
 
     return pkey_id;
 }
+
+const EVP_MD *get_digest_from_engine(const char *name)
+{
+#ifndef OPENSSL_NO_ENGINE
+    ENGINE *eng;
+
+    eng = ENGINE_get_digest_engine(OBJ_sn2nid(name));
+    if (eng != NULL) {
+        ENGINE_finish(eng);
+        return EVP_get_digestbyname(name);
+    }
+#endif
+    return NULL;
+}
+
+const EVP_CIPHER *get_cipher_from_engine(const char *name)
+{
+#ifndef OPENSSL_NO_ENGINE
+    ENGINE *eng;
+
+    eng = ENGINE_get_cipher_engine(OBJ_sn2nid(name));
+    if (eng != NULL) {
+        ENGINE_finish(eng);
+        return EVP_get_cipherbyname(name);
+    }
+#endif
+    return NULL;
+}
index cf63394107d33e479d4b1bd60918a4b625f29173..df25e00363da0957269ba450b050c20e06d68df4 100644 (file)
@@ -945,6 +945,38 @@ static void list_options_for_command(const char *command)
     BIO_printf(bio_out, "- -\n");
 }
 
+static int is_md_available(const char *name)
+{
+    EVP_MD *md;
+
+    /* Look through providers' digests */
+    ERR_set_mark();
+    md = EVP_MD_fetch(NULL, name, NULL);
+    ERR_pop_to_mark();
+    if (md != NULL) {
+        EVP_MD_free(md);
+        return 1;
+    }
+
+    return (get_digest_from_engine(name) == NULL) ? 0 : 1;
+}
+
+static int is_cipher_available(const char *name)
+{
+    EVP_CIPHER *cipher;
+
+    /* Look through providers' ciphers */
+    ERR_set_mark();
+    cipher = EVP_CIPHER_fetch(NULL, name, NULL);
+    ERR_pop_to_mark();
+    if (cipher != NULL) {
+        EVP_CIPHER_free(cipher);
+        return 1;
+    }
+
+    return (get_cipher_from_engine(name) == NULL) ? 0 : 1;
+}
+
 static void list_type(FUNC_TYPE ft, int one)
 {
     FUNCTION *fp;
@@ -958,6 +990,18 @@ static void list_type(FUNC_TYPE ft, int one)
     for (fp = functions; fp->name != NULL; fp++) {
         if (fp->type != ft)
             continue;
+        switch (ft) {
+        case FT_cipher:
+            if (!is_cipher_available(fp->name))
+                continue;
+            break;
+        case FT_md:
+            if (!is_md_available(fp->name))
+                continue;
+            break;
+        default:
+            break;
+        }
         if (one) {
             BIO_printf(bio_out, "%s\n", fp->name);
         } else {