예제 #1
0
 def OpenBrowseFile(self):
     ImageFileName = FileService.openFileNameDialog(self.Form, self.Form)
     if (ImageFileName != None and ImageFileName != ""):
         file = FileService.openFileContent(self, ImageFileName)
     else:
         #handle no file warning 
         return
     self.ImageData = file.read()
     self.ImageName = ImageFileName
     self.EmitSwitch(self.ImageData)
예제 #2
0
 def test_create_file_service_fixed_file_definition(self):
     """Create fixed file service given fixed file definition"""
     self.file_data[fc.FIELD_DEFINITIONS][0][fc.START_POSITION] = '0'
     self.file_data[fc.FIELD_DEFINITIONS][0][fc.FIELD_LENGTH] = '12'
     file_definition = self.create_file_definition(fc.FIXED)
     file_service = FileService.create_file_service(file_definition)
     self.assertTrue(isinstance(file_service, FixedFileService))
 def selectImage(self):
     selectedImage = FileService.openFileNameDialog(self, self) 
     print(selectedImage)
     selectedImage = str(selectedImage)
     print(selectedImage)
     if (selectedImage != None or selectedImage != ""):
         self.selectedImageLabel.setPixmap(QtGui.QPixmap(selectedImage))
예제 #4
0
 def test_create_file_service_delimited_file_definition(self):
     """Create delimited file service given a delimited file definition"""
     # arrange
     self.file_data[fc.DELIMITER] = "\t"
     file_definition = self.create_file_definition(fc.DELIMITED)
     # act
     file_service = FileService.create_file_service(file_definition)
     # assert
     self.assertTrue(isinstance(file_service, DelimitedFileService))
예제 #5
0
 def __save_output(self):
     file_path = FileService.saveFileDialog(self, self)
     self.output_file_path = file_path
     if file_path is not None and file_path != "":
         # file = open(file_path, 'wb')
         # file.close()
         self.output_file_path_line_edit.setText(file_path)
     else:
         #handle no file warning
         return None
예제 #6
0
 def save_private(self):
     file_path = FileService.saveFileDialog(self, self)
     self.file_name_priv_key = file_path
     if file_path is not None and file_path != "":
         # file = open(file_path, 'wb')
         # file.close()
         self.private_key_line_edit.setText(file_path)
     else:
         #handle no file warning
         return None
예제 #7
0
    def setUp(self) -> None:
        super(FileRipper2Tests, self).setUp()

        self.file_service = FileService()
        file_service_factory = Mock(return_value=self.file_service)

        self.expected = {}
        self.file_service.process = Mock(return_value=self.expected)

        self.file_data[fc.FILE_TYPE] = fc.FIXED
        self.file_ripper = FileRipper(file_service_factory)
        self.file_definition = FileDefinition(self.file_data)
예제 #8
0
 def setUp(self):
     super(FixedFileServiceTests, self).setUp()
     self.file_data[fc.FILE_TYPE] = fc.FIXED
     self.file_definition = FileDefinition(self.file_data)
     self.file_service = FileService.create_file_service(
         self.file_definition)
     self.file_name = 'Valid-fixed-09032019.txt'
     with open(self.file_name, 'w') as f:
         f.write('Name         Age      DOB       \n')
         f.write('Aaron        39       09/04/1980\n')
         f.write('Gene         61       01/15/1958\n')
         f.write('Xander       4        11/22/2014\n')
         f.write('Mason        12       04/13/2007\n')
예제 #9
0
 def __init__(self, imageData, config, CarrierDir,
              payloadDir):  # payloadDir is payload directory
     super(EncodeFile, self).__init__()
     uic.loadUi('./UIFiles/EncodeFile.ui', self)
     self.setFixedSize(750, 550)
     self.payloadDir = payloadDir
     self.imageData = imageData
     self.config = config
     self.carrierDir = CarrierDir
     self.label = self.findChild(QtWidgets.QLabel, 'carrierLabel')
     pixmap = QtGui.QPixmap()
     pixmap.loadFromData(imageData)
     self.label.setPixmap(pixmap)
     # self.label.resize(pixmap.width(), pixmap.height())
     self.label.setAlignment(QtCore.Qt.AlignCenter)  # center image label
     self.label_2 = self.findChild(QtWidgets.QLabel, 'payloadLabel')
     pixmap = QtGui.QPixmap()
     #TODO Validate payload Dir
     extension = os.path.splitext(payloadDir)[1]
     if (extension == ".png" or extension == ".jpeg" or extension == ".jpg"
             or extension == ".gif"):
         payloaddata = FileService.openFileContent(self, payloadDir)
         pixmap.loadFromData(payloaddata.read())
         self.label_2.setPixmap(pixmap)
         # self.label_2.resize(pixmap.width(), pixmap.height())
         self.label_2.setAlignment(
             QtCore.Qt.AlignCenter
         )  # center image labelself.label_2.setAlignment(QtCore.Qt.AlignCenter)  # center image label
     else:
         self.label_2.setText(payloadDir)
     self.pushButton_2 = self.findChild(QtWidgets.QAbstractButton,
                                        'nextButton')
     # self.pushButton_2.setText("Next")
     self.pushButton_2.clicked.connect(self.ShowResult)
     self.pushButton = self.findChild(QtWidgets.QAbstractButton,
                                      'previousButton')
     # self.pushButton_2.setText("Next")
     self.pushButton.clicked.connect(self.ShowPrevious)
예제 #10
0
 def __on_input_button_clicked(self):
     self.input_file_path = FileService.openAnyFileNameDialog(self, self)
     self.input_file_path_line_edit.setText(self.input_file_path)
예제 #11
0
 def __on_pvk_button_clicked(self):
     self.private_key_path = FileService.openAnyFileNameDialog(self, self)
     self.private_key_line_edit.setText(self.private_key_path)
예제 #12
0
 def test_process_records_not_implemented(self):
     file_service = FileService()
     self.assertRaises(NotImplementedError,
                       file_service.process_file_records, [])
예제 #13
0
 def test_create_file_service_xml_file_definition(self):
     """Create xml file service given and xml file definition"""
     file_definition = self.create_file_definition(fc.XML, 'record')
     file_service = FileService.create_file_service(file_definition)
     self.assertTrue(isinstance(file_service, XmlFileService))
    def EmitSwitchNext(
            self):  # implement event that will emit the switch window signal
        password = self.encryptionKeyTextEdit.toPlainText()
        privateKey = self.privateKeyLineEdit.text()
        publicKey = self.publicKeyLineEdit.text()
        if (self.Config == "Encode"):
            if (self.fileRadioButton.isChecked()):
                #Show Browser to select payload and pass it to next page (pass payload directory)
                payloadDir = FileService.openAnyFileNameDialog(
                    self.Form, self.Form)
                if (payloadDir != ''):
                    #### Adding cryptographic components
                    if (self.cryptographyCheckBox.isChecked()):
                        payloadDirCrypt = re.sub(r'\/(?=[^/]*$).*',
                                                 '/EncryptedFile', payloadDir)
                        if self.algorithmComboBox.currentIndex() == 0:  # AES
                            AesManager.write_encrypted_text(
                                password.encode('ascii'), payloadDirCrypt,
                                payloadDir)
                            self.show_encode_file.emit(self.imagedata,
                                                       self.Config,
                                                       self.carrierDir,
                                                       payloadDirCrypt)
                        elif (self.algorithmComboBox.currentIndex() == 1
                              ):  #DES
                            DesManager.write_encrypted_text(
                                password.encode('ascii'), payloadDirCrypt,
                                payloadDir)
                            self.show_encode_file.emit(self.imagedata,
                                                       self.Config,
                                                       self.carrierDir,
                                                       payloadDirCrypt)

                        elif (self.algorithmComboBox.currentIndex() == 2
                              ):  #RSA
                            if self.publicKeyLineEdit.hasAcceptableInput():
                                public_key_file_path = self.publicKeyLineEdit.text(
                                )
                                public_key_file = open(public_key_file_path,
                                                       'rb')
                                public_key = public_key_file.read()
                                public_key_file.close()
                                RsaManager.write_encrypted_stream(
                                    public_key, payloadDirCrypt, payloadDir)
                                self.show_encode_file.emit(
                                    self.imagedata, self.Config,
                                    self.carrierDir, payloadDirCrypt)

                    else:
                        self.show_encode_file.emit(self.imagedata, self.Config,
                                                   self.carrierDir, payloadDir)
            else:
                if (self.cryptographyCheckBox.isChecked()):
                    if self.algorithmComboBox.currentIndex() == 0:  # AES
                        self.show_encode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 1,
                                                   password, publicKey)
                    elif self.algorithmComboBox.currentIndex() == 1:  # DES
                        self.show_encode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 2,
                                                   password, publicKey)
                    elif self.algorithmComboBox.currentIndex() == 2:  # RSA
                        self.show_encode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 3,
                                                   password, publicKey)
                else:
                    self.show_encode_text.emit(self.imagedata, self.Config,
                                               self.carrierDir, 0, password,
                                               publicKey)
        else:
            if (self.fileRadioButton.isChecked()):
                if (self.cryptographyCheckBox.isChecked()):
                    if self.algorithmComboBox.currentIndex() == 0:  # AES
                        self.show_decode_file.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 1,
                                                   password, privateKey)
                    elif self.algorithmComboBox.currentIndex() == 1:  # DES
                        self.show_decode_file.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 2,
                                                   password, privateKey)
                    elif self.algorithmComboBox.currentIndex() == 2:  # RSA
                        self.show_decode_file.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 3,
                                                   password, privateKey)
                else:
                    self.show_decode_file.emit(self.imagedata, self.Config,
                                               self.carrierDir, 0, password,
                                               privateKey)
            else:
                if (self.cryptographyCheckBox.isChecked()):
                    if self.algorithmComboBox.currentIndex() == 0:  # AES
                        self.show_decode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 1,
                                                   password, privateKey)
                    elif self.algorithmComboBox.currentIndex() == 1:  # DES
                        self.show_decode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 2,
                                                   password, privateKey)
                    elif self.algorithmComboBox.currentIndex() == 2:  # RSA
                        self.show_decode_text.emit(self.imagedata, self.Config,
                                                   self.carrierDir, 3,
                                                   password, privateKey)
                else:
                    self.show_decode_text.emit(self.imagedata, self.Config,
                                               self.carrierDir, 0, password,
                                               privateKey)
 def privateKeyButtonClicked(self):
     privateKeyFile = FileService.openAnyFileNameDialog(
         self.Form, self.Form)
     self.privateKeyLineEdit.setText(privateKeyFile)
예제 #16
0
    def __init__(self, imageData, config, CarrierDir, cryptoAlgorithm,
                 password, privateKey):
        super(DecodeFile, self).__init__()
        uic.loadUi('./UIFiles/DecodeFile.ui', self)
        self.imageData = imageData
        self.config = config
        self.CarrierDir = CarrierDir
        self.cryptoAlgorithm = cryptoAlgorithm
        self.password = password
        self.privateKey = privateKey
        self.label = self.findChild(QtWidgets.QLabel, 'carrierLabel')
        pixmap = QtGui.QPixmap()
        pixmap.loadFromData(imageData)
        self.label.setPixmap(pixmap)
        self.label.resize(pixmap.width(), pixmap.height())
        self.label.setAlignment(QtCore.Qt.AlignCenter)  # center image label
        self.label_2 = self.findChild(QtWidgets.QLabel, 'payloadLabel_2')
        pixmap2 = QtGui.QPixmap()
        #newDir = "/home/kikohiho/Desktop/StegCapstone/StegoCapstone/Release/Official/UIFiles/recoveredFile"
        newDir = re.sub(r'\/(?=[^/]*$).*', '/recoveredFile', self.CarrierDir)
        newDirCrypt = newDir + "Decrypted"
        stegCommand = "python ./UIFiles/stegScript.py -d -f " + self.CarrierDir + " " + newDir
        subprocess.Popen(stegCommand.split(), stdout=subprocess.PIPE)
        while not os.path.exists(newDir):
            time.sleep(1)
        if self.cryptoAlgorithm == 1:  #AES
            AesManager.write_decrypted_text(self.password.encode('ascii'),
                                            newDirCrypt, newDir)
            if (imghdr.what(newDirCrypt) != None):
                payloaddata = FileService.openFileContent(
                    self, newDirCrypt
                )  ######### data of decoded image needs to go here
                extension = os.path.splitext(newDirCrypt)
                pixmap2.loadFromData(payloaddata.read())
                self.label_2.setPixmap(pixmap2)
                self.label_2.resize(pixmap2.width(), pixmap2.height())
                self.label_2.setAlignment(
                    QtCore.Qt.AlignCenter)  # center image label
            else:
                self.label_2.setText(newDirCrypt)

        elif self.cryptoAlgorithm == 2:  #DES
            DesManager.write_decrypted_text(self.password.encode('ascii'),
                                            newDirCrypt, newDir)
            if (imghdr.what(newDirCrypt) != None):
                payloaddata = FileService.openFileContent(
                    self, newDirCrypt
                )  ######### data of decoded image needs to go here
                extension = os.path.splitext(newDirCrypt)
                pixmap2.loadFromData(payloaddata.read())
                self.label_2.setPixmap(pixmap2)
                self.label_2.resize(pixmap2.width(), pixmap2.height())
                self.label_2.setAlignment(
                    QtCore.Qt.AlignCenter)  # center image label
            else:
                self.label_2.setText(newDirCrypt)

        elif self.cryptoAlgorithm == 3:  #RSA
            ####### THIS IS WHERE THE RSA PRIVATE KEY STUFF GOES MANUEL ############
            pvk_file = open(self.privateKey, 'rb')
            pvk_bytes = pvk_file.read()
            pvk_file.close()
            RsaManager.write_decrypted_stream(self.password.encode('ascii'),
                                              pvk_bytes, newDirCrypt, newDir)
            if imghdr.what(newDirCrypt) is not None:
                payloaddata = FileService.openFileContent(
                    self, newDirCrypt
                )  ######### data of decoded image needs to go here
                extension = os.path.splitext(newDirCrypt)
                pixmap2.loadFromData(payloaddata.read())
                self.label_2.setPixmap(pixmap2)
                self.label_2.resize(pixmap2.width(), pixmap2.height())
                self.label_2.setAlignment(
                    QtCore.Qt.AlignCenter)  # center image label
            else:
                self.label_2.setText(newDirCrypt)

        elif self.cryptoAlgorithm == 0:  #Nothing
            if imghdr.what(newDir) is not None:
                payloaddata = FileService.openFileContent(
                    self,
                    newDir)  ######### data of decoded image needs to go here
                extension = os.path.splitext(newDir)
                pixmap2.loadFromData(payloaddata.read())
                self.label_2.setPixmap(pixmap2)
                self.label_2.resize(pixmap2.width(), pixmap2.height())
                self.label_2.setAlignment(
                    QtCore.Qt.AlignCenter)  # center image label
            else:
                self.label_2.setText(newDir)

        self.pushButton_2 = self.findChild(QtWidgets.QAbstractButton,
                                           'restartButton')
        self.pushButton_2.setText("Restart")
        self.pushButton_2.clicked.connect(self.RestartDecode)
        self.pushButton = self.findChild(QtWidgets.QAbstractButton,
                                         'previousButton')
        # self.pushButton.setText("Previous")
        self.pushButton.clicked.connect(self.ShowPrevious)