issrg.SAWS
Class LogFileReader

java.lang.Object
  extended by issrg.SAWS.LogFileReader

public class LogFileReader
extends java.lang.Object

This is the log file reading class

Version:
0.1, Oct. 2005
Author:
W. Xu

Constructor Summary
LogFileReader(int debugLevel)
          This method is the constructor of LogFileReader.
LogFileReader(int debugLevel, byte userID)
           
LogFileReader(int debugLevel, byte userID, javax.security.auth.callback.CallbackHandler ch)
           
LogFileReader(int debugLevel, javax.security.auth.callback.CallbackHandler ch)
           
 
Method Summary
 byte[] ADecryptRecordBodyByPrivateKey(byte[] body, java.security.PrivateKey privateKey)
          This method is to asymmetric-decrypt a Record block
 int checkLogFile()
           
 int checkLogFile(byte[] secureRandomBytes)
          This method is for checking a log file.
 int checkSignature(java.security.PublicKey sawsCAPublicKey)
          This method is to verify the signature of the log file
 java.lang.String findPreviousLogfileName(byte[] secureRandomBytes)
          This method is to find the previous log file name stored in this log file.
 byte[] getAccumulatedHash(java.io.File CurrentLogFile)
          This method is to read the AccumulatedHash (byte[]) from the log file
 java.lang.String getAccumulatedHashAlgorithm(java.io.File CurrentLogFile)
          This method is to read the hash algorithm from the log file
 byte[] getAccumulatedHashByCalc()
          This method is to return accumulated hash got by calculation during verification.
 byte[] getAccumulatedHashFromLog()
          This method is to return accumulated hash stored in the log file
 java.lang.String getAllCheckingResult()
           
 java.security.cert.Certificate getCert(java.io.File CurrentLogFile)
          This method is to return the SAWS certificate stored in the log file.
 java.security.cert.Certificate getCertFromLog()
          This method is to return the certificate in the log file
 int getCurrentSN()
          This method is to return the current SN
 byte getEncryptionFlagFromRecordHeader(byte[] recordHeader)
          This method is to get encryption flag from a Record header.
 byte[] getHeaderSignature(java.io.File CurrentLogFile)
          This method is to read the signature of the log file's header (byte[]) from the log file.
 int getLastRecordLengthFromRecordHeader(byte[] recordHeader)
          This method is to get LastRecordLength from a Record header.
 byte[] getLogFileSignature(java.io.File CurrentLogFile)
          This method is to read the signature of the complete log (byte[]) from the log file
 LogRecordInfo getOneRecordInfoFromRAF(java.io.RandomAccessFile raf1, byte[] secureRandomBytes)
          This method is to read one complete log record from a RAF.
 java.lang.String getPreviousLogfileName()
           
 java.util.Vector getRecordBlockList()
           
 byte getRecordTypeFromRecordHeader(byte[] recordHeader)
          This method is to get record type from a Record header.
 byte[] getSecureRandomNumber(java.security.PrivateKey privateKey)
          This method is to read the secure random number from the log file with the given private key.
 byte[] getSignatureFromLog()
          This method is to return signature from the log file
 java.lang.String getSigningAlgorithm(java.io.File CurrentLogFile)
          This method is to read the signing algorithm from the log file.
 java.lang.String getSigningAlgorithmFromLog()
          This method returns the signing algorithm from the log file.
 int getSNFromRecordHeader(byte[] recordHeader)
          This method is to get SN from a Record header.
 javax.crypto.SecretKey getSymmetricKey()
           
 byte[] getSymmetricKey(java.io.File CurrentLogFile, java.security.PrivateKey privateKey)
          This method is to read the symmetric key (byte[]) from the log file with the given private key.
 int getThisRecordLengthFromRecordHeader(byte[] recordHeader)
          This method is to get this record length from a Record header.
 long getTimestampFromRecordHeader(byte[] recordHeader)
          This method is to get timestamp from a Record header.
 byte getUserIDFromRecordHeader(byte[] recordHeader)
          This method is to get the user ID from a Record header.
 java.lang.String getXMLClientLogData(byte[] secureRandomBytes)
           
 java.lang.String readOneRecordFromRAF(java.io.RandomAccessFile raf1)
          This method is to read one complete log record from a RAF.
 java.lang.String readOneRecordFromRAF(java.io.RandomAccessFile raf1, byte[] secureRandomBytes)
          This method is to read one complete log record from a RAF.
 byte[] readRecordBodyFromRAF(java.io.RandomAccessFile raf, int offset, int len)
          This method is to read a Record block (only body): log message .
 byte[] readRecordHashFromRAF(java.io.RandomAccessFile raf)
          This method is to read a Record Hash: 20 bytes
 byte[] readRecordHeaderFromRAF(java.io.RandomAccessFile raf1)
          This method is to read a Record header from a random access file.
 void resetAccMD()
          This method is to reset the MessageDigest for accumulated hash computation.
 byte[] SDecryptRecordBody(byte[] body)
          This method is to symmetric-decrypt a Record block: log message .
 void setCallbackHandler(javax.security.auth.callback.CallbackHandler ch)
          Method that sets the callback handler for the class.
 void setLogFilename(java.lang.String logRoot, java.lang.String logFilename)
          This method is to initialise the MessageDigest for accumulated hash computation.
 void setSAWSPrivateKey(java.security.PrivateKey pk)
          This method is to set saws private key.
 void setUserPrivateKey(java.security.PrivateKey pk)
          This method is to set VT private key.
 void shiftRAFPointer(java.io.RandomAccessFile raf, int offset)
          This method is to move the RAF pointer by a distance of len
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogFileReader

public LogFileReader(int debugLevel)
This method is the constructor of LogFileReader.


LogFileReader

public LogFileReader(int debugLevel,
                     byte userID)

LogFileReader

public LogFileReader(int debugLevel,
                     javax.security.auth.callback.CallbackHandler ch)

LogFileReader

public LogFileReader(int debugLevel,
                     byte userID,
                     javax.security.auth.callback.CallbackHandler ch)
Method Detail

getRecordBlockList

public java.util.Vector getRecordBlockList()

getAllCheckingResult

public java.lang.String getAllCheckingResult()

getPreviousLogfileName

public java.lang.String getPreviousLogfileName()

setCallbackHandler

public void setCallbackHandler(javax.security.auth.callback.CallbackHandler ch)
Method that sets the callback handler for the class. If the handler is null, the class will keep using the default callback handler.

Parameters:
ch - The callback handler.

setLogFilename

public void setLogFilename(java.lang.String logRoot,
                           java.lang.String logFilename)
                    throws logReadingException
This method is to initialise the MessageDigest for accumulated hash computation.

Parameters:
null -
Throws:
logReadingException

resetAccMD

public void resetAccMD()
This method is to reset the MessageDigest for accumulated hash computation.


ADecryptRecordBodyByPrivateKey

public byte[] ADecryptRecordBodyByPrivateKey(byte[] body,
                                             java.security.PrivateKey privateKey)
                                      throws logReadingException
This method is to asymmetric-decrypt a Record block

Parameters:
body - is the log record block
privateKey - is the private key
Returns:
decrypted byte []
Throws:
logReadingException

SDecryptRecordBody

public byte[] SDecryptRecordBody(byte[] body)
This method is to symmetric-decrypt a Record block: log message . sawsSecretKeyFromLog is used within this method.

Parameters:
body - is the encrypted log record block with the symmetric key
Returns:
decrypted byte []

readRecordBodyFromRAF

public byte[] readRecordBodyFromRAF(java.io.RandomAccessFile raf,
                                    int offset,
                                    int len)
                             throws logReadingException
This method is to read a Record block (only body): log message .

Parameters:
raf - is the random access file to be read
offset - is offset
len - is the length to be read
Returns:
bytes of the record body.
Throws:
logReadingException

shiftRAFPointer

public void shiftRAFPointer(java.io.RandomAccessFile raf,
                            int offset)
This method is to move the RAF pointer by a distance of len

Parameters:
raf - is the RAF file
offset - is the offset

readRecordHashFromRAF

public byte[] readRecordHashFromRAF(java.io.RandomAccessFile raf)
                             throws logReadingException
This method is to read a Record Hash: 20 bytes

Parameters:
raf - is the random access file
Returns:
bytes of the record hash (20 bytes).
Throws:
logReadingException

getSNFromRecordHeader

public int getSNFromRecordHeader(byte[] recordHeader)
This method is to get SN from a Record header.

Parameters:
recordHeader - record header
Returns:
byte SN of the record header.

getRecordTypeFromRecordHeader

public byte getRecordTypeFromRecordHeader(byte[] recordHeader)
This method is to get record type from a Record header.

Parameters:
recordHeader - record header
Returns:
byte of the record type.

getUserIDFromRecordHeader

public byte getUserIDFromRecordHeader(byte[] recordHeader)
This method is to get the user ID from a Record header.

Parameters:
recordHeader - record header
Returns:
byte of the user id.

getEncryptionFlagFromRecordHeader

public byte getEncryptionFlagFromRecordHeader(byte[] recordHeader)
This method is to get encryption flag from a Record header.

Parameters:
recordHeader - record header
Returns:
byte of the encryption flag

getTimestampFromRecordHeader

public long getTimestampFromRecordHeader(byte[] recordHeader)
This method is to get timestamp from a Record header.

Parameters:
recordHeader - record header
Returns:
bytes of the timestamp (8 bytes)

getLastRecordLengthFromRecordHeader

public int getLastRecordLengthFromRecordHeader(byte[] recordHeader)
This method is to get LastRecordLength from a Record header.

Parameters:
recordHeader - record header
Returns:
length of the LastRecordLength

getThisRecordLengthFromRecordHeader

public int getThisRecordLengthFromRecordHeader(byte[] recordHeader)
This method is to get this record length from a Record header.

Parameters:
recordHeader - record header
Returns:
length of this record

readOneRecordFromRAF

public java.lang.String readOneRecordFromRAF(java.io.RandomAccessFile raf1)
                                      throws logReadingException
This method is to read one complete log record from a RAF. This is used by SAWS VT who does not have the secure random number.

Parameters:
raf1 - is the RAF file
Returns:
String result. Return null if end of file is reached.
Throws:
logReadingException

readOneRecordFromRAF

public java.lang.String readOneRecordFromRAF(java.io.RandomAccessFile raf1,
                                             byte[] secureRandomBytes)
                                      throws logReadingException
This method is to read one complete log record from a RAF.

Parameters:
raf1 - is the RAF file
secureRandomBytes - is the secure number used for secure hash
Returns:
String result. Return null if end of file is reached.
Throws:
logReadingException

readRecordHeaderFromRAF

public byte[] readRecordHeaderFromRAF(java.io.RandomAccessFile raf1)
                               throws logReadingException
This method is to read a Record header from a random access file.

Parameters:
raf1 - is the RAF file
Returns:
bytes of the record header.
Throws:
logReadingException

setUserPrivateKey

public void setUserPrivateKey(java.security.PrivateKey pk)
This method is to set VT private key.

Parameters:
pk - is the VT private key

setSAWSPrivateKey

public void setSAWSPrivateKey(java.security.PrivateKey pk)
This method is to set saws private key.

Parameters:
pk - is the saws private key

getAccumulatedHashByCalc

public byte[] getAccumulatedHashByCalc()
This method is to return accumulated hash got by calculation during verification.


getAccumulatedHashFromLog

public byte[] getAccumulatedHashFromLog()
This method is to return accumulated hash stored in the log file


getSignatureFromLog

public byte[] getSignatureFromLog()
This method is to return signature from the log file


getSigningAlgorithmFromLog

public java.lang.String getSigningAlgorithmFromLog()
This method returns the signing algorithm from the log file.


getCertFromLog

public java.security.cert.Certificate getCertFromLog()
This method is to return the certificate in the log file


checkSignature

public int checkSignature(java.security.PublicKey sawsCAPublicKey)
                   throws logReadingException
This method is to verify the signature of the log file

Parameters:
sawsCAPublicKey - is the saws public key.
Throws:
logReadingException

checkLogFile

public int checkLogFile()
                 throws logReadingException
Throws:
logReadingException

checkLogFile

public int checkLogFile(byte[] secureRandomBytes)
                 throws logReadingException
This method is for checking a log file.

Parameters:
logFile - is File to be checked.
secureRandomBytes - is the secure number used for checking secure hashes
Returns:
int 0: true, otherwise: false.
Throws:
logReadingException

findPreviousLogfileName

public java.lang.String findPreviousLogfileName(byte[] secureRandomBytes)
                                         throws logReadingException
This method is to find the previous log file name stored in this log file.

Parameters:
secureRandomBytes - is secure random bytes.
Returns:
String the previous log file name.
Throws:
logReadingException

getCurrentSN

public int getCurrentSN()
This method is to return the current SN


getCert

public java.security.cert.Certificate getCert(java.io.File CurrentLogFile)
                                       throws logReadingException
This method is to return the SAWS certificate stored in the log file.

Parameters:
CurrentLogFile - is the current log file
Returns:
the certificate.
Throws:
logReadingException

getSecureRandomNumber

public byte[] getSecureRandomNumber(java.security.PrivateKey privateKey)
                             throws logReadingException
This method is to read the secure random number from the log file with the given private key.

Parameters:
CurrentLogFile - is the log file
is - the private key
Returns:
byte[] is the secure random number.
Throws:
logReadingException

getSymmetricKey

public javax.crypto.SecretKey getSymmetricKey()

getSymmetricKey

public byte[] getSymmetricKey(java.io.File CurrentLogFile,
                              java.security.PrivateKey privateKey)
                       throws logReadingException
This method is to read the symmetric key (byte[]) from the log file with the given private key.

Parameters:
CurrentLogFile - is the log file
is - the private key
Returns:
byte[] is the symmetric key.
Throws:
logReadingException

getAccumulatedHash

public byte[] getAccumulatedHash(java.io.File CurrentLogFile)
                          throws logReadingException
This method is to read the AccumulatedHash (byte[]) from the log file

Parameters:
CurrentLogFile - is the log file
is - the private key
Returns:
byte[] the accumualted hash.
Throws:
logReadingException

getAccumulatedHashAlgorithm

public java.lang.String getAccumulatedHashAlgorithm(java.io.File CurrentLogFile)
                                             throws logReadingException
This method is to read the hash algorithm from the log file

Parameters:
CurrentLogFile - is the log file
Returns:
String the accumualted hash algorithm.
Throws:
logReadingException

getSigningAlgorithm

public java.lang.String getSigningAlgorithm(java.io.File CurrentLogFile)
                                     throws logReadingException
This method is to read the signing algorithm from the log file.

Parameters:
CurrentLogFile - is the log file
Returns:
String the signing algorithm.
Throws:
logReadingException

getLogFileSignature

public byte[] getLogFileSignature(java.io.File CurrentLogFile)
                           throws logReadingException
This method is to read the signature of the complete log (byte[]) from the log file

Parameters:
CurrentLogFile - is the log file
is - the private key
Returns:
byte[] is the signature.
Throws:
logReadingException

getHeaderSignature

public byte[] getHeaderSignature(java.io.File CurrentLogFile)
                          throws logReadingException
This method is to read the signature of the log file's header (byte[]) from the log file.

Parameters:
CurrentLogFile - is the log file
is - the private key
Returns:
byte[] is the signature.
Throws:
logReadingException

getOneRecordInfoFromRAF

public LogRecordInfo getOneRecordInfoFromRAF(java.io.RandomAccessFile raf1,
                                             byte[] secureRandomBytes)
                                      throws logReadingException
This method is to read one complete log record from a RAF.

Parameters:
raf1 - is the RAF file
secureRandomBytes - is the secure number used for secure hash
Returns:
String result. Return null if end of file is reached.
Throws:
logReadingException

getXMLClientLogData

public java.lang.String getXMLClientLogData(byte[] secureRandomBytes)
                                     throws logReadingException
Throws:
logReadingException