Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
E01VerifyIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.e01verify;
20 
21 import java.security.MessageDigest;
22 import java.security.NoSuchAlgorithmException;
23 import java.util.logging.Level;
24 import javax.xml.bind.DatatypeConverter;
25 import org.openide.util.NbBundle;
37 
44 
45  private static final Logger logger = Logger.getLogger(E01VerifyIngestModule.class.getName());
46  private static final long DEFAULT_CHUNK_SIZE = 32 * 1024;
48 
49  private MessageDigest messageDigest;
50  private boolean verified = false;
51  private boolean skipped = false;
52  private String calculatedHash = "";
53  private String storedHash = "";
55 
57  }
58 
59  @Override
60  public void startUp(IngestJobContext context) throws IngestModuleException {
61  this.context = context;
62  verified = false;
63  storedHash = "";
64  calculatedHash = "";
65 
66  try {
67  messageDigest = MessageDigest.getInstance("MD5"); //NON-NLS
68  } catch (NoSuchAlgorithmException ex) {
69  logger.log(Level.WARNING, "Error getting md5 algorithm", ex); //NON-NLS
70  throw new RuntimeException(
71  NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.startUp.exception.failGetMd5"));
72  }
73  }
74 
75  @Override
76  public ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper) {
77  String imgName = dataSource.getName();
78  if (!(dataSource instanceof Image)) {
79  logger.log(Level.INFO, "Skipping disk image image {0}", imgName); //NON-NLS
81  NbBundle.getMessage(this.getClass(),
82  "EwfVerifyIngestModule.process.skipNonEwf",
83  imgName)));
84  return ProcessResult.OK;
85  }
86  Image img = (Image)dataSource;
87 
88  // Skip images that are not E01
90  logger.log(Level.INFO, "Skipping non-ewf image {0}", imgName); //NON-NLS
92  NbBundle.getMessage(this.getClass(),
93  "EwfVerifyIngestModule.process.skipNonEwf",
94  imgName)));
95  return ProcessResult.OK;
96  }
97 
98  if ((img.getMd5() != null) && !img.getMd5().isEmpty()) {
99  storedHash = img.getMd5().toLowerCase();
100  logger.log(Level.INFO, "Hash value stored in {0}: {1}", new Object[]{imgName, storedHash}); //NON-NLS
101  } else {
103  NbBundle.getMessage(this.getClass(),
104  "EwfVerifyIngestModule.process.noStoredHash",
105  imgName)));
106  return ProcessResult.ERROR;
107  }
108 
109  logger.log(Level.INFO, "Starting hash verification of {0}", img.getName()); //NON-NLS
111  NbBundle.getMessage(this.getClass(),
112  "EwfVerifyIngestModule.process.startingImg",
113  imgName)));
114 
115  long size = img.getSize();
116  if (size == 0) {
117  logger.log(Level.WARNING, "Size of image {0} was 0 when queried.", imgName); //NON-NLS
119  NbBundle.getMessage(this.getClass(),
120  "EwfVerifyIngestModule.process.errGetSizeOfImg",
121  imgName)));
122  }
123 
124  // Libewf uses a sector size of 64 times the sector size, which is the
125  // motivation for using it here.
126  long chunkSize = 64 * img.getSsize();
127  chunkSize = (chunkSize == 0) ? DEFAULT_CHUNK_SIZE : chunkSize;
128 
129  int totalChunks = (int) Math.ceil(size / chunkSize);
130  logger.log(Level.INFO, "Total chunks = {0}", totalChunks); //NON-NLS
131  int read;
132 
133  byte[] data;
134  statusHelper.switchToDeterminate(totalChunks);
135 
136  // Read in byte size chunks and update the hash value with the data.
137  for (int i = 0; i < totalChunks; i++) {
138  if (context.dataSourceIngestIsCancelled()) {
139  return ProcessResult.OK;
140  }
141  data = new byte[(int) chunkSize];
142  try {
143  read = img.read(data, i * chunkSize, chunkSize);
144  } catch (TskCoreException ex) {
145  String msg = NbBundle.getMessage(this.getClass(),
146  "EwfVerifyIngestModule.process.errReadImgAtChunk", imgName, i);
148  logger.log(Level.SEVERE, msg, ex);
149  return ProcessResult.ERROR;
150  }
151  messageDigest.update(data);
152  statusHelper.progress(i);
153  }
154 
155  // Finish generating the hash and get it as a string value
156  calculatedHash = DatatypeConverter.printHexBinary(messageDigest.digest()).toLowerCase();
157  verified = calculatedHash.equals(storedHash);
158  logger.log(Level.INFO, "Hash calculated from {0}: {1}", new Object[]{imgName, calculatedHash}); //NON-NLS
159 
160  logger.log(Level.INFO, "complete() {0}", E01VerifierModuleFactory.getModuleName()); //NON-NLS
161  String msg;
162  if (verified) {
163  msg = NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.verified");
164  } else {
165  msg = NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.notVerified");
166  }
167  String extra = NbBundle
168  .getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.verifyResultsHeader", imgName);
169  extra += NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.resultLi", msg);
170  extra += NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.calcHashLi", calculatedHash);
171  extra += NbBundle.getMessage(this.getClass(), "EwfVerifyIngestModule.shutDown.storedHashLi", storedHash);
172  services.postMessage(IngestMessage.createMessage( MessageType.INFO, E01VerifierModuleFactory.getModuleName(), imgName + msg, extra));
173  logger.log(Level.INFO, "{0}{1}", new Object[]{imgName, msg});
174 
175  return ProcessResult.OK;
176  }
177 }
TskData.TSK_IMG_TYPE_ENUM getType()
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
int read(byte[] buf, long offset, long len)
void postMessage(final IngestMessage message)
ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper)
static Logger getLogger(String name)
Definition: Logger.java:131
static synchronized IngestServices getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.