Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
98   226   31   32.67
0   135   0.34   3
3     11  
1    
 
 
  SAWSConstant       Line # 55 98 31 33.7% 0.33663365
 
No Tests
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45   
46   
47    package issrg.SAWS;
48   
49    /**
50    * SAWSConstant.java
51    *
52    * Created in Nov 2005
53    * @author W.Xu
54    */
 
55    public class SAWSConstant {
56   
57    /** Creates a new instance of SAWSConstant */
 
58  0 toggle public SAWSConstant() {
59    }
60    // Log record type difinitions
61    final static public byte SAWSSecretRandomNumberType = 0x01;
62    final static public byte SymmetricEncryptionKeyType = 0x02;
63    final static public byte SAWSLastFileType = 0x03;
64    final static public byte SAWSClientLogDataType = 0x04;
65    final static public byte SAWSAccumulatedHashType = 0x05;
66    final static public byte SAWSLogFileSignatureType = 0x06;
67    final static public byte SAWSCertificateType = 0x07;
68    final static public byte SysSAWSStartupType = 0x08;
69    final static public byte SysSAWSShutdownType = 0x09;
70    final static public byte SysUnauthorisedConnectionAttemptType = 0x0a;
71    final static public byte SysAuditorNotificationType = 0x0b;
72    final static public byte SysHeartbeatType = 0x0c;
73    final static public byte SysClientIDType = 0x0d;
74    final static public byte SAWSHashAlgorithmType = 0x0e;
75    final static public byte SAWSHeaderSignatureType = 0x0f;
76   
77    // Encryption type definitions
78    final static public byte AsymmetricEncryptionFlag = 0x01;
79    final static public byte SymmetricEncryptionFlag = 0x02;
80    final static public byte NoEncryptionFlag = 0x03;
81    final static public byte CommandFlag = 0x04;
82   
83    // SAWS user difinitions
84    final static public byte USERSAWS = 0x00;
85    final static public byte USERVT = 0x01;
86   
87    // contants used in SAWS
88    static public int HeaderLength = 27;
89    //static public int HashLength = 16;
90    static public int MAXINPUTSIZE = 117;
91    static public int OUTPUTSIZE = 128;
92   
93    //constants for error codes
94    final static int TrustedLocationMissingErrCode = 0;
95    final static int LogFileMissingErrCode = 1;
96    final static int SNNotMatchBetweenLogAndTCBLocationErrCode =2;
97    final static int AccHashNotMatchBetweenLogAndTCBLocationErrCode =3;
98    final static int ADecryptErrCode = 4;
99   
100    final static int LogFileFormatErrCode =10;
101    final static int LogFileReadingErrCode =11;
102    final static int LogFileIncompleteErrCode = 12;
103    final static int LogFileBodyReadingErrCode = 13;
104    final static int LogFileHashReadingErrCode = 14;
105    final static int CalculatedAccHashNotEqualsAccHashInLog = 15;
106    final static int CertificateInLogIsNotValidAgainstRootCA =16;
107    final static int SignatureIsNotValid = 17;
108    final static int SecureHashNotCorrect = 18;
109    final static int SNNotCorrectInLog =19;
110    final static int SecureRandomRecordErrCode = 20;
111    final static int HeaderSignatureIsNotValid = 21;
112   
113    final static int InvalidEncryptionFlag = 22;
114    final static int UnauthorizedUser = 23;
115    final static int LogFileClosed = 24;
116   
117    //constants for debug level
118    final static int VerboseInfo = 3;
119    final static int WarningInfo = 2;
120    final static int ErrorInfo = 1;
121    final static int NoInfo = 0;
122   
123    //constants for hash algorithms
124    public final static byte SHA1 = 0x00;
125    public final static byte MD5 = 0x01;
126    public final static byte SHA256 = 0x02;
127    public final static byte SHA384 = 0x03;
128    public final static byte SHA512 = 0x04;
129   
130    public final static String[] HASH_ALG_NAMES = {"SHA1", "MD5", "SHA256", "SHA384", "SHA512"};
131    public final static int[] HashLength = {20, 16, 32, 64, 64};
132   
133    public static final byte ENCRYPTION_PURPOSE = 0x00;
134    public static final byte SIGNING_PURPOSE = 0x01;
135   
136    /**
137    * This method is to get the error code string
138    * @param errCode is the error code
139    *
140    * @return the error message string
141    */
 
142  0 toggle static public String getErrorString(int errCode){
143  0 String str = null;
144  0 switch (errCode){
145  0 case LogFileIncompleteErrCode:
146  0 str = new String("This log file is not completed.");
147  0 break;
148  0 case SecureRandomRecordErrCode:
149  0 str = new String("The secure random number is corrupt in the log file.");
150  0 break;
151  0 case SNNotCorrectInLog:
152  0 str = new String("The sequence number is not correct.");
153  0 break;
154  0 case SecureHashNotCorrect:
155  0 str = new String("Secure hash is not correct.");
156  0 break;
157  0 case SignatureIsNotValid:
158  0 str = new String("Signature of this log is not valid.");
159  0 break;
160  0 case CertificateInLogIsNotValidAgainstRootCA:
161  0 str = new String("Certificate in the log is not valid against the root CA.");
162  0 break;
163  0 case LogFileFormatErrCode:
164  0 str = new String("log file format is wrong.");
165  0 break;
166  0 case LogFileReadingErrCode:
167  0 str = new String("log file reading error");
168  0 break;
169  0 case LogFileBodyReadingErrCode:
170  0 str = new String("log file body reading error");
171  0 break;
172  0 case LogFileHashReadingErrCode:
173  0 str = new String("log file hash reading error");
174  0 break;
175  0 case CalculatedAccHashNotEqualsAccHashInLog:
176  0 str = new String("Calculated accumulated hash does not equal the one stored in the log.");
177  0 break;
178  0 case ADecryptErrCode:
179  0 str = new String("Can't use the encryption key to read the log file.");
180  0 break;
181  0 case HeaderSignatureIsNotValid:
182  0 str = new String("Signature of this log's header is not valid.");
183  0 break;
184  0 case InvalidEncryptionFlag:
185  0 str = new String("The Encryption flag is not valid.");
186  0 break;
187  0 case UnauthorizedUser:
188  0 str = new String("This user is not allowed to send log records.");
189  0 break;
190   
191    }
192  0 return str;
193    }
194   
195    /**
196    * This method is to give the record type according to the type value
197    *
198    * @param
199    *
200    * @return String record type .
201    */
 
202  540 toggle static public String getRecordTypeString(byte RecordTypeIn){
203  540 String recordType = null;
204  540 switch (RecordTypeIn) {
205  28 case SAWSConstant.SAWSSecretRandomNumberType: recordType = new String("SAWSSecretRandomNumberType"); break;
206  112 case SAWSConstant.SymmetricEncryptionKeyType: recordType = new String("SymmetricEncryptionKeyType"); break;
207  28 case SAWSConstant.SAWSLastFileType: recordType = new String("SAWSLastFileType"); break;
208  160 case SAWSConstant.SAWSClientLogDataType: recordType = new String("SAWSClientLogDataType");break;
209  28 case SAWSConstant.SAWSAccumulatedHashType: recordType = new String("SAWSAccumulatedHashType");break;
210  28 case SAWSConstant.SAWSLogFileSignatureType: recordType = new String("SAWSLogFileSignatureType");break;
211  28 case SAWSConstant.SAWSCertificateType: recordType = new String("SAWSCertificateType");break;
212  0 case SAWSConstant.SysSAWSStartupType: recordType = new String("SysSAWSStartupType");break;
213  0 case SAWSConstant.SysSAWSShutdownType: recordType = new String("SysSAWSShutdownType");break;
214  0 case SAWSConstant.SysUnauthorisedConnectionAttemptType: recordType = new String("SysUnauthorisedConnectionAttemptType");break;
215  0 case SAWSConstant.SysAuditorNotificationType: recordType = new String("SysAuditorNotificationType");break;
216  72 case SAWSConstant.SysHeartbeatType: recordType = new String("SysHeartbeatType");break;
217  0 case SAWSConstant.SysClientIDType: recordType = new String("SysClientIDType");break;
218  28 case SAWSConstant.SAWSHashAlgorithmType: recordType = new String("SAWSHashAlgorithmType"); break;
219  28 case SAWSConstant.SAWSHeaderSignatureType: recordType = new String("SAWSHeaderSignatureType"); break;
220  0 default: recordType = null;
221    }
222  540 return recordType;
223    }
224   
225   
226    }