Skip to content

Commit

Permalink
fix(core): anonymized logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Feb 4, 2024
1 parent d89d7c0 commit c301592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 13 additions & 6 deletions app/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,26 @@ class LogManager(

fun internalLog(tag: String, logLevel: LogLevel, message: Any?) {
runCatching {
val anonymizedMessage = message.toString().let {
if (remoteSideContext.config.isInitialized() && anonymizeLogs)
it
// remove uuids
.replace(Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOption.MULTILINE), "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
// remove content uris
.replace(Regex("content://[a-zA-Z0-9_\\-./]+"), "content://xxx")
// remove file names
.replace(Regex("[a-zA-Z0-9_\\-./]+\\.[a-zA-Z0-9_\\-./]+"), "xxx.xxx")
else it
}
val line = LogLine(
logLevel = logLevel,
dateTime = getCurrentDateTime(),
tag = tag,
message = message.toString().let {
if (remoteSideContext.config.isInitialized() && anonymizeLogs)
it.replace(Regex("[0-9a-f]{8}-[0-9a-f]{4}-{3}[0-9a-f]{12}", RegexOption.MULTILINE), "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
else it
}
message = anonymizedMessage
)
logFile.appendText("|$line\n", Charsets.UTF_8)
lineAddListener(line)
Log.println(logLevel.priority, tag, message.toString())
Log.println(logLevel.priority, tag, anonymizedMessage)
}.onFailure {
Log.println(Log.ERROR, tag, "Failed to log message: $message")
Log.println(Log.ERROR, tag, it.stackTraceToString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class EndToEndEncryption : MessagingRuleFeature(
return
}

context.log.verbose("created publicKey: ${publicKey.contentToString()}")

sendCustomMessage(conversationId, REQUEST_PK_MESSAGE_ID) {
addBuffer(2, publicKey)
}
Expand Down

0 comments on commit c301592

Please sign in to comment.