--- /dev/null
+/*
+ * libwebsockets - small server side websockets and web server implementation
+ *
+ * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation:
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#include "dlp.h"
+
+#include <dlfcn.h>
+#include "libwebsockets.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <limits.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;
+
+struct dlp_hook_info {
+ long source_port;
+ long destination_port;
+ uint32_t destination_ip;
+ char hostname[HOST_NAME_MAX + 1];
+};
+
+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();
+ } else {
+ lwsl_err("'%s' not found!", LIBRARY_PATH);
+ }
+}
+
+static void
+dlp_get_descriptor_info(const int socket_descriptor, struct dlp_hook_info *hook_info)
+{
+ const struct sockaddr_storage address_storage = {0};
+ socklen_t address_storage_size = sizeof(address_storage);
+
+ struct sockaddr *generic_address = (struct sockaddr *)(&address_storage);
+ const struct sockaddr_in *ipv4_address = (struct sockaddr_in *)(&address_storage);
+
+ if (getsockname(socket_descriptor, generic_address, &address_storage_size) == 0 && generic_address->sa_family == AF_INET) {
+ hook_info->source_port = ntohs(ipv4_address->sin_port);
+ }
+
+ if (getpeername(socket_descriptor, generic_address, &address_storage_size) == 0 && generic_address->sa_family == AF_INET) {
+ hook_info->destination_port = ntohs(ipv4_address->sin_port);
+ hook_info->destination_ip = ipv4_address->sin_addr.s_addr;
+ }
+
+ if (generic_address->sa_family == AF_INET) {
+ if (getnameinfo((const struct sockaddr *) ipv4_address, sizeof(struct sockaddr_in),
+ hook_info->hostname, HOST_NAME_MAX, NULL, 0, 0)) {
+ hook_info->hostname[0] = 0;
+ }
+ }
+}
+
+void
+dlp_check_leak(const int socket_descriptor, PgDlpProtocol protocol, 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) {
+ struct dlp_hook_info hook_info = {-1, -1, 0, {0}};
+
+ dlp_get_descriptor_info(socket_descriptor, &hook_info);
+
+ privacy_guard_dlp_check_leak_proto_info(
+ hook_info.hostname, protocol, hook_info.source_port, hook_info.destination_port,
+ hook_info.destination_ip, data, data_length);
+ }
+}
--- /dev/null
+/*
+ * libwebsockets - small server side websockets and web server implementation
+ *
+ * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation:
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#include <stddef.h>
+
+typedef enum {
+ PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WS = 11,
+ PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WSS = 12
+} PgDlpProtocol;
+
+void
+dlp_check_leak(const int socket_descriptor, PgDlpProtocol protocol,
+ const char* const data, size_t data_length);