mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-03 23:15:44 +01:00
Show toast to internal users for invalid messages.
This commit is contained in:
committed by
Alex Hart
parent
ace47c61b1
commit
78b530f8b8
@@ -26,6 +26,14 @@ import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Typing
|
||||
object EnvelopeContentValidator {
|
||||
|
||||
fun validate(envelope: Envelope, content: Content): Result {
|
||||
if (envelope.type == Envelope.Type.PLAINTEXT_CONTENT) {
|
||||
val result: Result? = createPlaintextResultIfInvalid(content)
|
||||
|
||||
if (result != null) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return when {
|
||||
envelope.story && !content.meetsStoryFlagCriteria() -> Result.Invalid("Envelope was flagged as a story, but it did not have any story-related content!")
|
||||
content.hasDataMessage() -> validateDataMessage(envelope, content.dataMessage)
|
||||
@@ -288,6 +296,47 @@ object EnvelopeContentValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createPlaintextResultIfInvalid(content: Content): Result? {
|
||||
val errors: MutableList<String> = mutableListOf()
|
||||
|
||||
if (!content.hasDecryptionErrorMessage()) {
|
||||
errors += "Missing DecryptionErrorMessage"
|
||||
}
|
||||
if (content.hasStoryMessage()) {
|
||||
errors += "Unexpected StoryMessage"
|
||||
}
|
||||
if (content.hasSenderKeyDistributionMessage()) {
|
||||
errors += "Unexpected SenderKeyDistributionMessage"
|
||||
}
|
||||
if (content.hasCallMessage()) {
|
||||
errors += "Unexpected CallMessage"
|
||||
}
|
||||
if (content.hasEditMessage()) {
|
||||
errors += "Unexpected EditMessage"
|
||||
}
|
||||
if (content.hasNullMessage()) {
|
||||
errors += "Unexpected NullMessage"
|
||||
}
|
||||
if (content.hasPniSignatureMessage()) {
|
||||
errors += "Unexpected PniSignatureMessage"
|
||||
}
|
||||
if (content.hasReceiptMessage()) {
|
||||
errors += "Unexpected ReceiptMessage"
|
||||
}
|
||||
if (content.hasSyncMessage()) {
|
||||
errors += "Unexpected SyncMessage"
|
||||
}
|
||||
if (content.hasTypingMessage()) {
|
||||
errors += "Unexpected TypingMessage"
|
||||
}
|
||||
|
||||
return if (errors.isNotEmpty()) {
|
||||
Result.Invalid("Invalid PLAINTEXT_CONTENT! Errors: $errors")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateGroupContextV2(groupContext: GroupContextV2, prefix: String): Result.Invalid? {
|
||||
return if (!groupContext.hasMasterKey()) {
|
||||
Result.Invalid("$prefix Missing GV2 master key!")
|
||||
|
||||
Reference in New Issue
Block a user