Update DLP feature 46/246946/1
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 5 Nov 2020 08:22:43 +0000 (17:22 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 5 Nov 2020 08:22:43 +0000 (17:22 +0900)
Change-Id: I954089d7d9d6e75726df6981c8222403ae83facc

Makefile.am
configure.ac
extensions/Makefile.am
extensions/dlp.c [new file with mode: 0644]
extensions/dlp.h [new file with mode: 0644]
extensions/tizen_dlp.c [deleted file]
lib/Makefile.inc
lib/easy.c
lib/extensions/curl_extensions.c
lib/extensions/curl_extensions.h
lib/sendf.c

index 1524808..5ff681d 100644 (file)
@@ -179,7 +179,7 @@ CLEANFILES = $(VC6_LIBDSP) $(VC6_SRCDSP) $(VC7_LIBVCPROJ) $(VC7_SRCVCPROJ) \
 bin_SCRIPTS = curl-config
 
 SUBDIRS = lib src
-if USE_TIZEN_FEATURE_DLP
+if HAVE_TIZEN_DLP
 SUBDIRS += extensions
 endif
 DIST_SUBDIRS = $(SUBDIRS) tests packages scripts include docs
index 9ae44ec..837a1c8 100755 (executable)
@@ -3438,11 +3438,11 @@ AC_ARG_ENABLE([dlp],
     AS_HELP_STRING([--enable-dlp], [Enable DLP usage]))
 
 AS_IF([test "x$enable_dlp" = "xyes"], [
-    CPPFLAGS+=" -DUSE_TIZEN_FEATURE_DLP"
-    SUPPORT_TIZEN_FEATURES="$SUPPORT_TIZEN_FEATURES dlp"
+    AC_DEFINE(HAVE_TIZEN_DLP, 1, [Enadle DLP])
+    LIBS="-ldl $LIBS"
 ])
 
-AM_CONDITIONAL(USE_TIZEN_FEATURE_DLP, test "x$enable_dlp" = "xyes")
+AM_CONDITIONAL(HAVE_TIZEN_DLP, test "x$enable_dlp" = "xyes")
 
 dnl **********************************************************************
 dnl Check for nghttp2
index a7cca15..9346c9c 100644 (file)
@@ -1,3 +1,3 @@
 lib_LTLIBRARIES = libcurl_extension_dlp.la
 
-libcurl_extension_dlp_la_SOURCES = tizen_dlp.c
+libcurl_extension_dlp_la_SOURCES = dlp.c
diff --git a/extensions/dlp.c b/extensions/dlp.c
new file mode 100644 (file)
index 0000000..e17ca48
--- /dev/null
@@ -0,0 +1,68 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "dlp.h"
+
+#include <dlfcn.h>
+
+#define LIBRARY_PATH "/lib/libprivacy-guard-client.so"
+
+typedef void (*privacy_guard_dlp_init_t)();
+typedef int (*privacy_guard_dlp_check_leak_proto_info_t)(const char* const, PgDlpProtocol,
+                                                         long, long, uint32_t,
+                                                         const char* const, size_t);
+
+static privacy_guard_dlp_init_t privacy_guard_dlp_init = 0;
+static privacy_guard_dlp_check_leak_proto_info_t privacy_guard_dlp_check_leak_proto_info = 0;
+
+static void dlp_init()
+{
+  void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY | RTLD_NODELETE);
+  if(handle) {
+    privacy_guard_dlp_init =
+      (privacy_guard_dlp_init_t) dlsym(handle, "privacy_guard_dlp_init");
+    privacy_guard_dlp_check_leak_proto_info =
+      (privacy_guard_dlp_check_leak_proto_info_t) dlsym(handle, "privacy_guard_dlp_check_leak_proto_info");
+    dlclose(handle);
+
+    if(privacy_guard_dlp_init) {
+      privacy_guard_dlp_init();
+    }
+  }
+}
+
+void dlp_check_leak(const char* const hostname, PgDlpProtocol protocol,
+                    long source_port, long destination_port, uint32_t destination_ip,
+                    const char* const data, size_t data_length)
+{
+  static unsigned short int is_initialized = 0;
+  if(!is_initialized) {
+    dlp_init();
+    is_initialized = 1;
+  }
+
+  if(privacy_guard_dlp_check_leak_proto_info) {
+    privacy_guard_dlp_check_leak_proto_info(hostname, protocol, source_port,
+                                            destination_port, destination_ip, data, data_length);
+  }
+}
diff --git a/extensions/dlp.h b/extensions/dlp.h
new file mode 100644 (file)
index 0000000..9462112
--- /dev/null
@@ -0,0 +1,39 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#ifndef HEADER_CURL_DLP_H
+#define HEADER_CURL_DLP_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+typedef enum {
+    PRIV_GUARD_DLP_PROTOCOL_CURL_HTTP = 1,
+    PRIV_GUARD_DLP_PROTOCOL_CURL_HTTPS = 2,
+} PgDlpProtocol;
+
+void dlp_check_leak(const char* const hostname, PgDlpProtocol protocol,
+                    long source_port, long destination_port, uint32_t destination_ip,
+                    const char* const data, size_t data_length);
+
+#endif /* HEADER_CURL_DLP_H */
diff --git a/extensions/tizen_dlp.c b/extensions/tizen_dlp.c
deleted file mode 100644 (file)
index 200bce0..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * @file       tizen_dlp.cpp
- * @brief      external API functions for DLP
- */
-
-#include <dlfcn.h>
-
-#define LIBRARY_PATH "/lib/libprivacy-guard-client.so"
-
-static int first_run = 1;
-static void (*privacy_guard_dlp_init)(void) = 0;
-static void (*privacy_guard_dlp_check_leak)(const char *, char * const, size_t) = 0;
-
-/**
- * @fn void tizen_dlp_init(void)
- * @brief Initialize the DLP creating the Load Rules and Logging threads
- * @callgraph
- */
-void tizen_dlp_init(void)
-{
-    if (first_run) {
-        void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY|RTLD_NODELETE);
-        if (handle) {
-            privacy_guard_dlp_init = dlsym(handle, "privacy_guard_dlp_init");
-            privacy_guard_dlp_check_leak = dlsym(handle, "privacy_guard_dlp_check_leak");
-            dlclose(handle);
-            first_run = 0;
-        }
-    }
-
-    if (privacy_guard_dlp_init)
-        privacy_guard_dlp_init();
-}
-
-/**
- * @fn void tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
- * @brief Checks for information leak on a given request string
- *
- * @param[in] hostname                                 The hostname of the server to which the request will be sent
- * @param[in] mem                                              Text that we are going to validate for info leak
- * @param[in] len                                              Size of len in bytes
- *
- * @return  either PRIV_GUARD_DLP_RESULT_ALLOW or PRIV_GUARD_DLP_RESULT_DENY
- * @callgraph
- */
-void tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
-{
-    /**
-    * Send data to Tizen DLP verification
-    */
-    if(privacy_guard_dlp_check_leak)
-       privacy_guard_dlp_check_leak(hostname, mem, len);
-}
index 8813f1d..47a60d7 100644 (file)
@@ -46,7 +46,7 @@ LIB_VSSH_CFILES = vssh/libssh2.c vssh/libssh.c
 
 LIB_VSSH_HFILES = vssh/ssh.h
 
-if USE_TIZEN_FEATURE_DLP
+if HAVE_TIZEN_DLP
 LIB_EXTENSIONS_CFILES = extensions/curl_extensions.c
 LIB_EXTENSIONS_HFILES = extensions/curl_extensions.h
 endif
index 55b1d4f..6382cee 100644 (file)
@@ -81,9 +81,6 @@
 #include "curl_printf.h"
 #include "curl_memory.h"
 #include "memdebug.h"
-#ifdef USE_TIZEN_FEATURE_DLP
-#include "extensions/curl_extensions.h"
-#endif
 
 void Curl_version_init(void);
 
@@ -146,13 +143,6 @@ static CURLcode global_init(long flags, bool memoryfuncs)
   if(initialized++)
     return CURLE_OK;
 
-#ifdef USE_TIZEN_FEATURE_DLP
-  /**
-   * Initialize Tizen DLP
-   */
-  curl_extensions_tizen_dlp_init();
-#endif
-
   if(memoryfuncs) {
     /* Setup the default memory functions here (again) */
     Curl_cmalloc = (curl_malloc_callback)malloc;
index a0c9fdd..50a02aa 100644 (file)
@@ -6,6 +6,7 @@
  *                             \___|\___/|_| \_\_____|
  *
  * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  *
  ***************************************************************************/
 
-/**
- * @file    curl_extensions.cpp
- * @brief   external API functions for DLP
- */
-
-#ifdef USE_TIZEN_FEATURE_DLP
+#include "extensions/curl_extensions.h"
 #include <dlfcn.h>
-#include <extensions/curl_extensions.h>
 
-#define LIBRARY_PATH "/usr/lib/libcurl_extension_dlp.so.0"
+#define LIBRARY_PATH "/lib/libcurl_extension_dlp.so.0"
 
-static int first_run = 1;
-static void (*tizen_dlp_init)(void) = NULL;
-static void (*tizen_dlp_check_leak)(const char *, char * const, size_t) = NULL;
+typedef void (*dlp_check_leak_t)(const char* const, PgDlpProtocol,
+                                 long, long, uint32_t,
+                                 const char* const, size_t);
 
-/**
- * @fn void curl_extensions_init(void)
- * @brief Load the extension shared library looking for the function call
- * symbols it going to use
- * @callgraph
- */
-static void curl_extensions_init(void)
-{
-    if (first_run) {
-        void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY|RTLD_NODELETE);
-        if (handle) {
-            tizen_dlp_init = dlsym(handle, "tizen_dlp_init");
-            tizen_dlp_check_leak = dlsym(handle, "tizen_dlp_check_leak");
-            dlclose(handle);
-            first_run = 0;
-        }
-    }
-}
+static dlp_check_leak_t dlp_check_leak = 0;
 
-/**
- *   @callgraph
- */
-void curl_extensions_tizen_dlp_init(void)
+static void curl_extensions_init()
 {
-    curl_extensions_init();
+    void *handle = dlopen(LIBRARY_PATH, RTLD_LAZY | RTLD_NODELETE);
+    if(handle) {
+        dlp_check_leak = (dlp_check_leak_t) dlsym(handle, "dlp_check_leak");
+        dlclose(handle);
 
-    if (tizen_dlp_init)
-        tizen_dlp_init();
+    }
 }
 
-/**
- *   @callgraph
- */
-void curl_extensions_tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
+void curl_extensions_dlp_check_leak(const char* const hostname, PgDlpProtocol protocol,
+                                    long source_port, long destination_port, uint32_t destination_ip,
+                                    const char* const data, size_t data_length)
 {
-    if(tizen_dlp_check_leak)
-        tizen_dlp_check_leak(hostname, mem, len);
+    static unsigned short int is_initialized = 0;
+    if(!is_initialized) {
+        curl_extensions_init();
+        is_initialized = 1;
+    }
+
+    if(dlp_check_leak) {
+        dlp_check_leak(hostname, protocol, source_port,
+                destination_port, destination_ip, data, data_length);
+    }
 }
-#endif /* USE_TIZEN_FEATURE_DLP */
index 9b2aeb1..dd4869b 100644 (file)
@@ -6,6 +6,7 @@
  *                             \___|\___/|_| \_\_____|
  *
  * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  *
  ***************************************************************************/
 
-/**
- * @file       curl_extensions.h
- * @brief      API for privacy-guard-dlp
- */
-
-#ifdef USE_TIZEN_FEATURE_DLP
 #ifndef HEADER_CURL_EXTENSIONS_H
 #define HEADER_CURL_EXTENSIONS_H
 
+#include <stdint.h>
 #include <stddef.h>
 
-/**
- * @fn void curl_extensions_tizen_dlp_init(void)
- * @brief Initialize the DLP creating the Load Rules and Logging threads
- * @callgraph
- */
-void curl_extensions_tizen_dlp_init(void);
+typedef enum {
+    PRIV_GUARD_DLP_PROTOCOL_CURL_HTTP = 1,
+    PRIV_GUARD_DLP_PROTOCOL_CURL_HTTPS = 2,
+} PgDlpProtocol;
 
-/**
- * @fn void curl_extensions_tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len)
- * @brief Checks for information leak on a given request string
- *
- * @param[in] hostname                                 The hostname of the server to which the request will be sent
- * @param[in] mem                                              Text that we are going to validate for info leak
- * @param[in] len                                              Size of len in bytes
- *
- * @return  either PRIV_GUARD_DLP_RESULT_ALLOW or PRIV_GUARD_DLP_RESULT_DENY
- * @callgraph
- */
-void curl_extensions_tizen_dlp_check_leak(const char *hostname, char * const mem, size_t len);
+void curl_extensions_dlp_check_leak(const char* const hostname, PgDlpProtocol protocol,
+                                    long source_port, long destination_port, uint32_t destination_ip,
+                                    const char* const data, size_t data_length);
 
 #endif /* HEADER_CURL_EXTENSIONS_H */
-#endif /* USE_TIZEN_FEATURE_DLP */
index e9039dc..232f64d 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <curl/curl.h>
 
-#ifdef USE_TIZEN_FEATURE_DLP
+#ifdef HAVE_TIZEN_DLP
 #include "extensions/curl_extensions.h"
 #endif
 #include "urldata.h"
@@ -348,12 +348,23 @@ CURLcode Curl_write(struct connectdata *conn,
   CURLcode result = CURLE_OK;
   int num = (sockfd == conn->sock[SECONDARYSOCKET]);
 
-#ifdef USE_TIZEN_FEATURE_DLP
-  /**
-   * Send data to Tizen DLP verification
-   */
-  curl_extensions_tizen_dlp_check_leak(conn->host.dispname, (char *const)mem,
-                                       len);
+#ifdef HAVE_TIZEN_DLP
+  u_int32_t destination_ipv4 = 0;
+  if(conn->ip_addr != NULL && conn->ip_addr->ai_family == AF_INET &&
+     conn->ip_addr->ai_addr != NULL) {
+    destination_ipv4 =
+      ((struct sockaddr_in *) conn->ip_addr->ai_addr)->sin_addr.s_addr;
+  }
+
+  curl_extensions_dlp_check_leak(conn->host.dispname,
+                                 conn->ssl[0].use ?
+                                   PRIV_GUARD_DLP_PROTOCOL_CURL_HTTPS :
+                                   PRIV_GUARD_DLP_PROTOCOL_CURL_HTTP,
+                                 conn->local_port,
+                                 conn->remote_port,
+                                 destination_ipv4,
+                                 (const char *) mem,
+                                 len);
 #endif
 
   bytes_written = conn->send[num](conn, num, mem, len, &result);