* MA 02110-1301 USA
*/
-#include "private-lib-core.h"
#ifdef LWS_WITH_TIZEN_DLP
#include "dlp.h"
+#else
+#include "private-lib-core.h"
#endif
/*
LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len,
enum lws_write_protocol wp)
{
+#ifdef LWS_WITH_TIZEN_DLP
+ dlp_check_leak(wsi, (char *) buf, len);
+#endif
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
lws_stats_bump(pt, LWSSTATS_C_API_LWS_WRITE, 1);
lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len)
{
int n = 0;
-#ifdef LWS_WITH_TIZEN_DLP
- PgDlpProtocol protocol = PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WSS;
- if (!lws_is_ssl(wsi))
- protocol = PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WS;
- dlp_check_leak(wsi->desc.sockfd, protocol, (char *) buf, len);
-#endif
+
#if defined(LWS_PLAT_OPTEE)
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
#define LIBRARY_PATH "/lib/libprivacy-guard-client.so"
+typedef enum {
+ PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WS = 11,
+ PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WSS = 12
+} PgDlpProtocol;
+
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 void
-dlp_get_descriptor_info(const int socket_descriptor, struct dlp_hook_info *hook_info)
+dlp_get_descriptor_info(const struct lws *wsi, 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);
+ const struct sockaddr_in6 *ipv6_address = (struct sockaddr_in6 *)(&address_storage);
+
+ const int socket_descriptor = wsi->desc.sockfd;
+ if (getsockname(socket_descriptor, generic_address, &address_storage_size) == 0) {
+ if (generic_address->sa_family == AF_INET) {
+ hook_info->source_port = ntohs(ipv4_address->sin_port);
+ } else if (generic_address->sa_family == AF_INET6) {
+ hook_info->source_port = ntohs(ipv6_address->sin6_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 (getpeername(socket_descriptor, generic_address, &address_storage_size) == 0) {
+ if (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;
+ } else if (generic_address->sa_family == AF_INET6) {
+ hook_info->destination_port = ntohs(ipv6_address->sin6_port);
+ // TODO: IPv6 will be supported soon.
+ }
+ } else {
+ hook_info->destination_port = wsi->c_port;
}
- 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)) {
+ sa_family_t address_family = generic_address->sa_family;
+ if (address_family == AF_INET || address_family == AF_INET6) {
+ const struct sockaddr *ip_address = (address_family == AF_INET ? (struct sockaddr *) ipv4_address : (struct sockaddr *) ipv6_address);
+ const size_t ip_address_size = (address_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6));
+ if (getnameinfo(ip_address, ip_address_size, 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)
+dlp_check_leak(const struct lws *wsi, const char* const data, size_t data_length)
{
static unsigned short int is_initialized = 0;
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(wsi, &hook_info);
+
+ PgDlpProtocol protocol = PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WSS;
+ if (!lws_is_ssl((struct lws *) wsi))
+ protocol = PRIV_GUARD_DLP_PROTOCOL_LIBWEBSOCKET_WS;
+
if (privacy_guard_dlp_check_leak_proto_info) {
struct dlp_hook_info hook_info = {-1, -1, 0, {0}};