Security fixes and optimizations
- All known hosts now have a hardcoded trusted root ca, because we're not just going to trust that the user has a-ok certs installed - Remove some unused code - Properly fix a couple NetworkOnMainThread errors Signed-off-by: androidacy-user <opensource@androidacy.com>pull/27/head
parent
86c46de069
commit
66cb0b1813
@ -1,171 +0,0 @@
|
|||||||
package com.fox2code.mmm.utils;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.IdRes;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class NoodleDebug {
|
|
||||||
private static final String TAG = "NoodleDebug";
|
|
||||||
private static final WeakReference<Thread> NULL_THREAD_REF = new WeakReference<>(null);
|
|
||||||
private static final ThreadLocal<NoodleDebug> THREAD_NOODLE = new ThreadLocal<>();
|
|
||||||
@SuppressLint("StaticFieldLeak") // <- Null initialized
|
|
||||||
private static final NoodleDebug NULL = new NoodleDebug() {
|
|
||||||
@Override
|
|
||||||
public NoodleDebug bind() {
|
|
||||||
getNoodleDebug().unbind();
|
|
||||||
THREAD_NOODLE.remove();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEnabled(boolean enabled) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void markDirty() {}
|
|
||||||
};
|
|
||||||
private final Activity activity;
|
|
||||||
private final TextView textView;
|
|
||||||
private final LinkedList<String> tokens;
|
|
||||||
private final StringBuilder debug;
|
|
||||||
private WeakReference<Thread> thread;
|
|
||||||
private boolean enabled, updating;
|
|
||||||
|
|
||||||
private NoodleDebug() {
|
|
||||||
this.activity = null;
|
|
||||||
this.textView = null;
|
|
||||||
this.tokens = new LinkedList<>();
|
|
||||||
this.debug = new StringBuilder(0);
|
|
||||||
this.thread = NULL_THREAD_REF;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoodleDebug(Activity activity,@IdRes int textViewId) {
|
|
||||||
this(activity, activity.findViewById(textViewId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoodleDebug(Activity activity, TextView textView) {
|
|
||||||
this.activity = Objects.requireNonNull(activity);
|
|
||||||
this.textView = Objects.requireNonNull(textView);
|
|
||||||
this.tokens = new LinkedList<>();
|
|
||||||
this.debug = new StringBuilder(64);
|
|
||||||
this.thread = NULL_THREAD_REF;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoodleDebug bind() {
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
Thread thread;
|
|
||||||
if ((thread = this.thread.get()) != null) {
|
|
||||||
Log.e(TAG, "Trying to bind to thread \"" + Thread.currentThread().getName() +
|
|
||||||
"\" while already bound to \"" + thread.getName() + "\"");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
this.tokens.clear();
|
|
||||||
}
|
|
||||||
if (this.enabled) {
|
|
||||||
this.thread = new WeakReference<>(Thread.currentThread());
|
|
||||||
THREAD_NOODLE.set(this);
|
|
||||||
} else {
|
|
||||||
this.thread = NULL_THREAD_REF;
|
|
||||||
THREAD_NOODLE.remove();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unbind() {
|
|
||||||
this.thread = NULL_THREAD_REF;
|
|
||||||
boolean markDirty;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
markDirty = !this.tokens.isEmpty();
|
|
||||||
this.tokens.clear();
|
|
||||||
}
|
|
||||||
if (markDirty) this.markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBound() {
|
|
||||||
return this.thread.get() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void push(String token) {
|
|
||||||
if (!this.enabled) return;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
this.tokens.add(token);
|
|
||||||
}
|
|
||||||
if (!token.isEmpty())
|
|
||||||
this.markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pop() {
|
|
||||||
if (!this.enabled) return;
|
|
||||||
String last;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
last = this.tokens.removeLast();
|
|
||||||
}
|
|
||||||
if (!last.isEmpty())
|
|
||||||
this.markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replace(String token) {
|
|
||||||
if (!this.enabled) return;
|
|
||||||
String last;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
last = this.tokens.removeLast();
|
|
||||||
this.tokens.add(token);
|
|
||||||
}
|
|
||||||
if (!last.equals(token))
|
|
||||||
this.markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
if (this.enabled && !enabled) {
|
|
||||||
this.thread = NULL_THREAD_REF;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
this.tokens.clear();
|
|
||||||
}
|
|
||||||
this.markDirty();
|
|
||||||
}
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void markDirty() {
|
|
||||||
assert this.activity != null;
|
|
||||||
assert this.textView != null;
|
|
||||||
if (this.updating) return;
|
|
||||||
this.updating = true;
|
|
||||||
this.activity.runOnUiThread(() -> {
|
|
||||||
String debugText;
|
|
||||||
synchronized (this.tokens) {
|
|
||||||
StringBuilder debug = this.debug;
|
|
||||||
debug.setLength(0);
|
|
||||||
boolean first = true;
|
|
||||||
for (String text : this.tokens) {
|
|
||||||
if (text.isEmpty()) continue;
|
|
||||||
if (first) first = false;
|
|
||||||
else debug.append(" > ");
|
|
||||||
debug.append(text);
|
|
||||||
}
|
|
||||||
debugText = debug.toString();
|
|
||||||
}
|
|
||||||
this.updating = false;
|
|
||||||
this.textView.setText(debugText);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static NoodleDebug getNoodleDebug() {
|
|
||||||
NoodleDebug noodleDebug = THREAD_NOODLE.get();
|
|
||||||
if (noodleDebug == null) return NULL;
|
|
||||||
if (noodleDebug.thread.get() != Thread.currentThread() ||
|
|
||||||
noodleDebug.activity.isDestroyed()) {
|
|
||||||
THREAD_NOODLE.remove();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return noodleDebug;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
|
||||||
|
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||||
|
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
|
||||||
|
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
|
||||||
|
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
|
||||||
|
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
|
||||||
|
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
|
||||||
|
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
|
||||||
|
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
|
||||||
|
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
|
||||||
|
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
|
||||||
|
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
|
||||||
|
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
|
||||||
|
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
|
||||||
|
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
|
||||||
|
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
|
||||||
|
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
|
||||||
|
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
|
||||||
|
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
|
||||||
|
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG
|
||||||
|
A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
|
||||||
|
b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw
|
||||||
|
MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i
|
||||||
|
YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT
|
||||||
|
aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ
|
||||||
|
jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp
|
||||||
|
xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp
|
||||||
|
1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG
|
||||||
|
snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ
|
||||||
|
U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8
|
||||||
|
9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E
|
||||||
|
BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B
|
||||||
|
AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz
|
||||||
|
yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE
|
||||||
|
38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP
|
||||||
|
AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad
|
||||||
|
DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME
|
||||||
|
HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
Loading…
Reference in New Issue