Class PseudoDeviceAddress
- java.lang.Object
-
- io.heraldprox.herald.sensor.datatype.PseudoDeviceAddress
-
public class PseudoDeviceAddress extends java.lang.Object
Pseudo device address to enable caching of device payload without relying on device mac address that may change frequently like the A10 and A20. Pseudo device address is by default generated from an adaptation SecureRandom. This is necessary to avoid app blocking caused by SecureRandom on idle devices with limited entropy. SecureRandom uses /dev/urandom (derived from /dev/random) as random seed source which is a shared resource that when exhausted causes disruption across the whole system beyond the app. /dev/random gathers entropy from system events such as storage activities and user actions which can easily become exhausted on idle devices. Tests have shown blocking can start within 4 to 8 hours, and time to recover increases over time, leading the app and underlying services to eventually halt. The same issue has been observed on both mobile and server hardware, hence the use of SecureRandom should be reserved for the production of strong encryption keys on rare occasions, rather than repeated use in the production of ephemeral time limited address data. Given /dev/random is easily exhausted on idle mobile devices because entropy is gathered from a specific set of events (e.g. boot up, storage, user activities) that should normally occur more frequently than encryption key generation requests. A similar approach can be taken to adapt SecureRandom to use an entropy source that is guaranteed to be non-exhaustive in this context, thus avoiding the blocking issue while achieving appropriate strength that is fit for purpose. The adaptation takes advantage of the continuous running nature of the proximity detection process where timing and detection events are highly variable due to external factors such as OS state, phones in the vicinity, Bluetooth connection time, and other system processes. The result is a reliable entropy source that is sufficiently challenging to predict for this purpose.
-
-
Constructor Summary
Constructors Constructor Description PseudoDeviceAddress()
PseudoDeviceAddress(byte[] data)
Constructs a PseudoDeviceAddress from externally generated data.PseudoDeviceAddress(long value)
Constructs a PseudoDeviceAddress from externally generated data.PseudoDeviceAddress(RandomSource randomSource)
Generates a random PseudoDeviceAddress based on the requested RandomSource
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static long
decode(byte[] data)
protected static byte[]
encode(long value)
boolean
equals(java.lang.Object o)
int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
PseudoDeviceAddress
public PseudoDeviceAddress(@NonNull RandomSource randomSource)
Generates a random PseudoDeviceAddress based on the requested RandomSource- Parameters:
randomSource
- The random source to use for PseudoDeviceAddress generation, the recommended source is NonBlockingSecureRandom
-
PseudoDeviceAddress
public PseudoDeviceAddress()
-
PseudoDeviceAddress
public PseudoDeviceAddress(@NonNull byte[] data)
Constructs a PseudoDeviceAddress from externally generated data.- Parameters:
data
- Externally generated data (either real address, or should be securely randomly generated)
-
PseudoDeviceAddress
public PseudoDeviceAddress(long value)
Constructs a PseudoDeviceAddress from externally generated data.- Parameters:
value
- Externally generated data (either real address, or should be securely randomly generated)
-
-
Method Detail
-
encode
@NonNull protected static byte[] encode(long value)
-
decode
protected static long decode(@NonNull byte[] data)
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-