19 package org.sleuthkit.autopsy.modules.e01verify;
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;
26 import org.python.bouncycastle.util.Arrays;
67 messageDigest = MessageDigest.getInstance(
"MD5");
68 }
catch (NoSuchAlgorithmException ex) {
69 logger.log(Level.WARNING,
"Error getting md5 algorithm", ex);
70 throw new RuntimeException(
71 NbBundle.getMessage(
this.getClass(),
"EwfVerifyIngestModule.startUp.exception.failGetMd5"));
77 String imgName = dataSource.getName();
80 if (!(dataSource instanceof Image)) {
81 logger.log(Level.INFO,
"Skipping non-image {0}", imgName);
83 NbBundle.getMessage(this.getClass(),
84 "EwfVerifyIngestModule.process.skipNonEwf",
88 Image img = (Image) dataSource;
91 if (img.getType() != TskData.TSK_IMG_TYPE_ENUM.TSK_IMG_TYPE_EWF_EWF) {
92 logger.log(Level.INFO,
"Skipping non-ewf image {0}", imgName);
94 NbBundle.getMessage(this.getClass(),
95 "EwfVerifyIngestModule.process.skipNonEwf",
101 if ((img.getMd5() == null) || img.getMd5().isEmpty()) {
103 NbBundle.getMessage(this.getClass(),
104 "EwfVerifyIngestModule.process.noStoredHash",
109 storedHash = img.getMd5().toLowerCase();
110 logger.log(Level.INFO,
"Hash value stored in {0}: {1}",
new Object[]{imgName, storedHash});
112 logger.log(Level.INFO,
"Starting hash verification of {0}", img.getName());
114 NbBundle.getMessage(this.getClass(),
115 "EwfVerifyIngestModule.process.startingImg",
118 long size = img.getSize();
120 logger.log(Level.WARNING,
"Size of image {0} was 0 when queried.", imgName);
122 NbBundle.getMessage(this.getClass(),
123 "EwfVerifyIngestModule.process.errGetSizeOfImg",
129 long chunkSize = 64 * img.getSsize();
130 chunkSize = (chunkSize == 0) ? DEFAULT_CHUNK_SIZE : chunkSize;
133 int totalChunks = (int) Math.ceil((
double)size / (
double)chunkSize);
134 logger.log(Level.INFO,
"Total chunks = {0}", totalChunks);
137 byte[] data =
new byte[(int) chunkSize];
141 for (
int i = 0; i < totalChunks; i++) {
146 read = img.read(data, i * chunkSize, chunkSize);
147 }
catch (TskCoreException ex) {
148 String msg = NbBundle.getMessage(this.getClass(),
149 "EwfVerifyIngestModule.process.errReadImgAtChunk", imgName, i);
151 logger.log(Level.SEVERE, msg, ex);
156 if(read == chunkSize) {
157 messageDigest.update(data);
159 byte[] subData = Arrays.copyOfRange(data, 0, read);
160 messageDigest.update(subData);
166 calculatedHash = DatatypeConverter.printHexBinary(messageDigest.digest()).toLowerCase();
167 verified = calculatedHash.equals(storedHash);
168 logger.log(Level.INFO,
"Hash calculated from {0}: {1}",
new Object[]{imgName, calculatedHash});
173 msg = NbBundle.getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.verified");
175 msg = NbBundle.getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.notVerified");
177 String extra = NbBundle
178 .getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.verifyResultsHeader", imgName);
179 extra += NbBundle.getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.resultLi", msg);
180 extra += NbBundle.getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.calcHashLi", calculatedHash);
181 extra += NbBundle.getMessage(this.getClass(),
"EwfVerifyIngestModule.shutDown.storedHashLi", storedHash);
183 logger.log(Level.INFO,
"{0}{1}",
new Object[]{imgName, msg});
static final IngestServices services
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
MessageDigest messageDigest
static final Logger logger
void startUp(IngestJobContext context)
void postMessage(final IngestMessage message)
ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper)
static final long DEFAULT_CHUNK_SIZE
boolean dataSourceIngestIsCancelled()
void switchToDeterminate(int workUnits)
synchronized static Logger getLogger(String name)
void progress(int workUnits)
static synchronized IngestServices getInstance()