Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mishiranu.dashchan.chan.dvach;
- import android.net.Uri;
- import android.os.Build;
- import chan.content.Chan;
- import chan.http.HttpException;
- import chan.http.HttpHolder;
- import chan.http.HttpRequest;
- import chan.http.SimpleEntity;
- import chan.util.StringUtils;
- import com.mishiranu.dashchan.BuildConfig;
- import com.mishiranu.dashchan.content.Preferences;
- import com.mishiranu.dashchan.content.async.ExecutorTask;
- import com.mishiranu.dashchan.util.ConcurrentUtils;
- import org.json.JSONException;
- import org.json.JSONObject;
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- /* JADX INFO: loaded from: classes.dex */
- public final class DvachNoCaptchaProvisioning {
- public static final String DEFAULT_APP_BUILD = Integer.toString(BuildConfig.VERSION_CODE);
- public static final String DEFAULT_APP_NAME = "Slooop";
- public static final String DEFAULT_APP_VERSION = "3.2.22-beta1";
- public static final String DEFAULT_DEVICE_BRAND = "unknown";
- public static final String DEFAULT_DEVICE_MODEL = "unknown";
- public static final String DEFAULT_DEVICE_NAME = "Slooop beta device";
- public static final String DEFAULT_ENDPOINT = "https://api.slooop.ru/v1/ichan";
- public static final String DEFAULT_SERVER = "api.slooop.ru";
- public static final String DEFAULT_SOURCE = "google_play";
- private static final int MAX_PROFILE_VALUE_LENGTH = 1024;
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- public interface Callback {
- void onComplete(Result result);
- }
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- public enum Error {
- INVALID_SERVER,
- NETWORK,
- INVALID_RESPONSE,
- STORAGE
- }
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- public static final class Profile {
- public final String appBuild;
- public final String appName;
- public final String appVersion;
- public final String deviceBrand;
- public final String deviceFingerprint;
- public final String deviceModel;
- public final String deviceName;
- public final String source;
- public Profile(String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8) {
- this.appName = DvachNoCaptchaProvisioning.normalizeProfileValue(str);
- this.appVersion = DvachNoCaptchaProvisioning.normalizeProfileValue(str2);
- this.appBuild = DvachNoCaptchaProvisioning.normalizeProfileValue(str3);
- this.source = DvachNoCaptchaProvisioning.normalizeProfileValue(str4);
- this.deviceName = DvachNoCaptchaProvisioning.normalizeProfileValue(str5);
- this.deviceBrand = DvachNoCaptchaProvisioning.normalizeProfileValue(str6);
- this.deviceModel = DvachNoCaptchaProvisioning.normalizeProfileValue(str7);
- this.deviceFingerprint = DvachNoCaptchaProvisioning.normalizeProfileValue(str8);
- }
- }
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- public static final class RequestTask extends ExecutorTask<Void, Result> {
- private final Callback callback;
- private final String endpoint;
- private final HttpHolder holder;
- private final String postingServer;
- private final Profile profile;
- private RequestTask(String str, String str2, Profile profile, Callback callback) {
- this.holder = new HttpHolder(Chan.getFallback());
- this.endpoint = str;
- this.postingServer = str2;
- this.profile = profile;
- this.callback = callback;
- }
- @Override // com.mishiranu.dashchan.content.async.ExecutorTask
- public void cancel() {
- super.cancel();
- this.holder.interrupt();
- }
- @Override // com.mishiranu.dashchan.content.async.ExecutorTask
- public void onComplete(Result result) {
- Callback callback = this.callback;
- if (result == null) {
- result = Result.error(Error.NETWORK);
- }
- callback.onComplete(result);
- }
- /* JADX WARN: Can't rename method to resolve collision */
- @Override // com.mishiranu.dashchan.content.async.ExecutorTask
- public Result run() {
- HttpHolder.Use use = this.holder.use();
- try {
- Result resultRequest = DvachNoCaptchaProvisioning.request(this.holder, this.endpoint, this.postingServer, this.profile);
- if (use != null) {
- use.close();
- }
- return resultRequest;
- } catch (Throwable th) {
- if (use != null) {
- try {
- use.close();
- } catch (Throwable th2) {
- th.addSuppressed(th2);
- }
- }
- throw th;
- }
- }
- }
- /* JADX INFO: compiled from: r8-map-id-69b0d98fa0c655d6ba582ff17a9bb2b718caed2d43ea8140768c75d96d37a9a5 */
- public static final class Result {
- public final Error error;
- public final String publicKey;
- public final boolean success;
- private Result(boolean z, String str, Error error) {
- this.success = z;
- this.publicKey = str;
- this.error = error;
- }
- /* JADX INFO: Access modifiers changed from: private */
- public static Result error(Error error) {
- return new Result(false, null, error);
- }
- /* JADX INFO: Access modifiers changed from: private */
- public static Result success(String str) {
- return new Result(true, str, null);
- }
- }
- private DvachNoCaptchaProvisioning() {
- }
- private static String defaultIfEmpty(String str) {
- String strNormalizeProfileValue = normalizeProfileValue(str);
- return strNormalizeProfileValue != null ? strNormalizeProfileValue : "unknown";
- }
- public static String getDisplayServer(String str) {
- String strNormalizeEndpoint = normalizeEndpoint(str);
- if (!isValidEndpoint(strNormalizeEndpoint)) {
- return strNormalizeEndpoint;
- }
- Uri uri = Uri.parse(strNormalizeEndpoint);
- return "/v1/ichan".equals(uri.getPath()) ? uri.getHost() : strNormalizeEndpoint;
- }
- public static Profile getProfile() {
- return DvachNoCaptchaInstallIdentity.getProfile();
- }
- public static boolean isValidEndpoint(String str) {
- String strNormalizeEndpoint = normalizeEndpoint(str);
- if (strNormalizeEndpoint == null) {
- return false;
- }
- Uri uri = Uri.parse(strNormalizeEndpoint);
- 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());
- }
- public static boolean isValidProfile(Profile profile) {
- 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);
- }
- private static boolean isValidProfileValue(String str) {
- return str != null && str.length() <= 1024;
- }
- public static String keyToOutput(String str) {
- String strTrim = str != null ? str.trim() : null;
- if (strTrim == null || strTrim.length() <= 20 || strTrim.length() > 8192) {
- return null;
- }
- return strTrim.substring(10, strTrim.length() - 10).replace('!', 'a').replace('@', 'o').replace('-', '1');
- }
- public static String normalizeEndpoint(String str) {
- String strTrim = str != null ? str.trim() : null;
- if (!StringUtils.isEmpty(strTrim) && !strTrim.contains("://")) {
- strTrim = "https://".concat(strTrim);
- }
- while (strTrim != null && strTrim.endsWith("/")) {
- strTrim = strTrim.substring(0, strTrim.length() - 1);
- }
- if (!StringUtils.isEmpty(strTrim)) {
- Uri uri = Uri.parse(strTrim);
- if (StringUtils.isEmpty(uri.getPath())) {
- strTrim = uri.buildUpon().appendPath("v1").appendPath("ichan").build().toString();
- }
- }
- return StringUtils.nullIfEmpty(strTrim);
- }
- /* JADX INFO: Access modifiers changed from: private */
- public static String normalizeProfileValue(String str) {
- return StringUtils.nullIfEmpty(str != null ? str.trim() : null);
- }
- /* JADX INFO: Access modifiers changed from: private */
- public static Result request(HttpHolder httpHolder, String str, String str2, Profile profile) {
- if (!isValidEndpoint(str) || !DvachNoCaptchaPosting.isValidServer(str2) || !isValidProfile(profile)) {
- return Result.error(Error.INVALID_SERVER);
- }
- try {
- DvachNoCaptchaInstallIdentity.Value value = DvachNoCaptchaInstallIdentity.get();
- JSONObject jSONObject = new JSONObject();
- jSONObject.put("uuid", value.uuid);
- jSONObject.put("name", profile.deviceName);
- jSONObject.put("brand", profile.deviceBrand);
- jSONObject.put("model", profile.deviceModel);
- jSONObject.put("os_name", "android");
- jSONObject.put("os_version", "13");
- jSONObject.put("is_physical", true);
- jSONObject.put("fingerprint", profile.deviceFingerprint);
- jSONObject.put("timezone", "Europe/Moscow");
- jSONObject.put("lang", Preferences.DEFAULT_TRANSLATION_NATIVE_LANGUAGE);
- JSONObject jSONObject2 = new JSONObject();
- jSONObject2.put("name", profile.appName);
- jSONObject2.put("version", profile.appVersion);
- jSONObject2.put("build", profile.appBuild);
- JSONObject jSONObject3 = new JSONObject();
- jSONObject3.put("device", jSONObject);
- jSONObject3.put("app", jSONObject2);
- jSONObject3.put("source", profile.source);
- jSONObject3.put("email", "");
- SimpleEntity simpleEntity = new SimpleEntity();
- simpleEntity.setContentType("application/json; charset=utf-8");
- simpleEntity.setData(jSONObject3.toString());
- String string = new HttpRequest(Uri.parse(str), httpHolder).setPostMethod(simpleEntity).setRedirectHandler(HttpRequest.RedirectHandler.NONE).setTimeouts(15000, 15000).clearCookies().addHeader("Accept", "application/json").perform().readString();
- if (string != null && string.length() <= 65536) {
- JSONObject jSONObject4 = new JSONObject(string);
- if (jSONObject4.optBoolean("nocaptcha") && jSONObject4.optBoolean("post") && jSONObject4.optBoolean("test")) {
- String strKeyToOutput = keyToOutput(jSONObject4.optString("pbk", null));
- String strKeyToOutput2 = keyToOutput(jSONObject4.optString("pvk", null));
- if (DvachNoCaptchaPosting.isValidPublicKey(strKeyToOutput) && DvachNoCaptchaPosting.isValidPrivateKey(strKeyToOutput2)) {
- if (!DvachNoCaptchaPosting.saveConfiguration(str2, strKeyToOutput, strKeyToOutput2)) {
- return Result.error(Error.STORAGE);
- }
- Preferences.setDvachNoCaptchaProvisioningServer(getDisplayServer(str));
- return Result.success(strKeyToOutput);
- }
- return Result.error(Error.INVALID_RESPONSE);
- }
- return Result.error(Error.INVALID_RESPONSE);
- }
- return Result.error(Error.INVALID_RESPONSE);
- } catch (HttpException unused) {
- return Result.error(Error.NETWORK);
- } catch (RuntimeException | JSONException unused2) {
- return Result.error(Error.INVALID_RESPONSE);
- }
- }
- public static boolean saveProfile(Profile profile) {
- return isValidProfile(profile) && DvachNoCaptchaInstallIdentity.putProfile(profile);
- }
- public static RequestTask start(String str, String str2, Profile profile, Callback callback) {
- RequestTask requestTask = new RequestTask(normalizeEndpoint(str), str2, profile, callback);
- requestTask.execute(ConcurrentUtils.PARALLEL_EXECUTOR);
- return requestTask;
- }
- public static Profile useCurrentDevice(Profile profile) {
- String str = profile.appName;
- String str2 = profile.appVersion;
- String str3 = profile.appBuild;
- String str4 = profile.source;
- String str5 = Build.MODEL;
- return new Profile(str, str2, str3, str4, defaultIfEmpty(str5), defaultIfEmpty(Build.BRAND), defaultIfEmpty(str5), defaultIfEmpty(Build.FINGERPRINT));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment