com.jp.protection.pub
Class IntegrityHost

java.lang.Object
  extended by com.jp.protection.pub.IntegrityHost
Direct Known Subclasses:
CRCHost, IntegrityHostPro

public class IntegrityHost
extends java.lang.Object

Provides methods to ensure that certain files are still unchanged using previously calculated digest


Nested Class Summary
protected static class IntegrityHost.CRC32Digest
           
protected static interface IntegrityHost.Digest
           
protected static class IntegrityHost.MessageDigest
           
 
Field Summary
static int ALGORITHM_CRC32
          Deprecated. since 2.0 use SHA1 or MD5 instead
static int ALGORITHM_DEFAULT
          Specifies default digest algorithm constant
static int ALGORITHM_MD5
          Specifies MD5 digest algorithm constant
static int ALGORITHM_SHA_1
          Specifies SHA1 digest algorithm constant
protected  int fAlgorithm
           
protected  byte[] fCheckDigest
           
protected  long fCRC
           
protected  IntegrityHost.Digest fDigest
           
protected  byte[] fDigestBytes
           
protected  java.lang.String[] fDigestEntries
           
protected  boolean fVerbose
           
protected static java.lang.String WEB_INF
           
 
Constructor Summary
IntegrityHost()
          Creates a new instance of the IntegrityHost
IntegrityHost(java.lang.String[] aDigestEntries, byte[] aCheckDigest)
          Creates a new instance of the IntegrityHost
IntegrityHost(java.lang.String[] aDigestEntries, long aCRC)
          Deprecated. use IntegrityHost(String[] aDigestEntries, byte[] aCheckBytes) instead
 
Method Summary
protected  long calculate(byte[] aBytes)
           
protected static byte[] calculateDigest(long aCRC)
           
protected  void calculateDigest(java.lang.String[] aDigestEntries)
           
 boolean check()
          Main method that do all the work of checking that files are still unchanged against supplied check sum.
protected  boolean check(java.lang.String[] aDigestEntries, byte[] aCheckDigest)
           
protected  boolean check(java.lang.String[] aDigestEntries, long anCRC)
           
static boolean checkStatic(java.lang.String[] aDigestEntries, byte[] aCheckDigest)
          Static main method that do all the work of checking that files are still unchanged against supplied check sum.
static boolean checkStatic(java.lang.String[] aDigestEntries, byte[] aCheckDigest, int anAlgorithm)
          Static main method that do all the work of checking that files are still unchanged against supplied check sum.
static boolean checkStatic(java.lang.String[] aDigestEntries, long anCRC)
          Deprecated. since 2.0
protected  void error(java.lang.String aMessage)
           
protected  void error(java.lang.Throwable ex)
           
 int getAlgorithm()
          Returns algorithm used to calculate check sum.
static java.lang.String getAlgorithmStr(int anAlgorithm)
          Returns string representation of the algorithm used to calculate check sum.
 byte[] getCheckDigest()
          Returns digest to check
 long getCRC()
          Deprecated. since 2.0 use getCheckDigest() instead
 java.lang.String[] getCRCEntries()
          Deprecated. since 3.0 use getDigestEntries() instead
 byte[] getDigest()
          Returns digest value
 java.lang.String[] getDigestEntries()
          Returns entries to check
protected  java.io.InputStream getEntryStream(java.lang.String crcEntry)
           
 boolean isVerbose()
          Checks whether Integrity Host runs in verbose mode.
 void resetDigest()
          Resets digest
 void setAlgorithm(int aAlgorithm)
          Specifies algorithm used to calculate check sum as one of ALGORITHM_ constants.
 void setCheckDigest(byte[] aCheckDigest)
          Specifies digest to check
 void setCRC(long aCRC)
          Deprecated. since 2.0 use setCheckDigest() instead
 void setCRCEntries(java.lang.String[] aDigestEntries)
          Deprecated. since 3.0 use setDigestEntries() instead
 void setDigestEntries(java.lang.String[] aDigestEntries)
          Specifies entries to check
 void setVerbose(boolean aVerbose)
          Specifies that Integrity Host should run in verbose mode.
static java.lang.String toResourceName(java.lang.Class aClass)
          Makes resource name based on passed class name e.g.
 void updateDigest(byte[] aBytes)
          Updates digest with the array of bytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fDigestEntries

protected java.lang.String[] fDigestEntries

fCRC

protected long fCRC

ALGORITHM_CRC32

public static final int ALGORITHM_CRC32
Deprecated. since 2.0 use SHA1 or MD5 instead
Specifies CRC32 algorithm constant

See Also:
Constant Field Values

ALGORITHM_SHA_1

public static final int ALGORITHM_SHA_1
Specifies SHA1 digest algorithm constant

See Also:
Constant Field Values

ALGORITHM_MD5

public static final int ALGORITHM_MD5
Specifies MD5 digest algorithm constant

See Also:
Constant Field Values

ALGORITHM_DEFAULT

public static final int ALGORITHM_DEFAULT
Specifies default digest algorithm constant

See Also:
Constant Field Values

fDigest

protected IntegrityHost.Digest fDigest

fAlgorithm

protected int fAlgorithm

fDigestBytes

protected byte[] fDigestBytes

WEB_INF

protected static final java.lang.String WEB_INF
See Also:
Constant Field Values

fVerbose

protected boolean fVerbose

fCheckDigest

protected byte[] fCheckDigest
Constructor Detail

IntegrityHost

public IntegrityHost(java.lang.String[] aDigestEntries,
                     long aCRC)
Deprecated. use IntegrityHost(String[] aDigestEntries, byte[] aCheckBytes) instead

Creates a new instance of the IntegrityHost

Parameters:
aDigestEntries - classes and resources to check
aCRC - pre-calculated CRC to check

IntegrityHost

public IntegrityHost(java.lang.String[] aDigestEntries,
                     byte[] aCheckDigest)
Creates a new instance of the IntegrityHost

Parameters:
aDigestEntries - list of files to check
aCheckDigest - pre-calculated bytes array to check

IntegrityHost

public IntegrityHost()
Creates a new instance of the IntegrityHost

Method Detail

getAlgorithm

public int getAlgorithm()
Returns algorithm used to calculate check sum.

Returns:
algorithm used to calculate check sum.

getAlgorithmStr

public static java.lang.String getAlgorithmStr(int anAlgorithm)
Returns string representation of the algorithm used to calculate check sum.

Parameters:
anAlgorithm - algorithm
Returns:
string representation of the algorithm

setAlgorithm

public void setAlgorithm(int aAlgorithm)
Specifies algorithm used to calculate check sum as one of ALGORITHM_ constants.

Parameters:
aAlgorithm - algorithm should be used to calculate digest

getCRC

public long getCRC()
Deprecated. since 2.0 use getCheckDigest() instead

Returns CRC value

Returns:
CRC value

setCRC

public void setCRC(long aCRC)
Deprecated. since 2.0 use setCheckDigest() instead

Specifies CRC value

Parameters:
aCRC - CRC value

getCRCEntries

public java.lang.String[] getCRCEntries()
Deprecated. since 3.0 use getDigestEntries() instead

Returns entries to check

Returns:
entries to check

getDigestEntries

public java.lang.String[] getDigestEntries()
Returns entries to check

Returns:
entries to check

setCRCEntries

public void setCRCEntries(java.lang.String[] aDigestEntries)
Deprecated. since 3.0 use setDigestEntries() instead

Specifies entries to check

Parameters:
aDigestEntries - entries to check

setDigestEntries

public void setDigestEntries(java.lang.String[] aDigestEntries)
Specifies entries to check

Parameters:
aDigestEntries - entries to check

check

public boolean check()
Main method that do all the work of checking that files are still unchanged against supplied check sum.

Returns:
true if files are still unchanged; false otherwise

checkStatic

public static boolean checkStatic(java.lang.String[] aDigestEntries,
                                  long anCRC)
Deprecated. since 2.0

Static main method that do all the work of checking that files are still unchanged against supplied check sum. It creates and uses temporary IntegrityHost instance for the users' convenience

Parameters:
aDigestEntries - files to check
anCRC - check sum to check
Returns:
true if files are still unchanged; false otherwise

checkStatic

public static boolean checkStatic(java.lang.String[] aDigestEntries,
                                  byte[] aCheckDigest,
                                  int anAlgorithm)
Static main method that do all the work of checking that files are still unchanged against supplied check sum. It creates and uses temporary IntegrityHost instance for the users' convenience

Parameters:
aDigestEntries - classes and resources to check
aCheckDigest - check digest to check
anAlgorithm - algorithm should be used to check
Returns:
true if files are still unchanged; false otherwise

checkStatic

public static boolean checkStatic(java.lang.String[] aDigestEntries,
                                  byte[] aCheckDigest)
Static main method that do all the work of checking that files are still unchanged against supplied check sum. It creates and uses temporary IntegrityHost instance for the users' convenience. The ALGORITHM_DEFAULT will be used to check.

Parameters:
aDigestEntries - classes and resources
aCheckDigest - check digest to check
Returns:
true if files are still unchanged; false otherwise

check

protected boolean check(java.lang.String[] aDigestEntries,
                        long anCRC)

check

protected boolean check(java.lang.String[] aDigestEntries,
                        byte[] aCheckDigest)

resetDigest

public void resetDigest()
Resets digest


updateDigest

public void updateDigest(byte[] aBytes)
Updates digest with the array of bytes

Parameters:
aBytes - array of bytes to update digest

getDigest

public byte[] getDigest()
Returns digest value

Returns:
digest value

calculateDigest

protected void calculateDigest(java.lang.String[] aDigestEntries)

calculate

protected long calculate(byte[] aBytes)

getEntryStream

protected java.io.InputStream getEntryStream(java.lang.String crcEntry)

toResourceName

public static java.lang.String toResourceName(java.lang.Class aClass)
Makes resource name based on passed class name e.g. com/jp/samples/protection/DemoCalcProtectionSupport$1.class

Parameters:
aClass - class to get resource name for
Returns:
resource name

isVerbose

public boolean isVerbose()
Checks whether Integrity Host runs in verbose mode.

Returns:
true if Integrity Host runs in verbose mode, false otherwise.

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that Integrity Host should run in verbose mode. If it runs in verbose mode all exceptions stack traces and error messages will be printed to std err. Otherwise there is no output in order to prevent the code flow analysis.

Parameters:
aVerbose - true if Integrity Host should run in verbose mode, false otherwise.

error

protected void error(java.lang.String aMessage)

error

protected void error(java.lang.Throwable ex)

getCheckDigest

public byte[] getCheckDigest()
Returns digest to check

Returns:
digest to check

setCheckDigest

public void setCheckDigest(byte[] aCheckDigest)
Specifies digest to check

Parameters:
aCheckDigest - digest to check

calculateDigest

protected static byte[] calculateDigest(long aCRC)