open-keychain icon indicating copy to clipboard operation
open-keychain copied to clipboard

OpenKeychain will stop working on Android 14

Open M66B opened this issue 2 years ago • 6 comments

If the client (email) app is targeting SDK level 34, it is no longer possible to call a returned PendingIntent, for example to enter a password, due to this new security restriction:

https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents

Note that this was tested in practice (with FairEmail):

06-14 18:39:03.109 14262 14262 I fairemail: Executing pi=PendingIntent{4e7f9d2: android.os.BinderProxy@f4f8aa3}
06-14 18:39:03.111  1670  3958 E ActivityTaskManager: Without BAL hardening this activity start would be allowed! [callingPackage: org.sufficientlysecure.keychain; callingUid: 10264; appSwitchState: 2; callingUidHasAnyVisibleWindow: false; callingUidProcState: FOREGROUND_SERVICE; isCallingUidPersistentSystemProcess: false; balAllowedByPiSender: BackgroundStartPrivileges[allowsBackgroundActivityStarts=false, allowsBackgroundForegroundServiceStarts=true, originatingToken=null]; realCallingPackage: eu.faircode.email.debug; realCallingUid: 10296; realCallingUidHasAnyVisibleWindow: true; realCallingUidProcState: TOP; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: PendingIntentRecord{d78099f org.sufficientlysecure.keychain startActivity}; backgroundStartPrivileges: BackgroundStartPrivileges[allowsBackgroundActivityStarts=false, allowsBackgroundForegroundServiceStarts=false, originatingToken=null]; intent: Intent { cmp=org.sufficientlysecure.keychain/.remote.ui.RemotePassphraseDialogActivity (has extras) }; callerApp: null; inVisibleTask: false]
06-14 18:39:03.111  1670  3958 W ActivityTaskManager: **Background activity launch blocked** [callingPackage: org.sufficientlysecure.keychain; callingUid: 10264; appSwitchState: 2; callingUidHasAnyVisibleWindow: false; callingUidProcState: FOREGROUND_SERVICE; isCallingUidPersistentSystemProcess: false; balAllowedByPiSender: BackgroundStartPrivileges[allowsBackgroundActivityStarts=false, allowsBackgroundForegroundServiceStarts=true, originatingToken=null]; realCallingPackage: eu.faircode.email.debug; realCallingUid: 10296; realCallingUidHasAnyVisibleWindow: true; realCallingUidProcState: TOP; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: PendingIntentRecord{d78099f org.sufficientlysecure.keychain startActivity}; backgroundStartPrivileges: BackgroundStartPrivileges[allowsBackgroundActivityStarts=false, allowsBackgroundForegroundServiceStarts=false, originatingToken=null]; intent: Intent { cmp=org.sufficientlysecure.keychain/.remote.ui.RemotePassphraseDialogActivity (has extras) }; callerApp: null; inVisibleTask: false]
06-14 18:39:03.113  1670  3958 E ActivityTaskManager: Abort background activity starts from 10264

M66B avatar Jun 14 '23 17:06 M66B

Hey @M66B,

now that I've cleaned up everything for sdk34 in openkeychain, any idea about what to do here? Reading the documentation, it might be enough to set the BIND_ALLOW_ACTIVITY_STARTS flag on the activity launch, have you tried that?

I made a corresponding PR, would be great if you could check if that works for a FairMail build

Valodim avatar Feb 27 '24 10:02 Valodim

Please see here:

https://github.com/M66B/FairEmail/blob/master/app/src/main/java/eu/faircode/email/Helper.java#L1938

Meanwhile setPendingIntentBackgroundActivityLaunchAllowed was deprecated in favor of setPendingIntentBackgroundActivityStartMode.

M66B avatar Feb 27 '24 14:02 M66B

So this works now, provided clients set those options?

Valodim avatar Feb 27 '24 15:02 Valodim

Yes, it does, but ideally, OpenKeychain should set these flags when returning a PendingIntent.

M66B avatar Feb 27 '24 15:02 M66B

I would be surprised if OpenKeychain itself could set these flags. Since they lift background activity restrictions, this will have to be done by the app calling the pending intent, or not? :thinking: we could do it in the api lib, though

Valodim avatar Feb 27 '24 15:02 Valodim

I think you are right because this is a flag for startIntentSenderForResult. So, I guess this needs to be documented only.

M66B avatar Feb 27 '24 15:02 M66B