Make certificate automatically 69/276369/3
authorJunkyeong Kim <jk0430.kim@samsung.com>
Wed, 15 Jun 2022 07:35:56 +0000 (16:35 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Fri, 17 Jun 2022 07:55:32 +0000 (16:55 +0900)
if auto_cert flag is set, make certificate automatically.

Change-Id: If32dc919631a7faccdd4a3d66a36ce313fc30401
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
configure.ac
packaging/e-mod-tizen-rdp.spec
src/e_mod_main.h
src/e_mod_rdp.c
src/e_mod_rdp_conf.c

index 34488cd..3b60d3e 100644 (file)
@@ -78,7 +78,7 @@ fi
 AM_CONDITIONAL(HAVE_WAYLAND_ONLY, [test "x${have_wayland_only}" = xyes])
 
 if test "x${have_wayland_only}" = "xyes"; then
-       PKG_CHECK_MODULES(ENLIGHTENMENT, [enlightenment, dlog, libtbm, pixman-1, wayland-server, tizen-extension-server, freerdp2])
+       PKG_CHECK_MODULES(ENLIGHTENMENT, [enlightenment, dlog, libtbm, pixman-1, wayland-server, tizen-extension-server, freerdp2, winpr2, winpr-tools2])
        PKG_CHECK_MODULES(WAYLAND_SCANNER, wayland-scanner)
 else
        PKG_CHECK_MODULES(ENLIGHTENMENT, [enlightenment, dlog, libtbm, pixman-1, x11, utilX])
index 3d16399..a7af52a 100644 (file)
@@ -16,6 +16,8 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(wayland-server)
 BuildRequires: pkgconfig(libtbm)
 BuildRequires: pkgconfig(freerdp2)
+BuildRequires: pkgconfig(winpr2)
+BuildRequires: pkgconfig(winpr-tools2)
 BuildRequires: pkgconfig(pixman-1)
 BuildRequires: pkgconfig(openssl1.1)
 BuildRequires: libopenssl11
index 3ca2273..fe8e2a7 100644 (file)
@@ -22,6 +22,7 @@ struct _E_Rdp_Conf_Edd
    int no_clients_resize;
    int force_no_compression;
    int motionless;
+   int auto_cert;
 };
 
 /*** E Module ***/
index 608c38b..5534307 100644 (file)
@@ -26,6 +26,7 @@
 #include <freerdp/locale/keyboard.h>
 #include <winpr/input.h>
 #include <winpr/ssl.h>
+#include <winpr/tools/makecert.h>
 
 #include <pixman.h>
 #include <tbm_surface.h>
@@ -42,6 +43,8 @@
 #define RDP_DEBUG 0
 #define RDP_CURSOR_DEBUG 0
 
+#define RDP_PATH_LEN 1024
+
 #define E_RDP_WIDTH 1280
 #define E_RDP_HEIGHT 720
 #define E_RDP_DEVICE_NAME "rdp_input"
@@ -1600,6 +1603,102 @@ _e_rdp_get_pointer_y(E_Rdp_Output *output, int y)
    return temp_y * output->mouse_scale_h;
 }
 
+static Eina_Bool
+_e_rdp_file_check(const char *fname)
+{
+   struct stat info;
+
+  if (stat(fname, &info) == 0)
+    return EINA_TRUE;
+
+   return EINA_FALSE;
+}
+
+static Eina_Bool
+_e_rdp_dir_check(const char *dname)
+{
+   struct stat info;
+
+   if (stat(dname, &info) != 0)
+     return EINA_FALSE;
+   else if (info.st_mode & S_IFDIR)
+     return EINA_TRUE;
+
+   return EINA_FALSE;
+}
+
+static void
+_e_rdp_certificate(E_Rdp_Backend *b)
+{
+   MAKECERT_CONTEXT* makecert = NULL;
+   char path[RDP_PATH_LEN] = {0,};
+   char name[RDP_PATH_LEN] = {0,};
+   char temp[RDP_PATH_LEN] = {0,};
+   char key[RDP_PATH_LEN] = {0,};
+   char *buf = NULL, *buf_ptr = NULL, *buf2 = NULL, *buf_ptr2 = NULL;
+   char *makecert_parameter[13] = {"makecert", "-rdp", "-silent", "-n", NULL, "-path", NULL, "-y", "100", "-format", "crt", "-a", "sha256"};
+
+   // certificate already exist
+   if (_e_rdp_file_check(b->server_key) && _e_rdp_file_check(b->server_cert))
+     return;
+
+   strncpy(key, b->server_key, RDP_PATH_LEN - 1);
+
+   buf = strtok_r(key, "/", &buf_ptr);
+   if (buf == NULL)
+     {
+        ERR("certificate name error");
+        return;
+     }
+   path[0] = '/';
+   path[1] = '\0';
+
+   while (buf)
+     {
+        strncpy(temp, buf, RDP_PATH_LEN - 1);
+        buf = strtok_r(NULL, "/", &buf_ptr);
+        if (buf == NULL)
+          {
+             buf2 = strtok_r(temp, ".", &buf_ptr2);
+             strncpy(name, buf2, RDP_PATH_LEN - 1);
+          }
+        else
+          {
+             strncat(path, temp, RDP_PATH_LEN - strlen(path));
+             strncat(path, "/", 1);
+             if (_e_rdp_dir_check(path) == EINA_FALSE)
+               {
+                  if ((mkdir(path, 0755)) < 0)
+                    {
+                       ERR("mkdir failed %s", path);
+                       return;
+                    }
+               }
+          }
+     }
+   makecert_parameter[4] = name;
+   makecert_parameter[6] = path;
+
+   makecert = makecert_context_new();
+   if (!makecert)
+     {
+        ERR("makecert_context_new failed");
+        return;
+     }
+
+   if (makecert_context_process(makecert, 13, makecert_parameter) < 0)
+     {
+        ERR("makecert_context_process failed");
+        goto out;
+     }
+
+   INF("create certificate - path:%s, name:%s", path, name);
+   sync();
+
+out:
+   makecert_context_free(makecert);
+}
+
 static BOOL
 e_rdp_peer_capabilities(freerdp_peer *client)
 {
@@ -2343,6 +2442,11 @@ e_rdp_backend_create(E_Rdp_Conf_Edd *config)
           goto err_config;
         b->tls_enabled = 1;
      }
+   if (b->tls_enabled == 0 && b->rdp_key == NULL)
+     ERR("need key or certificate");
+
+   if (b->tls_enabled == 1 && config->auto_cert == 1)
+     _e_rdp_certificate(b);
 
    b->output = e_rdp_output_create();
    if (!b->output)
index 6a6e1c3..9679ca7 100644 (file)
@@ -17,10 +17,11 @@ _e_rdp_conf_value_check(E_Rdp_Config_Data *config)
         return EINA_FALSE;
      }
 
-   DBG("bindaddress:%s, rdp_key:%s, server_cert:%s, server_key:%s, port:%d, noresize:%d, nocompress:%d, motionless:%d",
+   DBG("bindaddress:%s, rdp_key:%s, server_cert:%s, server_key:%s, port:%d, noresize:%d, nocompress:%d, motionless:%d, auto_cert:%d",
        config->conf->bind_address?:"no_bind_address", config->conf->rdp_key?:"no_rdp_key",
        config->conf->server_cert?:"no_server_cert", config->conf->server_key?:"no_server_key",
-       config->conf->port, config->conf->no_clients_resize, config->conf->force_no_compression, config->conf->motionless);
+       config->conf->port, config->conf->no_clients_resize, config->conf->force_no_compression, config->conf->motionless,
+       config->conf->auto_cert);
 
    return EINA_TRUE;
 }
@@ -45,6 +46,7 @@ e_rdp_conf_init(E_Rdp_Config_Data *config)
    E_CONFIG_VAL(D, T, no_clients_resize, INT);
    E_CONFIG_VAL(D, T, force_no_compression, INT);
    E_CONFIG_VAL(D, T, motionless, INT);
+   E_CONFIG_VAL(D, T, auto_cert, INT);
 #undef T
 #undef D
    config->conf = e_config_domain_load("module.rdp", config->conf_edd);