TrueZIP 6.8.2

de.schlichtherle.crypto.io.raes
Class RaesReadOnlyFile

java.lang.Object
  extended by de.schlichtherle.io.rof.AbstractReadOnlyFile
      extended by de.schlichtherle.io.rof.FilterReadOnlyFile
          extended by de.schlichtherle.crypto.io.CipherReadOnlyFile
              extended by de.schlichtherle.crypto.io.raes.RaesReadOnlyFile
All Implemented Interfaces:
ReadOnlyFile
Direct Known Subclasses:
Type0RaesReadOnlyFile

public abstract class RaesReadOnlyFile
extends CipherReadOnlyFile

This class implements a ReadOnlyFile in order to provide transparent random read only access to the plain text data which has been encrypted and stored in a file according to the Random Access Encryption Specification (RAES).

To accomodate the transparent random read access feature, RAES specifies a multistep authentication process:

The first step is mandatory and implemented in the constructor of the concrete implementation of this abstract class. For this step only the cipher key and the file length is authenticated, which is fast to process (O(1)).

The second step is optional and must be initiated by the client by calling authenticate(). For this step the entire cipher text is authenticated, which is comparably slow (O(n)). Please note that this step does not require the cipher text to be decrypted first, which features comparably fast processing.

So it is up to the application which level of security it needs to provide: Most applications should always call authenticate() in order to guard against integrity attacks. However, some applications may provide additional (faster) methods for authentication of the pay load, in which case the authentication provided by this class may be safely skipped.

Note that this class implements its own virtual file pointer. Thus, if you would like to access the underlying ReadOnlyFile again after you have finished working with an instance of this class, you should synchronize their file pointers using the pattern as described in the base class FilterReadOnlyFile.

Since:
TrueZIP 6.0
Version:
$Id: RaesReadOnlyFile.java 06f3ba684701 2010/11/04 01:15:55 christian $
Author:
Christian Schlichtherle
See Also:
RaesOutputStream

Field Summary
 
Fields inherited from class de.schlichtherle.io.rof.FilterReadOnlyFile
rof
 
Constructor Summary
RaesReadOnlyFile(ReadOnlyFile rof)
           
 
Method Summary
abstract  void authenticate()
          Authenticates all encrypted data in the read only file.
private static RaesParameters findParameters(Class type, RaesParameters parameters)
           
static RaesReadOnlyFile getInstance(File file, RaesParameters parameters)
          Creates a new instance of RaesReadOnlyFile.
static RaesReadOnlyFile getInstance(ReadOnlyFile rof, RaesParameters parameters)
          Creates a new instance of RaesReadOnlyFile.
abstract  int getKeySizeBits()
          Returns the key size in bits which is actually used to decrypt the data of this RAES file.
(package private) static short readUByte(byte[] b, int off)
           
(package private) static long readUInt(byte[] b, int off)
           
(package private) static int readUShort(byte[] b, int off)
           
 
Methods inherited from class de.schlichtherle.crypto.io.CipherReadOnlyFile
close, computeMac, getFilePointer, init, length, read, read, seek
 
Methods inherited from class de.schlichtherle.io.rof.AbstractReadOnlyFile
read, readFully, readFully, skipBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RaesReadOnlyFile

RaesReadOnlyFile(ReadOnlyFile rof)
Method Detail

readUByte

static short readUByte(byte[] b,
                       int off)

readUShort

static int readUShort(byte[] b,
                      int off)

readUInt

static long readUInt(byte[] b,
                     int off)

getInstance

public static RaesReadOnlyFile getInstance(File file,
                                           RaesParameters parameters)
                                    throws FileNotFoundException,
                                           RaesParametersException,
                                           RaesException,
                                           IOException
Creates a new instance of RaesReadOnlyFile.

Parameters:
file - The file to read.
parameters - The RaesParameters required to access the RAES type actually found in the file. If the run time class of this parameter does not match the required parameter interface according to the RAES type found in the file, but is an instance of the RaesParametersAgent interface, it is used to find the required RAES parameters. This is applied recursively.
Throws:
NullPointerException - If any of the parameters is null.
FileNotFoundException - If the file cannot get opened for reading.
RaesParametersException - If no suitable RAES parameters have been provided or something is wrong with the parameters.
RaesException - If the file is not RAES compatible.
IOException - On any other I/O related issue.

getInstance

public static RaesReadOnlyFile getInstance(ReadOnlyFile rof,
                                           RaesParameters parameters)
                                    throws FileNotFoundException,
                                           RaesParametersException,
                                           RaesException,
                                           IOException
Creates a new instance of RaesReadOnlyFile.

Parameters:
rof - The read only file to read.
parameters - The RaesParameters required to access the RAES type actually found in the file. If the run time class of this parameter does not match the required parameter interface according to the RAES type found in the file, but is an instance of the RaesParametersAgent interface, it is used to find the required RAES parameters. This is applied recursively.
Throws:
NullPointerException - If any of the parameters is null.
FileNotFoundException - If the file cannot get opened for reading.
RaesParametersException - If no suitable RAES parameters have been provided or something is wrong with the parameters.
RaesException - If the file is not RAES compatible.
IOException - On any other I/O related issue.

findParameters

private static RaesParameters findParameters(Class type,
                                             RaesParameters parameters)
                                      throws RaesParametersException
Throws:
RaesParametersException

getKeySizeBits

public abstract int getKeySizeBits()
Returns the key size in bits which is actually used to decrypt the data of this RAES file.


authenticate

public abstract void authenticate()
                           throws RaesAuthenticationException,
                                  IOException
Authenticates all encrypted data in the read only file. It is safe to call this method multiple times to detect if the file has been tampered with meanwhile.

This is the second, optional step of authentication. The first, mandatory step is to computeMac the cipher key and cipher text length only and has already been successfully completed in the constructor.

Throws:
RaesAuthenticationException - If the computed MAC does not match the MAC declared in the RAES file.
IOException - On any I/O related issue.

TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.