issrg.SAWS
Class LogFileWriter

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

public class LogFileWriter
extends java.lang.Object

Author:
W.Xu

Field Summary
 byte[] accumulatedHash
           
 int currentRecordWriteCount
           
 byte[] finalSignature
           
 
Constructor Summary
LogFileWriter()
          This method is the constructor of LogFileWriter.
LogFileWriter(java.lang.String root, java.lang.String cLogFilename, java.security.PublicKey vt, java.security.PublicKey sawsEncPK, java.security.PrivateKey sawsSignPIK, byte[] ba, java.lang.String hashAlgorithm, byte[] secureBytes, java.util.Map UserIDPKMap, java.lang.String signingAlgorithm)
          This method is the constructor of LogFileWriter.
LogFileWriter(java.lang.String root, java.lang.String cLogFilename, java.security.PublicKey vt, java.security.PublicKey sawsEncPK, java.security.PrivateKey sawsSignPIK, byte[] ba, java.lang.String hashAlgorithm, byte[] secureBytes, java.util.Map UserIDPKMap, java.lang.String signingAlgorithm, javax.security.auth.callback.CallbackHandler ch)
          This method is the constructor of LogFileWriter.
 
Method Summary
 void createLastFileRecord(java.lang.String lastFilename, byte[] lastAccHash, byte[] lastSignature)
          This method is to generate the record body of a last log file record.
 void createSAWSRecord(byte[] messageBlock, byte recordType, byte encryptionFlag)
          This method is to create a SAWS Record .
 void createSAWSRecord(byte[] messageBlock, byte recordType, byte userID, byte encryptionFlag)
          This method is to create a SAWS Record .
 void createSAWSRecord(byte[] messageBlock, byte recordType, byte userID, byte encryptionFlag, java.security.PublicKey encryptionPublicKey)
          This method is to create a SAWS Record .
 void finalizeLogFile()
          This method is called to finalize the log file, i.e.
 byte[] getAccHash()
          This method is to get the final accumualted hash.
 int getCurrentRecordWriteCount()
          This method is to get the current writing record number in the current log file.
 java.lang.String getHashAlgorithm()
          This method returns the disgest algorithm name.
 byte[] getSignature()
          This method is to get the final signature.
 int prepareNewLog()
          This method creates a new log file, prepares this file for adding new log records to it in the future.
 int repairLog(java.lang.String logRoot, java.lang.String logFilename, byte[] secureRandomB, logReadingException e)
          This method is to repair a log file.
 void setCallbackHandler(javax.security.auth.callback.CallbackHandler ch)
          Method that sets the callback handler for the class.
 void setDebugLevel(int debugLevel)
          Method that sets the debug level.
 void setHashAlgorithm(java.lang.String hashAlgorithm)
          This method is to set the hashing algorithm name.
 void writeSignatureRecord(byte signatureType)
          This method is called to write a signature record to the log file after initialisation is finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentRecordWriteCount

public int currentRecordWriteCount

accumulatedHash

public byte[] accumulatedHash

finalSignature

public byte[] finalSignature
Constructor Detail

LogFileWriter

public LogFileWriter()
This method is the constructor of LogFileWriter.


LogFileWriter

public LogFileWriter(java.lang.String root,
                     java.lang.String cLogFilename,
                     java.security.PublicKey vt,
                     java.security.PublicKey sawsEncPK,
                     java.security.PrivateKey sawsSignPIK,
                     byte[] ba,
                     java.lang.String hashAlgorithm,
                     byte[] secureBytes,
                     java.util.Map UserIDPKMap,
                     java.lang.String signingAlgorithm)
This method is the constructor of LogFileWriter.

Parameters:
root - The log root, the place where the log files are stored.
cLogFilename - The log file name to be written.
vt - The SAWS VT public key.
sawsEncPK - The SAWS encryption public key.
sawsSignPIK - The SAWS signing private key.
ba - The binary array of the SAWS signing public key certificate to be written into the log file.
hashAlgorithm - The hash algorithm name, e.g. MD5.
secureBytes - The secure random number used for secure hashing.
UserIDPKMap - A map with the user's IDs and the respective public key.
signingAlgorithm - The signing algorithm name, e.g. MD5withRSA.

LogFileWriter

public LogFileWriter(java.lang.String root,
                     java.lang.String cLogFilename,
                     java.security.PublicKey vt,
                     java.security.PublicKey sawsEncPK,
                     java.security.PrivateKey sawsSignPIK,
                     byte[] ba,
                     java.lang.String hashAlgorithm,
                     byte[] secureBytes,
                     java.util.Map UserIDPKMap,
                     java.lang.String signingAlgorithm,
                     javax.security.auth.callback.CallbackHandler ch)
This method is the constructor of LogFileWriter.

Parameters:
root - The log root, the place where the log files are stored.
cLogFilename - The log file name to be written.
vt - The SAWS VT public key.
sawsEncPK - The SAWS encryption public key.
sawsSignPIK - The SAWS signing private key.
ba - The binary array of the SAWS signing public key certificate to be written into the log file.
hashAlgorithm - The hash algorithm name, e.g. MD5.
secureBytes - The secure random number used for secure hashing.
UserIDPKMap - A map with the user's IDs and the respective public key.
signingAlgorithm - The signing algorithm name, e.g. MD5withRSA.
ch - The callback hadler.
Method Detail

setDebugLevel

public void setDebugLevel(int debugLevel)
Method that sets the debug level.

Parameters:
debugLevel - indicates the different level of debug output information by SAWS. Its value is from 0 to 5. When its value is 0, then no debug information is output by SAWS. When its value is 5, then most debug information is output by SAWS.

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.

setHashAlgorithm

public void setHashAlgorithm(java.lang.String hashAlgorithm)
This method is to set the hashing algorithm name. SHA1 is the default algorithm.

Parameters:
hashAlgorithm - The hash algorithm name. Please consult the user guide for the supported algorithms.

getHashAlgorithm

public java.lang.String getHashAlgorithm()
This method returns the disgest algorithm name.

Returns:
The digest algorithm name.

getSignature

public byte[] getSignature()
This method is to get the final signature.

Returns:
The final signature.

getAccHash

public byte[] getAccHash()
This method is to get the final accumualted hash.

Returns:
The accumulated hash.

getCurrentRecordWriteCount

public int getCurrentRecordWriteCount()
This method is to get the current writing record number in the current log file.

Returns:
The current record write count.

prepareNewLog

public int prepareNewLog()
This method creates a new log file, prepares this file for adding new log records to it in the future.

Returns:
0 if success or -1 if fails.

createLastFileRecord

public void createLastFileRecord(java.lang.String lastFilename,
                                 byte[] lastAccHash,
                                 byte[] lastSignature)
This method is to generate the record body of a last log file record.

Parameters:
lastFilename - the file name of the previous log file
lastAccHash - the accumulated hash of the previous log file
lastSignature - the signature of the previous log file

createSAWSRecord

public void createSAWSRecord(byte[] messageBlock,
                             byte recordType,
                             byte encryptionFlag)
This method is to create a SAWS Record . It is a simplied invoke method of the following method.

Parameters:
messageBlock - log data block (here it is the secret random number to be wrapped into a record.
recordType - record type
encryptionFlag - encryption flag to indicate the encryption requirement.

createSAWSRecord

public void createSAWSRecord(byte[] messageBlock,
                             byte recordType,
                             byte userID,
                             byte encryptionFlag)
This method is to create a SAWS Record . It is a simplied invoke method of the following method.

Parameters:
messageBlock - log data block (here it is the secret random number to be wrapped into a record.
recordType - record type
userID - user ID
encryptionFlag - encryption flag to indicate the encryption requirement.

createSAWSRecord

public void createSAWSRecord(byte[] messageBlock,
                             byte recordType,
                             byte userID,
                             byte encryptionFlag,
                             java.security.PublicKey encryptionPublicKey)
This method is to create a SAWS Record .

Parameters:
messageBlock - log data block (here it is the secret random number to be wrapped into a record.
recordType - record type
userID - user ID
encryptionFlag - encryption flag to indicate the encryption requirement.
encryptionPublicKey - the encryption public key used for assymmetric encryption. This could be the VT enc public key, or the SAWS enc public key

repairLog

public int repairLog(java.lang.String logRoot,
                     java.lang.String logFilename,
                     byte[] secureRandomB,
                     logReadingException e)
This method is to repair a log file. Its main input is logReadingException e.

Parameters:
logRoot - the log root
logFilename - the log filename to be repaired.
secureRandomB - byte[] is the secure random bytes for this log file
logReadingException - e is the exception class containing all the necessary information for the repair.
Returns:
int. 0 for success, -1 for failure.

finalizeLogFile

public void finalizeLogFile()
This method is called to finalize the log file, i.e. write the accumulated hash and the signature to the log file.


writeSignatureRecord

public void writeSignatureRecord(byte signatureType)
This method is called to write a signature record to the log file after initialisation is finished.

Parameters:
signatureType - The type of signature record: SAWSConstant.SAWSHeaderSignatureType for the signature of the log file header; or SAWSConstant.SAWSSigningAlgorithmType for the signature of the complete log file.