diff options
author | Papoteur <papoteur@mageia.org> | 2018-10-19 09:01:16 +0200 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2018-10-19 09:01:16 +0200 |
commit | 0835bde83d98dc26912de3d5025d516667a07798 (patch) | |
tree | 76c55aa0ad8d8f22e6150aeb043317972bccb55f | |
parent | ae4851d5496d3bd2e7cf86cabda0eb37d0553dc2 (diff) | |
download | isodumper-0835bde83d98dc26912de3d5025d516667a07798.tar isodumper-0835bde83d98dc26912de3d5025d516667a07798.tar.gz isodumper-0835bde83d98dc26912de3d5025d516667a07798.tar.bz2 isodumper-0835bde83d98dc26912de3d5025d516667a07798.tar.xz isodumper-0835bde83d98dc26912de3d5025d516667a07798.zip |
Separate getting key and checking signature in a thread
Review the logic of checking
-rwxr-xr-x | backend/magiback | 10 | ||||
-rwxr-xr-x | backend/raw_write.py | 43 | ||||
-rwxr-xr-x | lib/isodumper.py | 4 |
3 files changed, 39 insertions, 18 deletions
diff --git a/backend/magiback b/backend/magiback index 7c56253..904afcf 100755 --- a/backend/magiback +++ b/backend/magiback @@ -36,6 +36,9 @@ class Isodumper(raw_write.Dumper): <arg type='s' name='target' direction='in'/> <arg type='s' name='source' direction='in'/> </method> + <method name='get_sum'> + <arg type='s' name='source' direction='in'/> + </method> <method name='end'> <arg type='b' name='success' direction='out'/> <arg type='s' name='message' direction='out'/> @@ -61,6 +64,9 @@ class Isodumper(raw_write.Dumper): self.return_message = "" self.authorized_sender_read = set() self.authorized_sender_write = set() + self.sum_check = "" + self.sum_check_searched = False + self.signature_checked = False def do_write(self,source, target, size, dbus_context): self.finished.clear() @@ -99,6 +105,10 @@ class Isodumper(raw_write.Dumper): print("Unmounting") return self._do_unmount([device]) + def get_sum(self, source): + key_thread = threading.Thread(target=self._get_sum, args=(source,)) + key_thread.start() + def check_write(self,target, source): self.thread = threading.Thread(target=self._check_write, args=(target, source,)) self.thread.start() diff --git a/backend/raw_write.py b/backend/raw_write.py index 40dc99b..d9a5a19 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -146,35 +146,42 @@ class Dumper(object): print(message) return not bool(retcode), message - def _check_write(self, target, source): + def _get_sum(self, source): self.return_state = False self.return_message = "" - b = os.path.getsize(source) # Check if the sum file has a valid signature - signature_checked = False gpg = gnupg.GPG() gpg.encoding = 'utf-8' # Use Mageia public key sig_file = source +'.sha512.gpg' - sumcheck = "" try: gpg.recv_keys('pgp.mit.edu', 'EDCA7A90') + self.sum_check_searched = True with open(sig_file, 'rb') as g: + self.signature_found = True verified = gpg.verify_file(g) if verified.valid: - signature_checked = True - # Look for sum files in the same directory as source - fs=open(source+'.sha512','r') - # Read the sum in the file - sumcheck=(fs.readline()).split()[0] + self.signature_checked = True + logging.debug("signature checked") else: - self.return_message = _('Invalid signature for %s.sha512')%source - self.return_state = True - self.finished.set() - return + self.signature_checked = False except: + self.signature_found = False self.return_message = _("Signature file {} not found\n").format(sig_file) - + try: + # Look for sum files in the same directory as source + with open(source+'.sha512','r') as fs: + # Read the sum in the file + self.sum_check=(fs.readline()).split()[0] + self.sum_file = True + except: + self.return_message = _("Sum SHA512 file {} not found\n").format(source+'.sha512') + self.sum_file = False + + def _check_write(self, target, source): + self.return_state = False + self.return_message = "" + b = os.path.getsize(source) # Compute the sum from the written device steps=list(range(0, b+1, int(b/100))) steps.append(b) @@ -195,11 +202,13 @@ class Dumper(object): sha512func.update(block) sha512sumcalc=sha512func.hexdigest() f.close() - if (sumcheck == "") : + if self.signature_found and not self.signature_checked: + self.return_message = _('Invalid signature for %s.sha512')%source + if (self.sum_check == "") : self.return_message += _('SHA512 sum: {}').format(sha512sumcalc) # compare the sums - elif (sha512sumcalc == sumcheck) : - if signature_checked: + elif (sha512sumcalc == self.sum_check) : + if self.signature_checked: self.return_message += _("The sha512 sum check is OK and the sum is signed") else : self.return_message += _("The sha512 sum check is OK but the signature can't be found") diff --git a/lib/isodumper.py b/lib/isodumper.py index d1d1e1c..e6df9df 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -296,6 +296,7 @@ class IsoDumper(object): #Writing step #Dump mode iface.do_write(source, target, b) + iface.get_sum(source) progress = iface.progress while not iface.done : progress = iface.progress @@ -306,7 +307,8 @@ class IsoDumper(object): self.logger(_('Image {source} successfully written to {target}').format( source=source.split('/')[-1], target=target)) self.logger(_('Bytes written: ')+str(b)) self.progress.setLabel(_('Checking ')+target.split('/')[-1]) - self.progress.setValue(0) + self.progress.setValue(0) + # Checking iface.check_write(target, source) progress = iface.progress while progress < 100 : |