27 lines
1.2 KiB
Dart
27 lines
1.2 KiB
Dart
|
|
import "package:smol_mail/smol/proto.dart";
|
||
|
|
import "package:smol_mail/smol/errors.dart";
|
||
|
|
import "package:smol_mail/smol/store.dart";
|
||
|
|
|
||
|
|
// Deploy-time configuration, empty by default (mirrors gsmol's config.js).
|
||
|
|
// A release may bake in a server key with:
|
||
|
|
// flutter build apk --dart-define=SMOL_PRESET_SERVER=example.org \
|
||
|
|
// --dart-define=SMOL_PRESET_SERVER_KEY=base32key
|
||
|
|
// It only makes sense when whoever ships this app and whoever runs that
|
||
|
|
// smolmaild are the same trusted party: the value arrives with the app
|
||
|
|
// itself, which is the trusted channel SPEC.md §4 asks a pin to come from.
|
||
|
|
// This only seeds the first run — once written it is an ordinary pin,
|
||
|
|
// removable in settings like any other, and never overwrites a host the user
|
||
|
|
// (or a previous install) already pinned.
|
||
|
|
const _presetHost = String.fromEnvironment("SMOL_PRESET_SERVER");
|
||
|
|
const _presetKey = String.fromEnvironment("SMOL_PRESET_SERVER_KEY");
|
||
|
|
|
||
|
|
void applyPresetServer(SmolStore store) {
|
||
|
|
if (_presetHost.isEmpty || _presetKey.isEmpty) return;
|
||
|
|
if (store.serverPin(_presetHost) != null) return;
|
||
|
|
try {
|
||
|
|
store.pinServer(_presetHost, b32decode(_presetKey));
|
||
|
|
} on SmolError {
|
||
|
|
// malformed preset: leave unpinned rather than block boot
|
||
|
|
}
|
||
|
|
}
|