117 String imgName = dataSource.getName();
120 if (!(dataSource instanceof Image)) {
121 logger.log(Level.INFO,
"Skipping non-image {0}", imgName);
123 NbBundle.getMessage(
this.getClass(),
124 "DataSourceIntegrityIngestModule.process.skipNonEwf",
128 Image img = (Image) dataSource;
131 long size = img.getSize();
133 logger.log(Level.WARNING,
"Size of image {0} was 0 when queried.", imgName);
141 if (img.getMd5() !=
null && !img.getMd5().isEmpty()) {
144 if (img.getSha1() !=
null && !img.getSha1().isEmpty()) {
147 if (img.getSha256() !=
null && !img.getSha256().isEmpty()) {
150 }
catch (TskCoreException ex) {
151 String msg = Bundle.DataSourceIntegrityIngestModule_process_errorLoadingHashes(imgName);
153 logger.log(Level.SEVERE, msg, ex);
166 if (mode.equals(
Mode.
COMPUTE) && !
this.computeHashes) {
167 logger.log(Level.INFO,
"Not computing hashes for {0} since the option was disabled", imgName);
169 Bundle.DataSourceIntegrityIngestModule_process_skipCompute(imgName)));
171 }
else if (mode.equals(
Mode.
VERIFY) && !
this.verifyHashes) {
172 logger.log(Level.INFO,
"Not verifying hashes for {0} since the option was disabled", imgName);
174 Bundle.DataSourceIntegrityIngestModule_process_skipVerify(imgName)));
189 hashData.digest = MessageDigest.getInstance(hashData.type.getName());
190 }
catch (NoSuchAlgorithmException ex) {
191 String msg = Bundle.DataSourceIntegrityIngestModule_process_hashAlgorithmError(hashData.type.getName());
193 logger.log(Level.SEVERE, msg, ex);
201 long chunkSize = 64 * img.getSsize();
205 int totalChunks = (int) Math.ceil((
double) size / (
double) chunkSize);
206 logger.log(Level.INFO,
"Total chunks = {0}", totalChunks);
209 logger.log(Level.INFO,
"Starting hash verification of {0}", img.getName());
211 logger.log(Level.INFO,
"Starting hash calculation for {0}", img.getName());
214 NbBundle.getMessage(
this.getClass(),
215 "DataSourceIntegrityIngestModule.process.startingImg",
222 byte[] data =
new byte[(int) chunkSize];
224 for (
int i = 0; i < totalChunks; i++) {
225 if (
context.dataSourceIngestIsCancelled()) {
229 read = img.read(data, i * chunkSize, chunkSize);
230 }
catch (TskCoreException ex) {
231 String msg = NbBundle.getMessage(this.getClass(),
232 "DataSourceIntegrityIngestModule.process.errReadImgAtChunk", imgName, i);
234 logger.log(Level.SEVERE, msg, ex);
239 if (read == chunkSize) {
241 struct.digest.update(data);
244 byte[] subData = Arrays.copyOfRange(data, 0, read);
246 struct.digest.update(subData);
254 hashData.calculatedHash = Hex.encodeHexString(hashData.digest.digest()).toLowerCase();
255 logger.log(Level.INFO,
"Hash calculated from {0}: {1}",
new Object[]{imgName, hashData.calculatedHash});
260 boolean verified =
true;
261 String detailedResults = NbBundle
262 .getMessage(this.getClass(),
"DataSourceIntegrityIngestModule.shutDown.verifyResultsHeader", imgName);
263 String hashResults =
"";
264 String artifactComment =
"";
267 if (hashData.storedHash.equals(hashData.calculatedHash)) {
268 hashResults += Bundle.DataSourceIntegrityIngestModule_process_hashMatch(hashData.type.name) +
" ";
271 hashResults += Bundle.DataSourceIntegrityIngestModule_process_hashNonMatch(hashData.type.name) +
" ";
272 artifactComment += Bundle.DataSourceIntegrityIngestModule_process_hashFailedForArtifact(hashData.type.name,
273 hashData.calculatedHash, hashData.storedHash) +
" ";
275 hashResults += Bundle.DataSourceIntegrityIngestModule_process_hashList(hashData.calculatedHash, hashData.storedHash);
278 String verificationResultStr;
279 String messageResultStr;
283 verificationResultStr = NbBundle.getMessage(this.getClass(),
"DataSourceIntegrityIngestModule.shutDown.verified");
284 messageResultStr = Bundle.DataSourceIntegrityIngestModule_process_verificationSuccess(imgName);
287 verificationResultStr = NbBundle.getMessage(this.getClass(),
"DataSourceIntegrityIngestModule.shutDown.notVerified");
288 messageResultStr = Bundle.DataSourceIntegrityIngestModule_process_verificationFailure(imgName);
291 detailedResults += NbBundle.getMessage(this.getClass(),
"DataSourceIntegrityIngestModule.shutDown.resultLi", verificationResultStr);
292 detailedResults += hashResults;
297 BlackboardArtifact.Type.TSK_VERIFICATION_FAILED,
298 img.getId(), img.getId(),
300 null,
null, artifactComment,
301 Arrays.asList(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT,
303 .getAnalysisResult();
307 }
catch (TskCoreException ex) {
308 logger.log(Level.SEVERE,
"Error creating verification failed artifact", ex);
309 }
catch (Blackboard.BlackboardException ex) {
310 logger.log(Level.SEVERE,
"Error posting verification failed artifact", ex);
315 messageResultStr, detailedResults));
320 String results = Bundle.DataSourceIntegrityIngestModule_process_calculateHashDone(imgName);
323 switch (hashData.type) {
326 img.setMD5(hashData.calculatedHash);
327 }
catch (TskDataException ex) {
328 logger.log(Level.SEVERE,
"Error setting calculated hash", ex);
333 img.setSha1(hashData.calculatedHash);
334 }
catch (TskDataException ex) {
335 logger.log(Level.SEVERE,
"Error setting calculated hash", ex);
340 img.setSha256(hashData.calculatedHash);
341 }
catch (TskDataException ex) {
342 logger.log(Level.SEVERE,
"Error setting calculated hash", ex);
348 results += Bundle.DataSourceIntegrityIngestModule_process_calcHashWithType(hashData.type.name, hashData.calculatedHash);
353 imgName + Bundle.DataSourceIntegrityIngestModule_process_hashesCalculated(), results));
355 }
catch (TskCoreException ex) {
356 String msg = Bundle.DataSourceIntegrityIngestModule_process_errorSavingHashes(imgName);
358 logger.log(Level.SEVERE,
"Error saving hash for image " + imgName +
" to database", ex);