Commit 8ed86a4e authored by Tijmen de Mes's avatar Tijmen de Mes

Added dialog to export private key

parent ae8f802e
import os
import re
import random
import uuid
from collections import deque
......@@ -133,6 +134,96 @@ class ImportPrivateKeyRequest(QObject):
self.rejected.emit(self)
del ui_class, base_class
ui_class, base_class = uic.loadUiType(Resources.get('export_private_key_dialog.ui'))
class ExportDialog(IncomingDialogBase, ui_class):
def __init__(self, parent=None):
super(ExportDialog, self).__init__(parent)
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_DeleteOnClose)
with Resources.directory:
self.setupUi(self)
self.slot = None
self.export_button = self.dialog_button_box.addButton("Export", QDialogButtonBox.AcceptRole)
self.export_button.setIcon(QApplication.style().standardIcon(QStyle.SP_DialogApplyButton))
self.export_button.setEnabled(False)
def show(self, activate=True):
self.setAttribute(Qt.WA_ShowWithoutActivating, not activate)
super(ExportDialog, self).show()
class ExportPrivateKeyRequest(QObject):
finished = pyqtSignal(object)
accepted = pyqtSignal(object, str)
rejected = pyqtSignal(object)
sip_prefix_re = re.compile('^sips?:')
priority = 5
def __init__(self, dialog, account):
super(ExportPrivateKeyRequest, self).__init__()
self.account = account
self.dialog = dialog
self.dialog.finished.connect(self._SH_DialogFinished)
uri = self.sip_prefix_re.sub('', str(account.uri))
self.dialog.account_value_label.setText(uri)
self.pincode = ''.join([str(random.randint(0, 99)).zfill(2) for _ in range(3)])
self.dialog.pincode_value_label.setText(self.pincode)
settings = SIPSimpleSettings()
id = account.id.replace('/', '_')
directory = os.path.join(settings.chat.keys_directory.normalized, 'private')
filename = os.path.join(directory, f'{id}')
with open(f'{filename}.privkey', 'rb') as f:
private_key = f.read().decode()
with open(f'{filename}.pubkey', 'rb') as f:
self.public_key = f.read().decode()
try:
pgp_message = PGPMessage.new(private_key)
self.enc_message = pgp_message.encrypt(self.pincode)
except PGPEncryptionError:
pass
else:
self.dialog.export_button.setEnabled(True)
def __eq__(self, other):
return self is other
def __ne__(self, other):
return self is not other
def __lt__(self, other):
return self.priority < other.priority
def __le__(self, other):
return self.priority <= other.priority
def __gt__(self, other):
return self.priority > other.priority
def __ge__(self, other):
return self.priority >= other.priority
def _SH_DialogFinished(self, result):
self.finished.emit(self)
if result == QDialog.Accepted:
self.accepted.emit(self, f'{self.public_key}{str(self.enc_message)}')
elif result == QDialog.Rejected:
self.rejected.emit(self)
del ui_class, base_class
class BlinkMessage(MSRPChatMessage):
__slots__ = 'id', 'disposition'
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>260</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>640</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>300</height>
</size>
</property>
<property name="windowTitle">
<string>Export Private Key</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>icons/blink48.png</normaloff>icons/blink48.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<property name="spacing">
<number>5</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>icons/work/lock.svg</pixmap>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Export Private Key</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Blink uses end-to-end encryption for messaging to contacts that support this. To replicate messages on multiple devices you need the same prive key on all of them. </string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Press **Export** and enter this pincode when prompted on your other device:</string>
</property>
<property name="textFormat">
<enum>Qt::MarkdownText</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="pincode_value_label">
<property name="font">
<font>
<pointsize>24</pointsize>
<weight>75</weight>
<bold>true</bold>
<underline>false</underline>
<strikeout>false</strikeout>
</font>
</property>
<property name="styleSheet">
<string notr="true">letter-spacing: 12px;</string>
</property>
<property name="text">
<string>PINCODE</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="account_value_label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">user@domain.com</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dialog_button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>dialog_button_box</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>dialog_button_box</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment