Add an ipv4 scrubber.

This commit is contained in:
Greyson Parrelli 2022-02-11 11:08:37 -05:00
parent 1692caeab7
commit 4db58a27a1
3 changed files with 39 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.logsubmit
import android.app.Application
import org.signal.core.util.logging.Scrubber
import org.signal.paging.PagedDataSource
import org.thoughtcrime.securesms.database.LogDatabase
import org.thoughtcrime.securesms.logsubmit.util.Scrubber

View file

@ -79,8 +79,8 @@ public final class ScrubberTest {
{ "JOB::a37cb654-c9e0-4c1e-93df-3d11ca3c97f4",
"JOB::a37cb654-c9e0-4c1e-93df-3d11ca3c97f4" },
{ "All patterns in a row __textsecure_group__!abcdefg1234567890 +1234567890123456 abc@def.com a37cb654-c9e0-4c1e-93df-3d11ca3c97f4 nl.motorsport.com with text after",
"All patterns in a row __...group...90 +*************456 a...@... ********-****-****-****-**********f4 ***.com with text after"
{ "All patterns in a row __textsecure_group__!abcdefg1234567890 +1234567890123456 abc@def.com a37cb654-c9e0-4c1e-93df-3d11ca3c97f4 nl.motorsport.com 192.168.1.1 with text after",
"All patterns in a row __...group...90 +*************456 a...@... ********-****-****-****-**********f4 ***.com ...ipv4... with text after"
},
{ "java.net.UnknownServiceException: CLEARTEXT communication to nl.motorsport.com not permitted by network security policy",
@ -96,7 +96,23 @@ public final class ScrubberTest {
},
{ " Caused by: java.io.IOException: unexpected end of stream on Connection{storage.signal.org:443, proxy=DIRECT hostAddress=storage.signal.org/142.251.32.211:443 cipherSuite=TLS_AES_128_GCM_SHA256 protocol=http/1.1}",
" Caused by: java.io.IOException: unexpected end of stream on Connection{storage.signal.org:443, proxy=DIRECT hostAddress=storage.signal.org/142.251.32.211:443 cipherSuite=TLS_AES_128_GCM_SHA256 protocol=http/1.1}"
" Caused by: java.io.IOException: unexpected end of stream on Connection{storage.signal.org:443, proxy=DIRECT hostAddress=storage.signal.org/...ipv4...:443 cipherSuite=TLS_AES_128_GCM_SHA256 protocol=http/1.1}"
},
{ "192.168.1.1",
"...ipv4..."
},
{ "255.255.255.255",
"...ipv4..."
},
{ "Text before 255.255.255.255 text after",
"Text before ...ipv4... text after"
},
{ "Not an ipv4 3.141",
"Not an ipv4 3.141"
}
});

View file

@ -66,6 +66,17 @@ public final class Scrubber {
private static final Pattern UUID_PATTERN = Pattern.compile("(JOB::)?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{10})([0-9a-f]{2})", Pattern.CASE_INSENSITIVE);
private static final String UUID_CENSOR = "********-****-****-****-**********";
/**
* The entire string is censored.
*/
private static final Pattern IPV4_PATTERN = Pattern.compile("\\b" +
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" +
"\\b");
private static final String IPV4_CENSOR = "...ipv4...";
/**
* The domain name except for TLD will be censored.
*/
@ -86,6 +97,7 @@ public final class Scrubber {
in = scrubGroupsV2(in);
in = scrubUuids(in);
in = scrubDomains(in);
in = scrubIpv4(in);
return in;
}
@ -153,6 +165,13 @@ public final class Scrubber {
});
}
private static CharSequence scrubIpv4(@NonNull CharSequence in) {
return scrub(in,
IPV4_PATTERN,
(matcher, output) -> output.append(IPV4_CENSOR));
}
private static CharSequence scrub(@NonNull CharSequence in, @NonNull Pattern pattern, @NonNull ProcessMatch processMatch) {
final StringBuilder output = new StringBuilder(in.length());
final Matcher matcher = pattern.matcher(in);