- Bundle current root certificates (Let's Encrypt, GTS, Sectigo, DigiCert G2, Amazon, ...) missing from Android 2.x's store (Roots.java, tools/gen_roots.py) - Ask once for unknown certificates, showing the SHA-256 fingerprint, and remember the answer; replaces "accept any certificate" (Trust*, Settings) - Local streaming proxy so Android 2.x's MediaPlayer can play https:// servers, with seeking and a fresh token per request (StreamProxy.java) - Tests over real TLS with good, expired, wrong-host, forged and self-signed certificates (test/make_pki.sh, TrustTest.java) - README: server setup for a legacy TLS 1.0 port Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.4 KiB
Java
122 lines
4.4 KiB
Java
package com.miniabs;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.text.InputType;
|
|
import android.view.View;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.widget.Button;
|
|
import android.widget.CheckBox;
|
|
import android.widget.CompoundButton;
|
|
import android.widget.EditText;
|
|
import android.widget.TextView;
|
|
|
|
public class LoginActivity extends Activity {
|
|
private EditText server, user, pass;
|
|
private CheckBox useKey;
|
|
private TextView status, userLabel, passLabel;
|
|
private Button connect;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle b) {
|
|
super.onCreate(b);
|
|
setContentView(R.layout.activity_login);
|
|
server = (EditText) findViewById(R.id.server);
|
|
user = (EditText) findViewById(R.id.user);
|
|
pass = (EditText) findViewById(R.id.pass);
|
|
useKey = (CheckBox) findViewById(R.id.use_key);
|
|
status = (TextView) findViewById(R.id.status);
|
|
userLabel = (TextView) findViewById(R.id.user_label);
|
|
passLabel = (TextView) findViewById(R.id.pass_label);
|
|
connect = (Button) findViewById(R.id.connect);
|
|
|
|
Prefs p = Prefs.get(this);
|
|
server.setText(p.server());
|
|
user.setText(p.username());
|
|
String msg = getIntent().getStringExtra("message");
|
|
if (msg != null) status.setText(msg);
|
|
|
|
useKey.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
public void onCheckedChanged(CompoundButton v, boolean on) {
|
|
int vis = on ? View.GONE : View.VISIBLE;
|
|
user.setVisibility(vis);
|
|
userLabel.setVisibility(vis);
|
|
passLabel.setText(on ? "API key" : "Password");
|
|
pass.setInputType(on ? InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
|
: InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
pass.setText("");
|
|
}
|
|
});
|
|
connect.setOnClickListener(new View.OnClickListener() {
|
|
public void onClick(View v) {
|
|
go();
|
|
}
|
|
});
|
|
}
|
|
|
|
static String normalize(String s) {
|
|
s = s.trim();
|
|
while (s.endsWith("/")) s = s.substring(0, s.length() - 1);
|
|
if (s.endsWith("/login")) s = s.substring(0, s.length() - 6);
|
|
if (s.length() > 0 && !s.startsWith("http://") && !s.startsWith("https://")) s = "http://" + s;
|
|
return s;
|
|
}
|
|
|
|
private void go() {
|
|
final String srv = normalize(server.getText().toString());
|
|
final String u = user.getText().toString().trim();
|
|
final String pw = pass.getText().toString();
|
|
final boolean key = useKey.isChecked();
|
|
if (srv.length() == 0) {
|
|
status.setText("Enter your server address.");
|
|
return;
|
|
}
|
|
if (key ? pw.trim().length() == 0 : u.length() == 0) {
|
|
status.setText(key ? "Paste your API key." : "Enter your username.");
|
|
return;
|
|
}
|
|
server.setText(srv);
|
|
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(pass.getWindowToken(), 0);
|
|
connect.setEnabled(false);
|
|
status.setText("Connecting…");
|
|
|
|
final Prefs p = Prefs.get(this);
|
|
p.logout();
|
|
App.clear();
|
|
HomeActivity.clearCache();
|
|
p.setServer(srv);
|
|
Trust.lastRejected = null;
|
|
new Job<String>() {
|
|
String work() throws Exception {
|
|
String version = Api.status(LoginActivity.this, srv);
|
|
String lib;
|
|
if (key) {
|
|
Api.loginWithKey(LoginActivity.this, pw.trim());
|
|
lib = "";
|
|
} else {
|
|
lib = Api.login(LoginActivity.this, srv, u, pw);
|
|
}
|
|
if (lib.length() > 0) p.setLibrary(lib, "");
|
|
return version;
|
|
}
|
|
|
|
void done(String version) {
|
|
startActivity(new Intent(LoginActivity.this, HomeActivity.class)
|
|
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
|
|
finish();
|
|
}
|
|
|
|
void failed(Exception e) {
|
|
connect.setEnabled(true);
|
|
status.setText(Util.describe(e));
|
|
TrustPrompt.offer(LoginActivity.this, new Runnable() {
|
|
public void run() {
|
|
go();
|
|
}
|
|
});
|
|
}
|
|
}.start();
|
|
}
|
|
}
|