Initialize End-to-End Encryption Keys Derived from BankID Identity on First Login
On first BankID-authenticated login, the Key Management Service generates an asymmetric X25519 key pair. The private key is stored in the device's hardware-backed secure enclave via the Secure Key Store (iOS Secure Enclave / Android Keystore via Flutter Secure Storage). The public key is uploaded to Supabase and associated with the user's account, making it discoverable by coordinators when composing encrypted assignments. Key generation is derived from the BankID-verified identity to ensure key ownership is tied to legal identity. The Encryption Infrastructure provides the low-level cryptographic primitives. For coordinators, the same key pair enables them to verify recipients' public keys before encrypting assignment payloads. If the app is reinstalled or the secure storage is cleared, the Key Management Service guides the user through re-deriving their key pair via BankID re-authentication.
User Story
Acceptance Criteria
- Given the user completes BankID authentication for the first time, when the session is established, then an X25519 key pair is generated and the private key is stored in the device secure enclave without any user interaction required
- Given key generation succeeds, when the public key is uploaded to Supabase, then the user's profile record is updated with the public key and is available for lookup by coordinators
- Given the app is reinstalled and secure storage is cleared, when the user logs in with BankID again, then they are prompted to re-derive their key pair and the private key is restored to the secure enclave
- Given key generation fails due to a hardware security module error, when the login flow continues, then the user is informed that encrypted messaging is unavailable and is prompted to retry on a compatible device
- Given the key pair already exists on the device, when the user logs in again, then no new key pair is generated and the existing keys are used
- Given a user's public key exists in Supabase, when a coordinator addresses an encrypted assignment to that user, then the correct public key is retrieved and used for encryption
Business Value
Key initialization is the foundational prerequisite for all encrypted dispatch functionality. Without it, neither sending nor receiving encrypted assignments is possible. Tying key derivation to BankID identity provides a legally auditable ownership chain, meeting the authentication strength requirements for handling sensitive personal data under GDPR. Automatic initialization eliminates adoption friction for non-technical volunteer users.
Components
- Key Management Service service
- Encryption Infrastructure infrastructure
- Secure Key Store infrastructure
- Supabase Client Service service