Class SecureStorageDeviceProtection

java.lang.Object
com.codename1.security.vault.spi.DeviceProtection
com.codename1.security.vault.SecureStorageDeviceProtection

public class SecureStorageDeviceProtection extends DeviceProtection

The DeviceProtection every port gets when it does not supply one of its own: a random wrapping key in SecureStorage, and AES-GCM performed in shared code.

This is the right implementation wherever SecureStorage is the operating system's secret store -- the iOS keychain, the Android keystore, the desktop credential store. The wrapping key is bytes, and it is bytes in the one place on the device that is built to hold bytes nobody else should reach.

It is the wrong implementation in a browser, where SecureStorage is ordinary origin-private storage: the wrapping key would sit beside the ciphertext it protects, which is no protection at all. The JavaScript port therefore overrides CodenameOneImplementation.getDeviceProtection() with one built on a non-extractable CryptoKey, and this class never runs there.

Racing callers

Key creation goes through SecureStorage.setIfAbsent(String, String), which returns what the store ended up holding rather than what this call wrote. Two processes that both find nothing therefore agree on one key instead of each overwriting the other -- which matters more here than almost anywhere, because the loser's key is what a device's remembered vault was wrapped under.