From 6365767c1320a10f70aeab92abdc713194c652b9 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Tue, 22 Jul 2025 07:12:07 -0400 Subject: [PATCH 1/3] Added JNI Wrappers for Sanitizer --- .../maesdk/src/main/cpp/CMakeLists.txt | 17 ++++ .../applications/events/Sanitizer.java | 73 ++++++++++++++++ .../events/SanitizerConfiguration.java | 39 +++++++++ lib/include/public/Version.hpp | 6 +- lib/jni/SanitizerHelper.hpp | 18 ++++ lib/jni/Sanitizer_jni.cpp | 83 +++++++++++++++++++ lib/modules | 2 +- 7 files changed, 234 insertions(+), 4 deletions(-) create mode 100644 lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java create mode 100644 lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java create mode 100644 lib/jni/SanitizerHelper.hpp create mode 100644 lib/jni/Sanitizer_jni.cpp diff --git a/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt b/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt index 824bbb278..cb70849b6 100644 --- a/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt +++ b/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD 11) option(BUILD_AZMON "Build for Azure Monitor" YES) option(BUILD_PRIVACYGUARD "Build Privacy Guard" YES) option(BUILD_SIGNALS "Build Signals" YES) +option(BUILD_SANITIZER "Build Sanitizer" YES) if(ENABLE_CAPI_HTTP_CLIENT) add_definitions(-DENABLE_CAPI_HTTP_CLIENT) @@ -113,6 +114,22 @@ if (EXISTS ${SDK_ROOT}/lib/modules/signals/ AND BUILD_SIGNALS) ) endif() +if (EXISTS ${SDK_ROOT}/lib/modules/sanitizer/ AND BUILD_SANITIZER) + list(APPEND SRCS + ${SDK_ROOT}/lib/jni/Sanitizer_jni.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/EmailAddressDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/JwtDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/SPOPassword.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/UrlDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/Sanitizer.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerProvider.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerStringUtils.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTargets.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTrie.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTrieNode.cpp + ) +endif() + if (USE_ROOM) add_definitions("-DUSE_ROOM") list(APPEND SRCS ${SDK_ROOT}/lib/offline/OfflineStorage_Room.cpp) diff --git a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java new file mode 100644 index 000000000..4ab6691b1 --- /dev/null +++ b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java @@ -0,0 +1,73 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +package com.microsoft.applications.events; + +public class Sanitizer { + + /** + * Initializes the sanitizer with the provided configuration. + * + * @param config The configuration object containing logger and event name. + * @return true if initialization succeeds, false otherwise. + * @throws IllegalArgumentException if config or any required field is null or invalid. + */ + public static boolean initialize(SanitizerConfiguration config) { + + // Validate that the configuration object is not null + if(config == null) { + throw new IllegalArgumentException("initConfig cannot be null"); + } + + // Ensure the logger instance is provided + if(config.LoggerInstance == null) { + throw new IllegalArgumentException(("loggerInstance cannot be null in config.")); + } + + // Ensure the notification event name is not null or empty + if (config.notificationEventName == null || config.notificationEventName.isEmpty()) { + throw new IllegalArgumentException(("notificationEventName cannot be null in config.")); + } + + return nativeInitialize(config.LoggerInstance.getNativeILoggerPtr(), config.notificationEventName); + } + + /** + * Checks if the sanitizer is initialized. + * + * @return true if initialized, false otherwise. + */ + public static native boolean isInitialized(); + + /** + * Initializes the sanitizer with the given logger pointer and optional notification event name. + * + * @param loggerNativePtr Native pointer to ILogger. + * @param notificationEventName Optional event name for sanitizer notifications. + * @return true if initialization was successful, false otherwise. + */ + public static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName); + + /** + * Uninitializes the sanitizer. + * + * @return true if uninitialization was successful, false otherwise. + */ + public static native boolean uninitialize(); + + /** + * Checks if the sanitizer is currently enabled. + * + * @return true if enabled, false otherwise. + */ + public static native boolean isEnabled(); + + /** + * Enables or disables the sanitizer. + * + * @param enabled true to enable, false to disable. + * @return true if the operation was successful, false otherwise. + */ + public static native boolean setEnabled(boolean enabled); +} \ No newline at end of file diff --git a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java new file mode 100644 index 000000000..1a51511e1 --- /dev/null +++ b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java @@ -0,0 +1,39 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +package com.microsoft.applications.events; + +/** + * Represents the configuration settings used to initialize a sanitizer instance. + */ + +public class SanitizerConfiguration { + + /** + * The logger instance used to record privacy concern events. + * This field is required. + */ + public final ILogger loggerInstance; + + /** +     * The custom event name used when logging sanitizer concerns. +     * Optional. Defaults to "SanitizerConcerns" if not specified. +     */ + public String notificationEventName = "SanitizerConcerns"; + + /** +     * Constructs a new SanitizerConfiguration with the specified logger. +     * +     * @param logger The ILogger implementation used to log privacy concern events. +     * @throws IllegalArgumentException if the logger is null. +     */ + public SanitizerConfiguration(ILogger logger) { + + if(logger == null) { + throw new IllegalArgumentException("logger cannot be null"); + } + + this.loggerInstance = logger; + } +} \ No newline at end of file diff --git a/lib/include/public/Version.hpp b/lib/include/public/Version.hpp index 8d7350af4..314254d14 100644 --- a/lib/include/public/Version.hpp +++ b/lib/include/public/Version.hpp @@ -6,8 +6,8 @@ #define MAT_VERSION_HPP // WARNING: DO NOT MODIFY THIS FILE! // This file has been automatically generated, manual changes will be lost. -#define BUILD_VERSION_STR "3.9.163.1" -#define BUILD_VERSION 3,9,163,1 +#define BUILD_VERSION_STR "3.9.203.1" +#define BUILD_VERSION 3,9,203,1 #ifndef RESOURCE_COMPILER_INVOKED #include "ctmacros.hpp" @@ -18,7 +18,7 @@ namespace MAT_NS_BEGIN { uint64_t const Version = ((uint64_t)3 << 48) | ((uint64_t)9 << 32) | - ((uint64_t)163 << 16) | + ((uint64_t)203 << 16) | ((uint64_t)1); } MAT_NS_END diff --git a/lib/jni/SanitizerHelper.hpp b/lib/jni/SanitizerHelper.hpp new file mode 100644 index 000000000..a2308fcad --- /dev/null +++ b/lib/jni/SanitizerHelper.hpp @@ -0,0 +1,18 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ctmacros.hpp" +#include "modules/sanitizer/Sanitizer.hpp" + +namespace MAT_NS_BEGIN +{ + struct Sanitizer { + /** + * Get the current instance of Sanitizer. + * @return SanitizerPtr if it is initialized, nullptr otherwise. + */ + static std::shared_ptr GetSanitizerPtr() noexcept; + }; +} MAT_NS_END \ No newline at end of file diff --git a/lib/jni/Sanitizer_jni.cpp b/lib/jni/Sanitizer_jni.cpp new file mode 100644 index 000000000..8f2d7c847 --- /dev/null +++ b/lib/jni/Sanitizer_jni.cpp @@ -0,0 +1,83 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ctmacros.hpp" +#include "JniConvertors.hpp" +#include "modules/sanitizer/Sanitizer.hpp" +#include "SanitizerHelper.hpp" + +using namespace MAT; + +std::shared_ptr spSanitizer; + +std::shared_ptr SanitizerHelper::GetSanitizerPtr() noexcept +{ + return spSanitizer; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_isInitialized(const JNIEnv *env, jclass/* this */) { + + return spSanitizer != nullptr; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_nativeInitialize( + JNIEnv *env, jclass /* this */, + jlong iLoggerNativePtr, + jstring notificationEventName) { + + if (spSanitizer != nullptr) { + return false; + } + + SanitizerConfiguration sanitizerConfig(reinterpret_cast(iLoggerNativePtr)); + + if (notificationEventName != nullptr) { + config.NotificationEventName = JStringToStdString(env, notificationEventName).c_str(); + } + + spSanitizer = std::make_shared(config); + return true; +} + + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_uninitialize(const JNIEnv *env, jclass /*this*/) { + + if(spSanitizer == nullptr) { + return false; + } + + spSanitizer.reset(); + + return true; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_isEnabled(JNIEnv *env, jclass clazz) { + + if (spSanitizer == nullptr) { + return false; + } + + return spSanitizer.get()->IsEnabled(); +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_setEnabled(JNIEnv *env, jclass clazz, + jboolean enabled) { + if (spDataInspector == nullptr) { + return false; + } + + spDataInspector->SetEnabled(static_cast(enabled)); + return true; +} \ No newline at end of file diff --git a/lib/modules b/lib/modules index eac5fe38a..bd40008a9 160000 --- a/lib/modules +++ b/lib/modules @@ -1 +1 @@ -Subproject commit eac5fe38a9bd3e54a1b609dc4ffc9b6f3e9336ea +Subproject commit bd40008a920f419c70c56fc5eed0f1f3e16fe58f From 73cfc53223b49ea9c70d0ec77bccedbbb159fe78 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Tue, 22 Jul 2025 07:16:24 -0400 Subject: [PATCH 2/3] revert version --- lib/include/public/Version.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/include/public/Version.hpp b/lib/include/public/Version.hpp index 314254d14..8d7350af4 100644 --- a/lib/include/public/Version.hpp +++ b/lib/include/public/Version.hpp @@ -6,8 +6,8 @@ #define MAT_VERSION_HPP // WARNING: DO NOT MODIFY THIS FILE! // This file has been automatically generated, manual changes will be lost. -#define BUILD_VERSION_STR "3.9.203.1" -#define BUILD_VERSION 3,9,203,1 +#define BUILD_VERSION_STR "3.9.163.1" +#define BUILD_VERSION 3,9,163,1 #ifndef RESOURCE_COMPILER_INVOKED #include "ctmacros.hpp" @@ -18,7 +18,7 @@ namespace MAT_NS_BEGIN { uint64_t const Version = ((uint64_t)3 << 48) | ((uint64_t)9 << 32) | - ((uint64_t)203 << 16) | + ((uint64_t)163 << 16) | ((uint64_t)1); } MAT_NS_END From 95bb6aec07ef9935dfc4c5af5311317a4ca45462 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Tue, 22 Jul 2025 07:32:54 -0400 Subject: [PATCH 3/3] fixed casing --- .../java/com/microsoft/applications/events/Sanitizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java index 4ab6691b1..eab0e2a41 100644 --- a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java +++ b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java @@ -21,7 +21,7 @@ public static boolean initialize(SanitizerConfiguration config) { } // Ensure the logger instance is provided - if(config.LoggerInstance == null) { + if(config.loggerInstance == null) { throw new IllegalArgumentException(("loggerInstance cannot be null in config.")); } @@ -30,7 +30,7 @@ public static boolean initialize(SanitizerConfiguration config) { throw new IllegalArgumentException(("notificationEventName cannot be null in config.")); } - return nativeInitialize(config.LoggerInstance.getNativeILoggerPtr(), config.notificationEventName); + return nativeInitialize(config.loggerInstance.getNativeILoggerPtr(), config.notificationEventName); } /**