Commit dd4eb483050d3ac8dd8df925738fab9e04a0021c

Authored by prolly
1 parent 16cfb354

Del 4. :)

1 -files/secondFolder/phones.txt,9ce6a51fe5769a96c7caa33169c77c83b9785ae4f75b05d3ce8d68bd08c8a723  
2 -files/firstFolder/names.txt,59f627f0b0b42327917128abb4a71486f57642807fcba6b58414a12fe9670b43  
3 \ No newline at end of file 1 \ No newline at end of file
  2 +files\firstFolder\names.txt,59f627f0b0b42327917128abb4a71486f57642807fcba6b58414a12fe9670b43
  3 +files\secondFolder\phones.txt,9ce6a51fe5769a96c7caa33169c77c83b9785ae4f75b05d3ce8d68bd08c8a723
4 \ No newline at end of file 4 \ No newline at end of file
signedhash
No preview for this file type
src/hashObl5/ExecutableFiles.java
@@ -237,6 +237,7 @@ public class ExecutableFiles extends Object { @@ -237,6 +237,7 @@ public class ExecutableFiles extends Object {
237 237
238 } 238 }
239 catch (FileNotFoundException ex) { 239 catch (FileNotFoundException ex) {
  240 + System.out.println("Error: File not found!");
240 } 241 }
241 catch (IOException ex) { 242 catch (IOException ex) {
242 } 243 }
@@ -280,6 +281,39 @@ public class ExecutableFiles extends Object { @@ -280,6 +281,39 @@ public class ExecutableFiles extends Object {
280 return data; 281 return data;
281 282
282 } 283 }
  284 + public static void checkFiles(File directory, String hashStoragePath) {
  285 + // executables
  286 +
  287 + File entry; // A reference to an entry
  288 + // in the directory
  289 + String entryName; // The full path name of a
  290 + // file
  291 +
  292 +
  293 +
  294 + if(directory == null) { return;} // Could not be opened;
  295 + // forget it
  296 +
  297 +
  298 + String contents[] = directory.list(); // Get an array of all the
  299 + // files in the directory
  300 + if(contents == null) return; // Could not access
  301 + // contents, skip it
  302 +
  303 + for(int i=0; i<contents.length; i++){ // Deal with each file
  304 + entry = new File(directory, contents[i]); // Read next directory
  305 + // entry
  306 +
  307 + if(contents[i].charAt(0) == '.') // Skip the . and ..
  308 + // directories
  309 + continue;
  310 + if (entry.isDirectory()){ // Is it a directory
  311 + checkFiles(entry,hashStoragePath); // Yes, enter and search it
  312 + } else { // No (file)
  313 + System.out.println("Does " +entry.getName()+"in"+entry.getPath()+ " checksum matches the expected one? " +verifisereHash(entry.getPath(),hashStoragePath)); // If executable, infect it
  314 +}
  315 +}
  316 + }
283 317
284 public static void main(String args[]) { 318 public static void main(String args[]) {
285 boolean testg=false; 319 boolean testg=false;
@@ -288,16 +322,22 @@ public class ExecutableFiles extends Object { @@ -288,16 +322,22 @@ public class ExecutableFiles extends Object {
288 final File root = new File("files"); 322 final File root = new File("files");
289 323
290 search(root); 324 search(root);
291 - System.out.println("Does the file's checksum matches the expected one? " + verifisereHash("files/firstFolder/names.txt", "hashfil.txt"));  
292 - System.out.println("Does the file's checksum matches the expected one? " + verifisereHash("files/secondFolder/phones.txt", "hashfil.txt"));  
293 -  
294 testg=genSig("test","hashfil.txt","testing","signedhash","pkey"); 325 testg=genSig("test","hashfil.txt","testing","signedhash","pkey");
295 - testv=verSig("pkey","signedhash","hashfil.txt");  
296 - if(testg && testv) { 326 +
  327 + if(testg) {
297 328
298 - System.out.println("Done"); 329 + System.out.println("Hashfile signed!");
299 }else{ 330 }else{
300 System.out.println("Failed to generate signature"); 331 System.out.println("Failed to generate signature");
301 } 332 }
  333 + checkFiles(root,"hashfil.txt");
  334 + testv=verSig("pkey","signedhash","hashfil.txt");
  335 + if(testv) {
  336 + System.out.println("Hashfile verified!");
  337 + }
  338 + else {
  339 + System.out.println("Warning! Failed to verify hashfile.");
  340 + }
  341 +
302 } 342 }
303 } 343 }