mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-06 15:30:28 +03:00
Include SHA-256 hash in addition to MD5
The MD5 hash element must come last, for compatibility with older clients.
This commit is contained in:
parent
7324d40b2d
commit
2414042f66
1 changed files with 13 additions and 4 deletions
17
update.py
17
update.py
|
|
@ -24,7 +24,7 @@ import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import zipfile
|
import zipfile
|
||||||
import md5
|
import hashlib
|
||||||
from xml.dom.minidom import Document
|
from xml.dom.minidom import Document
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
|
@ -139,15 +139,18 @@ for apkfile in glob.glob(os.path.join('repo','*.apk')):
|
||||||
print " WARNING: no SDK version information found"
|
print " WARNING: no SDK version information found"
|
||||||
thisinfo['sdkversion'] = 0
|
thisinfo['sdkversion'] = 0
|
||||||
|
|
||||||
# Calculate the md5...
|
# Calculate the md5 and sha256...
|
||||||
m = md5.new()
|
m = hashlib.md5()
|
||||||
|
sha = hashlib.sha256()
|
||||||
f = open(apkfile, 'rb')
|
f = open(apkfile, 'rb')
|
||||||
while True:
|
while True:
|
||||||
t = f.read(1024)
|
t = f.read(1024)
|
||||||
if len(t) == 0:
|
if len(t) == 0:
|
||||||
break
|
break
|
||||||
m.update(t)
|
m.update(t)
|
||||||
|
sha.update(t)
|
||||||
thisinfo['md5'] = m.hexdigest()
|
thisinfo['md5'] = m.hexdigest()
|
||||||
|
thisinfo['sha256'] = sha.hexdigest()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Get the signature (or md5 of, to be precise)...
|
# Get the signature (or md5 of, to be precise)...
|
||||||
|
|
@ -303,7 +306,13 @@ for app in apps:
|
||||||
addElement('apkname', apk['apkname'], doc, apkel)
|
addElement('apkname', apk['apkname'], doc, apkel)
|
||||||
if apk.has_key('srcname'):
|
if apk.has_key('srcname'):
|
||||||
addElement('srcname', apk['srcname'], doc, apkel)
|
addElement('srcname', apk['srcname'], doc, apkel)
|
||||||
addElement('hash', apk['md5'], doc, apkel)
|
for hash_type in ('sha256', 'md5'):
|
||||||
|
if not hash_type in apk:
|
||||||
|
continue
|
||||||
|
hashel = doc.createElement("hash")
|
||||||
|
hashel.setAttribute("type", hash_type)
|
||||||
|
hashel.appendChild(doc.createTextNode(apk[hash_type]))
|
||||||
|
apkel.appendChild(hashel)
|
||||||
addElement('sig', apk['sig'], doc, apkel)
|
addElement('sig', apk['sig'], doc, apkel)
|
||||||
addElement('size', str(apk['size']), doc, apkel)
|
addElement('size', str(apk['size']), doc, apkel)
|
||||||
addElement('sdkver', str(apk['sdkversion']), doc, apkel)
|
addElement('sdkver', str(apk['sdkversion']), doc, apkel)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue