Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a4b8704
K2GO-552 feat(dash-node): change and reset admin passwords inside the…
luisguzman-adfa Nov 20, 2026
0e11032
K2GO-552 feat(auth): change, repair and reset admin passwords in Sett…
luisguzman-adfa Nov 20, 2026
74dfed7
K2GO-552 i18n(auth): translate the password strings to all locales
luisguzman-adfa Nov 20, 2026
c1c3265
K2GO-552 fix(auth): say why Repair is off when the username does not …
luisguzman-adfa Nov 20, 2026
816d64f
K2GO-552 fix(auth): start the password notice when Home turns Ready
luisguzman-adfa Nov 21, 2026
2b2df5e
K2GO-552 fix(auth): wait until every Home card answered its probe
luisguzman-adfa Nov 21, 2026
96a7ccf
K2GO-552 fix(auth): count only a real probe answer as ready
luisguzman-adfa Nov 21, 2026
1719dd8
K2GO-552 fix(dash-node): a Forgejo without its admin account is not a…
luisguzman-adfa Nov 22, 2026
2fc7f9a
K2GO-552 i18n(auth): factory notice text that works for one or more s…
luisguzman-adfa Nov 22, 2026
d5fcf7b
K2GO-552 feat(dash-node): report an admin account that is not present
luisguzman-adfa Nov 22, 2026
ac9610e
K2GO-552 feat(auth): gray out a service whose admin account is not pr…
luisguzman-adfa Nov 22, 2026
78f7ac5
K2GO-552 fix(dash-node): read a missing Kolibri account from its sign…
luisguzman-adfa Nov 22, 2026
c59acc3
K2GO-552 feat(auth): no admin account closes the door; one service list
luisguzman-adfa Nov 22, 2026
c15ea5d
K2GO-552 refactor(home): one platform probe for Home and Settings
luisguzman-adfa Nov 22, 2026
8c1dd90
K2GO-552 feat(auth): a stopped service says "Not running"; a tap asks…
luisguzman-adfa Nov 22, 2026
4e4defa
Merge remote-tracking branch 'origin/main' into feat/K2GO-552-auth-pa…
luisguzman-adfa Nov 22, 2026
4b0101f
K2GO-552 feat(auth): factory notice lists the services in two columns
luisguzman-adfa Nov 22, 2026
e6fb5dc
K2GO-552 feat(dash-node): password rule is the length only
luisguzman-adfa Nov 22, 2026
8f6533d
K2GO-552 feat(auth): live checks under "Change password"
luisguzman-adfa Nov 22, 2026
a4a75a0
K2GO-552 feat(dash-node): a new password needs a letter and a digit
luisguzman-adfa Nov 22, 2026
95bab0a
K2GO-552 feat(auth): three live checks, the user name in bold
luisguzman-adfa Nov 22, 2026
d29d907
K2GO-552 fix(auth): notice with an odd number of services keeps its b…
luisguzman-adfa Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified controller/app/src/main/assets/help.db
Binary file not shown.
10 changes: 5 additions & 5 deletions controller/app/src/main/assets/module_sizes.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# module,bytes,fetched_date -- AUTO-GENERATED by the refreshModuleSizes Gradle task; do not edit by hand
calibreweb,1575845888,2026-11-04
code,602128384,2026-11-04
forgejo,114274304,2026-11-04
kiwix,72024064,2026-11-04
kolibri,419414016,2026-11-04
calibreweb,1578496000,2026-11-22
code,602157056,2026-11-22
forgejo,114270208,2026-11-22
kiwix,74080256,2026-11-22
kolibri,419389440,2026-11-22
12 changes: 6 additions & 6 deletions controller/app/src/main/assets/rootfs_sizes.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# tier,abi,bytes,fetched_date,installed_bytes -- AUTO-GENERATED by the refreshRootfsSizes Gradle task; do not edit by hand
basic,arm64-v8a,1588917178,2026-11-04,2854993420
basic,armeabi-v7a,1547456299,2026-11-04,2675812380
standard,arm64-v8a,2407725653,2026-11-04,4052770720
standard,armeabi-v7a,2367855828,2026-11-04,3872493487
full,arm64-v8a,4022768261,2026-11-04,6400628513
full,armeabi-v7a,3973646017,2026-11-04,6103918361
basic,arm64-v8a,1590750919,2026-11-22,2857836891
basic,armeabi-v7a,1588290646,2026-11-22,2748832011
standard,arm64-v8a,2422519767,2026-11-22,4064373076
standard,armeabi-v7a,2421621408,2026-11-22,3954274976
full,arm64-v8a,4041981242,2026-11-22,6418221292
full,armeabi-v7a,4031562580,2026-11-22,6191492309
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* ============================================================================
* Name : CredentialsClient.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : ADFA-5044, K2GO-552. App-side client for the dash-node service-credential store:
* GET /k2go-api/credentials/<service> -> { username, isDefault, origin }
* POST /k2go-api/credentials/<service> { username, password } -> { ok, verified }
* GET /k2go-api/credentials/<service>/status -> { state, factoryDefault }
* POST /k2go-api/credentials/<service>/password { password } -> { ok, verified }
* POST /k2go-api/credentials/<service>/reset -> { ok, verified }
* The stored password is never returned by the box, except the public factory one.
* Localhost-only; the box denies the API to remote clients.
* ============================================================================
*/
package org.appdevforall.k2go.auth.data;

import android.os.Handler;
import android.os.Looper;

import org.appdevforall.k2go.config.BoxEndpoints;
import org.appdevforall.k2go.util.AppExecutors;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public final class CredentialsClient {
private CredentialsClient() {}

private static final Handler MAIN = new Handler(Looper.getMainLooper());

/** {@code password} is only non-empty when the service is still at the factory default (the box
* returns the public default so the form can prefill it); a custom password is never returned. */
public interface DescribeCb { void onOk(String username, String password, boolean isDefault); void onErr(); }

/** A non-2xx answer. {@code code} is the box's error code ("weak_password", "mismatch", ...). */
static final class HttpError extends Exception {
final int status;
final String code;

HttpError(int status, String code) {
super("HTTP " + status + (code.isEmpty() ? "" : " " + code));
this.status = status;
this.code = code;
}
}

static String url(String service) { return BoxEndpoints.API + "/credentials/" + service; }

/** Current stored username + whether it's still the box default (no password is ever returned). */
public static void describe(String service, DescribeCb cb) {
AppExecutors.get().io().execute(() -> {
try {
JSONObject o = request("GET", url(service), null);
final String user = o.optString("username", "");
final String pass = o.optString("password", ""); // present only while default
final boolean isDefault = o.optBoolean("isDefault", false);
MAIN.post(() -> cb.onOk(user, pass, isDefault));
} catch (Exception e) {
MAIN.post(cb::onErr);
}
});
}

/** Blocking; call it off the main thread. Throws {@link HttpError} on a non-2xx answer. */
static JSONObject request(String method, String urlStr, JSONObject body) throws Exception {
HttpURLConnection c = (HttpURLConnection) new URL(urlStr).openConnection();
try {
c.setUseCaches(false);
c.setConnectTimeout(4000);
// A change runs the service's own admin tool (Kolibri and Calibre-Web take several seconds
// on a phone), then a sign-in check.
c.setReadTimeout(150_000);
c.setRequestMethod(method);
c.setRequestProperty("Accept", "application/json");
if (body != null) {
c.setDoOutput(true);
c.setRequestProperty("Content-Type", "application/json");
byte[] payload = body.toString().getBytes(StandardCharsets.UTF_8);
try (OutputStream os = c.getOutputStream()) { os.write(payload); }
}
int status = c.getResponseCode();
boolean ok = status >= 200 && status < 300;
String text = readAll(ok ? c.getInputStream() : c.getErrorStream());
if (!ok) {
String code = "";
try { code = new JSONObject(text).optString("error", ""); } catch (Exception ignore) { }
throw new HttpError(status, code);
}
return new JSONObject(text.isEmpty() ? "{}" : text);
} finally {
c.disconnect();
}
}

private static String readAll(InputStream is) throws Exception {
if (is == null) return "";
ByteArrayOutputStream buf = new ByteArrayOutputStream();
byte[] chunk = new byte[4096];
int n;
while ((n = is.read(chunk)) != -1) buf.write(chunk, 0, n);
is.close();
return buf.toString(StandardCharsets.UTF_8.name());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ============================================================================
* Name : FactoryReminderStore.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-552. The user's choice to stop the "factory password in use" reminder, with the
* time of that choice as the record that the risk was shown and accepted. Set by the
* confirmation dialog; cleared by the switch in Settings > Authentication.
* ============================================================================
*/
package org.appdevforall.k2go.auth.data;

import android.content.Context;
import android.content.SharedPreferences;

public final class FactoryReminderStore {

private static final String PREFS = "k2go_auth";
private static final String KEY_OFF_AT = "factory_reminders_off_at";

private final SharedPreferences prefs;

public FactoryReminderStore(Context ctx) {
prefs = ctx.getApplicationContext().getSharedPreferences(PREFS, Context.MODE_PRIVATE);
}

public boolean isOff() {
return prefs.getLong(KEY_OFF_AT, 0L) > 0L;
}

public void turnOff(long nowMillis) {
prefs.edit().putLong(KEY_OFF_AT, nowMillis).apply();
}

public void turnOn() {
prefs.edit().remove(KEY_OFF_AT).apply();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* ============================================================================
* Name : PasswordRepositoryImpl.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-552. PasswordRepository over the dash-node REST API (CredentialsClient).
* Callbacks run on the main thread.
* ============================================================================
*/
package org.appdevforall.k2go.auth.data;

import android.os.Handler;
import android.os.Looper;

import org.appdevforall.k2go.auth.domain.PasswordRepository;
import org.appdevforall.k2go.auth.domain.PasswordState;
import org.appdevforall.k2go.util.AppExecutors;
import org.json.JSONObject;

public final class PasswordRepositoryImpl implements PasswordRepository {

private static final Handler MAIN = new Handler(Looper.getMainLooper());

private interface Call<T> { T run() throws Exception; }

private static <T> void async(Call<T> call, Callback<T> cb) {
AppExecutors.get().io().execute(() -> {
try {
T v = call.run();
MAIN.post(() -> cb.onResult(v));
} catch (Exception e) {
Failure f = failureOf(e);
MAIN.post(() -> cb.onFailure(f));
}
});
}

/** Maps the box's error answer (sockets/passwords.ts and the POST /credentials route). */
static Failure failureOf(Exception e) {
if (!(e instanceof CredentialsClient.HttpError)) return Failure.UNREACHABLE;
CredentialsClient.HttpError h = (CredentialsClient.HttpError) e;
switch (h.code) {
case "weak_password": return Failure.WEAK_PASSWORD;
case "mismatch": return Failure.MISMATCH;
case "busy": return Failure.BUSY;
default: break;
}
if (h.status == 401 || h.status == 403) return Failure.REJECTED;
if (h.status == 503) return Failure.UNREACHABLE;
return Failure.FAILED;
}

static PasswordState parseState(String service, JSONObject o) {
PasswordState.Sync sync;
switch (o.optString("state", "")) {
case "ok": sync = PasswordState.Sync.OK; break;
case "mismatch": sync = PasswordState.Sync.MISMATCH; break;
case "no_account": sync = PasswordState.Sync.NO_ACCOUNT; break;
default: sync = PasswordState.Sync.UNREACHABLE; break;
}
Boolean factory = o.isNull("factoryDefault") ? null : o.optBoolean("factoryDefault");
return new PasswordState(service, sync, factory, o.optInt("minLength", 0),
o.optBoolean("letterAndDigit", false));
}

@Override
public void status(String service, Callback<PasswordState> cb) {
async(() -> parseState(service,
CredentialsClient.request("GET", CredentialsClient.url(service) + "/status", null)), cb);
}

@Override
public void change(String service, String newPassword, Callback<Boolean> cb) {
async(() -> CredentialsClient.request("POST", CredentialsClient.url(service) + "/password",
new JSONObject().put("password", newPassword)).optBoolean("verified", false), cb);
}

@Override
public void reset(String service, Callback<Boolean> cb) {
async(() -> CredentialsClient.request("POST", CredentialsClient.url(service) + "/reset",
new JSONObject()).optBoolean("verified", false), cb);
}

@Override
public void repair(String service, String username, String password, Callback<Boolean> cb) {
async(() -> CredentialsClient.request("POST", CredentialsClient.url(service),
new JSONObject().put("username", username).put("password", password))
.optBoolean("verified", false), cb);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* ============================================================================
* Name : AuthNotice.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-552. Which notice the app shows at start. A mismatch breaks auto-login, so it
* always shows and comes first. The factory-password risk shows unless the user
* turned those reminders off.
* ============================================================================
*/
package org.appdevforall.k2go.auth.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class AuthNotice {

public enum Kind { NONE, MISMATCH, FACTORY_PASSWORD }

public final Kind kind;
/** The services the notice names, in the order given. */
public final List<String> services;

private AuthNotice(Kind kind, List<String> services) {
this.kind = kind;
this.services = Collections.unmodifiableList(services);
}

public static AuthNotice decide(List<PasswordState> states, boolean factoryRemindersOff) {
List<String> mismatch = new ArrayList<>();
List<String> factory = new ArrayList<>();
for (PasswordState s : states) {
if (s.sync == PasswordState.Sync.MISMATCH) mismatch.add(s.service);
else if (s.usesFactoryPassword()) factory.add(s.service);
}
if (!mismatch.isEmpty()) return new AuthNotice(Kind.MISMATCH, mismatch);
if (!factory.isEmpty() && !factoryRemindersOff) return new AuthNotice(Kind.FACTORY_PASSWORD, factory);
return new AuthNotice(Kind.NONE, new ArrayList<>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ============================================================================
* Name : AuthServices.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-552. The box services whose admin password K2Go manages, in display order.
* One list for Settings > Authentication and the start notice: a new service is
* added here (plus its dash-node support and its screen name).
* ============================================================================
*/
package org.appdevforall.k2go.auth.domain;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public final class AuthServices {
private AuthServices() {}

public static final List<String> ALL =
Collections.unmodifiableList(Arrays.asList("calibre", "kolibri", "forgejo"));

/** The page of the service on the box and the key of its Home probe ("/books/" for Calibre-Web). */
public static String homeEndpoint(String id) {
return "calibre".equals(id) ? "books" : id;
}

/** The product name: a proper name, the same in every language. */
public static String productName(String id) {
switch (id) {
case "calibre": return "Calibre-Web";
case "kolibri": return "Kolibri";
case "forgejo": return "Forgejo";
default: return id;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* ============================================================================
* Name : PasswordRepository.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : K2GO-552. Port to the box admin passwords (Kolibri, Calibre-Web, Forgejo). The box
* changes the password inside the service and keeps its stored copy in step.
* ============================================================================
*/
package org.appdevforall.k2go.auth.domain;

public interface PasswordRepository {

/** Why a request failed, as the box reports it. */
enum Failure { WEAK_PASSWORD, MISMATCH, BUSY, UNREACHABLE, REJECTED, FAILED }

interface Callback<T> {
void onResult(T value);
void onFailure(Failure failure);
}

void status(String service, Callback<PasswordState> cb);

/** Sets a new password. The result is TRUE when the service confirmed the new sign-in. */
void change(String service, String newPassword, Callback<Boolean> cb);

/** Puts the factory password back. The result is TRUE when the service confirmed it. */
void reset(String service, Callback<Boolean> cb);

/** Stores the password the service uses now (changed outside the app). The box checks it first. */
void repair(String service, String username, String password, Callback<Boolean> cb);
}
Loading
Loading