aboutsummaryrefslogtreecommitdiffstats
path: root/backend/raw_write.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/raw_write.py')
-rwxr-xr-xbackend/raw_write.py43
1 files changed, 26 insertions, 17 deletions
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")