Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | *InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package base.jdbs; | |
21 | ||
22 | import java.io.File; | |
23 | import java.io.IOException; | |
24 | ||
25 | import org.apache.log4j.Logger; | |
26 | ||
27 | import base.jdbs.cryptography.asymmetric.KeyPair; | |
28 | import base.jdbs.cryptography.asymmetric.RSAAsymmetricCipher; | |
29 | import base.jdbs.cryptography.symmetric.DESSymmetricCipher; | |
30 | import base.jdbs.cryptography.symmetric.SymmetricKey; | |
31 | import base.util.FileUtil; | |
32 | import base.util.ZipUtil; | |
33 | ||
34 | /** | |
35 | * This class provided methods and utils to disassembly a previously created backup artifact. | |
36 | * @author Guido Angelo Ingenito | |
37 | */ | |
38 | 0 | public class BackupArtifactDisassembler { |
39 | ||
40 | 0 | private static final transient Logger logger = Logger.getLogger(BackupArtifactDisassembler.class.getName()); |
41 | 0 | |
42 | public static void disassemblyBackupArtifact(SymmetricKey symmetricKey, KeyPair keyPair, BackupDescriptor backupDescriptor, File outputDirectory) throws IOException{ | |
43 | 0 | |
44 | 0 | String originalCRC32 = FileUtil.fileContent(backupDescriptor.getCrc32ChecksumFile()); |
45 | 0 | logger.debug("originalCRC32: "+originalCRC32); |
46 | 0 | boolean crc32Check = FileUtil.checkCRC32Checksum(backupDescriptor.getBackupFile(),new Long(originalCRC32)); |
47 | 0 | if(crc32Check)logger.debug("CRC32 Check - VALID"); |
48 | 0 | else logger.warn("CRC32 - INVALID"); |
49 | 0 | |
50 | 0 | |
51 | 0 | String originalMD5Digest = FileUtil.fileContent(backupDescriptor.getMd5DigestFile()); |
52 | 0 | logger.debug("originalMD5Digest: "+originalMD5Digest); |
53 | 0 | boolean md5Check = FileUtil.checkMD5Digest(backupDescriptor.getBackupFile(),originalMD5Digest); |
54 | 0 | if(md5Check)logger.debug("MD5 Check - VALID"); |
55 | 0 | else logger.warn("MD5 Check - INVALID"); |
56 | 0 | |
57 | 0 | |
58 | 0 | RSAAsymmetricCipher asymmetricCipher = new RSAAsymmetricCipher(); |
59 | 0 | |
60 | 0 | boolean signatureCheck = asymmetricCipher.checkSignature(backupDescriptor.getMd5SignedFile(),backupDescriptor.getMd5DigestFile(), keyPair.getPublicKey()); |
61 | 0 | if(signatureCheck)logger.debug("Signature Check - VALID"); |
62 | 0 | else logger.warn("Signature Check - INVALID"); |
63 | 0 | |
64 | 0 | final File encryptionDir = new File(backupDescriptor.getArtifactDirectory(),BackupArtifactAssembler.ENCRYPTION_DIRECTORY_NAME); |
65 | 0 | final File decryptionDir = new File(backupDescriptor.getArtifactDirectory(),BackupArtifactAssembler.DECRYPTION_DIRECTORY_NAME); |
66 | 0 | |
67 | 0 | logger.debug("Backup Encryption Directory: "+ encryptionDir); |
68 | 0 | encryptionDir.mkdir(); |
69 | 0 | logger.debug("Backup Decryption Directory: "+ decryptionDir); |
70 | 0 | decryptionDir.mkdir(); |
71 | 0 | |
72 | 0 | logger.debug("The Backup Security Level is : "+backupDescriptor.getBackup().getSecurityLevel()); |
73 | 0 | if(backupDescriptor.getBackup().getSecurityLevel().equals(SecurityLevel.PRIVATE)){ |
74 | 0 | logger.debug("Backup has PRIVATE content, unzipping the content under the encryption directory"); |
75 | 0 | ZipUtil.unZipFile(backupDescriptor.getBackupFile(),encryptionDir); |
76 | 0 | logger.debug("Backup successfully unzipped, starting the decryption."); |
77 | 0 | DESSymmetricCipher symmetricCipher = new DESSymmetricCipher(symmetricKey); |
78 | 0 | logger.debug("This is the list of file o be decrypted:"); |
79 | 0 | File[] toBeDecrypted = FileUtil.allFileContent(encryptionDir); |
80 | 0 | File[] outputFile = new File[toBeDecrypted.length]; |
81 | 0 | |
82 | 0 | |
83 | 0 | for(int i=0;i<toBeDecrypted.length;i++){ |
84 | 0 | logger.debug("To Be Decrypted: "+toBeDecrypted[i]); |
85 | 0 | int lastIndexOfBakcupName = toBeDecrypted[i].getAbsolutePath().lastIndexOf(backupDescriptor.getBackup().getName()); |
86 | 0 | int pathLength = toBeDecrypted[i].getAbsolutePath().length(); |
87 | 0 | logger.debug("lastIndexOfBakcupName: "+lastIndexOfBakcupName + "pathLength: "+pathLength); |
88 | 0 | String originalFileName = toBeDecrypted[i].getAbsolutePath().substring(lastIndexOfBakcupName,pathLength); |
89 | 0 | logger.debug("Original File Name: "+ originalFileName); |
90 | 0 | |
91 | 0 | outputFile[i] = new File(outputDirectory,originalFileName); |
92 | 0 | outputFile[i].getParentFile().mkdirs(); |
93 | 0 | outputFile[i].createNewFile(); |
94 | 0 | |
95 | 0 | symmetricCipher.decrypt(toBeDecrypted[i],outputFile[i]); |
96 | 0 | } |
97 | 0 | } |
98 | 0 | else{ |
99 | 0 | logger.debug("Backup has private content, unzipping the content under the decryption directory"); |
100 | 0 | ZipUtil.unZipFile(backupDescriptor.getBackupFile(),decryptionDir); |
101 | 0 | File[] toBeResotored = FileUtil.allFileContent(decryptionDir); |
102 | 0 | for(int i=0;i<toBeResotored.length;i++) |
103 | 0 | { |
104 | 0 | logger.debug("To Be Restored: "+toBeResotored[i]); |
105 | 0 | int lastIndexOfBakcupName = toBeResotored[i].getAbsolutePath().lastIndexOf(backupDescriptor.getBackup().getName()); |
106 | 0 | int pathLength = toBeResotored[i].getAbsolutePath().length(); |
107 | 0 | logger.debug("lastIndexOfBakcupName: "+lastIndexOfBakcupName + "pathLength: "+pathLength); |
108 | 0 | String originalFileName = toBeResotored[i].getAbsolutePath().substring(lastIndexOfBakcupName,pathLength); |
109 | 0 | logger.debug("Original File Name: "+ originalFileName); |
110 | 0 | |
111 | 0 | File outputFile = new File(outputDirectory,originalFileName); |
112 | 0 | outputFile.getParentFile().mkdirs(); |
113 | 0 | outputFile.createNewFile(); |
114 | 0 | FileUtil.copyFile(toBeResotored[i],outputFile); |
115 | 0 | } |
116 | 0 | |
117 | 0 | } |
118 | 0 | |
119 | 0 | logger.debug("Encryption Directory Deletion Result: " + FileUtil.deleteDirectory(encryptionDir)); |
120 | 0 | logger.debug("Decryption Directory Deletion Result: " + FileUtil.deleteDirectory(decryptionDir)); |
121 | ||
122 | 0 | |
123 | 0 | |
124 | 0 | } |
125 | ||
126 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |