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..eab0e2a41 --- /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/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