1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 17:00:12 +01:00
Commit Graph

338 Commits

Author SHA1 Message Date
Torsten Grote
04db6870d1
Factor code for scanning a single APK out into its own method.
This allows projects using fdroidserver to scan individual APKs without
needing to re-scan all APKs present in a repository.
2017-03-17 10:40:45 -03:00
Hans-Christoph Steiner
866528de5b signindex: support signing index-v1.jar
This is a bit different than index.jar: instead of their being index.xml
and index_unsigned.jar, the presense of index-v1.json means that there is
unsigned data.  That file is then stuck into a jar and signed by the
signing process.  index-v1.json is never published to the repo.  It is
included in the binary transparency log, if that is enabled.
2017-03-17 14:12:03 +01:00
Hans-Christoph Steiner
fa657ce720 move update.signjar() to common so it can also be used in signindex 2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
696bae4d6d warn and ignore graphics files that have no matching app metadata
If there are graphics files that are in repo/ but there is no metadata for
the associated app, then do not include the graphics in the index. Issue a
warning about this.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
21ba89a581 copy graphic assets from fdroiddata and app source into repo
This looks for standard graphics assets in two standardized locations, one
in metadata/ subdirs and another in fastlane's standard dirs in the app's
source repo.  When it finds them, it copies them into the repo, where they
will then be included in the index for use by fdroidclient.  The images in
the metadata/ folder of fdroiddata take precendence over the files in the
app's source repo.

So like this for including graphics in fdroiddata:
  metadata/packageName/locale/filename.(png|jpg|jpeg)
for example:
  metadata/org.videolan.vlc/en-US/featureGraphic.png
or
  metadata/info.guardianproject.ripple/zh-CN/phoneScreenshots/screenshot1.png

Including graphics in fdroiddata would be optional. The prefered way to get
graphics into the repo would be for the files to be in the git repo in a
standard location.  This fastlane layout is currently supported:

https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
7044a909ca include graphics and screenshots from repo in V1 index
If the repo has store graphics and/or screenshots, then include those in
the metadata.  This follows the possible graphics for Google Play, and the
file naming scheme of the open source 'fastlane' tool for managing those
files.

https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots
https://support.google.com/googleplay/android-developer/answer/1078870?
https://android-developers.blogspot.com/2011/10/android-market-featured-image.html

Signed-off-by: Hans-Christoph Steiner <hans@eds.org>
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
ab7e85c951 include push install/uninstall requests in index-v1
Since the index-v1 is generated straight from the internal dict, this just
moves the generation earlier, and feeds it into the apps dict.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
6c2cf2ccdd convert internal dict keys to match fdroidclient's Apk class
This syncs up the field names between the fdroiddata .yml files, the keys
used in the implementation in fdroidserver, the index data format, and the
final data structures in fdroidclient.  This makes it easier for devs to
follow, and makes the Jackson parsing library automatically handle
converting the data from the index file to Java instances.

This bumps the metadata version since the apkcache will have to be
discarded.

Here are the name changes:
* apkname --> apkName
* id --> packageName
* sha256 --> hash
* version --> versionName
* versioncode --> versionCode

tests/repo/index.xml was changed only to bump the metadata version
from 17 to 18.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
fcb7a0feb4 fdroid update uses datetime instances for timestamps
Using datetime instances as the internal format makes it much easier to
convert between the formats needed for index.xml and index-v1.  apkcache
still uses time tuples and known_apks.txt still uses the ISO date.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
c9aa26d89e add index V1 format, a direct translation of internal dict
Python encode/decode libs work directly with dicts, so the internal dict
can just be passed directly to any of these libs (pyyaml, pyjson, msgpack,
simplejson, etc).  This still generates the exact same index.xml as before.

This converts the internal format for the repo timestamp to a datetime
instance, which can be easily converted to UNIX time in seconds for XML
and UNIX time in milliseconds for the new index formats.  UNIX time in
milliseconds is directly serialized into a java.util.Date instance by
Jackson.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
b3a5db52f7 break out jar signing into function so it can be reused
The new index format will also need to use jar signing
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
3afd6ca684 only set 'No description available' in the old index format
The new index format aims to be a direct representation of the data, then
the clients/website will handle the rest.
2017-03-17 13:55:40 +01:00
Hans-Christoph Steiner
110914ebf3 update: include git config name/email in binary transparency log 2017-03-16 17:48:54 +01:00
Hans-Christoph Steiner
03ec590989 new repo-wide config option for a Binary Transparency Log
A Binary Transparency Log is a append only log of all binaries published by
a repo.  This is useful for people to find whether the binary they have
matches what F-Droid has published, and also makes it more difficult for
the published history to be changed without notice, or for a server to give
specific users custom malware binaries.

https://www.eff.org/deeplinks/2014/02/open-letter-to-tech-companies
2017-03-15 22:12:04 +01:00
Hans-Christoph Steiner
4430d8b01c update: fix crash in debug logging message 2017-03-15 14:23:37 +01:00
Hans-Christoph Steiner
6fe27ad75e fix source tarball filename for media files
bug from 07ce948809
2017-03-10 19:05:51 +01:00
Hans-Christoph Steiner
6aca906863 include non-APKs that match metadata and fdroid-generated filenames
Since it is now possible to build and include arbitrary files, like OTA
update ZIP files, the update procedure needs to look for non-APK files that
match the packageName_versionCode pattern of fdroid-generated files.

!193
admin#14
privileged-extension#9
2017-03-10 18:37:18 +01:00
Hans-Christoph Steiner
9d363b91f4 update: do not include fdroid-generated tarballs as "media" files
`fdroid build` will generate source tarballs, and now with support for
adding any file to a repo, we need to explicitly ignore the fdroid-
generated source tarballs.  If people want to include source tarballs in a
repo, they still can, as long as that source tarball doesn't use the
`fdroid build` tarball naming scheme.
2017-03-10 18:37:18 +01:00
Hans-Christoph Steiner
650d52fb0a uses-permission maxSdkVersion as int, and enforces int string in XML
This forces <uses-permission maxSdkVersion=""> to be an integer in the
internal dict, and forces it to have no decimal point in XML.  Having it as
an integer in the internal dict means data will pass directly through to
the fdroidclient Apk instance, where it is ultimately an integer.
2017-03-06 22:04:14 +01:00
Hans-Christoph Steiner
7bae1075ba non-APK files will not have minSdkVersion, so don't force it
fdroidclient should handle no minSdkVersion fine, since it just parses the
text in <sdkver></sdkver> as an int, and uses a default value if there is
an Exception.
2017-03-06 22:03:20 +01:00
Hans-Christoph Steiner
5214889bbd fix bug including media files
'name' is not the full path, so it'll always fail common.is_repo_file()'s
os.path.isfile() check.

Introduced in 56d51fcd6b
2017-02-28 12:08:04 +01:00
Hans-Christoph Steiner
8b85c860a6 rename lastupdated to lastUpdated to match fdroid client
This lets index-v1 be parsed directly into class instances because the
field/instance var names match exactly.  The original index v0 element
must retain the 'lastupdated' name for backwards compatibility.
2017-02-28 12:08:04 +01:00
Hans-Christoph Steiner
e0f39a7e7b rename Build fields: version -> versionName, vercode -> versionCode
Since the YAML/JSON/etc. field names are now exactly the same as the field
names used in the internal dict in the Build class, this is a global rename

This keeps with the standard names used in Android:
https://developer.android.com/guide/topics/manifest/manifest-element.html
2017-02-24 11:01:01 +01:00
Hans-Christoph Steiner
b7fc7f2228 convert App to subclass of dict to support parsing/dumping libs
Python is heavily based on its core data types, and dict is one of the more
important ones.  Even classes are basically a wrapper around a dict. This
converts metadata.App to be a subclass of dict so it can behave like a dict
when being dumped and loaded.  This makes its drastically easier to use
different data formats for build metadata and for sending data to the
client.  This approach will ultimately mean we no longer have to maintain
custom parsing and dumping code.

This also means then that the YAML/JSON field names will not have spaces in
them, and they will match exactly what it used as the dict keys once the
data is parsed, as well as matching exactly the instance attribute names:

* CurrentVersion: 1.2.6
* app['CurrentVersion'] == '1.2.6'
* app.CurrentVersion == '1.2.6'

Inspired by:
https://goodcode.io/articles/python-dict-object/
2017-02-24 11:01:01 +01:00
Hans-Christoph Steiner
14f204cfe1 sort repo index data to make index.xml generation reproducible
This makes it easy to test that the code is still generating the exact same
index.xml.  It also might help the ZIP compression work better in index.jar
2017-02-24 11:01:01 +01:00
Boris Kraut
823e40eed0 update: add name to skeleton 2017-02-19 16:25:49 +01:00
thez3ro
5a9bcfbbf4
add git repo mirroring 2017-02-17 16:05:57 +01:00
Hans-Christoph Steiner
78a3e35ef7 break out categories.txt generation to standalone method
This is to clean up the code for the introduction of a new index format.
This also makes it so that only repo/categories.txt is generated, and not
archive/categories.txt.

Currently, the only thing that I can find that reads categories.txt is the
wordpress plugin, e.g. wp-fdroid.  And it only reads repo/categories.txt
not archive/categories.txt.
2017-01-20 10:47:35 +01:00
Hans-Christoph Steiner
d54ad41938 fix bad caching of non-APK files in the repo
Silly mistake in 07ce948809
2017-01-20 10:47:35 +01:00
Hans-Christoph Steiner
98297278bd check all APKs for old versions of OpenSSL
This scans all APKs for old versions of OpenSSL libraries that are known to
be vulnerable to issues, or fully unsupported.

This really should be implemented as a per-APK AntiFeature, so that it can
apply to any version that is vulnerable.  Since AntiFeatures are currently
only per-App, this instead sets the AntiFeature only if the latest APK is
vulnerable.

Google also enforces this:
https://support.google.com/faqs/answer/6376725?hl=en

apk['antiFeatures'] has the first letter small, since all build fields
start with a lowercase letter.  app.AntiFeatures has the first
uppercase since all App fields are that way.
2016-12-05 20:16:54 +01:00
Daniel Martí
82b1d7ad14 all: make newer pycodestyle happy
Apparently the "two empty lines" rule is now stricter.
2016-11-15 20:55:06 +00:00
Hans-Christoph Steiner
56d51fcd6b gpg-sign all valid files in the repo, including source tarballs
This makes sure there is a GPG signature on any file that is included in
the repo, including APKs, OBB, source tarballs, media files, OTA update
ZIPs, etc.  Having a GPG signature is more important on non-APK files since
they mostly do not have any signature mechanism of their own.

This also adds basic tests of adding non-APK/OBB files to a repo with
`fdroid update`.

closes #232
2016-11-07 14:53:01 +01:00
Hans-Christoph Steiner
84e09cd2a2 allow arbitrary build products, not only APKs
This makes it so that the final build product can be specified in output=
and it'll work no matter if its an APK or not.  This was developed around
the case of building the OTA update.zip for the Privileged Extension. It
should work for any build process in theory but it has not yet been tested.

https://gitlab.com/fdroid/privileged-extension/issues/9
2016-11-07 14:53:01 +01:00
Hans-Christoph Steiner
8e45d30020 reuse os.stat() result when checking for non-APK files
This should make things a bit more efficient when running on lots of files,
unless python was already caching the result...
2016-11-02 18:10:13 +01:00
Hans-Christoph Steiner
07ce948809 support adding arbitrary files to a repo
This adds the most basic level of support for including arbitrary files in
an F-Droid repository.  This is useful for things like including videos,
ebooks, update.zip files for ROM updates, and more.  The aim is to have
this as generic as possible to keep it flexible for unforeseen uses.

Code-wise, this is really just a first effort.  This area of code has not
been touched in a very long time, and the repo parsing is done in a giant
function that is not easy to break apart.  It should be broken up to more
cleanly support arbitrary files.

Also remove the TODO line, we've decided to keep the old permission
format for now, at least until there is a major overhaul of the index
data format.  And the issue tracker the proper place for TODOs.
2016-11-02 18:10:13 +01:00
Hans-Christoph Steiner
36a585c2fc create addElementIfInApk() function for clean up common operation
There are currently a couple different ways this is done in the code, this
commit changes all of them to be like addElementNonEmpty().
2016-11-02 18:10:13 +01:00
Hans-Christoph Steiner
47d9fd330d remove unused 'apps' argument from update.scan_apks() 2016-11-02 16:11:52 +01:00
Hans-Christoph Steiner
5faef55d67 support all valid versionCode values, i.e. Java Integer values
versionCode can be any Java Integer value, from Integer.MAX_VALUE
(2147483648) to Integer.MIN_VALUE (-2147483647)
2016-11-02 16:11:46 +01:00
Hans-Christoph Steiner
d522988d8c make metadata exceptions optional based on CLI flag
In many cases, there are times where metadata errors need to be ignored, or
at least not stop the command from running.  For example, there will
inevitably be new metadata fields added, in which case a packaged version
of fdroidserver will throw errors on each one.  This adds a standard -W
flag to customize the response: ignore, default, or error.

* by default, the errors are still errors
* `fdroid readmeta -W` will just print errors
* `fdroid readmeta -Wignore` will not even print errors

https://gitlab.com/fdroid/fdroidserver/issues/150
2016-09-12 12:55:48 +02:00
Hans-Christoph Steiner
6126b55136 rename server request from "delete" to "uninstall"
This matches the Android API's current Intent action for this, rather than
the deprecated one:

https://gitlab.com/fdroid/fdroidclient/blob/v0.101-alpha5/app/src/main/java/org/fdroid/fdroid/installer/DefaultInstallerActivity.java#L147
https://developer.android.com/reference/android/content/Intent.html#ACTION_UNINSTALL_PACKAGE
https://developer.android.com/reference/android/content/Intent.html#ACTION_DELETE
2016-08-24 23:05:34 +02:00
Hans-Christoph Steiner
a6a8d34528 sanitize mirror URLs to prevent path segments from being removed
urllib.parse.urljoin() will strip off the last path segment before joining
if that last path segment does not end with /.  That's a "feature" to make
it easy to replace file names.  Here it was stripping off the essential
'fdroid' segment, making URLs like:

https://foo.com/repo

when they should be

https://foo.com/fdroid/repo
2016-08-24 23:05:34 +02:00
Hans-Christoph Steiner
85632ba00e set up install/delete lists for "push" commands from server
It is now possible for the server operator to specify lists of apps that
must be installed or deleted on the client (aka "push installs).  If
the user has opted in, or the device is already setup to respond to
these requests, then fdroidclient will automatically install/delete
the packageNames listed.  This is protected by the same signing key
as the app index metadata.

It generates single XML elements with the data set in the attributes. This
keeps the XML compact and easily extensible, e.g. for adding versionCode,
signingKey, etc as attributes:

    <install packageName="com.fsck.k9"/>
    <install packageName="at.bitfire.davdroid"/>
    <delete packageName="com.facebook.orca"/>

Copyright: 2016 Blue Jay Wireless
Signed-off-by: Hans-Christoph Steiner <hans@eds.org>

closes #177
2016-08-16 21:02:15 +02:00
Hans-Christoph Steiner
911297272c Merge branch 'permission-parsing' into 'master'
Parse maxSdkVersion and -23 permission tags

Parse maxSdkVersion and uses-permission-sdk-23 tags and insert them into the index.

AndroidManifest:
```xml
    <uses-permission android:name="android.permission.READ_CALENDAR" />

    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />

    <uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
```

new index format:
```xml
<package>
            <version>1.0</version>
            <versioncode>1</versioncode>
            <apkname>maxmin.apk</apkname>
            <hash type="sha256">526eb6d643050c3fae42fb6c001c704006046db52e98998b21f7646ecae3dae5
            </hash>
            <sig>893fc1f22301c902d05c938b29d21648</sig>
            <size>8681</size>
            <sdkver>14</sdkver>
            <targetSdkVersion>24</targetSdkVersion>
            <added>2016-08-01</added>
            <permissions>READ_EXTERNAL_STORAGE,READ_CALENDAR,WRITE_EXTERNAL_STORAGE</permissions>
                <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE"
                    maxSdkVersion="18" />
                <uses-permission name="android.permission.READ_CALENDAR" />
                <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" />
                <uses-permission-sdk-23 name="android.permission.ACCESS_FINE_LOCATION" />
</package>
```

old format:
```xml
<permissions>READ_CALENDAR,ACCESS_FINE_LOCATION,WRITE_EXTERNAL_STORAGE</permissions>
```

This generates both formats for backward compatibility with old clients.

Also increase version of index format.

This is a proposal for the issues discussed in https://gitlab.com/fdroid/fdroidclient/issues/704

@eighthave @mvdan 

See merge request !150
2016-08-09 15:33:19 +00:00
Dominik Schürmann
cb965dcb07 Parse maxSdkVersion and -23 permission tags
Parse maxSdkVersion and uses-permission-sdk-23
tags and insert them into the index, e.g.,
<package>
 <permissions>READ_EXTERNAL_STORAGE,READ_CALENDAR,WRITE_EXTERNAL_STORAGE</permissions>
  <uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE"
   maxSdkVersion="18" />
  <uses-permission name="android.permission.READ_CALENDAR" />
  <uses-permission name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission-sdk-23 name="android.permission.ACCESS_FINE_LOCATION" />
</package>

Also increase version of index format
2016-08-09 10:14:57 +02:00
Ciaran Gultnieks
e99454868a Catch another case of invalid wiki page names 2016-08-01 12:25:22 +01:00
Ciaran Gultnieks
21404e8622 Merge branch 'use_date_from_apk_in_known_apks' into 'master'
Pass a date from APK to KnownApks.recordapk()

... if --use-date-from-apks option is used.

Essentially, it just expands influence of `--use-date-from-apks` option to `stats/known_apks.txt`.

See merge request !141
2016-07-13 11:43:33 +00:00
Hans-Christoph Steiner
2201df150f add SHA-256 hashes of each OBB file 2016-07-07 22:34:41 +02:00
Hans-Christoph Steiner
5074be224a support .obb files for Opaque Binary Blog APK Expansions
OBB files provide a mechanism to deliver large data blobs that do not need
to be part of the APK.  For example, a game's assets do not need to change
often, so they can be shipped as an OBB, then APK updates do not need to
include all those assets for each update.

https://developer.android.com/google/play/expansion-files.html
2016-07-07 22:34:41 +02:00
Hans-Christoph Steiner
d522bb7e17 handle APKs with filenames encoded with CP437
The ZIP format has no official encoding :-| so we have to do hacks.  The
zipfile devs couldn't even sort this out:
https://bugs.python.org/issue10614

closes #167
2016-06-27 20:30:32 +02:00
Hans-Christoph Steiner
d6c9a8466b properly close opened images
This stops these errors:

fdroid/fdroidserver/fdroidserver/update.py:744: ResourceWarning: unclosed
 file <_io.BufferedReader
 name='repo/icons-320/info.guardianproject.urzip.100.png'>

fdroid/fdroidserver/fdroidserver/update.py:721: DeprecationWarning: The
 'warn' function is deprecated, use 'warning' instead
2016-06-27 14:00:49 +02:00