Coverage details for base.jdbs.BackupArtifactDisassembler

LineHitsSource
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  */
380public class BackupArtifactDisassembler {
39  
400    private static final transient Logger logger = Logger.getLogger(BackupArtifactDisassembler.class.getName());
410 
42     public static void disassemblyBackupArtifact(SymmetricKey symmetricKey, KeyPair keyPair, BackupDescriptor backupDescriptor, File outputDirectory) throws IOException{
430        
440        String originalCRC32 = FileUtil.fileContent(backupDescriptor.getCrc32ChecksumFile());
450        logger.debug("originalCRC32: "+originalCRC32);
460        boolean crc32Check = FileUtil.checkCRC32Checksum(backupDescriptor.getBackupFile(),new Long(originalCRC32));
470        if(crc32Check)logger.debug("CRC32 Check - VALID");
480        else logger.warn("CRC32 - INVALID");
490        
500        
510        String originalMD5Digest = FileUtil.fileContent(backupDescriptor.getMd5DigestFile());
520        logger.debug("originalMD5Digest: "+originalMD5Digest);
530        boolean md5Check = FileUtil.checkMD5Digest(backupDescriptor.getBackupFile(),originalMD5Digest);
540        if(md5Check)logger.debug("MD5 Check - VALID");
550        else logger.warn("MD5 Check - INVALID");
560        
570        
580        RSAAsymmetricCipher asymmetricCipher = new RSAAsymmetricCipher();
590        
600        boolean signatureCheck = asymmetricCipher.checkSignature(backupDescriptor.getMd5SignedFile(),backupDescriptor.getMd5DigestFile(), keyPair.getPublicKey());
610        if(signatureCheck)logger.debug("Signature Check - VALID");
620        else logger.warn("Signature Check - INVALID");
630        
640        final File encryptionDir = new File(backupDescriptor.getArtifactDirectory(),BackupArtifactAssembler.ENCRYPTION_DIRECTORY_NAME);
650        final File decryptionDir = new File(backupDescriptor.getArtifactDirectory(),BackupArtifactAssembler.DECRYPTION_DIRECTORY_NAME);
660        
670        logger.debug("Backup Encryption Directory: "+ encryptionDir);
680        encryptionDir.mkdir();
690        logger.debug("Backup Decryption Directory: "+ decryptionDir);
700        decryptionDir.mkdir();
710        
720        logger.debug("The Backup Security Level is : "+backupDescriptor.getBackup().getSecurityLevel());
730        if(backupDescriptor.getBackup().getSecurityLevel().equals(SecurityLevel.PRIVATE)){
740            logger.debug("Backup has PRIVATE content, unzipping the content under the encryption directory");
750            ZipUtil.unZipFile(backupDescriptor.getBackupFile(),encryptionDir);
760            logger.debug("Backup successfully unzipped, starting the decryption.");
770            DESSymmetricCipher symmetricCipher = new DESSymmetricCipher(symmetricKey);
780            logger.debug("This is the list of file o be decrypted:");
790            File[] toBeDecrypted = FileUtil.allFileContent(encryptionDir);
800            File[] outputFile = new File[toBeDecrypted.length];
810            
820            
830            for(int i=0;i<toBeDecrypted.length;i++){
840                logger.debug("To Be Decrypted: "+toBeDecrypted[i]);
850                int lastIndexOfBakcupName = toBeDecrypted[i].getAbsolutePath().lastIndexOf(backupDescriptor.getBackup().getName());
860                int pathLength = toBeDecrypted[i].getAbsolutePath().length();
870                logger.debug("lastIndexOfBakcupName: "+lastIndexOfBakcupName + "pathLength: "+pathLength);
880                String originalFileName = toBeDecrypted[i].getAbsolutePath().substring(lastIndexOfBakcupName,pathLength);
890                logger.debug("Original File Name: "+ originalFileName);
900                
910                outputFile[i] = new File(outputDirectory,originalFileName);
920                outputFile[i].getParentFile().mkdirs();
930                outputFile[i].createNewFile();
940                
950                symmetricCipher.decrypt(toBeDecrypted[i],outputFile[i]);
960            }
970        }
980        else{
990            logger.debug("Backup has private content, unzipping the content under the decryption directory");
1000            ZipUtil.unZipFile(backupDescriptor.getBackupFile(),decryptionDir);
1010            File[] toBeResotored = FileUtil.allFileContent(decryptionDir);
1020            for(int i=0;i<toBeResotored.length;i++)
1030            {
1040                logger.debug("To Be Restored: "+toBeResotored[i]);
1050                int lastIndexOfBakcupName = toBeResotored[i].getAbsolutePath().lastIndexOf(backupDescriptor.getBackup().getName());
1060                int pathLength = toBeResotored[i].getAbsolutePath().length();
1070                logger.debug("lastIndexOfBakcupName: "+lastIndexOfBakcupName + "pathLength: "+pathLength);
1080                String originalFileName = toBeResotored[i].getAbsolutePath().substring(lastIndexOfBakcupName,pathLength);
1090                logger.debug("Original File Name: "+ originalFileName);
1100                
1110                File outputFile = new File(outputDirectory,originalFileName);
1120                outputFile.getParentFile().mkdirs();
1130                outputFile.createNewFile();
1140                FileUtil.copyFile(toBeResotored[i],outputFile);
1150            }
1160            
1170        }
1180        
1190        logger.debug("Encryption Directory Deletion Result: " + FileUtil.deleteDirectory(encryptionDir));
1200        logger.debug("Decryption Directory Deletion Result: " + FileUtil.deleteDirectory(decryptionDir));
121         
1220        
1230    
1240    }
125     
126 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.