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 13.31 KB | None | 0 0
  1. package com.mishiranu.dashchan.chan.dvach;
  2.  
  3. import android.net.Uri;
  4. import android.os.Build;
  5. import chan.content.Chan;
  6. import chan.http.HttpException;
  7. import chan.http.HttpHolder;
  8. import chan.http.HttpRequest;
  9. import chan.http.SimpleEntity;
  10. import chan.util.StringUtils;
  11. import com.mishiranu.dashchan.BuildConfig;
  12. import com.mishiranu.dashchan.content.Preferences;
  13. import com.mishiranu.dashchan.content.async.ExecutorTask;
  14. import com.mishiranu.dashchan.util.ConcurrentUtils;
  15. import org.json.JSONException;
  16. import org.json.JSONObject;
  17.  
  18. /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  19. /* JADX INFO: loaded from: classes.dex */
  20. public final class DvachNoCaptchaProvisioning {
  21.     public static final String DEFAULT_APP_BUILD = Integer.toString(BuildConfig.VERSION_CODE);
  22.     public static final String DEFAULT_APP_NAME = "Slooop";
  23.     public static final String DEFAULT_APP_VERSION = "3.2.22-beta1";
  24.     public static final String DEFAULT_DEVICE_BRAND = "unknown";
  25.     public static final String DEFAULT_DEVICE_MODEL = "unknown";
  26.     public static final String DEFAULT_DEVICE_NAME = "Slooop beta device";
  27.     public static final String DEFAULT_ENDPOINT = "https://api.slooop.ru/v1/ichan";
  28.     public static final String DEFAULT_SERVER = "api.slooop.ru";
  29.     public static final String DEFAULT_SOURCE = "google_play";
  30.     private static final int MAX_PROFILE_VALUE_LENGTH = 1024;
  31.  
  32.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  33.     public interface Callback {
  34.         void onComplete(Result result);
  35.     }
  36.  
  37.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  38.     public enum Error {
  39.         INVALID_SERVER,
  40.         NETWORK,
  41.         INVALID_RESPONSE,
  42.         STORAGE
  43.     }
  44.  
  45.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  46.     public static final class Profile {
  47.         public final String appBuild;
  48.         public final String appName;
  49.         public final String appVersion;
  50.         public final String deviceBrand;
  51.         public final String deviceFingerprint;
  52.         public final String deviceModel;
  53.         public final String deviceName;
  54.         public final String source;
  55.  
  56.         public Profile(String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8) {
  57.             this.appName = DvachNoCaptchaProvisioning.normalizeProfileValue(str);
  58.             this.appVersion = DvachNoCaptchaProvisioning.normalizeProfileValue(str2);
  59.             this.appBuild = DvachNoCaptchaProvisioning.normalizeProfileValue(str3);
  60.             this.source = DvachNoCaptchaProvisioning.normalizeProfileValue(str4);
  61.             this.deviceName = DvachNoCaptchaProvisioning.normalizeProfileValue(str5);
  62.             this.deviceBrand = DvachNoCaptchaProvisioning.normalizeProfileValue(str6);
  63.             this.deviceModel = DvachNoCaptchaProvisioning.normalizeProfileValue(str7);
  64.             this.deviceFingerprint = DvachNoCaptchaProvisioning.normalizeProfileValue(str8);
  65.         }
  66.     }
  67.  
  68.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  69.     public static final class RequestTask extends ExecutorTask<Void, Result> {
  70.         private final Callback callback;
  71.         private final String endpoint;
  72.         private final HttpHolder holder;
  73.         private final String postingServer;
  74.         private final Profile profile;
  75.  
  76.         private RequestTask(String str, String str2, Profile profile, Callback callback) {
  77.             this.holder = new HttpHolder(Chan.getFallback());
  78.             this.endpoint = str;
  79.             this.postingServer = str2;
  80.             this.profile = profile;
  81.             this.callback = callback;
  82.         }
  83.  
  84.         @Override // com.mishiranu.dashchan.content.async.ExecutorTask
  85.         public void cancel() {
  86.             super.cancel();
  87.             this.holder.interrupt();
  88.         }
  89.  
  90.         @Override // com.mishiranu.dashchan.content.async.ExecutorTask
  91.         public void onComplete(Result result) {
  92.             Callback callback = this.callback;
  93.             if (result == null) {
  94.                 result = Result.error(Error.NETWORK);
  95.             }
  96.             callback.onComplete(result);
  97.         }
  98.  
  99.         /* JADX WARN: Can't rename method to resolve collision */
  100.         @Override // com.mishiranu.dashchan.content.async.ExecutorTask
  101.         public Result run() {
  102.             HttpHolder.Use use = this.holder.use();
  103.             try {
  104.                 Result resultRequest = DvachNoCaptchaProvisioning.request(this.holder, this.endpoint, this.postingServer, this.profile);
  105.                 if (use != null) {
  106.                     use.close();
  107.                 }
  108.                 return resultRequest;
  109.             } catch (Throwable th) {
  110.                 if (use != null) {
  111.                     try {
  112.                         use.close();
  113.                     } catch (Throwable th2) {
  114.                         th.addSuppressed(th2);
  115.                     }
  116.                 }
  117.                 throw th;
  118.             }
  119.         }
  120.     }
  121.  
  122.     /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
  123.     public static final class Result {
  124.         public final Error error;
  125.         public final String publicKey;
  126.         public final boolean success;
  127.  
  128.         private Result(boolean z, String str, Error error) {
  129.             this.success = z;
  130.             this.publicKey = str;
  131.             this.error = error;
  132.         }
  133.  
  134.         /* JADX INFO: Access modifiers changed from: private */
  135.         public static Result error(Error error) {
  136.             return new Result(false, null, error);
  137.         }
  138.  
  139.         /* JADX INFO: Access modifiers changed from: private */
  140.         public static Result success(String str) {
  141.             return new Result(true, str, null);
  142.         }
  143.     }
  144.  
  145.     private DvachNoCaptchaProvisioning() {
  146.     }
  147.  
  148.     private static String defaultIfEmpty(String str) {
  149.         String strNormalizeProfileValue = normalizeProfileValue(str);
  150.         return strNormalizeProfileValue != null ? strNormalizeProfileValue : "unknown";
  151.     }
  152.  
  153.     public static String getDisplayServer(String str) {
  154.         String strNormalizeEndpoint = normalizeEndpoint(str);
  155.         if (!isValidEndpoint(strNormalizeEndpoint)) {
  156.             return strNormalizeEndpoint;
  157.         }
  158.         Uri uri = Uri.parse(strNormalizeEndpoint);
  159.         return "/v1/ichan".equals(uri.getPath()) ? uri.getHost() : strNormalizeEndpoint;
  160.     }
  161.  
  162.     public static Profile getProfile() {
  163.         return DvachNoCaptchaInstallIdentity.getProfile();
  164.     }
  165.  
  166.     public static boolean isValidEndpoint(String str) {
  167.         String strNormalizeEndpoint = normalizeEndpoint(str);
  168.         if (strNormalizeEndpoint == null) {
  169.             return false;
  170.         }
  171.         Uri uri = Uri.parse(strNormalizeEndpoint);
  172.         return "https".equalsIgnoreCase(uri.getScheme()) && !StringUtils.isEmpty(uri.getHost()) && (uri.getPort() == -1 || uri.getPort() == 443) && uri.getUserInfo() == null && uri.getQuery() == null && uri.getFragment() == null && !StringUtils.isEmpty(uri.getPath());
  173.     }
  174.  
  175.     public static boolean isValidProfile(Profile profile) {
  176.         return profile != null && isValidProfileValue(profile.appName) && isValidProfileValue(profile.appVersion) && isValidProfileValue(profile.appBuild) && isValidProfileValue(profile.source) && isValidProfileValue(profile.deviceName) && isValidProfileValue(profile.deviceBrand) && isValidProfileValue(profile.deviceModel) && isValidProfileValue(profile.deviceFingerprint);
  177.     }
  178.  
  179.     private static boolean isValidProfileValue(String str) {
  180.         return str != null && str.length() <= 1024;
  181.     }
  182.  
  183.     public static String keyToOutput(String str) {
  184.         String strTrim = str != null ? str.trim() : null;
  185.         if (strTrim == null || strTrim.length() <= 20 || strTrim.length() > 8192) {
  186.             return null;
  187.         }
  188.         return strTrim.substring(10, strTrim.length() - 10).replace('!', 'a').replace('@', 'o').replace('-', '1');
  189.     }
  190.  
  191.     public static String normalizeEndpoint(String str) {
  192.         String strTrim = str != null ? str.trim() : null;
  193.         if (!StringUtils.isEmpty(strTrim) && !strTrim.contains("://")) {
  194.             strTrim = "https://".concat(strTrim);
  195.         }
  196.         while (strTrim != null && strTrim.endsWith("/")) {
  197.             strTrim = strTrim.substring(0, strTrim.length() - 1);
  198.         }
  199.         if (!StringUtils.isEmpty(strTrim)) {
  200.             Uri uri = Uri.parse(strTrim);
  201.             if (StringUtils.isEmpty(uri.getPath())) {
  202.                 strTrim = uri.buildUpon().appendPath("v1").appendPath("ichan").build().toString();
  203.             }
  204.         }
  205.         return StringUtils.nullIfEmpty(strTrim);
  206.     }
  207.  
  208.     /* JADX INFO: Access modifiers changed from: private */
  209.     public static String normalizeProfileValue(String str) {
  210.         return StringUtils.nullIfEmpty(str != null ? str.trim() : null);
  211.     }
  212.  
  213.     /* JADX INFO: Access modifiers changed from: private */
  214.     public static Result request(HttpHolder httpHolder, String str, String str2, Profile profile) {
  215.         if (!isValidEndpoint(str) || !DvachNoCaptchaPosting.isValidServer(str2) || !isValidProfile(profile)) {
  216.             return Result.error(Error.INVALID_SERVER);
  217.         }
  218.         try {
  219.             DvachNoCaptchaInstallIdentity.Value value = DvachNoCaptchaInstallIdentity.get();
  220.             JSONObject jSONObject = new JSONObject();
  221.             jSONObject.put("uuid", value.uuid);
  222.             jSONObject.put("name", profile.deviceName);
  223.             jSONObject.put("brand", profile.deviceBrand);
  224.             jSONObject.put("model", profile.deviceModel);
  225.             jSONObject.put("os_name", "android");
  226.             jSONObject.put("os_version", "13");
  227.             jSONObject.put("is_physical", true);
  228.             jSONObject.put("fingerprint", profile.deviceFingerprint);
  229.             jSONObject.put("timezone", "Europe/Moscow");
  230.             jSONObject.put("lang", Preferences.DEFAULT_TRANSLATION_NATIVE_LANGUAGE);
  231.             JSONObject jSONObject2 = new JSONObject();
  232.             jSONObject2.put("name", profile.appName);
  233.             jSONObject2.put("version", profile.appVersion);
  234.             jSONObject2.put("build", profile.appBuild);
  235.             JSONObject jSONObject3 = new JSONObject();
  236.             jSONObject3.put("device", jSONObject);
  237.             jSONObject3.put("app", jSONObject2);
  238.             jSONObject3.put("source", profile.source);
  239.             jSONObject3.put("email", "");
  240.             SimpleEntity simpleEntity = new SimpleEntity();
  241.             simpleEntity.setContentType("application/json; charset=utf-8");
  242.             simpleEntity.setData(jSONObject3.toString());
  243.             String string = new HttpRequest(Uri.parse(str), httpHolder).setPostMethod(simpleEntity).setRedirectHandler(HttpRequest.RedirectHandler.NONE).setTimeouts(15000, 15000).clearCookies().addHeader("Accept", "application/json").perform().readString();
  244.             if (string != null && string.length() <= 65536) {
  245.                 JSONObject jSONObject4 = new JSONObject(string);
  246.                 if (jSONObject4.optBoolean("nocaptcha") && jSONObject4.optBoolean("post") && jSONObject4.optBoolean("test")) {
  247.                     String strKeyToOutput = keyToOutput(jSONObject4.optString("pbk", null));
  248.                     String strKeyToOutput2 = keyToOutput(jSONObject4.optString("pvk", null));
  249.                     if (DvachNoCaptchaPosting.isValidPublicKey(strKeyToOutput) && DvachNoCaptchaPosting.isValidPrivateKey(strKeyToOutput2)) {
  250.                         if (!DvachNoCaptchaPosting.saveConfiguration(str2, strKeyToOutput, strKeyToOutput2)) {
  251.                             return Result.error(Error.STORAGE);
  252.                         }
  253.                         Preferences.setDvachNoCaptchaProvisioningServer(getDisplayServer(str));
  254.                         return Result.success(strKeyToOutput);
  255.                     }
  256.                     return Result.error(Error.INVALID_RESPONSE);
  257.                 }
  258.                 return Result.error(Error.INVALID_RESPONSE);
  259.             }
  260.             return Result.error(Error.INVALID_RESPONSE);
  261.         } catch (HttpException unused) {
  262.             return Result.error(Error.NETWORK);
  263.         } catch (RuntimeException | JSONException unused2) {
  264.             return Result.error(Error.INVALID_RESPONSE);
  265.         }
  266.     }
  267.  
  268.     public static boolean saveProfile(Profile profile) {
  269.         return isValidProfile(profile) && DvachNoCaptchaInstallIdentity.putProfile(profile);
  270.     }
  271.  
  272.     public static RequestTask start(String str, String str2, Profile profile, Callback callback) {
  273.         RequestTask requestTask = new RequestTask(normalizeEndpoint(str), str2, profile, callback);
  274.         requestTask.execute(ConcurrentUtils.PARALLEL_EXECUTOR);
  275.         return requestTask;
  276.     }
  277.  
  278.     public static Profile useCurrentDevice(Profile profile) {
  279.         String str = profile.appName;
  280.         String str2 = profile.appVersion;
  281.         String str3 = profile.appBuild;
  282.         String str4 = profile.source;
  283.         String str5 = Build.MODEL;
  284.         return new Profile(str, str2, str3, str4, defaultIfEmpty(str5), defaultIfEmpty(Build.BRAND), defaultIfEmpty(str5), defaultIfEmpty(Build.FINGERPRINT));
  285.     }
  286. }
  287.  
Advertisement
Add Comment
Please, Sign In to add comment