Configurations/15-android.conf: add support for "standalone toolchain".
[openssl.git] / apps / openssl.c
index 8b75a8affbf88ed89fe9f32502054f6dd2db0262..3d6b276c40e57d9bdcc99f71cc2cdf3421cc7277 100644 (file)
@@ -27,8 +27,9 @@
 #ifdef OPENSSL_SYS_VMS
 # include <unixio.h>
 #endif
-#define INCLUDE_FUNCTION_TABLE
 #include "apps.h"
+#define INCLUDE_FUNCTION_TABLE
+#include "progs.h"
 
 /* Structure to hold the number of columns to be displayed and the
  * field width used to display them.
@@ -73,7 +74,7 @@ static void calculate_columns(DISPLAY_COLUMNS *dc)
     dc->columns = (80 - 1) / dc->width;
 }
 
-static int apps_startup()
+static int apps_startup(void)
 {
 #ifdef SIGPIPE
     signal(SIGPIPE, SIG_IGN);
@@ -89,12 +90,13 @@ static int apps_startup()
     return 1;
 }
 
-static void apps_shutdown()
+static void apps_shutdown(void)
 {
     destroy_ui_method();
+    destroy_prefix_method();
 }
 
-static char *make_config_name()
+static char *make_config_name(void)
 {
     const char *t;
     size_t len;
@@ -314,6 +316,56 @@ static void list_missing_help(void)
     }
 }
 
+static void list_objects(void)
+{
+    int max_nid = OBJ_new_nid(0);
+    int i;
+    char *oid_buf = NULL;
+    int oid_size = 0;
+
+    /* Skip 0, since that's NID_undef */
+    for (i = 1; i < max_nid; i++) {
+        const ASN1_OBJECT *obj = OBJ_nid2obj(i);
+        const char *sn = OBJ_nid2sn(i);
+        const char *ln = OBJ_nid2ln(i);
+        int n = 0;
+
+        /*
+         * If one of the retrieved objects somehow generated an error,
+         * we ignore it.  The check for NID_undef below will detect the
+         * error and simply skip to the next NID.
+         */
+        ERR_clear_error();
+
+        if (OBJ_obj2nid(obj) == NID_undef)
+            continue;
+
+        if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
+            BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
+            continue;
+        }
+        if (n < 0)
+            break;               /* Error */
+
+        if (n > oid_size) {
+            oid_buf = OPENSSL_realloc(oid_buf, n + 1);
+            if (oid_buf == NULL) {
+                BIO_printf(bio_err, "ERROR: Memory allocation\n");
+                break;           /* Error */
+            }
+            oid_size = n + 1;
+        }
+        if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
+            break;               /* Error */
+        if (ln == NULL || strcmp(sn, ln) == 0)
+            BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
+        else
+            BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
+    }
+
+    OPENSSL_free(oid_buf);
+}
+
 static void list_options_for_command(const char *command)
 {
     const FUNCTION *fp;
@@ -346,7 +398,8 @@ typedef enum HELPLIST_CHOICE {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE,
     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_OPTIONS,
     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
-    OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, OPT_MISSING_HELP
+    OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, OPT_MISSING_HELP,
+    OPT_OBJECTS
 } HELPLIST_CHOICE;
 
 const OPTIONS list_options[] = {
@@ -370,6 +423,8 @@ const OPTIONS list_options[] = {
      "List missing detailed help strings"},
     {"options", OPT_OPTIONS, 's',
      "List options for specified command"},
+    {"objects", OPT_OBJECTS, '-',
+     "List built in objects (OID<->name mappings)"},
     {NULL}
 };
 
@@ -420,6 +475,9 @@ opthelp:
         case OPT_MISSING_HELP:
             list_missing_help();
             break;
+        case OPT_OBJECTS:
+            list_objects();
+            break;
         case OPT_OPTIONS:
             list_options_for_command(opt_arg());
             break;
@@ -518,7 +576,7 @@ static void list_type(FUNC_TYPE ft, int one)
 {
     FUNCTION *fp;
     int i = 0;
-    DISPLAY_COLUMNS dc;
+    DISPLAY_COLUMNS dc = {0};
 
     if (!one)
         calculate_columns(&dc);
@@ -760,6 +818,9 @@ static void list_disabled(void)
 #ifdef OPENSSL_NO_SEED
     BIO_puts(bio_out, "SEED\n");
 #endif
+#ifdef OPENSSL_NO_SM2
+    BIO_puts(bio_out, "SM2\n");
+#endif
 #ifdef OPENSSL_NO_SM3
     BIO_puts(bio_out, "SM3\n");
 #endif