Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/android_build/maesdk/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 18 additions & 0 deletions lib/jni/SanitizerHelper.hpp
Original file line number Diff line number Diff line change
@@ -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<Sanitizer> GetSanitizerPtr() noexcept;
};
} MAT_NS_END
83 changes: 83 additions & 0 deletions lib/jni/Sanitizer_jni.cpp
Original file line number Diff line number Diff line change
@@ -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<Sanitizer> spSanitizer;

std::shared_ptr<Sanitizer> 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<ILogger*>(iLoggerNativePtr));

if (notificationEventName != nullptr) {
config.NotificationEventName = JStringToStdString(env, notificationEventName).c_str();
}

spSanitizer = std::make_shared<Sanitizer>(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<bool>(enabled));
return true;
}
2 changes: 1 addition & 1 deletion lib/modules
Loading