1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
package issrg.SAWS; |
47 |
|
|
48 |
|
import issrg.SAWS.util.SAWSLogWriter; |
49 |
|
|
50 |
|
import issrg.utils.*; |
51 |
|
|
52 |
|
import java.util.*; |
53 |
|
import org.w3c.dom.*; |
54 |
|
import javax.xml.parsers.*; |
55 |
|
import org.apache.soap.util.xml.*; |
56 |
|
import org.xml.sax.*; |
57 |
|
import java.io.*; |
58 |
|
|
59 |
|
import java.security.*; |
60 |
|
import javax.crypto.*; |
61 |
|
import java.security.AlgorithmParameters; |
62 |
|
import javax.crypto.spec.* ; |
63 |
|
|
64 |
|
import java.security.KeyStore; |
65 |
|
import java.security.Key; |
66 |
|
import java.security.cert.Certificate; |
67 |
|
|
68 |
|
import javax.security.auth.callback.*; |
69 |
|
import java.lang.reflect.Constructor; |
70 |
|
|
71 |
|
import javax.servlet.http.*; |
72 |
|
|
73 |
|
import issrg.SAWS.callback.*; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@author |
80 |
|
@version |
81 |
|
|
|
|
| 49% |
Uncovered Elements: 391 (766) |
Complexity: 135 |
Complexity Density: 0.31 |
|
82 |
|
public class SAWSServer { |
83 |
|
private static final issrg.utils.Version version = new issrg.utils.Version("issrg/SAWS/version", "saws"); |
84 |
|
private Callback[] cbs = null; |
85 |
|
private boolean writingHeartBeating = false; |
86 |
|
|
87 |
|
private String encryptionKeystoreLocation = null; |
88 |
|
private String signingKeystoreLocation = null; |
89 |
|
private int numberOfPasswordShares = 2; |
90 |
|
private int numberOfEncPasswordShares =2; |
91 |
|
private int heartbeatInterval = 0; |
92 |
|
private String rootCA = null; |
93 |
|
private String trustedLocation = null; |
94 |
|
private String vtPKC = null; |
95 |
|
private int signRecordNumber; |
96 |
|
private String SAWSInterface = null; |
97 |
|
private Map UserDNIDMap = new Hashtable(); |
98 |
|
private Map UserIDPKMap = new Hashtable(); |
99 |
|
private String logEncryption = "no"; |
100 |
|
private int debugLevel = SAWSConstant.ErrorInfo; |
101 |
|
|
102 |
|
private byte hashAlgorithm = SAWSConstant.SHA1; |
103 |
|
|
104 |
|
|
105 |
|
private String latestLogFilename = null; |
106 |
|
|
107 |
|
private int SNFromTCB = -1; |
108 |
|
private byte[] AccHashFromTCB = null; |
109 |
|
private CallbackHandler callbackHandler = new SAWSCmdPromptCallbackHandler(); |
110 |
|
private String callBackHandlerClass = "issrg.SAWS.callback.SAWSCmdPromptCallbackHandler"; |
111 |
|
|
112 |
|
private TCBContentRW tcbContent = null; |
113 |
|
|
114 |
|
private LogFilenameClass lfc = null; |
115 |
|
|
116 |
|
private LogFileWriter currentLogFileWriter = null; |
117 |
|
|
118 |
|
private TCBKeystoreManagement tcbKM = null; |
119 |
|
|
120 |
|
|
121 |
|
private String logFileRoot = null; |
122 |
|
private String currentInspectionLogFilename = null; |
123 |
|
byte [] currentInspecitonAccHash = null; |
124 |
|
byte [] currentInspectionSignature = null; |
125 |
|
private String previousLogFilenameFromLogRoot = null; |
126 |
|
private String previousLogFilenameFromLogRecord = null; |
127 |
|
|
128 |
|
|
129 |
|
public Vector logFileList = new Vector(); |
130 |
|
public int currentReadingFileNo = 0; |
131 |
|
public Vector recordBlockListFromOneLogFile = null; |
132 |
|
|
133 |
|
private SecretKey sawsTCBSecretKey = null; |
134 |
|
private PBEParameterSpec paramSpec = null; |
135 |
|
|
136 |
|
|
137 |
|
Vector waitingRecordList0 = new Vector(); |
138 |
|
Vector waitingRecordList1 = new Vector(); |
139 |
|
boolean busyFlag0V = false; |
140 |
|
boolean busyFlag1V = false; |
141 |
|
Thread thread = null; |
142 |
|
int recordCount = 0; |
143 |
|
|
144 |
|
|
145 |
|
private long currentTime ; |
146 |
|
private java.util.Timer timer = null; |
147 |
|
private TimerTask tt2 = null; |
148 |
|
|
149 |
|
private boolean closed = false; |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
private static SAWSLogWriter sawsDebugLog = new SAWSLogWriter(SAWSServer.class.getName()); |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.5 |
|
161 |
|
class WaitingRecordBlock { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
162 |
4
|
public WaitingRecordBlock(){}... |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
163 |
93
|
public WaitingRecordBlock(byte[] messageBlock, byte recordType, byte encryptionFlag, byte userID){... |
164 |
93
|
this.messageBlock = messageBlock; |
165 |
93
|
this.recordType = recordType; |
166 |
93
|
this.encryptionFlag = encryptionFlag; |
167 |
93
|
this.userID = userID; |
168 |
|
} |
169 |
|
public byte [] messageBlock = null; |
170 |
|
public byte recordType; |
171 |
|
public byte encryptionFlag; |
172 |
|
public byte userID; |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
@param |
179 |
|
|
180 |
|
@return |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
182 |
4
|
public SAWSServer() { ... |
183 |
4
|
readConf(); |
184 |
4
|
sawsInit(); |
185 |
4
|
sawsStart(); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
@param |
197 |
|
|
198 |
|
|
199 |
|
@return |
200 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
201 |
4
|
public SAWSServer(int flag) { ... |
202 |
4
|
readConf(); |
203 |
4
|
if (flag == 1){ |
204 |
0
|
sawsInit(); |
205 |
|
} |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@param |
213 |
|
|
214 |
|
@return |
215 |
|
|
|
|
| 56.2% |
Uncovered Elements: 63 (144) |
Complexity: 31 |
Complexity Density: 0.31 |
|
216 |
8
|
private void readConf(){... |
217 |
8
|
java.net.URL configURL = this.getClass().getResource("saws.xml"); |
218 |
8
|
File configFile = new File("saws.xml"); |
219 |
|
|
220 |
8
|
if ( !(configFile.exists()) ) |
221 |
0
|
configFile = new File(configURL.getFile() ); |
222 |
|
|
223 |
8
|
java.io.BufferedReader in = null; |
224 |
8
|
try{ |
225 |
8
|
in = new java.io.BufferedReader( new java.io.FileReader(configFile) ); |
226 |
|
} catch ( Exception e){ |
227 |
0
|
if (debugLevel >= SAWSConstant.ErrorInfo) |
228 |
|
|
229 |
0
|
sawsDebugLog.write(e.toString()); |
230 |
0
|
System.exit(-1); |
231 |
|
} |
232 |
|
|
233 |
8
|
DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); |
234 |
8
|
org.w3c.dom.Document doc = null; |
235 |
|
|
236 |
8
|
try { |
237 |
8
|
doc = xdb.parse(new InputSource(in) ); |
238 |
|
} |
239 |
|
catch (Exception e) { |
240 |
0
|
if (debugLevel >= SAWSConstant.ErrorInfo) { |
241 |
0
|
sawsDebugLog.write(e.toString() |
242 |
|
+ "\nThe SAWS configuration file saws.xml could not be read." |
243 |
|
+ "\nPlease check Line " + ((SAXParseException)e).getLineNumber() |
244 |
|
+ " and Column " + ((SAXParseException)e).getColumnNumber() |
245 |
|
+ " in saws.xml."); |
246 |
|
} |
247 |
|
|
248 |
0
|
this.showMessage("The SAWS configuration file saws.xml could not be read." |
249 |
|
+ "\nPlease check Line " + ((SAXParseException)e).getLineNumber() |
250 |
|
+ " and Column " + ((SAXParseException)e).getColumnNumber() |
251 |
|
+ " in saws.xml.", SAWSTextOutputCallback.ERROR); |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
0
|
System.exit(-1); |
262 |
|
} |
263 |
|
|
264 |
8
|
org.w3c.dom.Element root = null; |
265 |
8
|
if (doc != null ) { |
266 |
8
|
root = doc.getDocumentElement(); |
267 |
|
} |
268 |
|
|
269 |
8
|
NodeList nl4 = root.getElementsByTagName("CallbackHandler"); |
270 |
8
|
org.w3c.dom.Element e5 = (org.w3c.dom.Element) nl4.item (0); |
271 |
|
|
272 |
8
|
String className = null; |
273 |
8
|
if (e5 != null) { |
274 |
8
|
className = DOMUtils.getAttribute (e5, "class"); |
275 |
8
|
if (className != null) { |
276 |
8
|
this.callBackHandlerClass = className; |
277 |
8
|
String errorMessage = null; |
278 |
|
|
279 |
8
|
try { |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
8
|
if (this.callBackHandlerClass.equals("issrg.SAWS.callback.SAWSFileCallbackHandler")) { |
284 |
8
|
String inputFile = DOMUtils.getAttribute (e5, "inputFile"); |
285 |
8
|
String outputFile = DOMUtils.getAttribute (e5, "outputFile"); |
286 |
8
|
this.callbackHandler = new SAWSFileCallbackHandler(inputFile, outputFile); |
287 |
|
} else { |
288 |
0
|
this.callbackHandler = (CallbackHandler) |
289 |
|
(Class.forName(this.callBackHandlerClass).newInstance()); |
290 |
|
} |
291 |
|
|
292 |
|
} catch (IllegalArgumentException iae) { |
293 |
0
|
errorMessage = iae.getMessage(); |
294 |
|
} catch (InstantiationException ie) { |
295 |
0
|
errorMessage = "The callback handler class \"" + className + "\" could not be instantiated." |
296 |
|
+ "\nPlease check the class name in the configuration file (saws.xml)."; |
297 |
|
} catch (ClassNotFoundException cnfe) { |
298 |
0
|
errorMessage = "The callback handler class \"" + className + "\" could not be found." |
299 |
|
+ "\nPlease check the class name in the configuration file (saws.xml)" |
300 |
|
+ " or the class path."; |
301 |
|
} catch (IllegalAccessException iae) { |
302 |
0
|
errorMessage = "The callback handler class \"" + className + "\" could not be accessed." |
303 |
|
+ "\nPlease check the permissions to run the specified class."; |
304 |
|
} finally { |
305 |
8
|
if (errorMessage != null) { |
306 |
0
|
String[] options = {"Continue", "Stop"}; |
307 |
0
|
if (debugLevel >= SAWSConstant.ErrorInfo) { |
308 |
0
|
sawsDebugLog.write(errorMessage); |
309 |
|
} |
310 |
0
|
errorMessage = errorMessage |
311 |
|
+ "\n\nSAWS can use a default callback handler. Please select \"Continue\"" |
312 |
|
+ "\nto use the default handler, or select \"Stop\" to finish SAWS."; |
313 |
0
|
int selection = this.createConfirmCallback(errorMessage, options, |
314 |
|
SAWSChoiceCallback.WARNING, "CallbackHandlerError"); |
315 |
0
|
if (selection == 1) { |
316 |
0
|
System.exit(-1); |
317 |
|
} |
318 |
|
} |
319 |
|
} |
320 |
|
} |
321 |
|
|
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
8
|
NodeList nl= root.getElementsByTagName("SAWSBasic"); |
326 |
8
|
org.w3c.dom.Element e = (org.w3c.dom.Element) nl.item (0); |
327 |
|
|
328 |
8
|
encryptionKeystoreLocation = DOMUtils.getAttribute (e, "encryptionKeystoreLocation"); |
329 |
8
|
rootCA = DOMUtils.getAttribute (e, "rootCA"); |
330 |
|
|
331 |
|
|
332 |
8
|
if (rootCA != null ) { |
333 |
8
|
File rootCAFile = new File (rootCA); |
334 |
8
|
if ( !rootCAFile.exists() ) { |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
0
|
this.showMessage("SAWS can't find the rootCA public key certificate." + rootCA |
346 |
|
+ "\n\nSAWS will stop and the SAWS administrator needs to put the root CA public key certificate" |
347 |
|
+ "\nin the correct position as specified in the SAWS configuration file saws.xml.", |
348 |
|
SAWSTextOutputCallback.WARNING); |
349 |
0
|
System.exit(-1); |
350 |
|
} |
351 |
|
} else { |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
0
|
this.showMessage("The rootCA public key certificate was not specified." |
363 |
|
+ "\n\nSAWS will stop and the SAWS administrator needs to specify the root CA public key certificate" |
364 |
|
+ "\nin the SAWS configuration file saws.xml.", |
365 |
|
SAWSTextOutputCallback.WARNING); |
366 |
0
|
System.exit(-1); |
367 |
|
} |
368 |
|
|
369 |
8
|
signRecordNumber = Integer.parseInt ( DOMUtils.getAttribute (e, "signRecordNumber") ); |
370 |
8
|
numberOfEncPasswordShares = Integer.parseInt ( DOMUtils.getAttribute (e, "numberOfEncPasswordShares") ); |
371 |
8
|
heartbeatInterval = Integer.parseInt ( DOMUtils.getAttribute (e, "heartbeatInterval") ); |
372 |
8
|
logFileRoot = DOMUtils.getAttribute (e, "logFileRoot"); |
373 |
8
|
vtPKC = DOMUtils.getAttribute (e, "vtPKC"); |
374 |
8
|
SAWSInterface = DOMUtils.getAttribute (e, "SAWSInterface"); |
375 |
8
|
logEncryption = DOMUtils.getAttribute (e, "logEncryption"); |
376 |
8
|
debugLevel = Integer.parseInt ( DOMUtils.getAttribute (e, "debugLevel") ); |
377 |
|
|
378 |
8
|
NodeList nl2= root.getElementsByTagName("TPMAdvanced"); |
379 |
8
|
org.w3c.dom.Element e2 = (org.w3c.dom.Element) nl2.item (0); |
380 |
8
|
signingKeystoreLocation = DOMUtils.getAttribute (e2, "signingKeystoreLocation"); |
381 |
8
|
numberOfPasswordShares = Integer.parseInt ( DOMUtils.getAttribute (e2, "numberOfPasswordShares") ); |
382 |
8
|
trustedLocation = DOMUtils.getAttribute (e2, "trustedLocation"); |
383 |
|
|
384 |
8
|
String s1 = DOMUtils.getAttribute (e2, "hashAlg"); |
385 |
8
|
if (s1 != null) { |
386 |
8
|
if (s1.equalsIgnoreCase("SHA-1")) { |
387 |
8
|
this.hashAlgorithm = SAWSConstant.SHA1; |
388 |
0
|
} else if (s1.equalsIgnoreCase("MD5")) { |
389 |
0
|
this.hashAlgorithm = SAWSConstant.MD5; |
390 |
0
|
} else if (s1.equalsIgnoreCase("SHA-256")) { |
391 |
0
|
this.hashAlgorithm = SAWSConstant.SHA256; |
392 |
0
|
} else if (s1.equalsIgnoreCase("SHA-384")) { |
393 |
0
|
this.hashAlgorithm = SAWSConstant.SHA384; |
394 |
0
|
} else if (s1.equalsIgnoreCase("SHA-512")) { |
395 |
0
|
this.hashAlgorithm = SAWSConstant.SHA512; |
396 |
|
} else { |
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
0
|
this.showMessage("The hash algorithm specified in SAWS configuration file (saws.xml) is not supported." |
408 |
|
+ "\n\nSAWS will stop and the SAWS administrator needs to specify the the correct algorithm," |
409 |
|
+ "\nor remove the specification from the configuration file to use the default algorithm (SHA-1).", |
410 |
|
SAWSTextOutputCallback.WARNING); |
411 |
0
|
System.exit(-1); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
} |
416 |
|
|
417 |
8
|
NodeList nl3= root.getElementsByTagName("UserInfo"); |
418 |
8
|
int leng = nl3.getLength(); |
419 |
|
|
420 |
24
|
for (int i = 0; i < leng; i ++) { |
421 |
16
|
org.w3c.dom.Element e3 = (org.w3c.dom.Element) nl3.item (i); |
422 |
16
|
String UserDNString = DOMUtils.getAttribute(e3, "userDN"); |
423 |
16
|
UserDNString = issrg.utils.RFC2253NameParser.toCanonicalDN(UserDNString).toUpperCase(); |
424 |
16
|
Byte UserIDByte = new Byte( (byte) Integer.parseInt ( DOMUtils.getAttribute (e3, "userID") ) ); |
425 |
16
|
String userPKC = DOMUtils.getAttribute(e3, "userPKC"); |
426 |
|
|
427 |
16
|
PublicKey userPK = null; |
428 |
|
|
429 |
16
|
if (userPKC!= null) { |
430 |
16
|
userPK = retrievePublicKey(userPKC); |
431 |
|
} |
432 |
|
|
433 |
16
|
if ( UserDNString != null && UserIDByte != null ) { |
434 |
16
|
UserDNIDMap.put( UserDNString, UserIDByte); |
435 |
|
} |
436 |
|
|
437 |
16
|
if ( userPK!= null && UserIDByte != null ) { |
438 |
16
|
UserIDPKMap.put(UserIDByte, userPK); |
439 |
|
} |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
|
} |
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
|
|
| 38.7% |
Uncovered Elements: 19 (31) |
Complexity: 6 |
Complexity Density: 0.26 |
|
449 |
16
|
private PublicKey retrievePublicKey ( String PKCFilename) {... |
450 |
|
|
451 |
16
|
File f = new File(PKCFilename); |
452 |
16
|
if ( !f.exists() ) { |
453 |
0
|
String[] options = { "Continue", "Stop SAWS" }; |
454 |
0
|
int select = this.createConfirmCallback( |
455 |
|
"SAWS can't find the PKC file " + PKCFilename + ". " |
456 |
|
+ "\nYou will not be able to use the corresponding user Private Key to read the log file " |
457 |
|
+ "\nif the log file is encrypted. " |
458 |
|
+ "\nDo you want to continue? \n", options, SAWSChoiceCallback.WARNING, |
459 |
|
"MissingPKCFile"); |
460 |
|
|
461 |
0
|
if ( select == 1) |
462 |
0
|
System.exit(-1); |
463 |
0
|
return null; |
464 |
|
} |
465 |
|
|
466 |
16
|
PublicKey pk = null; |
467 |
16
|
try{ |
468 |
16
|
FileInputStream fis = new FileInputStream(PKCFilename); |
469 |
16
|
BufferedInputStream bis = new BufferedInputStream(fis); |
470 |
16
|
java.security.cert.CertificateFactory cf = null; |
471 |
16
|
cf = java.security.cert.CertificateFactory.getInstance("X.509"); |
472 |
16
|
java.security.cert.Certificate certTemp = cf.generateCertificate(bis); |
473 |
16
|
pk = certTemp.getPublicKey(); |
474 |
|
} catch (Exception e2) { |
475 |
0
|
if (debugLevel > SAWSConstant.ErrorInfo) |
476 |
|
|
477 |
|
|
478 |
0
|
sawsDebugLog.write(e2.toString()); |
479 |
0
|
String[] options = { "Continue", "Stop SAWS" }; |
480 |
|
|
481 |
0
|
int select = this.createConfirmCallback( |
482 |
|
"SAWS can't read the public key from the PKC file " + PKCFilename + "." |
483 |
|
+ "\nYou will not be able to use the corresponding user Private Key to read the log file " |
484 |
|
+ "\nif the log file is encrypted. " |
485 |
|
+ "\nDo you want to continue? \n", options, |
486 |
|
SAWSChoiceCallback.WARNING, "ReadingPKWarning"); |
487 |
|
|
488 |
0
|
if ( select == 1) |
489 |
0
|
System.exit(-1); |
490 |
0
|
return null; |
491 |
|
} |
492 |
|
|
493 |
16
|
return pk; |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@param |
502 |
|
|
503 |
|
@return |
504 |
|
|
|
|
| 66.2% |
Uncovered Elements: 22 (65) |
Complexity: 13 |
Complexity Density: 0.28 |
|
505 |
4
|
private void sawsInit() {... |
506 |
|
|
507 |
4
|
File logRoot = new File(logFileRoot); |
508 |
4
|
if ( !logRoot.exists() ) |
509 |
0
|
logRoot.mkdir(); |
510 |
4
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
511 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
512 |
|
this.hashAlgorithm, this.callbackHandler); |
513 |
4
|
tcbKM.checkSigningKeystoreFile(); |
514 |
4
|
tcbKM.checkEncKeystoreFile(); |
515 |
4
|
tcbKM.readKeystores(); |
516 |
4
|
sawsTCBSecretKey = tcbKM.getsawsTCBSecretKey(); |
517 |
4
|
if (sawsTCBSecretKey == null) { |
518 |
0
|
this.showMessage("SAWS cannot generate the necessary secret key for the TCB. " |
519 |
|
+ "There is probably some problem with your Java cryptography libray." |
520 |
|
+ "\nSAWS will stop.", SAWSTextOutputCallback.WARNING); |
521 |
0
|
System.exit(-1); |
522 |
|
} |
523 |
4
|
paramSpec = tcbKM.getparamSpec(); |
524 |
|
|
525 |
4
|
readTCBContent(trustedLocation); |
526 |
|
|
527 |
4
|
if ( (previousLogFilenameFromLogRoot == null) && (currentInspectionLogFilename == null) ) { |
528 |
1
|
String[] options = { "OK", "NO-ABORT" }; |
529 |
1
|
int selection = this.createConfirmCallback("This is the first time that SAWS has been started.", |
530 |
|
options, SAWSChoiceCallback.WARNING, "FirstTimeInitialization"); |
531 |
1
|
if (selection == 1 ) { |
532 |
0
|
System.exit(-1); |
533 |
|
} |
534 |
|
} |
535 |
|
|
536 |
4
|
latestLogFilename = lfc.generateNewLogFileName(); |
537 |
4
|
currentLogFileWriter = new LogFileWriter(logFileRoot, latestLogFilename, |
538 |
|
tcbKM.getvtEncryptionPublicKey(), |
539 |
|
tcbKM.getsawsEncryptionPublicKey(), |
540 |
|
tcbKM.getsawsSigningPrivateKey(), |
541 |
|
tcbKM.getbaSigningPublicKeyCert(), |
542 |
|
this.hashAlgorithm, |
543 |
|
null, |
544 |
|
UserIDPKMap, this.callbackHandler); |
545 |
4
|
currentLogFileWriter.setDebugLevel(debugLevel); |
546 |
4
|
int ret = currentLogFileWriter.prepareNewLog(); |
547 |
4
|
if (ret != 0) { |
548 |
0
|
System.exit(-1); |
549 |
|
} |
550 |
4
|
tcbContent = new TCBContentRW(trustedLocation, sawsTCBSecretKey, paramSpec, |
551 |
|
debugLevel, this.callbackHandler); |
552 |
4
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
553 |
|
currentLogFileWriter.getAccHash()); |
554 |
4
|
int result = tcbContent.write(); |
555 |
4
|
if (result != 0) { |
556 |
0
|
this.showMessage("SAWS cannot write to TCB correctly." |
557 |
|
+ "\nSAWS will stop.\n", SAWSTextOutputCallback.WARNING); |
558 |
0
|
closeLog(); |
559 |
0
|
System.exit(-1); |
560 |
|
} |
561 |
|
|
562 |
4
|
if ( (previousLogFilenameFromLogRoot == null) && (currentInspectionLogFilename == null) ) { |
563 |
1
|
currentLogFileWriter.createLastFileRecord("This is the very first SAWS log file.", |
564 |
|
"null".getBytes(), "null".getBytes() ); |
565 |
|
|
566 |
3
|
} else if ( (previousLogFilenameFromLogRoot != null) && (currentInspectionLogFilename == null ) ) { |
567 |
|
|
568 |
|
|
569 |
0
|
logFileList.addElement(previousLogFilenameFromLogRoot); |
570 |
0
|
currentLogFileWriter.createSAWSRecord(("" + SAWSConstant.TrustedLocationMissingErrCode + |
571 |
|
"; Trusted Location is missing and reconstructed." ).getBytes(), |
572 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
573 |
|
|
574 |
0
|
currentInspectionLogFilename = previousLogFilenameFromLogRoot; |
575 |
0
|
verifyOneLogFile(logFileRoot, currentInspectionLogFilename); |
576 |
0
|
currentLogFileWriter.createLastFileRecord(currentInspectionLogFilename, currentInspecitonAccHash, |
577 |
|
currentInspectionSignature); |
578 |
0
|
currentInspectionLogFilename = previousLogFilenameFromLogRecord; |
579 |
0
|
verifyLogFileChainWithPrompt(logFileRoot, currentInspectionLogFilename); |
580 |
|
|
581 |
3
|
} else if ( currentInspectionLogFilename != null ) { |
582 |
|
|
583 |
3
|
logFileList.addElement(currentInspectionLogFilename); |
584 |
3
|
verifyOneLogFile(logFileRoot, currentInspectionLogFilename); |
585 |
3
|
currentLogFileWriter.createLastFileRecord(currentInspectionLogFilename, currentInspecitonAccHash, |
586 |
|
currentInspectionSignature); |
587 |
3
|
currentInspectionLogFilename = previousLogFilenameFromLogRecord; |
588 |
3
|
verifyLogFileChainWithPrompt(logFileRoot, currentInspectionLogFilename); |
589 |
|
} |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
@param |
596 |
|
|
597 |
|
@return |
598 |
|
|
|
|
| 46.7% |
Uncovered Elements: 16 (30) |
Complexity: 8 |
Complexity Density: 0.44 |
|
599 |
4
|
public void sawsStart() {... |
600 |
4
|
if ( debugLevel> SAWSConstant.VerboseInfo && logFileList.size() != 0 ) { |
601 |
0
|
for (int i = logFileList.size()-1; i>=0 ; --i ) { |
602 |
0
|
String logFilename = (String) logFileList.get(i); |
603 |
|
|
604 |
0
|
sawsDebugLog.write(logFilename); |
605 |
|
} |
606 |
|
} |
607 |
|
|
608 |
4
|
if (this.closed) { |
609 |
0
|
this.showMessage("SAWS log file is already closed. SAWS have to be initialized again.", |
610 |
|
SAWSTextOutputCallback.WARNING); |
611 |
0
|
if ( debugLevel > SAWSConstant.NoInfo) { |
612 |
0
|
sawsDebugLog.write("SAWS log file is already closed when trying to start SAWS."); |
613 |
|
} |
614 |
|
} |
615 |
|
|
616 |
4
|
String[] options = { "Yes, continue", "No, stop SAWS" }; |
617 |
|
|
618 |
4
|
int selection = this.createConfirmCallback("SAWS has finished its initilisation process. " |
619 |
|
+ "\nNow SAWS can start to record client log records. Do you want to continue? \n", |
620 |
|
options, SAWSChoiceCallback.WARNING, "StartRecordingLogs"); |
621 |
4
|
if (selection == 1) { |
622 |
0
|
closeLog(); |
623 |
0
|
System.exit(-1); |
624 |
|
} |
625 |
|
|
626 |
4
|
thread = new WritingThread(); |
627 |
4
|
thread.start(); |
628 |
|
|
629 |
4
|
currentTime = System.currentTimeMillis(); |
630 |
4
|
if (heartbeatInterval != 0) { |
631 |
4
|
setHeartbeatWriter(heartbeatInterval); |
632 |
|
} |
633 |
|
|
634 |
|
} |
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
@param |
640 |
|
|
641 |
|
@return |
642 |
|
|
|
|
| 46% |
Uncovered Elements: 34 (63) |
Complexity: 12 |
Complexity Density: 0.29 |
|
643 |
4
|
private void readTCBContent(String trustedLocationLocal){... |
644 |
4
|
if (trustedLocationLocal == null) { |
645 |
|
|
646 |
0
|
this.showMessage("The trustedLocation is not present in the SAWS configuration file." |
647 |
|
+ "\nPlease set it correctly in the SAWS configuration file. \n" |
648 |
|
+ "\nSAWS will now stop.", SAWSTextOutputCallback.WARNING); |
649 |
0
|
System.exit(-1); |
650 |
|
} |
651 |
|
|
652 |
4
|
File TCBFile = new File(trustedLocationLocal); |
653 |
4
|
lfc = new LogFilenameClass(); |
654 |
4
|
if (!TCBFile.exists()) { |
655 |
1
|
String[] options = { "Create Trusted Location", "Stop SAWS", "Rebuild Trusted Location" }; |
656 |
1
|
int selection = this.createConfirmCallback( |
657 |
|
"SAWS cannot find the Trusted Location." |
658 |
|
+ "\n\nOption 1: A Trusted Location does not exist because this is the first time SAWS has been started. " |
659 |
|
+ "\nSAWS should create a new Trusted Location. " |
660 |
|
+ "\nOption 2: The Trusted Location has been lost due to computer failure, or the configuration file is wrong. " |
661 |
|
+ "\nSAWS should stop and then be manually restarted." |
662 |
|
+ "\nOption 3: The Trusted Location has been lost due to a compromise or computer failure. " |
663 |
|
+ "\nSAWS should try to rebuild it.", options, |
664 |
|
SAWSChoiceCallback.WARNING, "TrustedLocationNotFound"); |
665 |
0
|
if (selection == 1) System.exit(-1); |
666 |
|
|
667 |
1
|
if (selection == 2 ) { |
668 |
|
|
669 |
0
|
previousLogFilenameFromLogRoot = lfc.findLatestLogFileName(logFileRoot); |
670 |
0
|
currentInspectionLogFilename = null; |
671 |
0
|
AccHashFromTCB = null; |
672 |
|
} |
673 |
1
|
if (selection == 0 ) { |
674 |
1
|
previousLogFilenameFromLogRoot = null; |
675 |
1
|
currentInspectionLogFilename = null; |
676 |
1
|
AccHashFromTCB = null; |
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
} else { |
681 |
3
|
previousLogFilenameFromLogRoot = lfc.findLatestLogFileName(logFileRoot); |
682 |
3
|
tcbContent = new TCBContentRW(trustedLocationLocal, sawsTCBSecretKey, |
683 |
|
paramSpec, debugLevel, this.callbackHandler); |
684 |
3
|
int ret = tcbContent.read(); |
685 |
3
|
if (ret !=0 ) { |
686 |
0
|
String[] options = { "SAWS Stop", "Rebuild TCBLocation" }; |
687 |
|
|
688 |
0
|
int selection = this.createConfirmCallback( |
689 |
|
"Data corruption for the Trusted Location. " |
690 |
|
+ "\nOption 1: The Trusted Location has been tampered with. " |
691 |
|
+ "\nSAWS should stop and then the administrator needs to investigate it manually." |
692 |
|
+ "\nOption 2: SAWS will rebuild the Trusted Location.", |
693 |
|
options, SAWSChoiceCallback.WARNING, "TrustedLocationDataCorruption"); |
694 |
0
|
if (selection == 0 ) System.exit(-1); |
695 |
0
|
if (selection == 1) { |
696 |
0
|
previousLogFilenameFromLogRoot = lfc.findLatestLogFileName(logFileRoot); |
697 |
0
|
currentInspectionLogFilename = null; |
698 |
0
|
AccHashFromTCB = null; |
699 |
|
} |
700 |
|
|
701 |
|
} else { |
702 |
3
|
currentInspectionLogFilename= tcbContent.getLastFilename(); |
703 |
3
|
SNFromTCB = tcbContent.getLastSN(); |
704 |
3
|
AccHashFromTCB = tcbContent.getLastAccHash(); |
705 |
|
|
706 |
3
|
File cLogFile = new File(logFileRoot, currentInspectionLogFilename ); |
707 |
|
|
708 |
3
|
if ( !cLogFile.exists() ) { |
709 |
0
|
String[] options = { "Stop", "Continue"}; |
710 |
|
|
711 |
0
|
int selection = this.createConfirmCallback( |
712 |
|
"SAWS cannot find the current log file for verification: " + currentInspectionLogFilename |
713 |
|
+ " \n\nOption 1: The current log file is missing because of tampering. " |
714 |
|
+ "\nSAWS will stop and the SAWS administrator needs to check it manually. " |
715 |
|
+ "\nOption 2: The current log file is missing because of tampering or computer failure. " |
716 |
|
+ "\nSAWS will continue to verify the next previous file. ", |
717 |
|
options, SAWSChoiceCallback.WARNING, "MissingCurrentVerifyingLogFile"); |
718 |
|
|
719 |
0
|
if (selection == 0) |
720 |
0
|
System.exit(-1); |
721 |
0
|
if (selection == 1) { |
722 |
0
|
currentInspectionLogFilename = previousLogFilenameFromLogRoot; |
723 |
|
} |
724 |
|
|
725 |
|
} |
726 |
|
} |
727 |
|
} |
728 |
|
} |
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
@param |
737 |
|
@param |
738 |
|
|
739 |
|
@return |
740 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
741 |
0
|
private void pickupAllPreviousLogFileNames(String logFileRoot, String cLogFileName) {... |
742 |
0
|
currentInspectionLogFilename = cLogFileName; |
743 |
0
|
while ( currentInspectionLogFilename != null ){ |
744 |
0
|
File logF = new File(logFileRoot, currentInspectionLogFilename); |
745 |
0
|
if ( logF.exists()) { |
746 |
0
|
pickupOnePreviousLogFileName(logFileRoot, currentInspectionLogFilename); |
747 |
0
|
currentInspectionLogFilename = previousLogFilenameFromLogRecord; |
748 |
|
} else { |
749 |
0
|
this.showMessage("SAWS cannot find the previous log file for reading: " + currentInspectionLogFilename |
750 |
|
+ " \n\nSAWS will stop and the SAWS administrator needs to restart SAWS to check it. ", |
751 |
|
SAWSTextOutputCallback.WARNING); |
752 |
0
|
currentLogFileWriter.createSAWSRecord(("" + SAWSConstant.LogFileMissingErrCode + |
753 |
|
";" + currentInspectionLogFilename + |
754 |
|
";This log file is missing." ).getBytes(), |
755 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
756 |
0
|
closeLog(); |
757 |
0
|
System.exit(-1); |
758 |
|
} |
759 |
|
} |
760 |
|
} |
761 |
|
|
762 |
|
|
763 |
|
|
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
@param |
768 |
|
@param |
769 |
|
|
770 |
|
@return |
771 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 5 |
Complexity Density: 0.24 |
|
772 |
0
|
private void pickupOnePreviousLogFileName(String logFileRoot, String inspectLogFile) {... |
773 |
0
|
String cLogFilename = inspectLogFile; |
774 |
0
|
LogFileReader rr = new LogFileReader(debugLevel, this.callbackHandler); |
775 |
0
|
rr.setSAWSPrivateKey(tcbKM.getsawsEncryptionPrivateKey()); |
776 |
0
|
try { |
777 |
0
|
rr.setLogFilename(logFileRoot, cLogFilename); |
778 |
|
} catch (logReadingException e) { |
779 |
|
|
780 |
0
|
this.showMessage("The error for the log file " + cLogFilename + " is: " |
781 |
|
+ SAWSConstant.getErrorString(e.getErrorCode()) |
782 |
|
+ "\n\nThis log file cannot be read. " |
783 |
|
+ "\nSAWS will stop. Please restart SAWS to check it. ", |
784 |
|
SAWSTextOutputCallback.WARNING); |
785 |
0
|
closeLog(); |
786 |
0
|
System.exit(-1); |
787 |
|
} |
788 |
0
|
byte[] secureRandomB = null; |
789 |
0
|
try{ |
790 |
0
|
try{ |
791 |
0
|
secureRandomB = rr.getSecureRandomNumber(tcbKM.getsawsEncryptionPrivateKey()); |
792 |
|
} catch (logReadingException secureHashError){ |
793 |
0
|
secureHashError.setErrorCode(SAWSConstant.SecureRandomRecordErrCode); |
794 |
0
|
throw secureHashError; |
795 |
|
} |
796 |
0
|
previousLogFilenameFromLogRecord = rr.findPreviousLogfileName(secureRandomB); |
797 |
|
|
798 |
0
|
if (previousLogFilenameFromLogRecord!=null ) { |
799 |
0
|
logFileList.addElement(previousLogFilenameFromLogRecord); |
800 |
|
} |
801 |
|
|
802 |
|
} catch (logReadingException e){ |
803 |
|
|
804 |
0
|
this.showMessage("The error for the log file " + cLogFilename + " is: " |
805 |
|
+ SAWSConstant.getErrorString(e.getErrorCode()) |
806 |
|
+ "\n\nThis log file has been tampered with and it cannot be read. " |
807 |
|
+ "\nSAWS will stop. Please restart SAWS to check it. ", |
808 |
|
SAWSTextOutputCallback.WARNING); |
809 |
0
|
closeLog(); |
810 |
0
|
System.exit(-1); |
811 |
|
} |
812 |
|
|
813 |
0
|
return; |
814 |
|
} |
815 |
|
|
816 |
|
|
817 |
|
|
818 |
|
|
819 |
|
|
820 |
|
@param |
821 |
|
@param |
822 |
|
|
823 |
|
|
|
|
| 56.4% |
Uncovered Elements: 17 (39) |
Complexity: 8 |
Complexity Density: 0.32 |
|
824 |
3
|
private void verifyLogFileChainWithPrompt(String logFileRoot, String cLogFileName) {... |
825 |
3
|
currentInspectionLogFilename = cLogFileName; |
826 |
3
|
AccHashFromTCB = null; |
827 |
3
|
boolean inspectAll = false; |
828 |
14
|
while ( currentInspectionLogFilename != null ){ |
829 |
|
|
830 |
11
|
int selection = 0; |
831 |
11
|
if ( !inspectAll ) { |
832 |
3
|
String[] options = { "No", "Check it", "Check all" }; |
833 |
|
|
834 |
3
|
selection = this.createConfirmCallback( |
835 |
|
"This log file: " + currentInspectionLogFilename + " was created by SAWS before." |
836 |
|
+ " Do you want SAWS to check it? " |
837 |
|
+ "\n\nOption 1: No, SAWS will ignore the log file and start to record client records." |
838 |
|
+ "\nOption 2: Yes, SAWS will check this log file only" |
839 |
|
+ "\nOption 3: SAWS will check this log file and all previous log files " |
840 |
|
+ "linked by this log file.", options, |
841 |
|
SAWSChoiceCallback.WARNING, "CheckExistingLogFile"); |
842 |
|
|
843 |
|
|
844 |
3
|
if (selection == 0) { |
845 |
0
|
pickupAllPreviousLogFileNames(logFileRoot, currentInspectionLogFilename); |
846 |
0
|
return; |
847 |
|
} |
848 |
3
|
if (selection == 2) |
849 |
3
|
inspectAll = true; |
850 |
|
} |
851 |
|
|
852 |
11
|
File logF = new File(logFileRoot, currentInspectionLogFilename); |
853 |
11
|
if ( logF.exists()) { |
854 |
11
|
verifyOneLogFile(logFileRoot, currentInspectionLogFilename); |
855 |
11
|
currentInspectionLogFilename = previousLogFilenameFromLogRecord; |
856 |
|
} else { |
857 |
0
|
String[] options = { "Stop", "Continue" }; |
858 |
|
|
859 |
0
|
selection = this.createConfirmCallback( |
860 |
|
"SAWS cannot find the log file for verification: " + currentInspectionLogFilename + "." |
861 |
|
+ "\n\nOption 1: This log file is missing because of tampering. " |
862 |
|
+ "\nSAWS will stop and the SAWS administrator needs to check it manually. " |
863 |
|
+ "\nOption 2: The current log file is missing because of tampering or computer failure. " |
864 |
|
+ "\nSAWS will continue to verify the next previous file. ", |
865 |
|
options, SAWSChoiceCallback.WARNING, "CheckExistingLogFile"); |
866 |
|
|
867 |
|
|
868 |
0
|
currentLogFileWriter.createSAWSRecord(("" + SAWSConstant.LogFileMissingErrCode + |
869 |
|
";" + currentInspectionLogFilename + ";" + selection + |
870 |
|
";This log file is missing." ).getBytes(), |
871 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
872 |
0
|
if (selection == 0){ |
873 |
0
|
closeLog(); |
874 |
0
|
System.exit(-1); |
875 |
|
} |
876 |
0
|
if (selection == 1) { |
877 |
0
|
currentInspectionLogFilename = |
878 |
|
lfc.getPreviousLogFilename(logFileRoot, currentInspectionLogFilename); |
879 |
|
} |
880 |
|
|
881 |
|
} |
882 |
|
} |
883 |
|
|
884 |
|
} |
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
@param |
890 |
|
@param |
891 |
|
|
892 |
|
@return |
893 |
|
|
|
|
| 29.8% |
Uncovered Elements: 66 (94) |
Complexity: 18 |
Complexity Density: 0.26 |
|
894 |
28
|
private int verifyOneLogFile(String logFileRoot, String inspectLogFile){... |
895 |
28
|
String cLogFilename = inspectLogFile; |
896 |
28
|
LogFileReader rr = new LogFileReader(debugLevel, this.callbackHandler); |
897 |
28
|
rr.setSAWSPrivateKey(tcbKM.getsawsEncryptionPrivateKey()); |
898 |
|
|
899 |
28
|
try { |
900 |
28
|
rr.setLogFilename(logFileRoot, cLogFilename); |
901 |
|
} catch (logReadingException e) { |
902 |
|
|
903 |
|
|
904 |
|
|
905 |
|
|
906 |
|
|
907 |
|
|
908 |
|
|
909 |
|
|
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
|
914 |
0
|
this.showMessage("The error for the log file " + cLogFilename + " is: " |
915 |
|
+ SAWSConstant.getErrorString(e.getErrorCode()) |
916 |
|
+ "\n\nThis log file cannot be read. " |
917 |
|
+ "\nSAWS will stop. Please restart SAWS to check it. ", |
918 |
|
SAWSTextOutputCallback.WARNING); |
919 |
0
|
closeLog(); |
920 |
0
|
System.exit(-1); |
921 |
|
} |
922 |
28
|
byte[] secureRandomB = null; |
923 |
28
|
try{ |
924 |
28
|
try{ |
925 |
28
|
secureRandomB = rr.getSecureRandomNumber(tcbKM.getsawsEncryptionPrivateKey()); |
926 |
|
} catch (logReadingException secureRandomError){ |
927 |
0
|
secureRandomError.setErrorCode(SAWSConstant.SecureRandomRecordErrCode); |
928 |
0
|
throw secureRandomError; |
929 |
|
} |
930 |
28
|
rr.checkLogFile(secureRandomB); |
931 |
28
|
rr.checkSignature(tcbKM.getrootCAPublicKey()); |
932 |
28
|
recordBlockListFromOneLogFile = rr.getRecordBlockList(); |
933 |
28
|
int currentRecordWriteCount = rr.getCurrentSN(); |
934 |
28
|
currentInspecitonAccHash = rr.getAccumulatedHashFromLog(); |
935 |
28
|
currentInspectionSignature = rr.getSignatureFromLog(); |
936 |
28
|
if ( AccHashFromTCB != null) { |
937 |
3
|
if(SNFromTCB != currentRecordWriteCount ){ |
938 |
0
|
String[] options = { "Stop", "Continue after tampering", "Continue after crash" }; |
939 |
|
|
940 |
0
|
int selection = this.createConfirmCallback( |
941 |
|
"The last sequence number " + currentRecordWriteCount + " of the log file " + cLogFilename |
942 |
|
+ "\nis not equal to the last sequence number " + SNFromTCB + " in the Trusted Location" |
943 |
|
+ "\n\nOption 1: Either the log file or the Trusted Location has been tampered with. " |
944 |
|
+ "\nSAWS will stop and the SAWS administrator needs to check it manually." |
945 |
|
+ "\nOption 2: Either the log file or the Trusted Location has been tampered with, " |
946 |
|
+ "\nSAWS will record this incident, update the Trusted Location and continue." |
947 |
|
+ "\nOption 3: This error is due to computer crash. " |
948 |
|
+ "\nSAWS will record this incident, update the Trusted Location and continue.", |
949 |
|
options, SAWSChoiceCallback.WARNING, "SequenceNumberDifferentFromTCB"); |
950 |
|
|
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
|
|
958 |
|
|
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
0
|
currentLogFileWriter.createSAWSRecord( |
964 |
|
("" + SAWSConstant.SNNotMatchBetweenLogAndTCBLocationErrCode + |
965 |
|
";" + cLogFilename + ";" + currentRecordWriteCount + ";" + SNFromTCB + |
966 |
|
";" + selection +";Sequence number does not match." ).getBytes(), |
967 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
968 |
0
|
if (selection == 0) { |
969 |
0
|
closeLog(); |
970 |
0
|
System.exit(-1); |
971 |
|
} |
972 |
|
} |
973 |
|
|
974 |
3
|
if ( utility.toHexString(AccHashFromTCB).compareTo( |
975 |
|
utility.toHexString(currentInspecitonAccHash)) != 0 ) { |
976 |
0
|
String[] options = { "Stop", "Continue after tampering", "Continue after crash" }; |
977 |
|
|
978 |
0
|
int selection = this.createConfirmCallback( |
979 |
|
"The accumulated hash of the log file " + cLogFilename |
980 |
|
+ "is not equal to the one in the Trusted Location" |
981 |
|
+ "\n\nOption 1: Either the log file or the Trusted Location has been tampered with. " |
982 |
|
+ "\nSAWS will stop and the SAWS administrator needs to check it manually." |
983 |
|
+ "\nOption 2: Either the log file or the Trusted Location has been tampered with, " |
984 |
|
+ "\nSAWS will record this incident, update the Trusted Location and continue." |
985 |
|
+ "\nOption 3: This error is due to computer crash. " |
986 |
|
+ "\nSAWS will record this incident, update the Trusted Location and continue.", |
987 |
|
options, SAWSChoiceCallback.WARNING, "AccHashDifferentFromTCB"); |
988 |
|
|
989 |
|
|
990 |
|
|
991 |
|
|
992 |
|
|
993 |
|
|
994 |
|
|
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
0
|
currentLogFileWriter.createSAWSRecord( |
1002 |
|
("" + SAWSConstant.AccHashNotMatchBetweenLogAndTCBLocationErrCode + |
1003 |
|
";" + cLogFilename + ";" + utility.toHexString(currentInspecitonAccHash) + ";" + |
1004 |
|
utility.toHexString(AccHashFromTCB) + |
1005 |
|
";" + selection +";accumualted hash does not match." ).getBytes(), |
1006 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
1007 |
0
|
if (selection == 0) { |
1008 |
0
|
closeLog(); |
1009 |
0
|
System.exit(-1); |
1010 |
|
} |
1011 |
|
|
1012 |
|
} |
1013 |
|
} |
1014 |
28
|
previousLogFilenameFromLogRecord = rr.getPreviousLogfileName(); |
1015 |
|
|
1016 |
|
|
1017 |
|
} catch (logReadingException e){ |
1018 |
0
|
if ( e.getErrorCode() != SAWSConstant.LogFileIncompleteErrCode ) { |
1019 |
0
|
String[] options = { "Stop", "Continue after tampering", "Continue after crash" }; |
1020 |
|
|
1021 |
0
|
int selection = this.createConfirmCallback( |
1022 |
|
"The error for the log file " + cLogFilename + " is: " |
1023 |
|
+ SAWSConstant.getErrorString(e.getErrorCode()) |
1024 |
|
+ "\n\nOption 1: This log file has been tampered with and it cannot be recovered. " |
1025 |
|
+ "\nSAWS will record this incident and stop." |
1026 |
|
+ "The SAWS administrator needs to check it manually." |
1027 |
|
+ "\nOption 2: The log file has been tampered with. SAWS will record this incident and continue." |
1028 |
|
+ "\nOption 3: This error is due to computer crash. SAWS will record this incident and continue. ", |
1029 |
|
options, SAWSChoiceCallback.WARNING, "CannotRecoverLogFile"); |
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
|
|
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
|
|
1039 |
|
|
1040 |
|
|
1041 |
|
|
1042 |
|
|
1043 |
0
|
currentLogFileWriter.createSAWSRecord( |
1044 |
|
("" + e.getErrorCode() + |
1045 |
|
";" + cLogFilename + ";" + selection + ";" + e.getSequence() +";" + |
1046 |
|
SAWSConstant.getErrorString(e.getErrorCode()) ).getBytes(), |
1047 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
1048 |
0
|
if (selection == 0) { |
1049 |
0
|
closeLog(); |
1050 |
0
|
System.exit(-1); |
1051 |
|
} |
1052 |
0
|
currentInspecitonAccHash = "error".getBytes(); |
1053 |
0
|
currentInspectionSignature = "error".getBytes(); |
1054 |
0
|
previousLogFilenameFromLogRecord = |
1055 |
|
lfc.getPreviousLogFilename(logFileRoot, cLogFilename); |
1056 |
|
|
1057 |
|
|
1058 |
|
} |
1059 |
|
|
1060 |
0
|
if ( e.getErrorCode() == SAWSConstant.LogFileIncompleteErrCode ) { |
1061 |
0
|
String[] options = { "Stop", "Recover this log", "Ignore this log" }; |
1062 |
|
|
1063 |
0
|
int selection = this.createConfirmCallback( |
1064 |
|
"The error for the log file " + cLogFilename + " is: " |
1065 |
|
+ SAWSConstant.getErrorString(e.getErrorCode()) |
1066 |
|
+ "\n\nOption 1: This log file has been tampered with. " |
1067 |
|
+ "\nSAWS will record this incident and stop." |
1068 |
|
+ "The SAWS administrator needs to check it manually." |
1069 |
|
+ "\nOption 2: This error is a computer crash. SAWS will recover this log file and continue." |
1070 |
|
+ "\nOption 3: SAWS will ignore this log and continue. ", |
1071 |
|
options, SAWSChoiceCallback.WARNING, "ReadingLogFileError"); |
1072 |
|
|
1073 |
|
|
1074 |
|
|
1075 |
|
|
1076 |
|
|
1077 |
|
|
1078 |
|
|
1079 |
|
|
1080 |
|
|
1081 |
|
|
1082 |
|
|
1083 |
|
|
1084 |
|
|
1085 |
0
|
currentLogFileWriter.createSAWSRecord( |
1086 |
|
("" + e.getErrorCode() + |
1087 |
|
";" + cLogFilename + ";" + selection + ";" + e.getSequence() +";" + |
1088 |
|
SAWSConstant.getErrorString(e.getErrorCode()) ).getBytes(), |
1089 |
|
SAWSConstant.SysAuditorNotificationType, SAWSConstant.NoEncryptionFlag); |
1090 |
0
|
if (selection == 0) { |
1091 |
0
|
closeLog(); |
1092 |
0
|
System.exit(-1); |
1093 |
|
} |
1094 |
0
|
if (selection == 1) { |
1095 |
0
|
LogFileWriter repairWriter = new LogFileWriter(logFileRoot, cLogFilename, |
1096 |
|
tcbKM.getvtEncryptionPublicKey(), |
1097 |
|
tcbKM.getsawsEncryptionPublicKey(), |
1098 |
|
tcbKM.getsawsSigningPrivateKey(), |
1099 |
|
tcbKM.getbaSigningPublicKeyCert(), |
1100 |
|
this.hashAlgorithm, |
1101 |
|
secureRandomB, |
1102 |
|
null ); |
1103 |
0
|
int ret = repairWriter.repairLog(logFileRoot, cLogFilename, secureRandomB, e); |
1104 |
0
|
currentInspecitonAccHash = repairWriter.getAccHash(); |
1105 |
0
|
currentInspectionSignature = repairWriter.getSignature(); |
1106 |
0
|
previousLogFilenameFromLogRecord = |
1107 |
|
lfc.getPreviousLogFilename(logFileRoot, cLogFilename); |
1108 |
|
|
1109 |
0
|
if (ret !=0) { |
1110 |
0
|
return -1; |
1111 |
|
} |
1112 |
|
} |
1113 |
0
|
if (selection == 2) { |
1114 |
0
|
currentInspecitonAccHash = "error".getBytes(); |
1115 |
0
|
currentInspectionSignature = "error".getBytes(); |
1116 |
0
|
previousLogFilenameFromLogRecord = |
1117 |
|
lfc.getPreviousLogFilename(logFileRoot, cLogFilename); |
1118 |
|
|
1119 |
|
} |
1120 |
|
|
1121 |
|
} |
1122 |
|
|
1123 |
|
} |
1124 |
|
|
1125 |
28
|
if (previousLogFilenameFromLogRecord!=null && currentReadingFileNo==0 ) { |
1126 |
|
|
1127 |
|
|
1128 |
11
|
logFileList.addElement(previousLogFilenameFromLogRecord); |
1129 |
|
} |
1130 |
28
|
return 0; |
1131 |
|
} |
1132 |
|
|
1133 |
|
|
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
@param |
1138 |
|
|
1139 |
|
@return |
1140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
1141 |
18
|
public Vector sawsReadOneLogFile() {... |
1142 |
18
|
if (currentReadingFileNo == logFileList.size()){ |
1143 |
4
|
return null; |
1144 |
|
} |
1145 |
|
|
1146 |
14
|
verifyOneLogFile( logFileRoot, (String) logFileList.get(logFileList.size()- 1 - (currentReadingFileNo++) ) ); |
1147 |
|
|
1148 |
14
|
return recordBlockListFromOneLogFile; |
1149 |
|
} |
1150 |
|
|
1151 |
|
|
1152 |
|
|
1153 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
1154 |
4
|
public void closeLog(){... |
1155 |
4
|
if (this.tt2 != null) { |
1156 |
4
|
((HeartbeatRecordWriting)this.tt2).setStop(true); |
1157 |
4
|
timer.cancel(); |
1158 |
|
} |
1159 |
4
|
currentLogFileWriter.finalizeLogFile(); |
1160 |
4
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
1161 |
|
currentLogFileWriter.getAccHash()); |
1162 |
4
|
int result = tcbContent.write(); |
1163 |
4
|
if (result != 0) { |
1164 |
|
|
1165 |
|
|
1166 |
|
|
1167 |
|
|
1168 |
|
|
1169 |
|
|
1170 |
|
|
1171 |
|
|
1172 |
|
|
1173 |
0
|
this.showMessage("SAWS cannot write to TCB correctly. " + |
1174 |
|
"\nSAWS will stop. \n", SAWSTextOutputCallback.WARNING); |
1175 |
0
|
System.exit(-1); |
1176 |
|
} |
1177 |
4
|
this.closed = true; |
1178 |
|
|
1179 |
|
} |
1180 |
|
|
1181 |
|
|
1182 |
|
|
1183 |
|
|
1184 |
|
|
1185 |
|
|
1186 |
|
@param |
1187 |
|
@return |
1188 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
1189 |
65
|
public RecordStatus sendLogRecord(byte[] messageBlock) {... |
1190 |
65
|
byte flag; |
1191 |
65
|
if ( (logEncryption == null) || (logEncryption.compareTo("no")==0 ) ) { |
1192 |
0
|
flag = (byte) SAWSConstant.NoEncryptionFlag; |
1193 |
|
} else { |
1194 |
65
|
flag = (byte) SAWSConstant.SymmetricEncryptionFlag; |
1195 |
|
} |
1196 |
65
|
return sendLogRecord( messageBlock, flag ); |
1197 |
|
} |
1198 |
|
|
1199 |
|
|
1200 |
|
|
1201 |
|
|
1202 |
|
|
1203 |
|
|
1204 |
|
@param |
1205 |
|
@param |
1206 |
|
|
1207 |
|
|
1208 |
|
|
1209 |
|
|
1210 |
|
@return |
1211 |
|
|
|
|
| 51.7% |
Uncovered Elements: 29 (60) |
Complexity: 16 |
Complexity Density: 0.42 |
|
1212 |
65
|
public RecordStatus sendLogRecord(byte[] messageBlock, byte encryptionFlag ){... |
1213 |
65
|
if (this.closed) { |
1214 |
0
|
return new RecordStatus(-1, SAWSConstant.LogFileClosed); |
1215 |
|
} |
1216 |
|
|
1217 |
65
|
if ( (encryptionFlag != SAWSConstant.NoEncryptionFlag) && |
1218 |
|
(encryptionFlag != SAWSConstant.SymmetricEncryptionFlag) && |
1219 |
|
(encryptionFlag != SAWSConstant.CommandFlag)) { |
1220 |
0
|
return new RecordStatus(-1, SAWSConstant.InvalidEncryptionFlag); |
1221 |
|
} |
1222 |
|
|
1223 |
65
|
String mBlock = new String(messageBlock); |
1224 |
65
|
if ( (encryptionFlag == (byte)SAWSConstant.CommandFlag) && (mBlock.compareTo("closeLogFile") == 0) ) { |
1225 |
|
|
1226 |
0
|
while ( (busyFlag0V == true ) || (busyFlag1V == true ) ) { |
1227 |
0
|
if (debugLevel > SAWSConstant.NoInfo) |
1228 |
0
|
System.err.println("wait............."); |
1229 |
|
} |
1230 |
0
|
currentLogFileWriter.finalizeLogFile(); |
1231 |
0
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
1232 |
|
currentLogFileWriter.getAccHash()); |
1233 |
0
|
tcbContent.write(); |
1234 |
0
|
this.closed = true; |
1235 |
0
|
System.exit(0); |
1236 |
|
} |
1237 |
|
|
1238 |
65
|
byte userID = (byte)0x00; |
1239 |
65
|
String userdn = null; |
1240 |
65
|
if ( SAWSInterface.compareTo("webservice") == 0 ) { |
1241 |
0
|
userdn = getSSLDN(); |
1242 |
0
|
Byte B1 = (Byte) UserDNIDMap.get(userdn) ; |
1243 |
0
|
if (B1 == null) |
1244 |
0
|
return new RecordStatus(-1, SAWSConstant.UnauthorizedUser); |
1245 |
0
|
userID = (byte) (B1.byteValue()); |
1246 |
|
|
1247 |
|
} |
1248 |
|
|
1249 |
65
|
if ( busyFlag0V == false) { |
1250 |
64
|
if (debugLevel > SAWSConstant.NoInfo) { |
1251 |
0
|
sawsDebugLog.write("\nThis is in sending thread when busyFlag0V == false"); |
1252 |
|
} |
1253 |
64
|
busyFlag0V = true; |
1254 |
64
|
WaitingRecordBlock wRecordBlock = new WaitingRecordBlock(messageBlock, SAWSConstant.SAWSClientLogDataType, |
1255 |
|
encryptionFlag, userID); |
1256 |
64
|
waitingRecordList0.addElement(wRecordBlock); |
1257 |
64
|
busyFlag0V = false; |
1258 |
|
|
1259 |
|
} else { |
1260 |
1
|
if (debugLevel > SAWSConstant.VerboseInfo) { |
1261 |
0
|
sawsDebugLog.write("\nThis is in sending thread when busyFlag1V == false"); |
1262 |
|
} |
1263 |
1
|
busyFlag1V = true; |
1264 |
1
|
WaitingRecordBlock wRecordBlock = new WaitingRecordBlock(messageBlock, SAWSConstant.SAWSClientLogDataType, |
1265 |
|
encryptionFlag, userID); |
1266 |
1
|
waitingRecordList1.addElement(wRecordBlock); |
1267 |
1
|
busyFlag1V = false; |
1268 |
|
|
1269 |
|
} |
1270 |
1531445
|
while (writingHeartBeating) {} |
1271 |
65
|
thread.run(); |
1272 |
65
|
return new RecordStatus(0, currentLogFileWriter.getCurrentRecordWriteCount()); |
1273 |
|
} |
1274 |
|
|
1275 |
|
|
1276 |
|
|
1277 |
|
|
1278 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1279 |
0
|
public void outputPKCRequest() {... |
1280 |
0
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1281 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, |
1282 |
|
debugLevel, this.hashAlgorithm, this.callbackHandler); |
1283 |
0
|
tcbKM.outputPKCRequest(); |
1284 |
|
} |
1285 |
|
|
1286 |
|
|
1287 |
|
|
1288 |
|
|
1289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1290 |
1
|
public void exportSigningPKC() {... |
1291 |
1
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1292 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1293 |
|
this.hashAlgorithm, this.callbackHandler); |
1294 |
1
|
tcbKM.exportSigningPKC(); |
1295 |
|
} |
1296 |
|
|
1297 |
|
|
1298 |
|
|
1299 |
|
|
1300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1301 |
1
|
public void createEncryptionKeystore(){... |
1302 |
1
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1303 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1304 |
|
this.hashAlgorithm, this.callbackHandler); |
1305 |
1
|
tcbKM.createEncryptionKeystore(); |
1306 |
|
} |
1307 |
|
|
1308 |
|
|
1309 |
|
|
1310 |
|
|
1311 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1312 |
1
|
public void createSigningKeystore(){... |
1313 |
1
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1314 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1315 |
|
this.hashAlgorithm, this.callbackHandler); |
1316 |
1
|
tcbKM.createSigningKeystore(); |
1317 |
|
} |
1318 |
|
|
1319 |
|
|
1320 |
|
|
1321 |
|
|
1322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1323 |
1
|
public void importRootCA(){... |
1324 |
1
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1325 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1326 |
|
this.hashAlgorithm, this.callbackHandler); |
1327 |
1
|
tcbKM.checkSigningKeystoreFile(); |
1328 |
1
|
tcbKM.importRootCA(); |
1329 |
|
} |
1330 |
|
|
1331 |
|
|
1332 |
|
|
1333 |
|
|
1334 |
|
|
1335 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1336 |
0
|
public void importSigningPKC(){... |
1337 |
0
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1338 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1339 |
|
this.hashAlgorithm, this.callbackHandler); |
1340 |
0
|
tcbKM.checkSigningKeystoreFile(); |
1341 |
0
|
tcbKM.importSigningPKC(); |
1342 |
|
} |
1343 |
|
|
1344 |
|
|
1345 |
|
|
1346 |
|
|
1347 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1348 |
0
|
public void listSigningKeystore(){... |
1349 |
0
|
tcbKM = new TCBKeystoreManagement(signingKeystoreLocation, numberOfPasswordShares, |
1350 |
|
encryptionKeystoreLocation, numberOfEncPasswordShares, rootCA, vtPKC, debugLevel, |
1351 |
|
this.hashAlgorithm, this.callbackHandler); |
1352 |
0
|
tcbKM.checkSigningKeystoreFile(); |
1353 |
0
|
tcbKM.listSigningKeystore(); |
1354 |
|
} |
1355 |
|
|
1356 |
|
|
1357 |
|
|
1358 |
|
|
1359 |
|
@param |
1360 |
|
|
1361 |
|
@return |
1362 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
1363 |
0
|
private String getSSLDN() { ... |
1364 |
0
|
String issuerDN = null; |
1365 |
0
|
org.apache.axis.MessageContext mct = org.apache.axis.AxisEngine.getCurrentMessageContext(); |
1366 |
0
|
org.apache.axis.MessageContext context = mct.getCurrentContext(); |
1367 |
0
|
HttpServletRequest req = |
1368 |
|
(HttpServletRequest) context.getProperty( |
1369 |
|
org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST); |
1370 |
0
|
String certAttribute = "javax.servlet.request.X509Certificate"; |
1371 |
0
|
java.security.cert.X509Certificate[] certificate = |
1372 |
|
(java.security.cert.X509Certificate[]) req.getAttribute(certAttribute); |
1373 |
0
|
if (certificate != null) { |
1374 |
0
|
java.security.cert.X509Certificate certificateSource = certificate[0]; |
1375 |
0
|
if (certificateSource != null) { |
1376 |
|
|
1377 |
0
|
issuerDN = issrg.utils.RFC2253NameParser.toCanonicalDN(certificateSource.getSubjectDN().getName()).toUpperCase(); |
1378 |
0
|
if (debugLevel > SAWSConstant.NoInfo) |
1379 |
0
|
sawsDebugLog.write("DN is: " + issuerDN); |
1380 |
|
} |
1381 |
|
} else { |
1382 |
0
|
this.showMessage("Certificate is null.", SAWSTextOutputCallback.WARNING); |
1383 |
|
|
1384 |
|
} |
1385 |
|
|
1386 |
0
|
return issuerDN; |
1387 |
|
} |
1388 |
|
|
1389 |
|
|
1390 |
|
|
1391 |
|
|
1392 |
|
|
1393 |
|
|
|
|
| 87.7% |
Uncovered Elements: 7 (57) |
Complexity: 13 |
Complexity Density: 0.36 |
|
1394 |
|
class WritingThread extends Thread { |
1395 |
|
WaitingRecordBlock wRecordBlock = new WaitingRecordBlock(); |
1396 |
|
|
|
|
| 87.5% |
Uncovered Elements: 7 (56) |
Complexity: 13 |
Complexity Density: 0.36 |
|
1397 |
97
|
public void run() {... |
1398 |
|
|
1399 |
|
{ |
1400 |
97
|
if ( (busyFlag0V == false) && (waitingRecordList0.size() > 0 ) ){ |
1401 |
92
|
busyFlag0V = true; |
1402 |
92
|
boolean done = false; |
1403 |
184
|
while (waitingRecordList0.size() > 0 ) { |
1404 |
92
|
if (debugLevel > SAWSConstant.NoInfo) |
1405 |
0
|
System.out.println("this is in writing thread: " + recordCount); |
1406 |
92
|
recordCount ++; |
1407 |
92
|
wRecordBlock = (WaitingRecordBlock) waitingRecordList0.get(0); |
1408 |
92
|
currentLogFileWriter.createSAWSRecord( wRecordBlock.messageBlock, wRecordBlock.recordType, |
1409 |
|
wRecordBlock.userID, wRecordBlock.encryptionFlag, null); |
1410 |
92
|
waitingRecordList0.remove(0); |
1411 |
92
|
done = true; |
1412 |
|
} |
1413 |
92
|
if (done) { |
1414 |
92
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
1415 |
|
currentLogFileWriter.getAccHash()); |
1416 |
92
|
tcbContent.write(); |
1417 |
|
|
1418 |
92
|
currentTime = System.currentTimeMillis(); |
1419 |
|
|
1420 |
92
|
if (recordCount > signRecordNumber ){ |
1421 |
6
|
startANewLog(); |
1422 |
|
} |
1423 |
|
} |
1424 |
92
|
busyFlag0V = false; |
1425 |
|
} |
1426 |
|
|
1427 |
97
|
if ( (busyFlag1V == false) && (waitingRecordList1.size() > 0 ) ){ |
1428 |
1
|
busyFlag1V = true; |
1429 |
1
|
boolean done = false; |
1430 |
2
|
while (waitingRecordList1.size() > 0 ) { |
1431 |
1
|
if (debugLevel > SAWSConstant.NoInfo) |
1432 |
0
|
System.out.println("this is in writing thread: " + recordCount); |
1433 |
1
|
recordCount ++; |
1434 |
1
|
wRecordBlock = (WaitingRecordBlock) waitingRecordList1.get(0); |
1435 |
1
|
currentLogFileWriter.createSAWSRecord( wRecordBlock.messageBlock, wRecordBlock.recordType, |
1436 |
|
wRecordBlock.userID, wRecordBlock.encryptionFlag, null); |
1437 |
1
|
waitingRecordList1.remove(0); |
1438 |
1
|
done = true; |
1439 |
|
} |
1440 |
1
|
if (done) { |
1441 |
1
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
1442 |
|
currentLogFileWriter.getAccHash()); |
1443 |
1
|
tcbContent.write(); |
1444 |
1
|
currentTime = System.currentTimeMillis(); |
1445 |
|
|
1446 |
1
|
if (recordCount > signRecordNumber ){ |
1447 |
1
|
startANewLog(); |
1448 |
|
} |
1449 |
|
} |
1450 |
1
|
busyFlag1V = false; |
1451 |
|
} |
1452 |
|
|
1453 |
|
|
1454 |
|
|
1455 |
|
|
1456 |
|
} |
1457 |
|
} |
1458 |
|
} |
1459 |
|
|
1460 |
|
|
1461 |
|
|
1462 |
|
|
1463 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
1464 |
7
|
private void startANewLog(){... |
1465 |
7
|
currentLogFileWriter.finalizeLogFile(); |
1466 |
7
|
currentInspecitonAccHash = currentLogFileWriter.getAccHash(); |
1467 |
7
|
currentInspectionSignature = currentLogFileWriter.getSignature(); |
1468 |
7
|
previousLogFilenameFromLogRecord = latestLogFilename; |
1469 |
|
|
1470 |
7
|
latestLogFilename = lfc.generateNewLogFileName(); |
1471 |
7
|
currentLogFileWriter = new LogFileWriter(logFileRoot, latestLogFilename, |
1472 |
|
tcbKM.getvtEncryptionPublicKey(), |
1473 |
|
tcbKM.getsawsEncryptionPublicKey(), |
1474 |
|
tcbKM.getsawsSigningPrivateKey(), |
1475 |
|
tcbKM.getbaSigningPublicKeyCert(), |
1476 |
|
this.hashAlgorithm, |
1477 |
|
null, |
1478 |
|
UserIDPKMap, this.callbackHandler); |
1479 |
7
|
currentLogFileWriter.setDebugLevel(debugLevel); |
1480 |
7
|
int ret = currentLogFileWriter.prepareNewLog(); |
1481 |
7
|
if (ret != 0) { |
1482 |
0
|
System.exit(-1); |
1483 |
|
} |
1484 |
|
|
1485 |
7
|
currentLogFileWriter.createLastFileRecord(previousLogFilenameFromLogRecord, currentInspecitonAccHash, |
1486 |
|
currentInspectionSignature); |
1487 |
|
|
1488 |
7
|
tcbContent.setTCBContent(latestLogFilename, currentLogFileWriter.getCurrentRecordWriteCount(), |
1489 |
|
currentLogFileWriter.getAccHash()); |
1490 |
7
|
tcbContent.write(); |
1491 |
7
|
recordCount = 0; |
1492 |
|
} |
1493 |
|
|
1494 |
|
|
1495 |
|
|
1496 |
|
|
1497 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 7 |
Complexity Density: 0.6 |
|
1498 |
|
public class HeartbeatRecordWriting extends TimerTask{ |
1499 |
|
private volatile boolean stop = false; |
1500 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
1501 |
4
|
public HeartbeatRecordWriting(){... |
1502 |
|
} |
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 7 |
Complexity Density: 0.5 |
|
1503 |
44
|
public void run(){... |
1504 |
44
|
if (!stop) { |
1505 |
44
|
long t1 = System.currentTimeMillis(); |
1506 |
44
|
if (debugLevel > 0) |
1507 |
0
|
System.out.println("In HeartbeatRecordWriting: busyFlag0V * busyFlag1V " + busyFlag0V + "*" + busyFlag1V ); |
1508 |
44
|
if ( (busyFlag0V== false) && (busyFlag1V== false) && |
1509 |
|
(heartbeatInterval>=5) && ( ( t1 - currentTime) >= heartbeatInterval-5) ) { |
1510 |
28
|
writingHeartBeating = true; |
1511 |
28
|
busyFlag0V = true; |
1512 |
28
|
WaitingRecordBlock wRecordBlock = new WaitingRecordBlock(utility.longToByteArray(t1), |
1513 |
|
SAWSConstant.SysHeartbeatType, SAWSConstant.NoEncryptionFlag, (byte)0x00); |
1514 |
28
|
waitingRecordList0.addElement(wRecordBlock); |
1515 |
28
|
busyFlag0V = false; |
1516 |
28
|
currentTime = t1; |
1517 |
28
|
thread.run(); |
1518 |
28
|
writingHeartBeating = false; |
1519 |
|
|
1520 |
|
} |
1521 |
|
} else { |
1522 |
0
|
this.cancel(); |
1523 |
|
} |
1524 |
|
} |
1525 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1526 |
4
|
public void setStop(boolean stop) {... |
1527 |
4
|
this.stop = stop; |
1528 |
|
} |
1529 |
|
} |
1530 |
|
|
1531 |
|
|
1532 |
|
|
1533 |
|
|
1534 |
|
@param |
1535 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1536 |
4
|
private void setHeartbeatWriter(int interval){... |
1537 |
4
|
tt2 = new HeartbeatRecordWriting(); |
1538 |
4
|
timer = new java.util.Timer(true ); |
1539 |
4
|
timer.schedule(tt2, 1000, interval); |
1540 |
|
} |
1541 |
|
|
1542 |
|
|
1543 |
|
|
1544 |
|
|
1545 |
|
|
1546 |
|
@param |
1547 |
|
@param |
1548 |
|
|
1549 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
1550 |
0
|
private void showMessage(String message, int type) {... |
1551 |
0
|
this.cbs = new Callback[1]; |
1552 |
0
|
this.cbs[0] = new SAWSTextOutputCallback(type, message); |
1553 |
0
|
try { |
1554 |
0
|
this.callbackHandler.handle(this.cbs); |
1555 |
|
} |
1556 |
|
catch (Exception e) { |
1557 |
0
|
System.err.println(e.getMessage()); |
1558 |
0
|
sawsDebugLog.write(e); |
1559 |
|
} |
1560 |
|
} |
1561 |
|
|
1562 |
|
|
1563 |
|
|
1564 |
|
|
1565 |
|
|
1566 |
|
@param |
1567 |
|
@param |
1568 |
|
@param |
1569 |
|
|
1570 |
|
@return |
1571 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
1572 |
9
|
private int createConfirmCallback(String prompt, String[] options, int type, String key) {... |
1573 |
9
|
this.cbs = new Callback[1]; |
1574 |
9
|
this.cbs[0] = new SAWSChoiceCallback(prompt, options, key, 0, type); |
1575 |
9
|
try { |
1576 |
9
|
this.callbackHandler.handle(cbs); |
1577 |
|
} |
1578 |
|
catch (Exception e) { |
1579 |
0
|
System.err.println(e.getMessage()); |
1580 |
0
|
sawsDebugLog.write(e); |
1581 |
|
} |
1582 |
|
|
1583 |
9
|
return ((SAWSChoiceCallback)this.cbs[0]).getSelectedIndex(); |
1584 |
|
} |
1585 |
|
|
1586 |
|
|
1587 |
|
|
1588 |
|
|
1589 |
|
|
|
|
| 50.7% |
Uncovered Elements: 35 (71) |
Complexity: 13 |
Complexity Density: 0.25 |
|
1590 |
4
|
public static void main(String[] args) throws Exception { ... |
1591 |
4
|
System.out.println("Secure Audit Web-Service v" + version.getVersion()); |
1592 |
|
|
1593 |
4
|
String sIn = null; |
1594 |
4
|
try { |
1595 |
4
|
if (args.length > 0) { |
1596 |
4
|
sIn = args[0]; |
1597 |
|
} else { |
1598 |
0
|
System.out.println("\nSAWS is now working in the keystore creation mode. Please select the following options:"); |
1599 |
0
|
System.out.println("\nOption 1: Create an encryption keystore." ); |
1600 |
0
|
System.out.println("\nOption 2: Create a signing keystore." ); |
1601 |
0
|
System.out.println("\nOption 3: Import the rootCA specified in the SAWS configuration file into the signing keystore. " + |
1602 |
|
"This is required by keytool to be able to later import the PKC issued by this rootCA into the signing keystore." ); |
1603 |
0
|
System.out.println("\nOption 4: Output a PKC request file from the signing keystore." ); |
1604 |
0
|
System.out.println("\nOption 5: Input the PKC issued by the rootCA into the signing keystore." ); |
1605 |
0
|
System.out.println("\nOption 6: List all the entries in the signing keystore." ); |
1606 |
0
|
System.out.println("\nOption 7: Export the Signing PKC from the sining keystore." ); |
1607 |
0
|
System.out.println("\nOption 9: Test mode: SAWS will create a new log file and check old log files, then close the new log file. " + |
1608 |
|
"This is for testing purposes. " ); |
1609 |
0
|
System.out.println("\n\nPlease input your choice (1, 2, 3, 4, 5, 6, 7 or 9) or any other input to stop: " ); |
1610 |
0
|
InputStreamReader is = new InputStreamReader(System.in); |
1611 |
0
|
BufferedReader systemIn = new BufferedReader(is); |
1612 |
0
|
sIn = systemIn.readLine(); |
1613 |
|
} |
1614 |
|
|
1615 |
|
} catch (IOException e){ |
1616 |
0
|
e.printStackTrace(System.err); |
1617 |
0
|
System.exit(-1); |
1618 |
|
} |
1619 |
4
|
if ( (sIn.compareTo("1") == 0) ) { |
1620 |
1
|
SAWSServer sw = new SAWSServer(0); |
1621 |
1
|
sw.createEncryptionKeystore(); |
1622 |
|
} |
1623 |
|
|
1624 |
4
|
if ( (sIn.compareTo("2") == 0) ) { |
1625 |
1
|
SAWSServer sw = new SAWSServer(0); |
1626 |
1
|
sw.createSigningKeystore(); |
1627 |
|
} |
1628 |
|
|
1629 |
4
|
if ( (sIn.compareTo("3") == 0) ) { |
1630 |
1
|
SAWSServer sw = new SAWSServer(0); |
1631 |
1
|
sw.importRootCA(); |
1632 |
|
} |
1633 |
|
|
1634 |
4
|
if ( (sIn.compareTo("4") == 0) ) { |
1635 |
0
|
SAWSServer sw = new SAWSServer(0); |
1636 |
0
|
sw.outputPKCRequest(); |
1637 |
|
} |
1638 |
4
|
if ( (sIn.compareTo("5") == 0) ) { |
1639 |
0
|
SAWSServer sw = new SAWSServer(0); |
1640 |
0
|
sw.importSigningPKC(); |
1641 |
|
} |
1642 |
4
|
if ( (sIn.compareTo("6") == 0) ) { |
1643 |
0
|
SAWSServer sw = new SAWSServer(0); |
1644 |
0
|
sw.listSigningKeystore(); |
1645 |
|
} |
1646 |
|
|
1647 |
4
|
if ( (sIn.compareTo("7") == 0) ) { |
1648 |
1
|
SAWSServer sw = new SAWSServer(0); |
1649 |
1
|
sw.exportSigningPKC(); |
1650 |
|
} |
1651 |
4
|
if ( (sIn.compareTo("9") == 0) ) { |
1652 |
0
|
SAWSServer sw = new SAWSServer(1); |
1653 |
0
|
sw.sawsStart(); |
1654 |
0
|
sw.sendLogRecord("This is a test.".getBytes()); |
1655 |
0
|
sw.sendLogRecord("This is a test 2.".getBytes()); |
1656 |
0
|
sw.sendLogRecord("This is a test 3.".getBytes()); |
1657 |
|
|
1658 |
0
|
sw.closeLog(); |
1659 |
0
|
System.exit(0); |
1660 |
|
} |
1661 |
|
|
1662 |
4
|
if (args == null || args.length == 0) { |
1663 |
0
|
System.exit(0); |
1664 |
|
} |
1665 |
|
} |
1666 |
|
|
1667 |
|
} |