Exemple #1
0
 def test_get_key(self):
     """
     Tests get key
     """
     key_mgr = keymgr.create(":memory:")
     key_mgr.connect()
     key_mgr.write_key('hello', 'email', b'hello')
     uid = key_mgr.list_key()[0]['uid']
     self.assertEqual(key_mgr.get_key(uid), b'hello')
     key_mgr.close()
Exemple #2
0
 def test_delete_key(self):
     """
     Tests delete key
     """
     key_mgr = keymgr.create(":memory:")
     key_mgr.connect()
     key_mgr.write_key('hello', 'email', b'hello')
     uid = key_mgr.list_key()[0]['uid']
     key_mgr.delete_key(uid)
     self.assertEqual(len(key_mgr.list_key()), 0)
     key_mgr.close()
Exemple #3
0
 def test_write_key(self):
     """
     Tests write key
     """
     key_mgr = keymgr.create(":memory:")
     key_mgr.connect()
     self.assertEqual(key_mgr.write_key('hello', 'email', b'hello'), True)
     self.assertEqual(key_mgr.write_key('hello', 'email', b'hello'), False)
     with self.assertRaises(ValueError):
         key_mgr.write_key('', 'email', b'hello')
     key_mgr.close()
Exemple #4
0
 def test_list_key(self):
     """
     Tests read key
     """
     key_mgr = keymgr.create(":memory:")
     key_mgr.connect()
     key_mgr.write_key('hello', 'email', b'hello')
     self.assertEqual(key_mgr.list_key(), [{
         'uid': 1,
         'name': 'hello',
         'email': 'email',
         'public_key': b'hello'
     }])
     key_mgr.close()
Exemple #5
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setStyleSheet(
            "background-color:#315d90; font: 12pt Helvetica; color: #d3e1ed")
        self.setWindowTitle("Photo Crypto")
        self.setFixedSize(850, 600)

        self.title = QLabel("AES-128 Photo Encryption wrapped with RSA-2048",
                            self)
        self.title.setWordWrap(True)
        self.title.setAlignment(Qt.AlignCenter)
        self.title.setStyleSheet("font: 30pt;")
        self.title.resize(700, 200)
        self.title.move(120, 30)

        icon_image = QPixmap()
        icon_image.load(join(WORKING_DIRECTORY, 'resource', 'icon.png'))
        self.icon = QLabel(self)
        self.icon.setPixmap(icon_image)
        self.icon.resize(icon_image.width(), icon_image.height())
        self.icon.move(60, 80)

        self.subtitle = QLabel("Created by Hosung Lee and Sean Kullmann", self)
        self.subtitle.setStyleSheet("font: 10pt; color: #d3e1ed")
        self.subtitle.resize(self.subtitle.sizeHint().width(),
                             self.subtitle.sizeHint().height())
        self.subtitle.move(
            self.width() // 2 - self.subtitle.sizeHint().width() // 2, 220)

        self.rbutton = QPushButton("Generate RSA public and private key", self)
        self.rbutton.resize(self.rbutton.sizeHint().width(),
                            self.rbutton.sizeHint().height())
        self.rbutton.setStyleSheet(green_button_style())
        self.rbutton.move(
            self.width() // 2 - self.rbutton.sizeHint().width() // 2, 300)
        self.rbutton.clicked.connect(self.generate_key)

        self.ebutton = QPushButton("Encrypt", self)
        self.ebutton.resize(self.ebutton.sizeHint().width(),
                            self.ebutton.sizeHint().height())
        self.ebutton.setStyleSheet(blue_button_style())
        self.ebutton.move(180, 350)
        self.ebutton.setDisabled(True)
        self.ebutton.setStyleSheet(disabled_button_style())
        self.ebutton.clicked.connect(self.encrypt)

        self.dbutton = QPushButton("Decrypt", self)
        self.dbutton.resize(self.dbutton.sizeHint().width(),
                            self.dbutton.sizeHint().height())
        self.dbutton.setStyleSheet(blue_button_style())
        self.dbutton.move(280, 350)
        self.dbutton.setDisabled(True)
        self.dbutton.setStyleSheet(disabled_button_style())
        self.dbutton.clicked.connect(self.decrypt)

        self.cbutton = QPushButton("Contacts", self)
        self.cbutton.resize(self.cbutton.sizeHint().width(),
                            self.cbutton.sizeHint().height())
        self.cbutton.setStyleSheet(blue_button_style())
        self.cbutton.move(380, 350)
        self.cbutton.clicked.connect(self.open_contact)

        self.pbutton = QPushButton("Update private key", self)
        self.pbutton.resize(self.pbutton.sizeHint().width(),
                            self.pbutton.sizeHint().height())
        self.pbutton.setStyleSheet(blue_button_style())
        self.pbutton.move(480, 350)
        self.pbutton.clicked.connect(self.update_private_key)

        self.private_found_indicator = QLabel(
            "Private key not loaded - update or generate private key", self)
        self.private_found_indicator.resize(
            self.private_found_indicator.sizeHint().width(),
            self.private_found_indicator.sizeHint().height())

        self.current_recipient = QLabel(
            "Recipient: Not selected. Use Contacts", self)
        self.current_recipient.resize(
            800,
            self.current_recipient.sizeHint().height())
        self.current_recipient.move(
            10,
            self.height() - self.current_recipient.height() - 10)
        self.private_found_indicator.move(
            10,
            self.height() - self.current_recipient.height() -
            self.private_found_indicator.height() - 10)

        if not isfile(join(WORKING_DIRECTORY, 'data')) and not isdir(
                join(WORKING_DIRECTORY, 'data')):
            mkdir(join(WORKING_DIRECTORY, 'data'))

        if isfile(join(WORKING_DIRECTORY, 'data')):
            raise Exception("cannot create data directory.")

        self.keymgr = keymgr.create(
            join(WORKING_DIRECTORY, 'data', 'keystore.db'))
        self.recipient = None
        self.private_key_path = None

        if not isfile(
                join(WORKING_DIRECTORY, 'data', 'private_key_location.txt')):
            with open(
                    join(WORKING_DIRECTORY, 'data',
                         'private_key_location.txt'), 'w') as file:
                file.write('')
        with open(join(WORKING_DIRECTORY, 'data', 'private_key_location.txt'),
                  'r') as file:
            location = file.read()
            if isfile(location):
                self.private_key_path = location
                self.set_private_key_found_indicator(True)

        self.contact = Contacts(self.keymgr, self.set_recipient_key)
        self.imview = None

        self.show()