Class FlashStorage
- java.lang.Object
-
- com.intel.util.FlashStorage
-
public class FlashStorage extends java.lang.Object
This class exposes flash storage access APIs for the applets.
In general, using flash for applets data storage is not recommended since the flash space available for applets is very limited. In addition, by default applets are not granted flash storage access permissions, unless explicitly specified in the permissions section of the applet installation package. The applet data is stored in flash as an encrypted BLOB with integrity protection. Each applet can only access its own flash data. However, different sessions of the same applet are sharing flash resources and access the exact same files. Currently, only one flash data file per applet is supported. Due to flash wear-out considerations, an applet is allowed to use up to 100 write/erase flash data operations per machine boot. In addition, the applet allowed operations counter will be reset again 24 hours after the applet was installed and every 24 hours since the last write/erase operation.
Instead of using flash storage, applets should use offline data storage (for example, hard disk) for saving their non-volatile data.
File Properties
Default values for non-existing file are:
-
-
Field Summary
Fields Modifier and Type Field and Description static int
FLASH_STORAGE_PROPERTY_ANTI_REPLAY
If property is set to true, the files are stored with anti-replay protection.
-
Method Summary
Methods Modifier and Type Method and Description static void
eraseFlashData(int fileName)
Removes the specified applet file from the flash. Note: after erasing the file all file properties are restored to defaultstatic int
getFlashDataSize(int fileName)
Returns the size of the specified applet file on the flash.static int
getMaxFileName()
Returns the maximum file name value that can be used in this class.static boolean
getProperty(int fileName, int propertyId)
Returns the value of a specific algorithm property for a given filestatic int
readFlashData(int fileName, byte[] dest, int destOff)
Reads the data from the specified applet file in flash and copies it into the given destination array.static void
setProperty(int fileName, int propertyId, boolean state)
Sets a property that modifies the algorithm behavior for a given file Notes: Properties can only be modified on non existing files. Properties are saved only after creating a file usingwriteFlashData(int, byte[], int, int)
static void
writeFlashData(int fileName, byte[] src, int srcOff, int srcLen)
Writes the provided data into the specified applet file in the flash.
-
-
-
Field Detail
-
FLASH_STORAGE_PROPERTY_ANTI_REPLAY
public static final int FLASH_STORAGE_PROPERTY_ANTI_REPLAY
If property is set to true, the files are stored with anti-replay protection. Default is false. Note that this resource is limited and setting this property might fail if more than a given amount of anti-replay files are already being used- See Also:
- Constant Field Values
-
-
Method Detail
-
getFlashDataSize
public static int getFlashDataSize(int fileName) throws UtilException
Returns the size of the specified applet file on the flash.- Parameters:
fileName
- the index of the file.getMaxFileName()
indicates the maximum file number value (including) that can be used.- Returns:
- The size of the applet file in flash. For invalid/non existent files, the returned size will be 0.
- Throws:
IllegalParameterException
- if the file's index is invalid.UtilSecurityException
- if the file was identified as compromised.UtilException
- some internal error occurred.
-
readFlashData
public static int readFlashData(int fileName, byte[] dest, int destOff) throws UtilException
Reads the data from the specified applet file in flash and copies it into the given destination array.- Parameters:
fileName
- the index of the file to read.getMaxFileName()
indicates the maximum file number value (including) that can be used.dest
- the destination array to hold the file datadestOff
- the offset in dest array- Returns:
- The number of bytes copied into dest array.
- Throws:
FileNotFoundException
- if the file doesn't exist.IllegalParameterException
- if the file's index is invalid.UtilSecurityException
- if the file was identified as compromised.UtilException
- some internal error occurred.
-
writeFlashData
public static void writeFlashData(int fileName, byte[] src, int srcOff, int srcLen) throws UtilException
Writes the provided data into the specified applet file in the flash.- Parameters:
fileName
- the index of the file to write.getMaxFileName()
indicates the maximum file number value (including) that can be used.src
- an array holding the data to be copied into the filesrcOff
- the offset in src arraysrcLen
- the length of the data to write- Throws:
AccessDeniedException
- if the size of the new data along with any other flash data already allocated for this applet exceeds the applet flash quota.FlashWearoutException
- if the flash wearout mechanism blocked the write/erase, or if the applet exhausted the number of operations allowed for the current period.UtilOutOfResourcesException
- if a property was set to a state that causes resources exhaustion (e.g. setting the propertyFLASH_STORAGE_PROPERTY_ANTI_REPLAY
to true can cause the exception after reaching max of resources}) of not enough flash storage leftIllegalParameterException
- if the file's index is invalid.UtilSecurityException
- if the file was identified as compromised.UtilException
- in case of internal error.
-
eraseFlashData
public static void eraseFlashData(int fileName) throws UtilException
Removes the specified applet file from the flash. Note: after erasing the file all file properties are restored to default- Parameters:
fileName
- the index of the file to remove.getMaxFileName()
indicates the maximum file number value (including) that can be used.- Throws:
FlashWearoutException
- if the flash wearout mechanism blocked the write/erase, or if the applet exhausted the number of operations allowed for the current period.IllegalParameterException
- if the file's index is invalid.FileNotFoundException
- if the file doesn't exist.UtilSecurityException
- if the file was identified as compromised.UtilException
- in case of internal error.
-
setProperty
public static void setProperty(int fileName, int propertyId, boolean state) throws UtilException
Sets a property that modifies the algorithm behavior for a given file Notes:- Properties can only be modified on non existing files.
- Properties are saved only after creating a file using
writeFlashData(int, byte[], int, int)
- Parameters:
fileName
- the index of the file.getMaxFileName()
indicates the maximum file number value (including) that can be used.propertyId
- the property to be set, one of FLASH_STORAGE_PROPERTY_XYZstate
- determines whether the property is enabled or disabled- Throws:
IllegalParameterException
- if one of the following occurs:- the file's index is invalid
- propertyId is unknown
IllegalUseException
- if the fileName already exists and was saved with a different property stateUtilSecurityException
- if the file was identified as compromised.UtilException
- for any other error
-
getProperty
public static boolean getProperty(int fileName, int propertyId) throws UtilException
Returns the value of a specific algorithm property for a given file- Parameters:
fileName
- the index of the file.getMaxFileName()
indicates the maximum file number value (including) that can be used.propertyId
- the property to get, one of FLASH_STORAGE_PROPERTY_XYZ- Returns:
- Returns whether a specific property is disabled or enabled
- Throws:
IllegalParameterException
- if one of the following occurs:- the file's index is invalid
- propertyId is unknown
UtilSecurityException
- if the file was identified as compromised.UtilException
- for any other error
-
getMaxFileName
public static int getMaxFileName()
Returns the maximum file name value that can be used in this class.- Returns:
- The maximum file name value that can be used in this class.
-
-