Guest User

Untitled

a guest
Aug 7th, 2026
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.65 KB | None | 0 0
  1. package com.mishiranu.dashchan.chan.dvach;
  2.  
  3. import android.net.Uri;
  4. import chan.content.ChanPerformer;
  5. import chan.util.StringUtils;
  6. import com.mishiranu.dashchan.content.Preferences;
  7. import java.util.Arrays;
  8. import java.util.HashSet;
  9. import java.util.Locale;
  10. import java.util.Set;
  11. import java.util.concurrent.ConcurrentHashMap;
  12.  
  13. /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  14. /* JADX INFO: loaded from: classes.dex */
  15. public final class DvachNoCaptchaPosting {
  16.     public static final String CAPTCHA_DATA_APP_ID_PENDING = "slooopDvachAppIdPending";
  17.     public static final String DEFAULT_SERVER = "https://2ch.su";
  18.     private static final int MAX_CHALLENGE_ID_LENGTH = 4096;
  19.     private static final int MAX_PRIVATE_KEY_LENGTH = 4096;
  20.     private static final int MAX_PUBLIC_KEY_LENGTH = 4096;
  21.     private static final Set<String> ALLOWED_BOARDS = new HashSet(Arrays.asList("test", "mobi"));
  22.     private static final Set<String> OFFICIAL_HOSTS = new HashSet(Arrays.asList("2ch.su", "2ch.org", "2ch.life", "2ch.hk", "2ch.pm", "beta.2ch.hk", "2ch.cm", "2ch.re", "2ch.tf", "2ch.wf", "2ch.yt", "2-ch.so"));
  23.     private static final Set<String> MANUAL_CAPTCHA_FALLBACKS = ConcurrentHashMap.newKeySet();
  24.  
  25.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  26.     public static final class Configuration {
  27.         public final String publicKey;
  28.         public final String server;
  29.  
  30.         private Configuration(String str, String str2) {
  31.             this.server = str;
  32.             this.publicKey = str2;
  33.         }
  34.     }
  35.  
  36.     private DvachNoCaptchaPosting() {
  37.     }
  38.  
  39.     public static Uri buildUri(Configuration configuration, String... strArr) {
  40.         Uri.Builder builderBuildUpon = Uri.parse(configuration.server).buildUpon();
  41.         for (String str : strArr) {
  42.             builderBuildUpon.appendPath(str);
  43.         }
  44.         return builderBuildUpon.build();
  45.     }
  46.  
  47.     public static void clearPrivateKey() {
  48.         DvachNoCaptchaSecretStore.clear();
  49.         Preferences.setDvachNoCaptchaPostingEnabled(false);
  50.     }
  51.  
  52.     public static ChanPerformer.CaptchaData createPendingCaptchaData() {
  53.         ChanPerformer.CaptchaData captchaData = new ChanPerformer.CaptchaData();
  54.         captchaData.put(CAPTCHA_DATA_APP_ID_PENDING, "1");
  55.         return captchaData;
  56.     }
  57.  
  58.     public static Configuration getConfiguration() {
  59.         String strNormalizeServer = normalizeServer(Preferences.getDvachNoCaptchaServer());
  60.         String strNormalizePublicKey = normalizePublicKey(Preferences.getDvachNoCaptchaAppId());
  61.         if (isValidServer(strNormalizeServer) && isValidPublicKey(strNormalizePublicKey) && hasPrivateKey()) {
  62.             return new Configuration(strNormalizeServer, strNormalizePublicKey);
  63.         }
  64.         return null;
  65.     }
  66.  
  67.     public static Configuration getEnabledConfiguration() {
  68.         if (Preferences.isDvachNoCaptchaPostingEnabled()) {
  69.             return getConfiguration();
  70.         }
  71.         return null;
  72.     }
  73.  
  74.     public static Configuration getEnabledConfigurationForCaptcha(String str, String str2) {
  75.         if (isAllowedBoard(str) && !MANUAL_CAPTCHA_FALLBACKS.remove(makeTarget(str, str2)) && Preferences.getDvachAssistedPostingCooldownRemaining(str) <= 0) {
  76.             return getEnabledConfiguration();
  77.         }
  78.         return null;
  79.     }
  80.  
  81.     public static Configuration getEnabledConfigurationForPost(String str, String str2) {
  82.         if (isAllowedBoard(str) && Preferences.getDvachAssistedPostingCooldownRemaining(str) == 0 && !MANUAL_CAPTCHA_FALLBACKS.contains(makeTarget(str, str2))) {
  83.             return getEnabledConfiguration();
  84.         }
  85.         return null;
  86.     }
  87.  
  88.     public static boolean hasPrivateKey() {
  89.         return DvachNoCaptchaSecretStore.hasPrivateKey();
  90.     }
  91.  
  92.     private static boolean isAllowedBoard(String str) {
  93.         return isSupportedBoard(str);
  94.     }
  95.  
  96.     public static boolean isAppIdPending(ChanPerformer.CaptchaData captchaData) {
  97.         return captchaData != null && "1".equals(captchaData.get(CAPTCHA_DATA_APP_ID_PENDING));
  98.     }
  99.  
  100.     public static boolean isConfigured() {
  101.         return getConfiguration() != null;
  102.     }
  103.  
  104.     public static boolean isSupportedBoard(String str) {
  105.         return ALLOWED_BOARDS.contains(str);
  106.     }
  107.  
  108.     public static boolean isValidChallengeId(String str) {
  109.         return !StringUtils.isEmpty(str) && str.length() <= 4096;
  110.     }
  111.  
  112.     public static boolean isValidPrivateKey(String str) {
  113.         String strNormalizePrivateKey = normalizePrivateKey(str);
  114.         return strNormalizePrivateKey != null && strNormalizePrivateKey.length() <= 4096;
  115.     }
  116.  
  117.     public static boolean isValidPublicKey(String str) {
  118.         String strNormalizePublicKey = normalizePublicKey(str);
  119.         return strNormalizePublicKey != null && strNormalizePublicKey.length() <= 4096;
  120.     }
  121.  
  122.     public static boolean isValidServer(String str) {
  123.         String strNormalizeServer = normalizeServer(str);
  124.         if (strNormalizeServer == null) {
  125.             return false;
  126.         }
  127.         Uri uri = Uri.parse(strNormalizeServer);
  128.         String host = uri.getHost();
  129.         String path = uri.getPath();
  130.         return "https".equalsIgnoreCase(uri.getScheme()) && !StringUtils.isEmpty(host) && OFFICIAL_HOSTS.contains(host.toLowerCase(Locale.US)) && (uri.getPort() == -1 || uri.getPort() == 443) && uri.getUserInfo() == null && uri.getQuery() == null && uri.getFragment() == null && (StringUtils.isEmpty(path) || "/".equals(path));
  131.     }
  132.  
  133.     private static String makeTarget(String str, String str2) {
  134.         return str + "/" + StringUtils.emptyIfNull(str2);
  135.     }
  136.  
  137.     public static void markRateLimited() {
  138.         Preferences.markDvachAssistedPostingUsed();
  139.     }
  140.  
  141.     public static void markSuccessfulPost() {
  142.         Preferences.markDvachAssistedPostingUsed();
  143.     }
  144.  
  145.     public static String normalizePrivateKey(String str) {
  146.         return StringUtils.nullIfEmpty(str != null ? str.trim() : null);
  147.     }
  148.  
  149.     public static String normalizePublicKey(String str) {
  150.         return StringUtils.nullIfEmpty(str != null ? str.trim() : null);
  151.     }
  152.  
  153.     public static String normalizeServer(String str) {
  154.         String strTrim = str != null ? str.trim() : null;
  155.         if (StringUtils.isEmpty(strTrim)) {
  156.             return null;
  157.         }
  158.         while (strTrim.endsWith("/")) {
  159.             strTrim = strTrim.substring(0, strTrim.length() - 1);
  160.         }
  161.         return strTrim;
  162.     }
  163.  
  164.     public static void requestManualCaptchaFallback(String str, String str2) {
  165.         if (isAllowedBoard(str)) {
  166.             MANUAL_CAPTCHA_FALLBACKS.add(makeTarget(str, str2));
  167.         }
  168.     }
  169.  
  170.     public static boolean saveConfiguration(String str, String str2, String str3) {
  171.         String strNormalizeServer = normalizeServer(str);
  172.         String strNormalizePublicKey = normalizePublicKey(str2);
  173.         String strNormalizePrivateKey = normalizePrivateKey(str3);
  174.         if (!isValidServer(strNormalizeServer) || !isValidPublicKey(strNormalizePublicKey) || (strNormalizePrivateKey == null && !hasPrivateKey())) {
  175.             return false;
  176.         }
  177.         if (strNormalizePrivateKey != null && (!isValidPrivateKey(strNormalizePrivateKey) || !DvachNoCaptchaSecretStore.put(strNormalizePrivateKey))) {
  178.             return false;
  179.         }
  180.         Preferences.setDvachNoCaptchaConfiguration(strNormalizeServer, strNormalizePublicKey);
  181.         return true;
  182.     }
  183.  
  184.     public static String signChallenge(String str) {
  185.         if (isValidChallengeId(str)) {
  186.             return DvachNoCaptchaSecretStore.sign(str);
  187.         }
  188.         return null;
  189.     }
  190. }
  191.  
Add Comment
Please, Sign In to add comment