2017-03-29 18:10:04 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# update.py - part of the FDroid server tools
|
|
|
|
# Copyright (C) 2017, Torsten Grote <t at grobox dot de>
|
|
|
|
# Copyright (C) 2016, Blue Jay Wireless
|
|
|
|
# Copyright (C) 2014-2016, Hans-Christoph Steiner <hans@eds.org>
|
|
|
|
# Copyright (C) 2010-2015, Ciaran Gultnieks <ciaran@ciarang.com>
|
|
|
|
# Copyright (C) 2013-2014, Daniel Martí <mvdan@mvdan.cc>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
2017-03-29 23:33:09 +02:00
|
|
|
import tempfile
|
2017-03-29 18:10:04 +02:00
|
|
|
import urllib.parse
|
2022-05-23 12:39:17 +02:00
|
|
|
import yaml
|
2017-03-29 23:33:09 +02:00
|
|
|
import zipfile
|
2017-09-03 23:07:43 +02:00
|
|
|
import calendar
|
2021-01-25 09:35:25 +01:00
|
|
|
import qrcode
|
2017-03-29 18:10:04 +02:00
|
|
|
from binascii import hexlify, unhexlify
|
2018-04-25 14:20:19 +02:00
|
|
|
from datetime import datetime, timezone
|
2022-05-23 12:39:17 +02:00
|
|
|
from pathlib import Path
|
2017-03-29 18:10:04 +02:00
|
|
|
from xml.dom.minidom import Document
|
|
|
|
|
2017-09-13 18:03:57 +02:00
|
|
|
from . import _
|
|
|
|
from . import common
|
|
|
|
from . import metadata
|
|
|
|
from . import net
|
|
|
|
from . import signindex
|
2017-09-20 00:16:13 +02:00
|
|
|
from fdroidserver.common import FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
|
2020-06-03 22:28:18 +02:00
|
|
|
from fdroidserver.exception import FDroidException, VerificationException
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
|
2020-06-03 22:27:09 +02:00
|
|
|
def make(apps, apks, repodir, archive):
|
2017-03-29 18:10:04 +02:00
|
|
|
"""Generate the repo index files.
|
|
|
|
|
|
|
|
This requires properly initialized options and config objects.
|
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
apps
|
|
|
|
OrderedDict of apps to go into the index, each app should have
|
|
|
|
at least one associated apk
|
|
|
|
apks
|
|
|
|
list of apks to go into the index
|
|
|
|
repodir
|
|
|
|
the repo directory
|
|
|
|
archive
|
|
|
|
True if this is the archive repo, False if it's the
|
|
|
|
main one.
|
2017-03-29 18:10:04 +02:00
|
|
|
"""
|
|
|
|
from fdroidserver.update import METADATA_VERSION
|
|
|
|
|
2022-05-17 23:46:44 +02:00
|
|
|
if not hasattr(common.options, 'nosign') or not common.options.nosign:
|
2017-10-16 18:11:57 +02:00
|
|
|
common.assert_config_keystore(common.config)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2020-06-03 22:28:18 +02:00
|
|
|
# Historically the index has been sorted by App Name, so we enforce this ordering here
|
2020-11-17 23:49:04 +01:00
|
|
|
sortedids = sorted(apps, key=lambda appid: common.get_app_display_name(apps[appid]).upper())
|
2020-06-03 22:28:18 +02:00
|
|
|
sortedapps = collections.OrderedDict()
|
|
|
|
for appid in sortedids:
|
|
|
|
sortedapps[appid] = apps[appid]
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
repodict = collections.OrderedDict()
|
2018-04-25 14:20:19 +02:00
|
|
|
repodict['timestamp'] = datetime.utcnow().replace(tzinfo=timezone.utc)
|
2017-03-29 18:10:04 +02:00
|
|
|
repodict['version'] = METADATA_VERSION
|
|
|
|
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.config['repo_maxage'] != 0:
|
|
|
|
repodict['maxage'] = common.config['repo_maxage']
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
if archive:
|
2017-03-31 15:50:15 +02:00
|
|
|
repodict['name'] = common.config['archive_name']
|
2018-07-09 22:41:08 +02:00
|
|
|
repodict['icon'] = common.config.get('archive_icon', common.default_config['repo_icon'])
|
2017-03-31 15:50:15 +02:00
|
|
|
repodict['description'] = common.config['archive_description']
|
2021-01-23 19:36:15 +01:00
|
|
|
archive_url = common.config.get('archive_url', common.config['repo_url'][:-4] + 'archive')
|
|
|
|
repodict['address'] = archive_url
|
2022-06-03 09:35:43 +02:00
|
|
|
if 'archive_web_base_url' in common.config:
|
|
|
|
repodict["webBaseUrl"] = common.config['archive_web_base_url']
|
2021-01-23 19:36:15 +01:00
|
|
|
urlbasepath = os.path.basename(urllib.parse.urlparse(archive_url).path)
|
2017-03-29 18:10:04 +02:00
|
|
|
else:
|
2017-03-31 15:50:15 +02:00
|
|
|
repodict['name'] = common.config['repo_name']
|
2018-07-09 22:41:08 +02:00
|
|
|
repodict['icon'] = common.config.get('repo_icon', common.default_config['repo_icon'])
|
2017-03-31 15:50:15 +02:00
|
|
|
repodict['address'] = common.config['repo_url']
|
2022-06-03 09:35:43 +02:00
|
|
|
if 'repo_web_base_url' in common.config:
|
|
|
|
repodict["webBaseUrl"] = common.config['repo_web_base_url']
|
2017-03-31 15:50:15 +02:00
|
|
|
repodict['description'] = common.config['repo_description']
|
|
|
|
urlbasepath = os.path.basename(urllib.parse.urlparse(common.config['repo_url']).path)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
mirrorcheckfailed = False
|
|
|
|
mirrors = []
|
2019-02-22 21:38:20 +01:00
|
|
|
for mirror in common.config.get('mirrors', []):
|
2017-03-29 18:10:04 +02:00
|
|
|
base = os.path.basename(urllib.parse.urlparse(mirror).path.rstrip('/'))
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.config.get('nonstandardwebroot') is not True and base != 'fdroid':
|
2017-09-13 18:03:57 +02:00
|
|
|
logging.error(_("mirror '%s' does not end with 'fdroid'!") % mirror)
|
2017-03-29 18:10:04 +02:00
|
|
|
mirrorcheckfailed = True
|
|
|
|
# must end with / or urljoin strips a whole path segment
|
|
|
|
if mirror.endswith('/'):
|
|
|
|
mirrors.append(urllib.parse.urljoin(mirror, urlbasepath))
|
|
|
|
else:
|
|
|
|
mirrors.append(urllib.parse.urljoin(mirror + '/', urlbasepath))
|
2017-03-31 15:50:15 +02:00
|
|
|
for mirror in common.config.get('servergitmirrors', []):
|
2017-07-19 12:59:20 +02:00
|
|
|
for url in get_mirror_service_urls(mirror):
|
|
|
|
mirrors.append(url + '/' + repodir)
|
2017-03-29 18:10:04 +02:00
|
|
|
if mirrorcheckfailed:
|
2017-09-13 18:03:57 +02:00
|
|
|
raise FDroidException(_("Malformed repository mirrors."))
|
2017-03-29 18:10:04 +02:00
|
|
|
if mirrors:
|
|
|
|
repodict['mirrors'] = mirrors
|
|
|
|
|
2017-04-03 11:29:21 +02:00
|
|
|
requestsdict = collections.OrderedDict()
|
2017-03-29 18:10:04 +02:00
|
|
|
for command in ('install', 'uninstall'):
|
|
|
|
packageNames = []
|
|
|
|
key = command + '_list'
|
2017-03-31 15:50:15 +02:00
|
|
|
if key in common.config:
|
|
|
|
if isinstance(common.config[key], str):
|
|
|
|
packageNames = [common.config[key]]
|
|
|
|
elif all(isinstance(item, str) for item in common.config[key]):
|
|
|
|
packageNames = common.config[key]
|
2017-03-29 18:10:04 +02:00
|
|
|
else:
|
2017-09-13 18:03:57 +02:00
|
|
|
raise TypeError(_('only accepts strings, lists, and tuples'))
|
2017-03-29 18:10:04 +02:00
|
|
|
requestsdict[command] = packageNames
|
|
|
|
|
2017-09-20 00:16:13 +02:00
|
|
|
fdroid_signing_key_fingerprints = load_stats_fdroid_signing_key_fingerprints()
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2020-06-03 22:28:18 +02:00
|
|
|
make_v0(sortedapps, apks, repodir, repodict, requestsdict,
|
2017-09-20 00:16:13 +02:00
|
|
|
fdroid_signing_key_fingerprints)
|
2020-06-03 22:28:18 +02:00
|
|
|
make_v1(sortedapps, apks, repodir, repodict, requestsdict,
|
2017-09-20 00:16:13 +02:00
|
|
|
fdroid_signing_key_fingerprints)
|
2022-05-23 12:39:17 +02:00
|
|
|
make_v2(sortedapps, apks, repodir, repodict, requestsdict,
|
|
|
|
fdroid_signing_key_fingerprints, archive)
|
2021-01-18 13:12:46 +01:00
|
|
|
make_website(sortedapps, repodir, repodict)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2021-01-25 10:17:06 +01:00
|
|
|
|
2021-01-26 13:06:06 +01:00
|
|
|
def _should_file_be_generated(path, magic_string):
|
|
|
|
if os.path.exists(path):
|
|
|
|
with open(path) as f:
|
2021-02-12 10:52:14 +01:00
|
|
|
# if the magic_string is not in the first line the file should be overwritten
|
|
|
|
if magic_string not in f.readline():
|
2021-01-26 13:06:06 +01:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-01-18 13:12:46 +01:00
|
|
|
def make_website(apps, repodir, repodict):
|
2021-02-12 10:51:26 +01:00
|
|
|
_ignored, repo_pubkey_fingerprint = extract_pubkey()
|
2021-01-25 11:25:49 +01:00
|
|
|
repo_pubkey_fingerprint_stripped = repo_pubkey_fingerprint.replace(" ", "")
|
|
|
|
link = repodict["address"]
|
2021-02-12 10:52:14 +01:00
|
|
|
link_fingerprinted = ('{link}?fingerprint={fingerprint}'
|
|
|
|
.format(link=link, fingerprint=repo_pubkey_fingerprint_stripped))
|
|
|
|
# do not change this string, as it will break updates for files with older versions of this string
|
|
|
|
autogenerate_comment = "auto-generated - fdroid index updates will overwrite this file"
|
2021-01-25 11:25:49 +01:00
|
|
|
|
2021-01-25 09:35:25 +01:00
|
|
|
if not os.path.exists(repodir):
|
|
|
|
os.makedirs(repodir)
|
2021-02-01 06:42:53 +01:00
|
|
|
|
2021-01-26 13:06:06 +01:00
|
|
|
qrcode.make(link_fingerprinted).save(os.path.join(repodir, "index.png"))
|
2021-01-18 13:12:46 +01:00
|
|
|
|
2021-01-26 13:06:06 +01:00
|
|
|
html_name = 'index.html'
|
2021-01-25 09:35:25 +01:00
|
|
|
html_file = os.path.join(repodir, html_name)
|
2021-01-26 13:06:06 +01:00
|
|
|
|
|
|
|
if _should_file_be_generated(html_file, autogenerate_comment):
|
|
|
|
with open(html_file, 'w') as f:
|
|
|
|
name = repodict["name"]
|
|
|
|
description = repodict["description"]
|
|
|
|
icon = repodict["icon"]
|
|
|
|
f.write("""<!-- {autogenerate_comment} -->
|
2021-02-01 07:54:48 +01:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
|
|
<meta content="width=device-width; initial-scale=1.0; minimum-scale=0.5; maximum-scale=2.0; user-scalable=1;" name="viewport">
|
|
|
|
<title>
|
|
|
|
{name}
|
|
|
|
</title>
|
|
|
|
<base href="index.html">
|
|
|
|
<link href="index.css" rel="stylesheet" type="text/css">
|
|
|
|
<link href="icons/{icon}" rel="icon" type="image/png">
|
|
|
|
<link href="icons/{icon}" rel="shortcut icon" type="image/png">
|
|
|
|
<meta content="{name}" property="og:site_name">
|
|
|
|
<meta content="{name}" property="og:title">
|
2021-11-19 17:53:43 +01:00
|
|
|
<meta content property="og:determiner">
|
2021-02-01 07:54:48 +01:00
|
|
|
<meta content="{description}" property="og:description">
|
|
|
|
<meta content="index,nofollow" name="robots">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>
|
|
|
|
{name}
|
|
|
|
</h2>
|
|
|
|
<div id="intro">
|
|
|
|
<p style="margin-bottom:.2em;">
|
|
|
|
<span style="float:right;width:100px;margin-left:.5em;">
|
|
|
|
<a href="index.png" title="QR: test">
|
|
|
|
<img alt="QR: test" src="index.png" width="100">
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
{description}
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
Currently it serves
|
|
|
|
<kbd>
|
|
|
|
{number_of_apps}
|
|
|
|
</kbd>
|
|
|
|
apps. To add it to your F-Droid client, scan the QR code (click it to enlarge) or use this URL:
|
|
|
|
</p>
|
|
|
|
<p class="center" style="margin-top:.5em">
|
|
|
|
<a href="{link_fingerprinted}">
|
|
|
|
<code style="color:#000000;font-weight:bold;">
|
|
|
|
{link}
|
|
|
|
</code>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
If you would like to manually verify the fingerprint (SHA-256) of the repository signing key, here it is:
|
|
|
|
<br>
|
|
|
|
<blockcode style="color:#000000;font-weight:bold;">
|
|
|
|
{fingerprint}
|
|
|
|
</blockcode>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""".format(autogenerate_comment=autogenerate_comment,
|
2021-02-01 06:42:53 +01:00
|
|
|
description=description,
|
|
|
|
fingerprint=repo_pubkey_fingerprint,
|
|
|
|
icon=icon,
|
|
|
|
link=link,
|
|
|
|
link_fingerprinted=link_fingerprinted,
|
2021-02-01 07:54:48 +01:00
|
|
|
name=name,
|
|
|
|
number_of_apps=str(len(apps))))
|
2021-01-25 09:35:25 +01:00
|
|
|
|
2021-01-26 13:06:06 +01:00
|
|
|
css_file = os.path.join(repodir, "index.css")
|
|
|
|
if _should_file_be_generated(css_file, autogenerate_comment):
|
2021-01-25 09:35:25 +01:00
|
|
|
with open(css_file, "w") as f:
|
2021-01-26 13:06:06 +01:00
|
|
|
# this auto generated comment was not included via .format(), as python seems to have problems with css files in combination with .format()
|
|
|
|
f.write("""/* auto-generated - fdroid index updates will overwrite this file */
|
2021-01-25 09:35:25 +01:00
|
|
|
BODY {
|
2021-02-01 07:54:48 +01:00
|
|
|
font-family : Arial, Helvetica, Sans-Serif;
|
|
|
|
color : #0000ee;
|
|
|
|
background-color : #ffffff;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
text-align : justify;
|
|
|
|
}
|
|
|
|
p.center {
|
|
|
|
text-align : center;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
TD {
|
2021-02-01 07:54:48 +01:00
|
|
|
font-family : Arial, Helvetica, Sans-Serif;
|
|
|
|
color : #0000ee;
|
|
|
|
}
|
|
|
|
body,td {
|
|
|
|
font-size : 14px;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
TH {
|
2021-02-01 07:54:48 +01:00
|
|
|
font-family : Arial, Helvetica, Sans-Serif;
|
|
|
|
color : #0000ee;
|
|
|
|
background-color : #F5EAD4;
|
|
|
|
}
|
|
|
|
a:link {
|
|
|
|
color : #bb0000;
|
|
|
|
}
|
|
|
|
a:visited {
|
|
|
|
color : #ff0000;
|
|
|
|
}
|
|
|
|
.zitat {
|
|
|
|
margin-left : 1cm;
|
|
|
|
margin-right : 1cm;
|
|
|
|
font-style : italic;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
#intro {
|
2021-02-01 07:54:48 +01:00
|
|
|
border-spacing : 1em;
|
|
|
|
border : 1px solid gray;
|
|
|
|
border-radius : 0.5em;
|
|
|
|
box-shadow : 10px 10px 5px #888;
|
|
|
|
margin : 1.5em;
|
|
|
|
font-size : .9em;
|
|
|
|
width : 600px;
|
|
|
|
max-width : 90%;
|
|
|
|
display : table;
|
|
|
|
margin-left : auto;
|
|
|
|
margin-right : auto;
|
|
|
|
font-size : .8em;
|
|
|
|
color : #555555;
|
|
|
|
}
|
|
|
|
#intro > p {
|
|
|
|
margin-top : 0;
|
|
|
|
}
|
|
|
|
#intro p:last-child {
|
|
|
|
margin-bottom : 0;
|
|
|
|
}
|
2021-01-25 09:35:25 +01:00
|
|
|
.last {
|
2021-02-01 07:54:48 +01:00
|
|
|
border-bottom : 1px solid black;
|
|
|
|
padding-bottom : .5em;
|
|
|
|
text-align : center;
|
|
|
|
}
|
|
|
|
table {
|
|
|
|
border-collapse : collapse;
|
|
|
|
}
|
|
|
|
h2 {
|
|
|
|
text-align : center;
|
|
|
|
}
|
|
|
|
.perms {
|
|
|
|
font-family : monospace;
|
|
|
|
font-size : .8em;
|
|
|
|
}
|
|
|
|
.repoapplist {
|
|
|
|
display : table;
|
|
|
|
border-collapse : collapse;
|
|
|
|
margin-left : auto;
|
|
|
|
margin-right : auto;
|
|
|
|
width : 600px;
|
|
|
|
max-width : 90%;
|
|
|
|
}
|
|
|
|
.approw, appdetailrow {
|
|
|
|
display : table-row;
|
|
|
|
}
|
|
|
|
.appdetailrow {
|
|
|
|
display : flex;
|
|
|
|
padding : .5em;
|
|
|
|
}
|
|
|
|
.appiconbig, .appdetailblock, .appdetailcell {
|
|
|
|
display : table-cell
|
|
|
|
}
|
|
|
|
.appiconbig {
|
|
|
|
vertical-align : middle;
|
|
|
|
text-align : center;
|
|
|
|
}
|
|
|
|
.appdetailinner {
|
|
|
|
width : 100%;
|
|
|
|
}
|
|
|
|
.applinkcell {
|
|
|
|
text-align : center;
|
|
|
|
float : right;
|
|
|
|
width : 100%;
|
|
|
|
margin-bottom : .1em;
|
|
|
|
}
|
|
|
|
.paddedlink {
|
|
|
|
margin : 1em;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
.approw {
|
2021-02-01 07:54:48 +01:00
|
|
|
border-spacing : 1em;
|
|
|
|
border : 1px solid gray;
|
|
|
|
border-radius : 0.5em;
|
|
|
|
padding : 0.5em;
|
|
|
|
margin : 1.5em;
|
|
|
|
}
|
|
|
|
.appdetailinner .appdetailrow:first-child {
|
|
|
|
background-color : #d5d5d5;
|
|
|
|
}
|
|
|
|
.appdetailinner .appdetailrow:first-child .appdetailcell {
|
|
|
|
min-width : 33%;
|
|
|
|
flex : 1 33%;
|
|
|
|
text-align : center;
|
|
|
|
}
|
|
|
|
.appdetailinner .appdetailrow:first-child .appdetailcell:first-child {
|
|
|
|
text-align : left;
|
|
|
|
}
|
|
|
|
.appdetailinner .appdetailrow:first-child .appdetailcell:last-child {
|
|
|
|
float : none;
|
|
|
|
text-align : right;
|
|
|
|
}
|
|
|
|
.minor-details {
|
|
|
|
font-size : .8em;
|
|
|
|
color : #555555;
|
|
|
|
}
|
|
|
|
.boldname {
|
|
|
|
font-weight : bold;
|
|
|
|
}
|
|
|
|
#appcount {
|
|
|
|
text-align : center;
|
|
|
|
margin-bottom : .5em;
|
|
|
|
}
|
2021-01-25 09:35:25 +01:00
|
|
|
kbd {
|
2021-02-01 07:54:48 +01:00
|
|
|
padding : 0.1em 0.6em;
|
|
|
|
border : 1px solid #CCC;
|
|
|
|
background-color : #F7F7F7;
|
|
|
|
color : #333;
|
|
|
|
box-shadow : 0px 1px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 2px #FFF inset;
|
|
|
|
border-radius : 3px;
|
|
|
|
display : inline-block;
|
|
|
|
margin : 0px 0.1em;
|
|
|
|
text-shadow : 0px 1px 0px #FFF;
|
|
|
|
white-space : nowrap;
|
|
|
|
}
|
|
|
|
div.filterline, div.repoline {
|
|
|
|
display : table;
|
|
|
|
margin-left : auto;
|
|
|
|
margin-right : auto;
|
|
|
|
margin-bottom : 1em;
|
|
|
|
vertical-align : middle;
|
|
|
|
display : table;
|
|
|
|
font-size : .8em;
|
|
|
|
}
|
|
|
|
.filterline form {
|
|
|
|
display : table-row;
|
|
|
|
}
|
|
|
|
.filterline .filtercell {
|
|
|
|
display : table-cell;
|
|
|
|
vertical-align : middle;
|
|
|
|
}
|
|
|
|
fieldset {
|
|
|
|
float : left;
|
|
|
|
}
|
|
|
|
fieldset select, fieldset input, #reposelect select, #reposelect input {
|
|
|
|
font-size : .9em;
|
|
|
|
}
|
|
|
|
.pager {
|
|
|
|
display : table;
|
|
|
|
margin-left : auto;
|
|
|
|
margin-right : auto;
|
|
|
|
width : 600px;
|
|
|
|
max-width : 90%;
|
|
|
|
padding-top : .6em;
|
|
|
|
}
|
|
|
|
/* should correspond to .repoapplist */
|
|
|
|
.pagerrow {
|
|
|
|
display : table-row;
|
|
|
|
}
|
|
|
|
.pagercell {
|
|
|
|
display : table-cell;
|
|
|
|
}
|
|
|
|
.pagercell.left {
|
|
|
|
text-align : left;
|
|
|
|
padding-right : 1em;
|
|
|
|
}
|
|
|
|
.pagercell.middle {
|
|
|
|
text-align : center;
|
|
|
|
font-size : .9em;
|
|
|
|
color : #555;
|
|
|
|
}
|
|
|
|
.pagercell.right {
|
|
|
|
text-align : right;
|
|
|
|
padding-left : 1em;
|
|
|
|
}
|
|
|
|
.anti {
|
|
|
|
color : peru;
|
|
|
|
}
|
|
|
|
.antibold {
|
|
|
|
color : crimson;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
#footer {
|
2021-02-01 07:54:48 +01:00
|
|
|
text-align : center;
|
|
|
|
margin-top : 1em;
|
|
|
|
font-size : 11px;
|
|
|
|
color : #555;
|
|
|
|
}
|
|
|
|
#footer img {
|
|
|
|
vertical-align : middle;
|
2021-01-25 09:35:25 +01:00
|
|
|
}
|
|
|
|
@media (max-width: 600px) {
|
2021-02-01 07:54:48 +01:00
|
|
|
.repoapplist {
|
|
|
|
display : block;
|
|
|
|
}
|
|
|
|
.appdetailinner, .appdetailrow {
|
|
|
|
display : block;
|
|
|
|
}
|
|
|
|
.appdetailcell {
|
|
|
|
display : block;
|
|
|
|
float : left;
|
|
|
|
line-height : 1.5em;
|
|
|
|
}
|
2021-01-25 10:17:06 +01:00
|
|
|
}""")
|
2021-01-25 09:35:25 +01:00
|
|
|
|
2017-09-20 00:16:13 +02:00
|
|
|
|
2022-05-23 12:39:17 +02:00
|
|
|
def dict_diff(source, target):
|
|
|
|
if not isinstance(target, dict) or not isinstance(source, dict):
|
|
|
|
return target
|
|
|
|
|
|
|
|
result = {key: None for key in source if key not in target}
|
|
|
|
|
|
|
|
for key, value in target.items():
|
|
|
|
if key not in source:
|
|
|
|
result[key] = value
|
|
|
|
elif value != source[key]:
|
|
|
|
result[key] = dict_diff(source[key], value)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def file_entry(filename, hashType=None, hsh=None, size=None):
|
|
|
|
meta = {}
|
|
|
|
meta["name"] = "/" + filename.split("/", 1)[1]
|
|
|
|
if hsh:
|
|
|
|
meta[hashType] = hsh
|
|
|
|
if hsh != "sha256":
|
|
|
|
meta["sha256"] = common.sha256sum(filename)
|
|
|
|
if size:
|
|
|
|
meta["size"] = size
|
|
|
|
else:
|
|
|
|
meta["size"] = os.stat(filename).st_size
|
|
|
|
return meta
|
|
|
|
|
|
|
|
|
|
|
|
def load_locale(name, repodir):
|
|
|
|
lst = {}
|
|
|
|
for yml in Path().glob("config/**/{name}.yml".format(name=name)):
|
|
|
|
locale = yml.parts[1]
|
|
|
|
if len(yml.parts) == 2:
|
|
|
|
locale = "en-US"
|
|
|
|
with open(yml, encoding="utf-8") as fp:
|
|
|
|
elem = yaml.safe_load(fp)
|
|
|
|
for akey, avalue in elem.items():
|
|
|
|
if akey not in lst:
|
|
|
|
lst[akey] = {}
|
|
|
|
for key, value in avalue.items():
|
|
|
|
if key not in lst[akey]:
|
|
|
|
lst[akey][key] = {}
|
|
|
|
if key == "icon":
|
|
|
|
shutil.copy(os.path.join("config", value), os.path.join(repodir, "icons"))
|
|
|
|
lst[akey][key][locale] = file_entry(os.path.join(repodir, "icons", value))
|
|
|
|
else:
|
|
|
|
lst[akey][key][locale] = value
|
|
|
|
|
|
|
|
return lst
|
|
|
|
|
|
|
|
|
|
|
|
def convert_datetime(obj):
|
|
|
|
if isinstance(obj, datetime):
|
|
|
|
# Java prefers milliseconds
|
|
|
|
# we also need to account for time zone/daylight saving time
|
|
|
|
return int(calendar.timegm(obj.timetuple()) * 1000)
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
def package_metadata(app, repodir):
|
|
|
|
meta = {}
|
|
|
|
for element in (
|
|
|
|
"added",
|
|
|
|
# "binaries",
|
|
|
|
"Categories",
|
|
|
|
"Changelog",
|
|
|
|
"IssueTracker",
|
|
|
|
"lastUpdated",
|
|
|
|
"License",
|
|
|
|
"SourceCode",
|
|
|
|
"Translation",
|
|
|
|
"WebSite",
|
|
|
|
"video",
|
|
|
|
"featureGraphic",
|
|
|
|
"promoGraphic",
|
|
|
|
"tvBanner",
|
|
|
|
"screenshots",
|
|
|
|
"AuthorEmail",
|
|
|
|
"AuthorName",
|
|
|
|
"AuthorPhone",
|
|
|
|
"AuthorWebSite",
|
|
|
|
"Bitcoin",
|
|
|
|
"FlattrID",
|
|
|
|
"Liberapay",
|
|
|
|
"LiberapayID",
|
|
|
|
"Litecoin",
|
|
|
|
"OpenCollective",
|
|
|
|
):
|
|
|
|
if element in app and app[element]:
|
|
|
|
element_new = element[:1].lower() + element[1:]
|
|
|
|
meta[element_new] = convert_datetime(app[element])
|
|
|
|
|
|
|
|
for element in (
|
|
|
|
"Name",
|
|
|
|
"Summary",
|
|
|
|
"Description",
|
|
|
|
):
|
|
|
|
element_new = element[:1].lower() + element[1:]
|
|
|
|
if element in app and app[element]:
|
|
|
|
meta[element_new] = {"en-US": convert_datetime(app[element])}
|
|
|
|
elif "localized" in app:
|
|
|
|
localized = {k: v[element_new] for k, v in app["localized"].items() if element_new in v}
|
|
|
|
if localized:
|
|
|
|
meta[element_new] = localized
|
|
|
|
|
|
|
|
if "name" not in meta and app["AutoName"]:
|
|
|
|
meta["name"] = {"en-US": app["AutoName"]}
|
|
|
|
|
|
|
|
# fdroidserver/metadata.py App default
|
|
|
|
if meta["license"] == "Unknown":
|
|
|
|
del meta["license"]
|
|
|
|
|
|
|
|
if app["Donate"]:
|
|
|
|
meta["donate"] = [app["Donate"]]
|
|
|
|
|
|
|
|
# TODO handle different resolutions
|
|
|
|
if app.get("icon"):
|
|
|
|
meta["icon"] = {"en-US": file_entry(os.path.join(repodir, "icons", app["icon"]))}
|
|
|
|
|
|
|
|
if "iconv2" in app:
|
|
|
|
meta["icon"] = app["iconv2"]
|
|
|
|
|
|
|
|
return meta
|
|
|
|
|
|
|
|
|
|
|
|
def convert_version(version, app, repodir):
|
|
|
|
ver = {}
|
|
|
|
if "added" in version:
|
|
|
|
ver["added"] = convert_datetime(version["added"])
|
|
|
|
else:
|
|
|
|
ver["added"] = 0
|
|
|
|
|
|
|
|
ver["file"] = {
|
|
|
|
"name": "/{}".format(version["apkName"]),
|
|
|
|
version["hashType"]: version["hash"],
|
|
|
|
"size": version["size"]
|
|
|
|
}
|
|
|
|
|
|
|
|
if "srcname" in version:
|
|
|
|
ver["src"] = file_entry(os.path.join(repodir, version["srcname"]))
|
|
|
|
|
|
|
|
if "obbMainFile" in version:
|
|
|
|
ver["obbMainFile"] = file_entry(
|
|
|
|
os.path.join(repodir, version["obbMainFile"]),
|
|
|
|
"sha256", version["obbMainFileSha256"]
|
|
|
|
)
|
|
|
|
|
|
|
|
if "obbPatchFile" in version:
|
|
|
|
ver["obbPatchFile"] = file_entry(
|
|
|
|
os.path.join(repodir, version["obbPatchFile"]),
|
|
|
|
"sha256", version["obbPatchFileSha256"]
|
|
|
|
)
|
|
|
|
|
|
|
|
ver["manifest"] = manifest = {}
|
|
|
|
|
|
|
|
for element in (
|
|
|
|
"nativecode",
|
|
|
|
"versionName",
|
|
|
|
"maxSdkVersion",
|
|
|
|
):
|
|
|
|
if element in version:
|
|
|
|
manifest[element] = version[element]
|
|
|
|
|
|
|
|
if "versionCode" in version:
|
|
|
|
manifest["versionCode"] = int(version["versionCode"])
|
|
|
|
|
|
|
|
if "features" in version and version["features"]:
|
|
|
|
manifest["features"] = features = []
|
|
|
|
for feature in version["features"]:
|
|
|
|
# TODO get version from manifest, default (0) is omitted
|
|
|
|
# features.append({"name": feature, "version": 1})
|
|
|
|
features.append({"name": feature})
|
|
|
|
|
|
|
|
if "minSdkVersion" in version:
|
|
|
|
manifest["usesSdk"] = {}
|
|
|
|
manifest["usesSdk"]["minSdkVersion"] = version["minSdkVersion"]
|
|
|
|
if "targetSdkVersion" in version:
|
|
|
|
manifest["usesSdk"]["targetSdkVersion"] = version["targetSdkVersion"]
|
|
|
|
else:
|
|
|
|
# https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#target
|
|
|
|
manifest["usesSdk"]["targetSdkVersion"] = manifest["usesSdk"]["minSdkVersion"]
|
|
|
|
|
|
|
|
if "signer" in version:
|
|
|
|
manifest["signer"] = {"sha256": [version["signer"]]}
|
|
|
|
|
|
|
|
for element in ("uses-permission", "uses-permission-sdk-23"):
|
|
|
|
en = element.replace("uses-permission", "usesPermission").replace("-sdk-23", "Sdk23")
|
|
|
|
if element in version and version[element]:
|
|
|
|
manifest[en] = []
|
|
|
|
for perm in version[element]:
|
|
|
|
if perm[1]:
|
|
|
|
manifest[en].append({"name": perm[0], "maxSdkVersion": perm[1]})
|
|
|
|
else:
|
|
|
|
manifest[en].append({"name": perm[0]})
|
|
|
|
|
|
|
|
if "AntiFeatures" in app and app["AntiFeatures"]:
|
|
|
|
ver["antiFeatures"] = {}
|
|
|
|
for antif in app["AntiFeatures"]:
|
|
|
|
# TODO: get reasons from fdroiddata
|
|
|
|
# ver["antiFeatures"][antif] = {"en-US": "reason"}
|
|
|
|
ver["antiFeatures"][antif] = {}
|
|
|
|
|
|
|
|
if "AntiFeatures" in version and version["AntiFeatures"]:
|
|
|
|
if "antiFeatures" not in ver:
|
|
|
|
ver["antiFeatures"] = {}
|
|
|
|
for antif in version["AntiFeatures"]:
|
|
|
|
# TODO: get reasons from fdroiddata
|
|
|
|
# ver["antiFeatures"][antif] = {"en-US": "reason"}
|
|
|
|
ver["antiFeatures"][antif] = {}
|
|
|
|
|
|
|
|
if "versionCode" in version:
|
|
|
|
if int(version["versionCode"]) > int(app["CurrentVersionCode"]):
|
|
|
|
ver["releaseChannels"] = ["Beta"]
|
|
|
|
|
|
|
|
versionCodeStr = str(version['versionCode']) # TODO build.versionCode should be int!
|
|
|
|
for build in app.get('Builds', []):
|
|
|
|
if build['versionCode'] == versionCodeStr and "whatsNew" in build:
|
|
|
|
ver["whatsNew"] = build["whatsNew"]
|
|
|
|
break
|
|
|
|
|
|
|
|
return ver
|
|
|
|
|
|
|
|
|
|
|
|
def v2_repo(repodict, repodir, archive):
|
|
|
|
repo = {}
|
|
|
|
|
|
|
|
repo["name"] = {"en-US": repodict["name"]}
|
|
|
|
repo["description"] = {"en-US": repodict["description"]}
|
|
|
|
repo["icon"] = {"en-US": file_entry("{}/icons/{}".format(repodir, repodict["icon"]))}
|
|
|
|
|
|
|
|
config = load_locale("config", repodir)
|
|
|
|
if config:
|
|
|
|
repo["name"] = config["archive" if archive else "repo"]["name"]
|
|
|
|
repo["description"] = config["archive" if archive else "repo"]["description"]
|
|
|
|
repo["icon"] = config["archive" if archive else "repo"]["icon"]
|
|
|
|
|
|
|
|
repo["address"] = repodict["address"]
|
2022-06-03 09:35:43 +02:00
|
|
|
if "webBaseUrl" in repodict:
|
|
|
|
repo["webBaseUrl"] = repodict["webBaseUrl"]
|
2022-05-23 12:39:17 +02:00
|
|
|
|
|
|
|
if "mirrors" in repodict:
|
|
|
|
repo["mirrors"] = [{"url": mirror} for mirror in repodict["mirrors"]]
|
|
|
|
|
2022-06-03 09:17:28 +02:00
|
|
|
# the first entry is traditionally the primary mirror
|
|
|
|
if repodict['address'] not in repodict["mirrors"]:
|
|
|
|
repo["mirrors"].insert(0, {"url": repodict['address'], "isPrimary": True})
|
|
|
|
|
2022-05-23 12:39:17 +02:00
|
|
|
repo["timestamp"] = repodict["timestamp"]
|
|
|
|
|
|
|
|
anti_features = load_locale("antiFeatures", repodir)
|
|
|
|
if anti_features:
|
|
|
|
repo["antiFeatures"] = anti_features
|
|
|
|
|
|
|
|
categories = load_locale("categories", repodir)
|
|
|
|
if categories:
|
|
|
|
repo["categories"] = categories
|
|
|
|
|
|
|
|
channels = load_locale("channels", repodir)
|
|
|
|
if channels:
|
|
|
|
repo["releaseChannels"] = channels
|
|
|
|
|
|
|
|
return repo
|
|
|
|
|
|
|
|
|
|
|
|
def make_v2(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints, archive):
|
|
|
|
|
|
|
|
def _index_encoder_default(obj):
|
|
|
|
if isinstance(obj, set):
|
|
|
|
return sorted(list(obj))
|
|
|
|
if isinstance(obj, datetime):
|
|
|
|
# Java prefers milliseconds
|
|
|
|
# we also need to account for time zone/daylight saving time
|
|
|
|
return int(calendar.timegm(obj.timetuple()) * 1000)
|
|
|
|
if isinstance(obj, dict):
|
|
|
|
d = collections.OrderedDict()
|
|
|
|
for key in sorted(obj.keys()):
|
|
|
|
d[key] = obj[key]
|
|
|
|
return d
|
|
|
|
raise TypeError(repr(obj) + " is not JSON serializable")
|
|
|
|
|
|
|
|
output = collections.OrderedDict()
|
|
|
|
output["repo"] = v2_repo(repodict, repodir, archive)
|
|
|
|
if requestsdict and requestsdict["install"] or requestsdict["uninstall"]:
|
|
|
|
output["repo"]["requests"] = requestsdict
|
|
|
|
|
|
|
|
# establish sort order of the index
|
|
|
|
v1_sort_packages(packages, fdroid_signing_key_fingerprints)
|
|
|
|
|
|
|
|
output_packages = collections.OrderedDict()
|
|
|
|
output['packages'] = output_packages
|
|
|
|
for package in packages:
|
|
|
|
packageName = package['packageName']
|
|
|
|
if packageName not in apps:
|
|
|
|
logging.info(_('Ignoring package without metadata: ') + package['apkName'])
|
|
|
|
continue
|
|
|
|
if not package.get('versionName'):
|
|
|
|
app = apps[packageName]
|
|
|
|
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
|
|
|
|
for build in app.get('Builds', []):
|
|
|
|
if build['versionCode'] == versionCodeStr:
|
|
|
|
versionName = build.get('versionName')
|
|
|
|
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
|
|
|
|
.format(apkfilename=package['apkName'], version=versionName))
|
|
|
|
package['versionName'] = versionName
|
|
|
|
break
|
|
|
|
if packageName in output_packages:
|
|
|
|
packagelist = output_packages[packageName]
|
|
|
|
else:
|
|
|
|
packagelist = {}
|
|
|
|
output_packages[packageName] = packagelist
|
|
|
|
packagelist["metadata"] = package_metadata(apps[packageName], repodir)
|
|
|
|
if "signer" in package:
|
|
|
|
packagelist["metadata"]["preferredSigner"] = package["signer"]
|
|
|
|
|
|
|
|
packagelist["versions"] = {}
|
|
|
|
|
|
|
|
packagelist["versions"][package["hash"]] = convert_version(package, apps[packageName], repodir)
|
|
|
|
|
|
|
|
entry = {}
|
|
|
|
entry["timestamp"] = repodict["timestamp"]
|
|
|
|
|
|
|
|
entry["version"] = repodict["version"]
|
|
|
|
if "maxage" in repodict:
|
|
|
|
entry["maxAge"] = repodict["maxage"]
|
|
|
|
|
|
|
|
json_name = 'index-v2.json'
|
|
|
|
index_file = os.path.join(repodir, json_name)
|
|
|
|
with open(index_file, "w", encoding="utf-8") as fp:
|
|
|
|
if common.options.pretty:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default, indent=2, ensure_ascii=False)
|
|
|
|
else:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default, ensure_ascii=False)
|
|
|
|
|
|
|
|
json_name = "tmp/{}_{}.json".format(repodir, convert_datetime(repodict["timestamp"]))
|
|
|
|
with open(json_name, "w", encoding="utf-8") as fp:
|
|
|
|
if common.options.pretty:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default, indent=2, ensure_ascii=False)
|
|
|
|
else:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default, ensure_ascii=False)
|
|
|
|
|
|
|
|
entry["index"] = file_entry(index_file)
|
|
|
|
entry["index"]["numPackages"] = len(output.get("packages", []))
|
|
|
|
|
|
|
|
indexes = sorted(Path().glob("tmp/{}*.json".format(repodir)), key=lambda x: x.name)
|
|
|
|
indexes.pop() # remove current index
|
|
|
|
# remove older indexes
|
|
|
|
while len(indexes) > 10:
|
|
|
|
indexes.pop(0).unlink()
|
|
|
|
|
|
|
|
indexes = [json.loads(Path(fn).read_text(encoding="utf-8")) for fn in indexes]
|
|
|
|
|
|
|
|
for diff in Path().glob("{}/diff/*.json".format(repodir)):
|
|
|
|
diff.unlink()
|
|
|
|
|
|
|
|
entry["diffs"] = {}
|
|
|
|
for old in indexes:
|
|
|
|
diff_name = str(old["repo"]["timestamp"]) + ".json"
|
|
|
|
diff_file = os.path.join(repodir, "diff", diff_name)
|
|
|
|
diff = dict_diff(old, output)
|
|
|
|
if not os.path.exists(os.path.join(repodir, "diff")):
|
|
|
|
os.makedirs(os.path.join(repodir, "diff"))
|
|
|
|
with open(diff_file, "w", encoding="utf-8") as fp:
|
|
|
|
if common.options.pretty:
|
|
|
|
json.dump(diff, fp, default=_index_encoder_default, indent=2, ensure_ascii=False)
|
|
|
|
else:
|
|
|
|
json.dump(diff, fp, default=_index_encoder_default, ensure_ascii=False)
|
|
|
|
|
|
|
|
entry["diffs"][old["repo"]["timestamp"]] = file_entry(diff_file)
|
|
|
|
entry["diffs"][old["repo"]["timestamp"]]["numPackages"] = len(diff.get("packages", []))
|
|
|
|
|
|
|
|
json_name = "entry.json"
|
|
|
|
index_file = os.path.join(repodir, json_name)
|
|
|
|
with open(index_file, "w", encoding="utf-8") as fp:
|
|
|
|
if common.options.pretty:
|
|
|
|
json.dump(entry, fp, default=_index_encoder_default, indent=2, ensure_ascii=False)
|
|
|
|
else:
|
|
|
|
json.dump(entry, fp, default=_index_encoder_default, ensure_ascii=False)
|
|
|
|
|
|
|
|
if common.options.nosign:
|
|
|
|
_copy_to_local_copy_dir(repodir, index_file)
|
|
|
|
logging.debug(_('index-v2 must have a signature, use `fdroid signindex` to create it!'))
|
|
|
|
else:
|
|
|
|
signindex.config = common.config
|
2022-05-23 23:08:16 +02:00
|
|
|
signindex.sign_index(repodir, json_name)
|
2022-05-23 12:39:17 +02:00
|
|
|
|
|
|
|
|
2017-09-20 00:16:13 +02:00
|
|
|
def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints):
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
def _index_encoder_default(obj):
|
|
|
|
if isinstance(obj, set):
|
2017-08-16 05:46:32 +02:00
|
|
|
return sorted(list(obj))
|
2017-03-29 18:10:04 +02:00
|
|
|
if isinstance(obj, datetime):
|
2017-09-03 23:07:43 +02:00
|
|
|
# Java prefers milliseconds
|
2020-06-29 21:45:22 +02:00
|
|
|
# we also need to account for time zone/daylight saving time
|
2017-09-03 23:07:43 +02:00
|
|
|
return int(calendar.timegm(obj.timetuple()) * 1000)
|
2017-09-04 02:23:17 +02:00
|
|
|
if isinstance(obj, dict):
|
|
|
|
d = collections.OrderedDict()
|
|
|
|
for key in sorted(obj.keys()):
|
|
|
|
d[key] = obj[key]
|
|
|
|
return d
|
2017-03-29 18:10:04 +02:00
|
|
|
raise TypeError(repr(obj) + " is not JSON serializable")
|
|
|
|
|
|
|
|
output = collections.OrderedDict()
|
|
|
|
output['repo'] = repodict
|
|
|
|
output['requests'] = requestsdict
|
|
|
|
|
2017-09-20 00:16:13 +02:00
|
|
|
# establish sort order of the index
|
2018-05-14 14:07:40 +02:00
|
|
|
v1_sort_packages(packages, fdroid_signing_key_fingerprints)
|
2017-09-20 00:16:13 +02:00
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
appslist = []
|
|
|
|
output['apps'] = appslist
|
2017-05-15 20:11:41 +02:00
|
|
|
for packageName, appdict in apps.items():
|
2017-03-29 18:10:04 +02:00
|
|
|
d = collections.OrderedDict()
|
|
|
|
appslist.append(d)
|
|
|
|
for k, v in sorted(appdict.items()):
|
|
|
|
if not v:
|
|
|
|
continue
|
eliminate app.builds everywhere, it should be app['Builds']
The .txt format was the last place where the lowercase "builds" was used,
this converts references everywhere to be "Builds". This makes it possible
to load metadata YAML files with any YAML parser, then have it possible to
use fdroidserver methods on that data, like metadata.write_metadata().
The test files in tests/metadata/dump/*.yaml were manually edited by cutting
the builds: block and putting it the sort order for Builds: so the contents
should be unchanged.
```
sed -i \
-e 's/app\.builds/app.get('Builds', \[\])/g' \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\])/app.get('Builds', \[\])/g" \
-e "s/app\.get('Builds', \[\])\.append/app\['Builds'\].append/g" \
-e "s/app\['builds'\]/app.get('Builds', [])/g" \
*/*.*
```
2020-12-09 16:01:21 +01:00
|
|
|
if k in ('Builds', 'comments', 'metadatapath',
|
2020-01-13 15:43:42 +01:00
|
|
|
'ArchivePolicy', 'AutoName', 'AutoUpdateMode', 'MaintainerNotes',
|
2017-03-29 18:10:04 +02:00
|
|
|
'Provides', 'Repo', 'RepoType', 'RequiresRoot',
|
|
|
|
'UpdateCheckData', 'UpdateCheckIgnore', 'UpdateCheckMode',
|
2022-05-23 12:39:17 +02:00
|
|
|
'UpdateCheckName', 'NoSourceSince', 'VercodeOperation',
|
|
|
|
'summary', 'description', 'promoGraphic', 'screenshots', 'whatsNew',
|
|
|
|
'featureGraphic', 'iconv2', 'tvBanner',
|
|
|
|
):
|
2017-03-29 18:10:04 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
# name things after the App class fields in fdroidclient
|
|
|
|
if k == 'id':
|
|
|
|
k = 'packageName'
|
|
|
|
elif k == 'CurrentVersionCode': # TODO make SuggestedVersionCode the canonical name
|
|
|
|
k = 'suggestedVersionCode'
|
|
|
|
elif k == 'CurrentVersion': # TODO make SuggestedVersionName the canonical name
|
|
|
|
k = 'suggestedVersionName'
|
|
|
|
else:
|
|
|
|
k = k[:1].lower() + k[1:]
|
|
|
|
d[k] = v
|
|
|
|
|
2017-09-04 02:23:17 +02:00
|
|
|
# establish sort order in localized dicts
|
|
|
|
for app in output['apps']:
|
|
|
|
localized = app.get('localized')
|
|
|
|
if localized:
|
|
|
|
lordered = collections.OrderedDict()
|
|
|
|
for lkey, lvalue in sorted(localized.items()):
|
|
|
|
lordered[lkey] = collections.OrderedDict()
|
|
|
|
for ikey, iname in sorted(lvalue.items()):
|
|
|
|
lordered[lkey][ikey] = iname
|
|
|
|
app['localized'] = lordered
|
|
|
|
|
2017-04-03 11:29:21 +02:00
|
|
|
output_packages = collections.OrderedDict()
|
2017-03-29 18:10:04 +02:00
|
|
|
output['packages'] = output_packages
|
|
|
|
for package in packages:
|
|
|
|
packageName = package['packageName']
|
2017-05-15 20:11:41 +02:00
|
|
|
if packageName not in apps:
|
2017-09-13 18:03:57 +02:00
|
|
|
logging.info(_('Ignoring package without metadata: ') + package['apkName'])
|
2017-05-15 20:11:41 +02:00
|
|
|
continue
|
2018-04-17 12:15:51 +02:00
|
|
|
if not package.get('versionName'):
|
|
|
|
app = apps[packageName]
|
|
|
|
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
|
eliminate app.builds everywhere, it should be app['Builds']
The .txt format was the last place where the lowercase "builds" was used,
this converts references everywhere to be "Builds". This makes it possible
to load metadata YAML files with any YAML parser, then have it possible to
use fdroidserver methods on that data, like metadata.write_metadata().
The test files in tests/metadata/dump/*.yaml were manually edited by cutting
the builds: block and putting it the sort order for Builds: so the contents
should be unchanged.
```
sed -i \
-e 's/app\.builds/app.get('Builds', \[\])/g' \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\])/app.get('Builds', \[\])/g" \
-e "s/app\.get('Builds', \[\])\.append/app\['Builds'\].append/g" \
-e "s/app\['builds'\]/app.get('Builds', [])/g" \
*/*.*
```
2020-12-09 16:01:21 +01:00
|
|
|
for build in app.get('Builds', []):
|
2018-04-17 12:15:51 +02:00
|
|
|
if build['versionCode'] == versionCodeStr:
|
|
|
|
versionName = build.get('versionName')
|
|
|
|
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
|
|
|
|
.format(apkfilename=package['apkName'], version=versionName))
|
|
|
|
package['versionName'] = versionName
|
|
|
|
break
|
2017-03-29 18:10:04 +02:00
|
|
|
if packageName in output_packages:
|
|
|
|
packagelist = output_packages[packageName]
|
|
|
|
else:
|
|
|
|
packagelist = []
|
|
|
|
output_packages[packageName] = packagelist
|
|
|
|
d = collections.OrderedDict()
|
|
|
|
packagelist.append(d)
|
|
|
|
for k, v in sorted(package.items()):
|
|
|
|
if not v:
|
|
|
|
continue
|
|
|
|
if k in ('icon', 'icons', 'icons_src', 'name', ):
|
|
|
|
continue
|
|
|
|
d[k] = v
|
|
|
|
|
|
|
|
json_name = 'index-v1.json'
|
|
|
|
index_file = os.path.join(repodir, json_name)
|
|
|
|
with open(index_file, 'w') as fp:
|
2017-04-02 21:58:34 +02:00
|
|
|
if common.options.pretty:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default, indent=2)
|
|
|
|
else:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.options.nosign:
|
2020-08-20 15:22:02 +02:00
|
|
|
_copy_to_local_copy_dir(repodir, index_file)
|
2017-09-13 18:03:57 +02:00
|
|
|
logging.debug(_('index-v1 must have a signature, use `fdroid signindex` to create it!'))
|
2017-03-29 18:10:04 +02:00
|
|
|
else:
|
2017-03-31 15:50:15 +02:00
|
|
|
signindex.config = common.config
|
2022-05-23 12:39:17 +02:00
|
|
|
signindex.sign_index(repodir, json_name)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
|
2020-08-20 15:22:02 +02:00
|
|
|
def _copy_to_local_copy_dir(repodir, f):
|
|
|
|
local_copy_dir = common.config.get('local_copy_dir', '')
|
|
|
|
if os.path.exists(local_copy_dir):
|
|
|
|
destdir = os.path.join(local_copy_dir, repodir)
|
|
|
|
if not os.path.exists(destdir):
|
|
|
|
os.mkdir(destdir)
|
|
|
|
shutil.copy2(f, destdir, follow_symlinks=False)
|
|
|
|
elif local_copy_dir:
|
|
|
|
raise FDroidException(_('"local_copy_dir" {path} does not exist!')
|
|
|
|
.format(path=local_copy_dir))
|
|
|
|
|
|
|
|
|
2018-05-14 14:07:40 +02:00
|
|
|
def v1_sort_packages(packages, fdroid_signing_key_fingerprints):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Sort the supplied list to ensure a deterministic sort order for package entries in the index file.
|
2021-06-07 12:49:16 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
This sort-order also expresses
|
2017-09-20 00:58:19 +02:00
|
|
|
installation preference to the clients.
|
|
|
|
(First in this list = first to install)
|
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
packages
|
|
|
|
list of packages which need to be sorted before but into index file.
|
2017-09-20 00:58:19 +02:00
|
|
|
"""
|
2017-09-20 00:16:13 +02:00
|
|
|
GROUP_DEV_SIGNED = 1
|
|
|
|
GROUP_FDROID_SIGNED = 2
|
|
|
|
GROUP_OTHER_SIGNED = 3
|
|
|
|
|
|
|
|
def v1_sort_keys(package):
|
|
|
|
packageName = package.get('packageName', None)
|
|
|
|
|
2021-03-04 15:01:42 +01:00
|
|
|
signer = package.get('signer', None)
|
2017-09-20 00:16:13 +02:00
|
|
|
|
2021-03-04 15:01:42 +01:00
|
|
|
dev_signer = common.metadata_find_developer_signature(packageName)
|
2017-09-20 00:16:13 +02:00
|
|
|
group = GROUP_OTHER_SIGNED
|
2021-03-04 15:01:42 +01:00
|
|
|
if dev_signer and dev_signer == signer:
|
2017-09-20 00:16:13 +02:00
|
|
|
group = GROUP_DEV_SIGNED
|
|
|
|
else:
|
2021-03-04 15:01:42 +01:00
|
|
|
fdroid_signer = fdroid_signing_key_fingerprints.get(packageName, {}).get('signer')
|
|
|
|
if fdroid_signer and fdroid_signer == signer:
|
2017-09-20 00:16:13 +02:00
|
|
|
group = GROUP_FDROID_SIGNED
|
|
|
|
|
|
|
|
versionCode = None
|
|
|
|
if package.get('versionCode', None):
|
|
|
|
versionCode = -int(package['versionCode'])
|
|
|
|
|
2022-07-31 09:14:17 +02:00
|
|
|
return packageName, group, signer, versionCode
|
2017-09-20 00:16:13 +02:00
|
|
|
|
|
|
|
packages.sort(key=v1_sort_keys)
|
|
|
|
|
|
|
|
|
2017-09-20 00:58:19 +02:00
|
|
|
def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Aka index.jar aka index.xml."""
|
2017-03-29 18:10:04 +02:00
|
|
|
doc = Document()
|
|
|
|
|
|
|
|
def addElement(name, value, doc, parent):
|
|
|
|
el = doc.createElement(name)
|
|
|
|
el.appendChild(doc.createTextNode(value))
|
|
|
|
parent.appendChild(el)
|
|
|
|
|
|
|
|
def addElementNonEmpty(name, value, doc, parent):
|
|
|
|
if not value:
|
|
|
|
return
|
|
|
|
addElement(name, value, doc, parent)
|
|
|
|
|
|
|
|
def addElementIfInApk(name, apk, key, doc, parent):
|
|
|
|
if key not in apk:
|
|
|
|
return
|
|
|
|
value = str(apk[key])
|
|
|
|
addElement(name, value, doc, parent)
|
|
|
|
|
2017-07-19 10:59:05 +02:00
|
|
|
def addElementCheckLocalized(name, app, key, doc, parent, default=''):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Fill in field from metadata or localized block.
|
2017-07-19 10:59:05 +02:00
|
|
|
|
|
|
|
For name/summary/description, they can come only from the app source,
|
|
|
|
or from a dir in fdroiddata. They can be entirely missing from the
|
|
|
|
metadata file if there is localized versions. This will fetch those
|
|
|
|
from the localized version if its not available in the metadata file.
|
index: xml.dom.minidom no longer sorts attribs
It seems now that xml.dom.minidom preserves the order of attributes, rather
than sorting them. We assume alpha-sort, so this manually
This diff in the test suite running on Debian/testing pointed it out:
https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383
```diff
--- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000
+++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<fdroid>
- <repo icon="fdroid-icon.png" name="My First F-Droid Repo Demo" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a" timestamp="1480431575" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21">
+ <repo name="My First F-Droid Repo Demo" icon="fdroid-icon.png" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21" timestamp="1480431575" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a">
<description>This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. </description>
<mirror>http://foobarfoobarfoobar.onion/fdroid/repo</mirror>
<mirror>https://foo.bar/fdroid/repo</mirror>
@@ -94,9 +94,9 @@
<added>2017-12-22</added>
<sig>056c9f1554c40ba59a2103009c82b420</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE</permissions>
- <uses-permission maxSdkVersion="18" name="android.permission.READ_EXTERNAL_STORAGE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission-sdk-23 maxSdkVersion="27" name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
+ <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" maxSdkVersion="27"/>
</package>
</application>
<application id="fake.ota.update">
@@ -182,9 +182,9 @@
<added>2013-12-31</added>
<sig>eb41d4d6082bb3e81c3d58dbf7fc7332</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED</permissions>
- <uses-permission maxSdkVersion="22" name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission-sdk-23 maxSdkVersion="25" name="android.permission.WRITE_SETTINGS"/>
+ <uses-permission name="android.permission.ACCESS_NETWORK_STATE" maxSdkVersion="22"/>
+ <uses-permission name="android.permission.BLUETOOTH_ADMIN" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.WRITE_SETTINGS" maxSdkVersion="25"/>
</package>
</application>
<application id="obb.main.twoversions">
```
2020-04-15 21:43:41 +02:00
|
|
|
|
|
|
|
Attributes should be alpha-sorted, so they must be added in
|
|
|
|
alpha- sort order.
|
|
|
|
|
|
|
|
"""
|
2017-07-19 10:59:05 +02:00
|
|
|
el = doc.createElement(name)
|
|
|
|
value = app.get(key)
|
|
|
|
lkey = key[:1].lower() + key[1:]
|
|
|
|
localized = app.get('localized')
|
|
|
|
if not value and localized:
|
|
|
|
for lang in ['en-US'] + [x for x in localized.keys()]:
|
|
|
|
if not lang.startswith('en'):
|
|
|
|
continue
|
|
|
|
if lang in localized:
|
|
|
|
value = localized[lang].get(lkey)
|
|
|
|
if value:
|
|
|
|
break
|
|
|
|
if not value and localized and len(localized) > 1:
|
|
|
|
lang = list(localized.keys())[0]
|
|
|
|
value = localized[lang].get(lkey)
|
|
|
|
if not value:
|
|
|
|
value = default
|
2020-01-13 15:43:42 +01:00
|
|
|
if not value and name == 'name' and app.get('AutoName'):
|
|
|
|
value = app['AutoName']
|
2017-07-19 10:59:05 +02:00
|
|
|
el.appendChild(doc.createTextNode(value))
|
|
|
|
parent.appendChild(el)
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
root = doc.createElement("fdroid")
|
|
|
|
doc.appendChild(root)
|
|
|
|
|
|
|
|
repoel = doc.createElement("repo")
|
2018-07-09 22:41:08 +02:00
|
|
|
repoel.setAttribute("icon", repodict['icon'])
|
2017-03-29 18:10:04 +02:00
|
|
|
if 'maxage' in repodict:
|
|
|
|
repoel.setAttribute("maxage", str(repodict['maxage']))
|
index: xml.dom.minidom no longer sorts attribs
It seems now that xml.dom.minidom preserves the order of attributes, rather
than sorting them. We assume alpha-sort, so this manually
This diff in the test suite running on Debian/testing pointed it out:
https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383
```diff
--- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000
+++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<fdroid>
- <repo icon="fdroid-icon.png" name="My First F-Droid Repo Demo" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a" timestamp="1480431575" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21">
+ <repo name="My First F-Droid Repo Demo" icon="fdroid-icon.png" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21" timestamp="1480431575" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a">
<description>This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. </description>
<mirror>http://foobarfoobarfoobar.onion/fdroid/repo</mirror>
<mirror>https://foo.bar/fdroid/repo</mirror>
@@ -94,9 +94,9 @@
<added>2017-12-22</added>
<sig>056c9f1554c40ba59a2103009c82b420</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE</permissions>
- <uses-permission maxSdkVersion="18" name="android.permission.READ_EXTERNAL_STORAGE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission-sdk-23 maxSdkVersion="27" name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
+ <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" maxSdkVersion="27"/>
</package>
</application>
<application id="fake.ota.update">
@@ -182,9 +182,9 @@
<added>2013-12-31</added>
<sig>eb41d4d6082bb3e81c3d58dbf7fc7332</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED</permissions>
- <uses-permission maxSdkVersion="22" name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission-sdk-23 maxSdkVersion="25" name="android.permission.WRITE_SETTINGS"/>
+ <uses-permission name="android.permission.ACCESS_NETWORK_STATE" maxSdkVersion="22"/>
+ <uses-permission name="android.permission.BLUETOOTH_ADMIN" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.WRITE_SETTINGS" maxSdkVersion="25"/>
</package>
</application>
<application id="obb.main.twoversions">
```
2020-04-15 21:43:41 +02:00
|
|
|
repoel.setAttribute("name", repodict['name'])
|
|
|
|
pubkey, repo_pubkey_fingerprint = extract_pubkey()
|
|
|
|
repoel.setAttribute("pubkey", pubkey.decode('utf-8'))
|
|
|
|
repoel.setAttribute("timestamp", '%d' % repodict['timestamp'].timestamp())
|
2017-03-29 18:10:04 +02:00
|
|
|
repoel.setAttribute("url", repodict['address'])
|
index: xml.dom.minidom no longer sorts attribs
It seems now that xml.dom.minidom preserves the order of attributes, rather
than sorting them. We assume alpha-sort, so this manually
This diff in the test suite running on Debian/testing pointed it out:
https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383
```diff
--- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000
+++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<fdroid>
- <repo icon="fdroid-icon.png" name="My First F-Droid Repo Demo" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a" timestamp="1480431575" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21">
+ <repo name="My First F-Droid Repo Demo" icon="fdroid-icon.png" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21" timestamp="1480431575" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a">
<description>This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. </description>
<mirror>http://foobarfoobarfoobar.onion/fdroid/repo</mirror>
<mirror>https://foo.bar/fdroid/repo</mirror>
@@ -94,9 +94,9 @@
<added>2017-12-22</added>
<sig>056c9f1554c40ba59a2103009c82b420</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE</permissions>
- <uses-permission maxSdkVersion="18" name="android.permission.READ_EXTERNAL_STORAGE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission-sdk-23 maxSdkVersion="27" name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
+ <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" maxSdkVersion="27"/>
</package>
</application>
<application id="fake.ota.update">
@@ -182,9 +182,9 @@
<added>2013-12-31</added>
<sig>eb41d4d6082bb3e81c3d58dbf7fc7332</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED</permissions>
- <uses-permission maxSdkVersion="22" name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission-sdk-23 maxSdkVersion="25" name="android.permission.WRITE_SETTINGS"/>
+ <uses-permission name="android.permission.ACCESS_NETWORK_STATE" maxSdkVersion="22"/>
+ <uses-permission name="android.permission.BLUETOOTH_ADMIN" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.WRITE_SETTINGS" maxSdkVersion="25"/>
</package>
</application>
<application id="obb.main.twoversions">
```
2020-04-15 21:43:41 +02:00
|
|
|
repoel.setAttribute("version", str(repodict['version']))
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
addElement('description', repodict['description'], doc, repoel)
|
|
|
|
for mirror in repodict.get('mirrors', []):
|
|
|
|
addElement('mirror', mirror, doc, repoel)
|
|
|
|
|
|
|
|
root.appendChild(repoel)
|
|
|
|
|
|
|
|
for command in ('install', 'uninstall'):
|
|
|
|
for packageName in requestsdict[command]:
|
|
|
|
element = doc.createElement(command)
|
|
|
|
root.appendChild(element)
|
|
|
|
element.setAttribute('packageName', packageName)
|
|
|
|
|
|
|
|
for appid, appdict in apps.items():
|
|
|
|
app = metadata.App(appdict)
|
|
|
|
|
2020-11-13 11:19:24 +01:00
|
|
|
if app.get('Disabled') is not None:
|
2017-03-29 18:10:04 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
# Get a list of the apks for this app...
|
|
|
|
apklist = []
|
2020-01-13 15:43:42 +01:00
|
|
|
name_from_apk = None
|
2017-08-09 17:14:51 +02:00
|
|
|
apksbyversion = collections.defaultdict(lambda: [])
|
2017-03-29 18:10:04 +02:00
|
|
|
for apk in apks:
|
2017-08-09 17:14:51 +02:00
|
|
|
if apk.get('versionCode') and apk.get('packageName') == appid:
|
|
|
|
apksbyversion[apk['versionCode']].append(apk)
|
2020-01-13 15:43:42 +01:00
|
|
|
if name_from_apk is None:
|
|
|
|
name_from_apk = apk.get('name')
|
2017-08-09 17:14:51 +02:00
|
|
|
for versionCode, apksforver in apksbyversion.items():
|
2021-03-04 15:01:42 +01:00
|
|
|
fdroid_signer = fdroid_signing_key_fingerprints.get(appid, {}).get('signer')
|
2017-08-09 17:14:51 +02:00
|
|
|
fdroid_signed_apk = None
|
|
|
|
name_match_apk = None
|
|
|
|
for x in apksforver:
|
2021-03-04 15:01:42 +01:00
|
|
|
if fdroid_signer and x.get('signer', None) == fdroid_signer:
|
2017-08-09 17:14:51 +02:00
|
|
|
fdroid_signed_apk = x
|
|
|
|
if common.apk_release_filename.match(x.get('apkName', '')):
|
|
|
|
name_match_apk = x
|
|
|
|
# choose which of the available versions is most
|
|
|
|
# suiteable for index v0
|
|
|
|
if fdroid_signed_apk:
|
|
|
|
apklist.append(fdroid_signed_apk)
|
|
|
|
elif name_match_apk:
|
|
|
|
apklist.append(name_match_apk)
|
|
|
|
else:
|
|
|
|
apklist.append(apksforver[0])
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
if len(apklist) == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
apel = doc.createElement("application")
|
|
|
|
apel.setAttribute("id", app.id)
|
|
|
|
root.appendChild(apel)
|
|
|
|
|
|
|
|
addElement('id', app.id, doc, apel)
|
|
|
|
if app.added:
|
|
|
|
addElement('added', app.added.strftime('%Y-%m-%d'), doc, apel)
|
|
|
|
if app.lastUpdated:
|
|
|
|
addElement('lastupdated', app.lastUpdated.strftime('%Y-%m-%d'), doc, apel)
|
2017-07-19 10:59:05 +02:00
|
|
|
|
2020-01-13 15:43:42 +01:00
|
|
|
addElementCheckLocalized('name', app, 'Name', doc, apel, name_from_apk)
|
2017-07-19 10:59:05 +02:00
|
|
|
addElementCheckLocalized('summary', app, 'Summary', doc, apel)
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
if app.icon:
|
|
|
|
addElement('icon', app.icon, doc, apel)
|
|
|
|
|
2017-07-19 10:59:05 +02:00
|
|
|
addElementCheckLocalized('desc', app, 'Description', doc, apel,
|
2020-11-17 14:17:08 +01:00
|
|
|
'No description available')
|
2017-07-19 10:59:05 +02:00
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
addElement('license', app.License, doc, apel)
|
|
|
|
if app.Categories:
|
|
|
|
addElement('categories', ','.join(app.Categories), doc, apel)
|
|
|
|
# We put the first (primary) category in LAST, which will have
|
|
|
|
# the desired effect of making clients that only understand one
|
|
|
|
# category see that one.
|
|
|
|
addElement('category', app.Categories[0], doc, apel)
|
|
|
|
addElement('web', app.WebSite, doc, apel)
|
|
|
|
addElement('source', app.SourceCode, doc, apel)
|
|
|
|
addElement('tracker', app.IssueTracker, doc, apel)
|
|
|
|
addElementNonEmpty('changelog', app.Changelog, doc, apel)
|
|
|
|
addElementNonEmpty('author', app.AuthorName, doc, apel)
|
|
|
|
addElementNonEmpty('email', app.AuthorEmail, doc, apel)
|
|
|
|
addElementNonEmpty('donate', app.Donate, doc, apel)
|
|
|
|
addElementNonEmpty('bitcoin', app.Bitcoin, doc, apel)
|
|
|
|
addElementNonEmpty('litecoin', app.Litecoin, doc, apel)
|
|
|
|
addElementNonEmpty('flattr', app.FlattrID, doc, apel)
|
2017-12-12 10:53:34 +01:00
|
|
|
addElementNonEmpty('liberapay', app.LiberapayID, doc, apel)
|
2020-03-10 15:56:03 +01:00
|
|
|
addElementNonEmpty('openCollective', app.OpenCollective, doc, apel)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
# These elements actually refer to the current version (i.e. which
|
|
|
|
# one is recommended. They are historically mis-named, and need
|
|
|
|
# changing, but stay like this for now to support existing clients.
|
|
|
|
addElement('marketversion', app.CurrentVersion, doc, apel)
|
|
|
|
addElement('marketvercode', app.CurrentVersionCode, doc, apel)
|
|
|
|
|
|
|
|
if app.Provides:
|
|
|
|
pv = app.Provides.split(',')
|
|
|
|
addElementNonEmpty('provides', ','.join(pv), doc, apel)
|
|
|
|
if app.RequiresRoot:
|
|
|
|
addElement('requirements', 'root', doc, apel)
|
|
|
|
|
2021-01-29 15:28:55 +01:00
|
|
|
# Sort the APK list into version order, just so the web site
|
2017-03-29 18:10:04 +02:00
|
|
|
# doesn't have to do any work by default...
|
|
|
|
apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True)
|
|
|
|
|
|
|
|
if 'antiFeatures' in apklist[0]:
|
|
|
|
app.AntiFeatures.extend(apklist[0]['antiFeatures'])
|
|
|
|
if app.AntiFeatures:
|
|
|
|
addElementNonEmpty('antifeatures', ','.join(app.AntiFeatures), doc, apel)
|
|
|
|
|
|
|
|
# Check for duplicates - they will make the client unhappy...
|
|
|
|
for i in range(len(apklist) - 1):
|
2017-05-30 14:52:33 +02:00
|
|
|
first = apklist[i]
|
|
|
|
second = apklist[i + 1]
|
|
|
|
if first['versionCode'] == second['versionCode'] \
|
|
|
|
and first['sig'] == second['sig']:
|
|
|
|
if first['hash'] == second['hash']:
|
|
|
|
raise FDroidException('"{0}/{1}" and "{0}/{2}" are exact duplicates!'.format(
|
|
|
|
repodir, first['apkName'], second['apkName']))
|
|
|
|
else:
|
|
|
|
raise FDroidException('duplicates: "{0}/{1}" - "{0}/{2}"'.format(
|
|
|
|
repodir, first['apkName'], second['apkName']))
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
current_version_code = 0
|
|
|
|
current_version_file = None
|
|
|
|
for apk in apklist:
|
|
|
|
file_extension = common.get_file_extension(apk['apkName'])
|
|
|
|
# find the APK for the "Current Version"
|
|
|
|
if current_version_code < int(app.CurrentVersionCode):
|
|
|
|
current_version_file = apk['apkName']
|
2021-01-14 14:43:37 +01:00
|
|
|
if current_version_code < apk['versionCode']:
|
|
|
|
current_version_code = apk['versionCode']
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
apkel = doc.createElement("package")
|
|
|
|
apel.appendChild(apkel)
|
2018-04-17 12:15:51 +02:00
|
|
|
|
|
|
|
versionName = apk.get('versionName')
|
|
|
|
if not versionName:
|
|
|
|
versionCodeStr = str(apk['versionCode']) # TODO build.versionCode should be int!
|
eliminate app.builds everywhere, it should be app['Builds']
The .txt format was the last place where the lowercase "builds" was used,
this converts references everywhere to be "Builds". This makes it possible
to load metadata YAML files with any YAML parser, then have it possible to
use fdroidserver methods on that data, like metadata.write_metadata().
The test files in tests/metadata/dump/*.yaml were manually edited by cutting
the builds: block and putting it the sort order for Builds: so the contents
should be unchanged.
```
sed -i \
-e 's/app\.builds/app.get('Builds', \[\])/g' \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
-e "s/app\.get(Builds, \[\])/app.get('Builds', \[\])/g" \
-e "s/app\.get('Builds', \[\])\.append/app\['Builds'\].append/g" \
-e "s/app\['builds'\]/app.get('Builds', [])/g" \
*/*.*
```
2020-12-09 16:01:21 +01:00
|
|
|
for build in app.get('Builds', []):
|
2018-04-17 12:15:51 +02:00
|
|
|
if build['versionCode'] == versionCodeStr and 'versionName' in build:
|
|
|
|
versionName = build['versionName']
|
|
|
|
break
|
|
|
|
if versionName:
|
|
|
|
addElement('version', versionName, doc, apkel)
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
addElement('versioncode', str(apk['versionCode']), doc, apkel)
|
|
|
|
addElement('apkname', apk['apkName'], doc, apkel)
|
|
|
|
addElementIfInApk('srcname', apk, 'srcname', doc, apkel)
|
|
|
|
|
|
|
|
hashel = doc.createElement("hash")
|
|
|
|
hashel.setAttribute('type', 'sha256')
|
|
|
|
hashel.appendChild(doc.createTextNode(apk['hash']))
|
|
|
|
apkel.appendChild(hashel)
|
|
|
|
|
|
|
|
addElement('size', str(apk['size']), doc, apkel)
|
|
|
|
addElementIfInApk('sdkver', apk,
|
|
|
|
'minSdkVersion', doc, apkel)
|
|
|
|
addElementIfInApk('targetSdkVersion', apk,
|
|
|
|
'targetSdkVersion', doc, apkel)
|
|
|
|
addElementIfInApk('maxsdkver', apk,
|
|
|
|
'maxSdkVersion', doc, apkel)
|
|
|
|
addElementIfInApk('obbMainFile', apk,
|
|
|
|
'obbMainFile', doc, apkel)
|
|
|
|
addElementIfInApk('obbMainFileSha256', apk,
|
|
|
|
'obbMainFileSha256', doc, apkel)
|
|
|
|
addElementIfInApk('obbPatchFile', apk,
|
|
|
|
'obbPatchFile', doc, apkel)
|
|
|
|
addElementIfInApk('obbPatchFileSha256', apk,
|
|
|
|
'obbPatchFileSha256', doc, apkel)
|
|
|
|
if 'added' in apk:
|
|
|
|
addElement('added', apk['added'].strftime('%Y-%m-%d'), doc, apkel)
|
|
|
|
|
|
|
|
if file_extension == 'apk': # sig is required for APKs, but only APKs
|
|
|
|
addElement('sig', apk['sig'], doc, apkel)
|
|
|
|
|
|
|
|
old_permissions = set()
|
|
|
|
sorted_permissions = sorted(apk['uses-permission'])
|
|
|
|
for perm in sorted_permissions:
|
2018-09-03 18:07:40 +02:00
|
|
|
perm_name = perm[0]
|
2017-03-29 18:10:04 +02:00
|
|
|
if perm_name.startswith("android.permission."):
|
|
|
|
perm_name = perm_name[19:]
|
|
|
|
old_permissions.add(perm_name)
|
2017-04-03 11:29:21 +02:00
|
|
|
addElementNonEmpty('permissions', ','.join(sorted(old_permissions)), doc, apkel)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
for permission in sorted_permissions:
|
|
|
|
permel = doc.createElement('uses-permission')
|
2018-09-03 18:07:40 +02:00
|
|
|
if permission[1] is not None:
|
|
|
|
permel.setAttribute('maxSdkVersion', '%d' % permission[1])
|
2017-03-29 18:10:04 +02:00
|
|
|
apkel.appendChild(permel)
|
index: xml.dom.minidom no longer sorts attribs
It seems now that xml.dom.minidom preserves the order of attributes, rather
than sorting them. We assume alpha-sort, so this manually
This diff in the test suite running on Debian/testing pointed it out:
https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383
```diff
--- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000
+++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<fdroid>
- <repo icon="fdroid-icon.png" name="My First F-Droid Repo Demo" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a" timestamp="1480431575" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21">
+ <repo name="My First F-Droid Repo Demo" icon="fdroid-icon.png" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21" timestamp="1480431575" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a">
<description>This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. </description>
<mirror>http://foobarfoobarfoobar.onion/fdroid/repo</mirror>
<mirror>https://foo.bar/fdroid/repo</mirror>
@@ -94,9 +94,9 @@
<added>2017-12-22</added>
<sig>056c9f1554c40ba59a2103009c82b420</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE</permissions>
- <uses-permission maxSdkVersion="18" name="android.permission.READ_EXTERNAL_STORAGE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission-sdk-23 maxSdkVersion="27" name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
+ <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" maxSdkVersion="27"/>
</package>
</application>
<application id="fake.ota.update">
@@ -182,9 +182,9 @@
<added>2013-12-31</added>
<sig>eb41d4d6082bb3e81c3d58dbf7fc7332</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED</permissions>
- <uses-permission maxSdkVersion="22" name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission-sdk-23 maxSdkVersion="25" name="android.permission.WRITE_SETTINGS"/>
+ <uses-permission name="android.permission.ACCESS_NETWORK_STATE" maxSdkVersion="22"/>
+ <uses-permission name="android.permission.BLUETOOTH_ADMIN" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.WRITE_SETTINGS" maxSdkVersion="25"/>
</package>
</application>
<application id="obb.main.twoversions">
```
2020-04-15 21:43:41 +02:00
|
|
|
permel.setAttribute('name', permission[0])
|
2017-03-29 18:10:04 +02:00
|
|
|
for permission_sdk_23 in sorted(apk['uses-permission-sdk-23']):
|
|
|
|
permel = doc.createElement('uses-permission-sdk-23')
|
2018-09-03 18:07:40 +02:00
|
|
|
if permission_sdk_23[1] is not None:
|
|
|
|
permel.setAttribute('maxSdkVersion', '%d' % permission_sdk_23[1])
|
2017-03-29 18:10:04 +02:00
|
|
|
apkel.appendChild(permel)
|
index: xml.dom.minidom no longer sorts attribs
It seems now that xml.dom.minidom preserves the order of attributes, rather
than sorting them. We assume alpha-sort, so this manually
This diff in the test suite running on Debian/testing pointed it out:
https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383
```diff
--- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000
+++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<fdroid>
- <repo icon="fdroid-icon.png" name="My First F-Droid Repo Demo" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a" timestamp="1480431575" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21">
+ <repo name="My First F-Droid Repo Demo" icon="fdroid-icon.png" url="https://MyFirstFDroidRepo.org/fdroid/repo" version="21" timestamp="1480431575" pubkey="308204e1308202c9a003020102020434597643300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303931333230313930395a170d3434303133303230313930395a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a028202010086ef94b5aacf2ba4f38c875f4194b44f5644392e3715575d7c92828577e692c352b567172823851c8c72347fbc9d99684cd7ca3e1db3e4cca126382c53f2a5869fb4c19bdec989b2930501af3e758ff40588915fe96b10076ce3346a193a0277d79e83e30fd8657c20e35260dd085aa32eac7c4b85786ffefbf1555cafe2bc928443430cdbba48cfbe701e12ae86e676477932730d4fc7c00af820aef85038a5b4df084cf6470d110dc4c49ea1b749b80b34709d199b3db516b223625c5de4501e861f7d261b3838f8f616aa78831d618d41d25872dc810c9b2087b5a9e146ca95be740316dcdbcb77314e23ab87d4487913b800b1113c0603ea2294188b71d3e49875df097b56f9151211fc6832f9790c5c83d17481f14ad37915fd164f4fd713f6732a15f4245714b84cd665bdbd085660ea33ad7d7095dcc414f09e3903604a40facc2314a115c0045bb50e9df38efb57e1b8e7cc105f340a26eeb46aba0fa6672953eee7f1f92dcb408e561909bbd4bdf4a4948c4d57c467d21aa238c34ba43be050398be963191fa2b49828bc1e4eeed224b40dbe9dc3e570890a71a974a2f4527edb1b07105071755105edcb2af2f269facfb89180903a572a99b46456e80d4a01685a80b233278805f2c876678e731f4ec4f52075aeef6b2b023efbb8a3637ef507c4c37c27e428152ec1817fcba640ad601cb09f72f0fbe2d274a2410203010001a321301f301d0603551d0e04160414c28bf33dd5a9a17338e5b1d1a6edd8c7d141ed0b300d06092a864886f70d01010b0500038202010084e20458b2aafd7fc27146b0986f9324f4260f244920417a77c9bf15e2e2d22d2725bdd8093ec261c3779c3ca03312516506f9410075b90595b41345956d8eb2786fb5994f195611382c2b99dba13381b0100a30bc9e6e47248bf4325e2f6eec9d789216dc7536e753bf1f4be603d9fa2e6f5e192b4eb988b8cdb0bb1e8668a9225426f7d4636479f73ed24ad1d2657c31e63c93d9679b9080171b3bd1bf10a3b92b80bd790fbf62d3644900cd08eae8b9bf9c2567be98dc8cdd2ae19a8d57a3e3e2de899f81f1279f578989e6af906f80c8c2b67651730ee7e568c1af5bcb845b6d685dc55332a9984aeceaea3b7e883447edf1c76b155d95253e39b9710eaa22efa6c81468829702b5dce7126538f3ca70c2f0ad9a5795435fdb1f715f20d60359ef9a9926c7050116e802df651727447848827815f70bd82af3cedd08783156102d2d8ce995c4c43b8e47e91a3e6927f3505a5d395e6bebb84542c570903eeab4382a1c2151f1471c7a06a34dc4d268d8fa72e93bdcd2dccc4302ecac47b9e7e3d8bc9b46d21cd097874a24d529548018dc190ff568c6aa428f0a5eedff1a347730931c74f19277538e49647a4ad7254f4c1ec7d4da12cce9e1fad9607534e66ab40a56b473d9d7e3d563fd03cad2052bad365c5a29f8ae54f09b60dbca3ea768d7767cbe1c133ca08ce725c1c1370f4aab8e5b6e286f52dc0be8d0982b5a">
<description>This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. </description>
<mirror>http://foobarfoobarfoobar.onion/fdroid/repo</mirror>
<mirror>https://foo.bar/fdroid/repo</mirror>
@@ -94,9 +94,9 @@
<added>2017-12-22</added>
<sig>056c9f1554c40ba59a2103009c82b420</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE</permissions>
- <uses-permission maxSdkVersion="18" name="android.permission.READ_EXTERNAL_STORAGE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission-sdk-23 maxSdkVersion="27" name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
+ <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" maxSdkVersion="27"/>
</package>
</application>
<application id="fake.ota.update">
@@ -182,9 +182,9 @@
<added>2013-12-31</added>
<sig>eb41d4d6082bb3e81c3d58dbf7fc7332</sig>
<permissions>ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED</permissions>
- <uses-permission maxSdkVersion="22" name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission maxSdkVersion="18" name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission-sdk-23 maxSdkVersion="25" name="android.permission.WRITE_SETTINGS"/>
+ <uses-permission name="android.permission.ACCESS_NETWORK_STATE" maxSdkVersion="22"/>
+ <uses-permission name="android.permission.BLUETOOTH_ADMIN" maxSdkVersion="18"/>
+ <uses-permission-sdk-23 name="android.permission.WRITE_SETTINGS" maxSdkVersion="25"/>
</package>
</application>
<application id="obb.main.twoversions">
```
2020-04-15 21:43:41 +02:00
|
|
|
permel.setAttribute('name', permission_sdk_23[0])
|
2017-03-29 18:10:04 +02:00
|
|
|
if 'nativecode' in apk:
|
|
|
|
addElement('nativecode', ','.join(sorted(apk['nativecode'])), doc, apkel)
|
|
|
|
addElementNonEmpty('features', ','.join(sorted(apk['features'])), doc, apkel)
|
|
|
|
|
|
|
|
if current_version_file is not None \
|
2017-03-31 15:50:15 +02:00
|
|
|
and common.config['make_current_version_link'] \
|
2017-03-29 18:10:04 +02:00
|
|
|
and repodir == 'repo': # only create these
|
2017-03-31 15:50:15 +02:00
|
|
|
namefield = common.config['current_version_name_source']
|
2020-01-13 15:43:42 +01:00
|
|
|
name = app.get(namefield)
|
|
|
|
if not name and namefield == 'Name':
|
|
|
|
name = app.get('localized', {}).get('en-US', {}).get('name')
|
|
|
|
if not name:
|
|
|
|
name = app.id
|
|
|
|
sanitized_name = re.sub(b'''[ '"&%?+=/]''', b'', name.encode('utf-8'))
|
2017-06-01 10:29:30 +02:00
|
|
|
apklinkname = sanitized_name + os.path.splitext(current_version_file)[1].encode('utf-8')
|
2017-04-03 20:24:00 +02:00
|
|
|
current_version_path = os.path.join(repodir, current_version_file).encode('utf-8', 'surrogateescape')
|
2017-03-29 18:10:04 +02:00
|
|
|
if os.path.islink(apklinkname):
|
|
|
|
os.remove(apklinkname)
|
|
|
|
os.symlink(current_version_path, apklinkname)
|
|
|
|
# also symlink gpg signature, if it exists
|
2017-04-03 20:24:00 +02:00
|
|
|
for extension in (b'.asc', b'.sig'):
|
2017-03-29 18:10:04 +02:00
|
|
|
sigfile_path = current_version_path + extension
|
|
|
|
if os.path.exists(sigfile_path):
|
|
|
|
siglinkname = apklinkname + extension
|
|
|
|
if os.path.islink(siglinkname):
|
|
|
|
os.remove(siglinkname)
|
|
|
|
os.symlink(sigfile_path, siglinkname)
|
|
|
|
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.options.pretty:
|
2017-03-29 18:10:04 +02:00
|
|
|
output = doc.toprettyxml(encoding='utf-8')
|
|
|
|
else:
|
|
|
|
output = doc.toxml(encoding='utf-8')
|
|
|
|
|
|
|
|
with open(os.path.join(repodir, 'index.xml'), 'wb') as f:
|
|
|
|
f.write(output)
|
|
|
|
|
2020-08-20 14:38:42 +02:00
|
|
|
if 'repo_keyalias' in common.config \
|
|
|
|
or (common.options.nosign and 'repo_pubkey' in common.config):
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.options.nosign:
|
2017-09-13 18:03:57 +02:00
|
|
|
logging.info(_("Creating unsigned index in preparation for signing"))
|
2017-03-29 18:10:04 +02:00
|
|
|
else:
|
2017-09-13 18:03:57 +02:00
|
|
|
logging.info(_("Creating signed index with this key (SHA256):"))
|
2017-03-29 18:10:04 +02:00
|
|
|
logging.info("%s" % repo_pubkey_fingerprint)
|
|
|
|
|
|
|
|
# Create a jar of the index...
|
2017-03-31 15:50:15 +02:00
|
|
|
jar_output = 'index_unsigned.jar' if common.options.nosign else 'index.jar'
|
2017-03-29 18:10:04 +02:00
|
|
|
p = FDroidPopen(['jar', 'cf', jar_output, 'index.xml'], cwd=repodir)
|
|
|
|
if p.returncode != 0:
|
2017-05-22 21:33:52 +02:00
|
|
|
raise FDroidException("Failed to create {0}".format(jar_output))
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
# Sign the index...
|
|
|
|
signed = os.path.join(repodir, 'index.jar')
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.options.nosign:
|
2020-08-20 15:22:02 +02:00
|
|
|
_copy_to_local_copy_dir(repodir, os.path.join(repodir, jar_output))
|
2017-03-29 18:10:04 +02:00
|
|
|
# Remove old signed index if not signing
|
|
|
|
if os.path.exists(signed):
|
|
|
|
os.remove(signed)
|
|
|
|
else:
|
2017-03-31 15:50:15 +02:00
|
|
|
signindex.config = common.config
|
2022-05-23 23:08:16 +02:00
|
|
|
signindex.sign_jar(signed, use_old_algs=True)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
# Copy the repo icon into the repo directory...
|
|
|
|
icon_dir = os.path.join(repodir, 'icons')
|
2020-10-01 10:02:05 +02:00
|
|
|
repo_icon = common.config.get('repo_icon', common.default_config['repo_icon'])
|
|
|
|
iconfilename = os.path.join(icon_dir, os.path.basename(repo_icon))
|
|
|
|
if os.path.exists(repo_icon):
|
|
|
|
shutil.copyfile(common.config['repo_icon'], iconfilename)
|
|
|
|
else:
|
2018-07-09 22:41:08 +02:00
|
|
|
logging.warning(_('repo_icon "repo/icons/%s" does not exist, generating placeholder.')
|
2020-10-01 10:02:05 +02:00
|
|
|
% repo_icon)
|
|
|
|
os.makedirs(os.path.dirname(iconfilename), exist_ok=True)
|
|
|
|
try:
|
|
|
|
qrcode.make(common.config['repo_url']).save(iconfilename)
|
|
|
|
except Exception:
|
|
|
|
exampleicon = os.path.join(common.get_examples_dir(),
|
|
|
|
common.default_config['repo_icon'])
|
|
|
|
shutil.copy(exampleicon, iconfilename)
|
2017-03-29 18:10:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
def extract_pubkey():
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Extract and return the repository's public key from the keystore.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
public key in hex
|
|
|
|
repository fingerprint
|
2017-03-29 18:10:04 +02:00
|
|
|
"""
|
2017-03-31 15:50:15 +02:00
|
|
|
if 'repo_pubkey' in common.config:
|
|
|
|
pubkey = unhexlify(common.config['repo_pubkey'])
|
2022-05-17 23:46:44 +02:00
|
|
|
elif 'keystorepass' in common.config:
|
2018-08-03 04:36:00 +02:00
|
|
|
env_vars = {'LC_ALL': 'C.UTF-8',
|
|
|
|
'FDROID_KEY_STORE_PASS': common.config['keystorepass']}
|
2017-03-31 15:50:15 +02:00
|
|
|
p = FDroidPopenBytes([common.config['keytool'], '-exportcert',
|
|
|
|
'-alias', common.config['repo_keyalias'],
|
|
|
|
'-keystore', common.config['keystore'],
|
2017-04-11 21:34:49 +02:00
|
|
|
'-storepass:env', 'FDROID_KEY_STORE_PASS']
|
2020-08-04 17:26:29 +02:00
|
|
|
+ list(common.config['smartcardoptions']),
|
2017-04-11 21:34:49 +02:00
|
|
|
envs=env_vars, output=False, stderr_to_stdout=False)
|
2017-03-29 18:10:04 +02:00
|
|
|
if p.returncode != 0 or len(p.output) < 20:
|
|
|
|
msg = "Failed to get repo pubkey!"
|
2017-03-31 15:50:15 +02:00
|
|
|
if common.config['keystore'] == 'NONE':
|
2017-03-29 18:10:04 +02:00
|
|
|
msg += ' Is your crypto smartcard plugged in?'
|
2017-05-22 21:33:52 +02:00
|
|
|
raise FDroidException(msg)
|
2017-03-29 18:10:04 +02:00
|
|
|
pubkey = p.output
|
2022-05-17 23:46:44 +02:00
|
|
|
else:
|
|
|
|
raise FDroidException(_('Neither "repo_pubkey" nor "keystorepass" set in config.yml'))
|
|
|
|
|
2017-03-29 18:10:04 +02:00
|
|
|
repo_pubkey_fingerprint = common.get_cert_fingerprint(pubkey)
|
|
|
|
return hexlify(pubkey), repo_pubkey_fingerprint
|
|
|
|
|
|
|
|
|
2017-07-19 12:59:20 +02:00
|
|
|
def get_mirror_service_urls(url):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Get direct URLs from git service for use by fdroidclient.
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2017-04-11 12:28:36 +02:00
|
|
|
Via 'servergitmirrors', fdroidserver can create and push a mirror
|
2021-08-23 12:45:03 +02:00
|
|
|
to certain well known git services like GitLab or GitHub. This
|
2017-04-11 12:28:36 +02:00
|
|
|
will always use the 'master' branch since that is the default
|
2017-07-19 12:59:20 +02:00
|
|
|
branch in git. The files are then accessible via alternate URLs,
|
|
|
|
where they are served in their raw format via a CDN rather than
|
|
|
|
from git.
|
2021-08-23 12:45:03 +02:00
|
|
|
|
|
|
|
Both of the GitLab URLs will work with F-Droid, but only the
|
|
|
|
GitLab Pages will work in the browser This is because the "raw"
|
|
|
|
URLs are not served with the correct mime types, so any index.html
|
|
|
|
which is put in the repo will not be rendered. Putting an
|
|
|
|
index.html file in the repo root is a common way for to make
|
|
|
|
information about the repo available to end user.
|
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
"""
|
2017-04-11 12:28:36 +02:00
|
|
|
if url.startswith('git@'):
|
2020-12-08 19:44:39 +01:00
|
|
|
url = re.sub(r'^git@([^:]+):(.+)', r'https://\1/\2', url)
|
2017-04-11 12:28:36 +02:00
|
|
|
|
|
|
|
segments = url.split("/")
|
2017-05-17 20:37:49 +02:00
|
|
|
|
|
|
|
if segments[4].endswith('.git'):
|
|
|
|
segments[4] = segments[4][:-4]
|
|
|
|
|
2017-04-11 12:28:36 +02:00
|
|
|
hostname = segments[2]
|
2017-05-17 20:37:49 +02:00
|
|
|
user = segments[3]
|
|
|
|
repo = segments[4]
|
2017-03-29 18:10:04 +02:00
|
|
|
branch = "master"
|
|
|
|
folder = "fdroid"
|
|
|
|
|
2017-07-19 12:59:20 +02:00
|
|
|
urls = []
|
2017-03-29 18:10:04 +02:00
|
|
|
if hostname == "github.com":
|
2017-07-19 12:59:20 +02:00
|
|
|
# Github-like RAW segments "https://raw.githubusercontent.com/user/repo/branch/folder"
|
2017-04-11 12:28:36 +02:00
|
|
|
segments[2] = "raw.githubusercontent.com"
|
|
|
|
segments.extend([branch, folder])
|
2017-07-19 12:59:20 +02:00
|
|
|
urls.append('/'.join(segments))
|
2017-03-29 18:10:04 +02:00
|
|
|
elif hostname == "gitlab.com":
|
2021-09-11 18:00:52 +02:00
|
|
|
if common.get_dir_size(folder) <= common.GITLAB_COM_PAGES_MAX_SIZE:
|
2021-08-23 12:45:03 +02:00
|
|
|
# Gitlab-like Pages segments "https://user.gitlab.io/repo/folder"
|
|
|
|
gitlab_pages = ["https:", "", user + ".gitlab.io", repo, folder]
|
|
|
|
urls.append('/'.join(gitlab_pages))
|
|
|
|
else:
|
|
|
|
logging.warning(
|
|
|
|
_(
|
|
|
|
'Skipping GitLab Pages mirror because the repo is too large (>%.2fGB)!'
|
|
|
|
)
|
|
|
|
% (common.GITLAB_COM_PAGES_MAX_SIZE / 1000000000)
|
|
|
|
)
|
2020-12-08 19:44:39 +01:00
|
|
|
# GitLab Raw "https://gitlab.com/user/repo/-/raw/branch/folder"
|
|
|
|
gitlab_raw = segments + ['-', 'raw', branch, folder]
|
2018-01-17 22:02:07 +01:00
|
|
|
urls.append('/'.join(gitlab_raw))
|
2017-07-19 12:59:20 +02:00
|
|
|
|
|
|
|
return urls
|
2017-03-29 18:10:04 +02:00
|
|
|
|
2017-03-29 23:33:09 +02:00
|
|
|
|
2019-01-10 14:48:29 +01:00
|
|
|
def download_repo_index(url_str, etag=None, verify_fingerprint=True, timeout=600):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Download and verifies index file, then returns its data.
|
2018-12-17 14:03:12 +01:00
|
|
|
|
|
|
|
Downloads the repository index from the given :param url_str and
|
|
|
|
verifies the repository's fingerprint if :param verify_fingerprint
|
|
|
|
is not False.
|
2017-03-29 23:33:09 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Raises
|
|
|
|
------
|
|
|
|
VerificationException() if the repository could not be verified
|
2017-03-29 23:33:09 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
A tuple consisting of:
|
2017-05-02 17:05:48 +02:00
|
|
|
- The index in JSON format or None if the index did not change
|
|
|
|
- The new eTag as returned by the HTTP request
|
2018-12-17 14:03:12 +01:00
|
|
|
|
2017-03-29 23:33:09 +02:00
|
|
|
"""
|
|
|
|
url = urllib.parse.urlsplit(url_str)
|
|
|
|
|
|
|
|
fingerprint = None
|
|
|
|
if verify_fingerprint:
|
|
|
|
query = urllib.parse.parse_qs(url.query)
|
|
|
|
if 'fingerprint' not in query:
|
2017-09-13 18:03:57 +02:00
|
|
|
raise VerificationException(_("No fingerprint in URL."))
|
2017-03-29 23:33:09 +02:00
|
|
|
fingerprint = query['fingerprint'][0]
|
|
|
|
|
2021-04-02 14:36:42 +02:00
|
|
|
if url.path.endswith('/index-v1.jar'):
|
|
|
|
path = url.path[:-13].rstrip('/')
|
|
|
|
else:
|
|
|
|
path = url.path.rstrip('/')
|
|
|
|
|
|
|
|
url = urllib.parse.SplitResult(url.scheme, url.netloc, path + '/index-v1.jar', '', '')
|
2019-01-10 14:48:29 +01:00
|
|
|
download, new_etag = net.http_get(url.geturl(), etag, timeout)
|
2017-05-02 17:05:48 +02:00
|
|
|
|
|
|
|
if download is None:
|
|
|
|
return None, new_etag
|
2017-03-29 23:33:09 +02:00
|
|
|
|
|
|
|
with tempfile.NamedTemporaryFile() as fp:
|
2017-05-02 17:05:48 +02:00
|
|
|
fp.write(download)
|
2019-03-22 17:15:58 +01:00
|
|
|
fp.flush()
|
2018-12-17 14:03:12 +01:00
|
|
|
index, public_key, public_key_fingerprint = get_index_from_jar(fp.name, fingerprint)
|
|
|
|
index["repo"]["pubkey"] = hexlify(public_key).decode()
|
|
|
|
index["repo"]["fingerprint"] = public_key_fingerprint
|
|
|
|
index["apps"] = [metadata.App(app) for app in index["apps"]]
|
|
|
|
return index, new_etag
|
2017-03-29 23:33:09 +02:00
|
|
|
|
|
|
|
|
2018-12-17 14:03:12 +01:00
|
|
|
def get_index_from_jar(jarfile, fingerprint=None):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Return the data, public key, and fingerprint from index-v1.jar.
|
2017-03-29 23:33:09 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
fingerprint is the SHA-256 fingerprint of signing key. Only
|
|
|
|
hex digits count, all other chars will can be discarded.
|
2020-10-22 14:39:18 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Raises
|
|
|
|
------
|
|
|
|
VerificationException() if the repository could not be verified
|
2020-10-22 14:39:18 +02:00
|
|
|
|
2018-12-17 14:03:12 +01:00
|
|
|
"""
|
|
|
|
logging.debug(_('Verifying index signature:'))
|
|
|
|
common.verify_jar_signature(jarfile)
|
|
|
|
with zipfile.ZipFile(jarfile) as jar:
|
|
|
|
public_key, public_key_fingerprint = get_public_key_from_jar(jar)
|
|
|
|
if fingerprint is not None:
|
2020-10-22 14:39:18 +02:00
|
|
|
fingerprint = re.sub(r'[^0-9A-F]', r'', fingerprint.upper())
|
|
|
|
if fingerprint != public_key_fingerprint:
|
2018-12-17 14:03:12 +01:00
|
|
|
raise VerificationException(_("The repository's fingerprint does not match."))
|
|
|
|
data = json.loads(jar.read('index-v1.json').decode())
|
|
|
|
return data, public_key, public_key_fingerprint
|
2017-03-29 23:33:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_public_key_from_jar(jar):
|
2021-06-07 12:26:57 +02:00
|
|
|
"""Get the public key and its fingerprint from a JAR file.
|
|
|
|
|
|
|
|
Raises
|
|
|
|
------
|
|
|
|
VerificationException() if the JAR was not signed exactly once
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
jar
|
|
|
|
a zipfile.ZipFile object
|
2021-06-07 12:49:16 +02:00
|
|
|
|
2021-06-07 12:26:57 +02:00
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
the public key from the jar and its fingerprint
|
2017-03-29 23:33:09 +02:00
|
|
|
"""
|
|
|
|
# extract certificate from jar
|
2019-01-30 14:12:51 +01:00
|
|
|
certs = [n for n in jar.namelist() if common.SIGNATURE_BLOCK_FILE_REGEX.match(n)]
|
2017-03-29 23:33:09 +02:00
|
|
|
if len(certs) < 1:
|
2017-09-13 18:03:57 +02:00
|
|
|
raise VerificationException(_("Found no signing certificates for repository."))
|
2017-03-29 23:33:09 +02:00
|
|
|
if len(certs) > 1:
|
2017-09-13 18:03:57 +02:00
|
|
|
raise VerificationException(_("Found multiple signing certificates for repository."))
|
2017-03-29 23:33:09 +02:00
|
|
|
|
|
|
|
# extract public key from certificate
|
2017-04-03 14:23:06 +02:00
|
|
|
public_key = common.get_certificate(jar.read(certs[0]))
|
2017-03-29 23:33:09 +02:00
|
|
|
public_key_fingerprint = common.get_cert_fingerprint(public_key).replace(' ', '')
|
|
|
|
|
|
|
|
return public_key, public_key_fingerprint
|