fix: add missing awaits when changing client certificate (#20189)

I ran into this while testing out
<https://github.com/immich-app/immich/pull/19830>. When I add, change,
or remove a client certificate under Immich's advanced settings, the
change wouldn't take effect until some mysterious point in the future.
For example:

1. Add a client certificate. It doesn't get used.
2. Remove certificate. *Now* the client certificate from step 1) is used.
3. Restart application. Now no client certificate is used.

This all boils down to some missing `await`s. The user would change the
cert, and we'd start asynchronously saving it to the store, and while
the save is still happening, [`HttpSSLOptions` pulls the "old" value out of
`SSLClientCertStoreVal`](https://github.com/immich-app/immich/blob/v1.136.0/mobile/lib/utils/http_ssl_options.dart#L30).

With the appropriate `await`s, this behaves much more sanely.
This commit is contained in:
Jeremy Fleischman 2025-07-24 22:28:33 -07:00 committed by GitHub
parent b4780e89af
commit de67d22bc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View File

@ -13,11 +13,11 @@ class SSLClientCertStoreVal {
const SSLClientCertStoreVal(this.data, this.password); const SSLClientCertStoreVal(this.data, this.password);
void save() { Future<void> save() async {
final b64Str = base64Encode(data); final b64Str = base64Encode(data);
Store.put(StoreKey.sslClientCertData, b64Str); await Store.put(StoreKey.sslClientCertData, b64Str);
if (password != null) { if (password != null) {
Store.put(StoreKey.sslClientPasswd, password!); await Store.put(StoreKey.sslClientPasswd, password!);
} }
} }
@ -31,8 +31,8 @@ class SSLClientCertStoreVal {
return SSLClientCertStoreVal(certData, passwd); return SSLClientCertStoreVal(certData, passwd);
} }
static void delete() { static Future<void> delete() async {
Store.delete(StoreKey.sslClientCertData); await Store.delete(StoreKey.sslClientCertData);
Store.delete(StoreKey.sslClientPasswd); await Store.delete(StoreKey.sslClientPasswd);
} }
} }

View File

@ -61,7 +61,7 @@ class _SslClientCertSettingsState extends State<SslClientCertSettings> {
width: 15, width: 15,
), ),
ElevatedButton( ElevatedButton(
onPressed: widget.isLoggedIn || !isCertExist ? null : () => removeCert(context), onPressed: widget.isLoggedIn || !isCertExist ? null : () async => await removeCert(context),
child: Text("remove".tr()), child: Text("remove".tr()),
), ),
], ],
@ -86,7 +86,11 @@ class _SslClientCertSettingsState extends State<SslClientCertSettings> {
); );
} }
void storeCert(BuildContext context, Uint8List data, String? password) { Future<void> storeCert(
BuildContext context,
Uint8List data,
String? password,
) async {
if (password != null && password.isEmpty) { if (password != null && password.isEmpty) {
password = null; password = null;
} }
@ -100,7 +104,7 @@ class _SslClientCertSettingsState extends State<SslClientCertSettings> {
showMessage(context, "client_cert_invalid_msg".tr()); showMessage(context, "client_cert_invalid_msg".tr());
return; return;
} }
cert.save(); await cert.save();
HttpSSLOptions.apply(); HttpSSLOptions.apply();
setState( setState(
() => isCertExist = true, () => isCertExist = true,
@ -124,7 +128,7 @@ class _SslClientCertSettingsState extends State<SslClientCertSettings> {
), ),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => {ctx.pop(), storeCert(context, data, password.text)}, onPressed: () async => {ctx.pop(), await storeCert(context, data, password.text)},
child: Text("client_cert_dialog_msg_confirm".tr()), child: Text("client_cert_dialog_msg_confirm".tr()),
), ),
], ],
@ -147,8 +151,8 @@ class _SslClientCertSettingsState extends State<SslClientCertSettings> {
} }
} }
void removeCert(BuildContext context) { Future<void> removeCert(BuildContext context) async {
SSLClientCertStoreVal.delete(); await SSLClientCertStoreVal.delete();
HttpSSLOptions.apply(); HttpSSLOptions.apply();
setState( setState(
() => isCertExist = false, () => isCertExist = false,