tls: some rework based on TLS openssl C API 53/21453/5
authorPing Yu <ping.yu@intel.com>
Thu, 22 Aug 2019 17:43:00 +0000 (13:43 -0400)
committerDamjan Marion <dmarion@me.com>
Mon, 2 Sep 2019 18:24:41 +0000 (18:24 +0000)
Type: fix

Change-Id: I5d0ac1fe6a6770ab8b3a9c366d10387718391199
Signed-off-by: Ping Yu <ping.yu@intel.com>
src/plugins/tlsopenssl/tls_openssl.api
src/plugins/tlsopenssl/tls_openssl_api.c
src/plugins/tlsopenssl/tls_openssl_test.c

index 7de7752..8111f51 100644 (file)
@@ -2,7 +2,7 @@
 
 option version = "2.0.0";
 
-define tls_openssl_set_engine {
+autoreply define tls_openssl_set_engine {
     /* Client identifier, set from api_main.my_client_index */
     u32 client_index;
 
@@ -10,7 +10,7 @@ define tls_openssl_set_engine {
     u32 context;
 
     /* if async is enabled */
-    u32 async;
+    u32 async_enable;
 
     /* engine name */
     u8 engine[64];
@@ -21,11 +21,3 @@ define tls_openssl_set_engine {
     /* cipher */
     u8 ciphers[64];
 };
-
-define tls_openssl_set_engine_reply {
-    /* From the request */
-    u32 context;
-
-    /* Return value, zero means all OK */
-    i32 retval;
-};
index 9474aae..99ef3fe 100644 (file)
@@ -55,32 +55,37 @@ extern openssl_main_t openssl_main;
 
 /* API message handler */
 static void
-vl_api_tls_openssl_set_engine_t_handler (vl_api_tls_openssl_set_engine_t *mp)
+vl_api_tls_openssl_set_engine_t_handler (vl_api_tls_openssl_set_engine_t * mp)
 {
   vl_api_tls_openssl_set_engine_reply_t *rmp;
   openssl_main_t *om = &openssl_main;
-  char *engine, *alg, *ciphers;
+  char *engine, *alg;
+  char *ciphers;
   int rv;
 
-  engine = (char *)&mp->engine;
-  alg = (char *)&mp->algorithm;
-  ciphers = (char *)&mp->ciphers;
-
-  if (mp->async)
+  if (mp->async_enable)
     {
       om->async = 1;
       openssl_async_node_enable_disable (1);
     }
 
+  ciphers = (char *) &mp->ciphers;
+  ciphers[63] = '\0';
   if (ciphers[0])
     tls_openssl_set_ciphers (ciphers);
+
+  engine = (char *) mp->engine;
+  engine[63] = '\0';
+  alg = (char *) mp->algorithm;
+  alg[63] = '\0';
   rv = openssl_engine_register (engine, alg);
 
   REPLY_MACRO (VL_API_TLS_OPENSSL_SET_ENGINE_REPLY);
 }
 
 /* Set up the API message handling tables */
-static clib_error_t *tls_openssl_plugin_api_hookup (vlib_main_t *vm)
+static clib_error_t *
+tls_openssl_plugin_api_hookup (vlib_main_t * vm)
 {
   openssl_main_t *om = &openssl_main;
 #define _(N, n)                                                         \
@@ -98,7 +103,8 @@ static clib_error_t *tls_openssl_plugin_api_hookup (vlib_main_t *vm)
 #include <tlsopenssl/tls_openssl_all_api_h.h>
 #undef vl_msg_name_crc_list
 
-static void setup_message_id_table (openssl_main_t *om, api_main_t *am)
+static void
+setup_message_id_table (openssl_main_t * om, api_main_t * am)
 {
 #define _(id, n, crc) \
   vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + om->msg_id_base);
@@ -106,7 +112,8 @@ static void setup_message_id_table (openssl_main_t *om, api_main_t *am)
 #undef _
 }
 
-clib_error_t *tls_openssl_api_init (vlib_main_t *vm)
+clib_error_t *
+tls_openssl_api_init (vlib_main_t * vm)
 {
   openssl_main_t *om = &openssl_main;
   clib_error_t *error = 0;
@@ -116,7 +123,7 @@ clib_error_t *tls_openssl_api_init (vlib_main_t *vm)
 
   /* Ask for a correctly-sized block of API message decode slots */
   om->msg_id_base =
-      vl_msg_api_get_msg_ids ((char *)name, VL_MSG_FIRST_AVAILABLE);
+    vl_msg_api_get_msg_ids ((char *) name, VL_MSG_FIRST_AVAILABLE);
 
   error = tls_openssl_plugin_api_hookup (vm);
 
@@ -126,3 +133,11 @@ clib_error_t *tls_openssl_api_init (vlib_main_t *vm)
 
   return error;
 }
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
index 1c810c9..aa64fb8 100644 (file)
@@ -127,24 +127,24 @@ api_tls_openssl_set_engine (vat_main_t * vam)
     engine_alg = format (0, "ALL");
   else
     {
-      for (int i = 0; i < strnlen ((char *) engine_alg, 64); i++)
+      for (int i = 0; i < strnlen ((char *) engine_alg, 63); i++)
        engine_alg[i] = toupper (engine_alg[i]);
     }
 
 
   /* Construct the API message */
   M (TLS_OPENSSL_SET_ENGINE, mp);
-  mp->async = async;
+  mp->async_enable = async;
 
   clib_memcpy_fast (mp->engine, engine_name,
-                   strnlen ((const char *) engine_name, 64));
+                   strnlen ((const char *) engine_name, 63));
 
   clib_memcpy_fast (mp->algorithm, engine_alg,
-                   strnlen ((const char *) engine_alg, 64));
+                   strnlen ((const char *) engine_alg, 63));
 
   if (ciphers)
     clib_memcpy_fast (mp->ciphers, ciphers,
-                     strnlen ((const char *) ciphers, 64));
+                     strnlen ((const char *) ciphers, 63));
 
   /* send it... */
   S (mp);