public static final class Armadillo.Builder
extends java.lang.Object
ArmadilloSharedPreferences instance| Modifier and Type | Method and Description |
|---|---|
Armadillo.Builder |
addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig config)
Add new
EncryptionProtocolConfig to be added to the supported decryption-config
list. |
ArmadilloSharedPreferences |
build()
Build a
SharedPreferences instance |
Armadillo.Builder |
clearAdditionalDecryptionProtocolConfigs()
Clear additionalDecryptionConfigs list.
|
Armadillo.Builder |
compress()
Compresses the content with Gzip before encrypting and writing it to shared preference.
|
Armadillo.Builder |
compress(at.favre.lib.armadillo.Compressor compressor)
Compresses the content with given compressor before encrypting and writing it to shared preference.
|
Armadillo.Builder |
contentKeyDigest(byte[] salt)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
contentKeyDigest(int contentKeyOutLength)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
contentKeyDigest(StringMessageDigest stringMessageDigest)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
cryptoProtocolVersion(int version)
Per default the crypto/data format version is '0', but if the behavior is changed by e.g.
|
Armadillo.Builder |
dataObfuscatorFactory(DataObfuscator.Factory dataObfuscatorFactory)
Set your own data obfuscation implementation.
|
Armadillo.Builder |
enableDerivedPasswordCache(boolean enable)
Per default every put and get operation, when using a user provided password, requires the
full expensive key derivation function (KDF) to derive the key.
|
Armadillo.Builder |
enableKitKatSupport(boolean enable)
Manually enable kitkatSupport.
|
Armadillo.Builder |
encryptionFingerprint(byte[] fingerprint)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context,
byte[] additionalData)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context,
java.lang.String... additionalData)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(EncryptionFingerprint fingerprint)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionKeyStrength(int keyStrength)
Set the key length for the symmetric encryption.
|
Armadillo.Builder |
keyStretchingFunction(KeyStretchingFunction keyStretchingFunction)
Set a different key derivation function for provided password.
|
Armadillo.Builder |
password(char[] password)
Provide a user password used for encrypting all of values of the
SharedPreferences. |
Armadillo.Builder |
recoveryPolicy(boolean throwRuntimeException,
boolean removeBrokenContent)
The recovery policy defines how to behave when a value cannot be decrypted.
|
Armadillo.Builder |
recoveryPolicy(RecoveryPolicy recoveryPolicy)
The recovery policy defines how to behave when a value cannot be decrypted.
|
Armadillo.Builder |
secureRandom(java.security.SecureRandom secureRandom)
Provide your own
SecureRandom implementation. |
Armadillo.Builder |
securityProvider(java.security.Provider provider)
Set the security provider for most cryptographic primitives (symmetric encryption,
pbkdf2, ...).
|
Armadillo.Builder |
supportVerifyPassword(boolean supported)
Enabling support verify password allows you to use
ArmadilloSharedPreferences.isValidPassword()
to verify the validity of the user-provided password used to initialise Armadillo. |
Armadillo.Builder |
symmetricEncryption(AuthenticatedEncryption authenticatedEncryption)
Set your own implementation of
AuthenticatedEncryption. |
public Armadillo.Builder encryptionFingerprint(android.content.Context context)
Set the default fingerprint using sources explained in EncryptionFingerprintFactory.
context - used to gather sources from the Android OSpublic Armadillo.Builder encryptionFingerprint(android.content.Context context, byte[] additionalData)
Set the default fingerprint using sources explained in {@link EncryptionFingerprintFactory with addtional custom data. Setting this is highly recommended as it makes it more difficult for an attacker calculate the key the more random the input is.
See the README.md for explainating on what to use as additionalData.
context - used to gather sources from the Android OSadditionalData - provided additional custom datapublic Armadillo.Builder encryptionFingerprint(android.content.Context context, java.lang.String... additionalData)
Set the default fingerprint using sources explained in EncryptionFingerprintFactory with addtional custom data. Setting this is highly recommended as it makes it more difficult for an attacker calculate the key the more random the input is.
This is the same as {@link #encryptionFingerprint(Context, byte[])} but accepts strings instead of a byte array.
See the README.md for explainating on what to use as additionalData.
context - used to gather sources from the Android OSadditionalData - provided additional custom datapublic Armadillo.Builder encryptionFingerprint(EncryptionFingerprint fingerprint)
Provide a fully custom fingerprint implementation (or instance). Use this if you don't agree with the default implementation.
fingerprint - fully custom instancepublic Armadillo.Builder encryptionFingerprint(byte[] fingerprint)
Provide a fully custom fingerprint byte array. Use this if you don't agree with the default implementation.
fingerprint - fully custom byte array containing the fingerprintpublic Armadillo.Builder contentKeyDigest(byte[] salt)
This method will alter the salt used for that hash. Setting this is highly recommended, since
it will change the default hashes of the key (so that somebody else's "name" key, won't
hash to the exact same output). Recommended value: use the AndroidID, as it will be different
on every app install from SDK 26+. See Settings.Secure#ANDROID_ID.
Note that changing the salt will make old data inaccessible, since the key won't match anymore.
salt - to be used for content key hash (should be > 16 byte)public Armadillo.Builder contentKeyDigest(int contentKeyOutLength)
This is a more advanced setting. Per default a hash will be Armadillo.CONTENT_KEY_OUT_BYTE_LENGTH
bytes long. If you think that is too long (wasting space) or too small (not enough entropy)
modify the length with this config.
contentKeyOutLength - to be used for content key hashpublic Armadillo.Builder contentKeyDigest(StringMessageDigest stringMessageDigest)
Use this to set a fully custom implementation of the digest.
stringMessageDigest - custom implementationpublic Armadillo.Builder encryptionKeyStrength(int keyStrength)
Currently there are 2 options:
Note: Usually there is no real advantage to set it to VERY HIGH as HIGH (128 bit key length) is fully secure for the foreseeable future. VERY HIGH only adds more security margin for possible quantum computer attacks (but if you are a user which is threatened by these kinds of attacks you probably require higher degrees af protection).
keyStrength - HIGH (default) or VERY HIGHpublic Armadillo.Builder securityProvider(java.security.Provider provider)
provider - JCA providerpublic Armadillo.Builder symmetricEncryption(AuthenticatedEncryption authenticatedEncryption)
AuthenticatedEncryption. Use this if setting
the security provider with securityProvider(Provider) is not enough
customization. With this a any symmetric encryption algorithm might be used.
authenticatedEncryption - to be used by the shared preferencespublic Armadillo.Builder keyStretchingFunction(KeyStretchingFunction keyStretchingFunction)
ArmadilloBcryptKeyStretcher
is used. There is also a implementation PBKDF2 (see PBKDF2KeyStretcher. If you want
to use a different function (e.g. scrypt) set the implementation here.
If you want to disable the key stretching feature you might use FastKeyStretcher here.
keyStretchingFunction - to be used by the shared preferencespublic Armadillo.Builder dataObfuscatorFactory(DataObfuscator.Factory dataObfuscatorFactory)
HkdfXorObfuscator for the default obfuscation technique.
dataObfuscatorFactory - that creates a obfuscator with given keypublic Armadillo.Builder secureRandom(java.security.SecureRandom secureRandom)
SecureRandom implementation.
Per default a no-provider constructor is used for SecureRandom which
is the currently recommended way (https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/)
secureRandom - implementationpublic Armadillo.Builder recoveryPolicy(boolean throwRuntimeException, boolean removeBrokenContent)
throwRuntimeException - if a exception will be thrown (out of the '.get*()' method)removeBrokenContent - if the content should be automatically be removedpublic Armadillo.Builder recoveryPolicy(RecoveryPolicy recoveryPolicy)
recoveryPolicy - a custom implementationpublic Armadillo.Builder password(char[] password)
SharedPreferences.
The password is treated as weak and is therefore subject to be stretched by the provided key
derivation function with key stretching property (see keyStretchingFunction(KeyStretchingFunction).
A side-effect is that putting or reading content is expensive and should not be done on the main thread.
A null password or zero length password will be treated as if no user-provided password was set.
If you want to be able to verify the password, set supportVerifyPassword(boolean)
to true and use ArmadilloSharedPreferences.isValidPassword() to verify.
By default, support verify password is disabled.
password - provided by userpublic Armadillo.Builder supportVerifyPassword(boolean supported)
ArmadilloSharedPreferences.isValidPassword()
to verify the validity of the user-provided password used to initialise Armadillo.
In order to verify the password, a known value is stored encrypted with the password the
first time that Armadillo is initialised. When ArmadilloSharedPreferences.isValidPassword()
is called, it tries to decrypt this value and compares it to the original value. If the values
match the validation succeeds, otherwise, it fails.
By default, support verify password is disabled.supported - true to supported password verification, false otherwisepublic Armadillo.Builder cryptoProtocolVersion(int version)
The protocol version will be used as additional associated data with the authenticated encryption.
version - to persist with the datapublic Armadillo.Builder enableDerivedPasswordCache(boolean enable)
To make get* calls faster, you can enable this cache, which caches the derived password. This will not speed up put* operations since every time a new salt will be created making it impossible to cache. The disadvantage is that the derived password stays in cache , therefor in memory for way longer, making it easier to read when the device is used with instrumentation tool like FRIDA (this is a more specific attack, since when the attacker has full access to the device, there is not much you can do).
Summary
See DerivedPasswordCache for details of the implementation.
enable - cachingpublic Armadillo.Builder compress()
public Armadillo.Builder compress(at.favre.lib.armadillo.Compressor compressor)
compressor - to setpublic Armadillo.Builder addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig config)
EncryptionProtocolConfig to be added to the supported decryption-config
list. That means, if you have encrypted data with an older encryption config you may add
it here to be able to decrypt it again. These configs are however never
used for encryption.
To match configs EncryptionProtocolConfig.protocolVersion is used, therefore if
you add a config here it must match the persisted protocolVersion (Armadillo default is
Armadillo.DEFAULT_PROTOCOL_VERSION)
This may be used for migration of encryption protocols.
config - to be added to the listpublic Armadillo.Builder clearAdditionalDecryptionProtocolConfigs()
addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig).public Armadillo.Builder enableKitKatSupport(boolean enable)
AesCbcEncryption) which uses CBC + Encrypt-then-mac which should have
a similar security strength.
The backwards compatible implementation will only be used if
Build.VERSION#SDK_INT is lower or equal to 19, the default version otherwise.
Additionally this implementation will be added to the additionalDecryptionConfigs so you
can still decrypt the old content after upgrading to lollipop and above (uses protocol-version
Armadillo.KITKAT_PROTOCOL_VERSION to mark.
enable - kitkat supportpublic ArmadilloSharedPreferences build()
SharedPreferences instance