Commit graph

1236 commits

Author SHA1 Message Date
Alexis Métaireau
99f1e15fd2
chore: Do not use fstrings without placeholders
> f-strings are a convenient way to format strings, but they are not
> necessary if there are no placeholder expressions to format. In this
> case, a regular string should be used instead, as an f-string without
> placeholders can be confusing for readers, who may expect such a
> placeholder to be present.
>
> — [ruff docs](https://docs.astral.sh/ruff/rules/f-string-missing-placeholders/)
2024-06-05 14:19:31 +02:00
Alexis Métaireau
5aa4863b52
chore(imports): remove useless imports
As detected by [ruff](https://github.com/astral-sh/ruff)

Related to #254, although it doesn't provide the command to lint the
codebase itself.
2024-06-05 14:19:30 +02:00
Alexis Métaireau
850199c2a3
chore: update poetry.lock with latest versions 2024-06-04 19:57:40 +02:00
Alexis Métaireau
c01515b775
Bump the minimum python version to 3.9
The minimum python version when installing from source is now python
3.9, as Pyside6 6.7.1 dropped support for python 3.8 (see #780 for more
information).

On Debian-derivatives distributions, the minimum Python version is now
set to 3.8. In practice, because Pyside6 is not packaged for Debian, we
use Pyside2 [0], which is why we can relax the python version requirement.

In practice, when installing from source on an environment where
python3.9 is not the default python, poetry will look for it and use it
if available

> For various reasons, this Python version might not be compatible with
> the python range supported by the project. In this case, Poetry will
> try to find one that is and use it.
>
> [Poetry docs](https://python-poetry.org/docs/managing-environments/)

On Ubuntu Focal (20.04) where Python 3.9 is not installed by default,
it is possible to install it using the `python3.9` package.

Additionally, In version 1.24.3, PyMuPDF changed its package name from `fitz`
to `pymupdf` [2], resulting in a breakage on how it is installed in our
container. This is now fixed.

[0] More information on how Pyside6 packaging affects dangerzone on #221
[1] See [the current status of Pyside6 packaging](https://repology.org/
project/python:pyside6/packages)
[2] PyMuPDF changelog: https://pymupdf.readthedocs.io/en/latest/changes.html#change-log
2024-06-04 19:57:40 +02:00
Alex Pyrgiotis
2aee6f4ad2
Fix some minor lint issues 2024-06-04 13:16:06 +03:00
Alex Pyrgiotis
aebc091400
Explain how to create, sign, and verify source tarballs
Update our docs and scripts to be able to create a source tarball for a
Dangerzone version, sign it, and explain how can users verify it.

Closes #822
2024-06-03 12:59:22 +03:00
Alex Pyrgiotis
5320b33d17
dev_scripts: Bump PySide6 version to 6.7.1
Bump the PySide6 version used in our user environments to 6.7.1, to
mirror the one we ship to our users, and also fix a segfault issue in
our CI tests.

Refs #801
2024-05-29 19:28:59 +03:00
Alex Pyrgiotis
1e1d9274f0
Handle complaints about shebangs during RPM build
When building the Dangerzone RPMs, we were seeing the following shebang
warnings:

    + /usr/lib/rpm/redhat/brp-mangle-shebangs
    mangling shebang in /usr/lib/python3.12/site-packages/dangerzone/conversion/doc_to_pixels.py from /usr/bin/env python3 to #!/usr/bin/python3
    mangling shebang in /usr/lib/python3.12/site-packages/dangerzone/conversion/common.py from /usr/bin/env python3 to #!/usr/bin/python3
    mangling shebang in /usr/lib/python3.12/site-packages/dangerzone/conversion/pixels_to_pdf.py from /usr/bin/env python3 to #!/usr/bin/python3
    mangling shebang in /etc/qubes-rpc/dz.ConvertDev from /usr/bin/env python3 to #!/usr/bin/python3
    mangling shebang in /etc/qubes-rpc/dz.Convert from /bin/sh to #!/usr/bin/sh

These warnings are benign in nature, but coupled with #727, they could
lead to incorrect file permissions.

Remove shebangs from the following files, since they are not executed
directly, but are imported instead:

    dangerzone/conversion/common.py
    dangerzone/conversion/doc_to_pixels.py
    dangerzone/conversion/pixels_to_pdf.py

Also, accept the suggestions by Fedora (/bin/sh -> /usr/bin/sh,
/usr/bin/env python3 -> /usr/bin/python3) for the following files:

    qubes/dz.Convert
    qubes/dz.ConvertDev

Refs #727
2024-05-28 18:06:34 +03:00
Alex Pyrgiotis
797b28e191
install: Build RPM in different directory
Switch build directory for the `rpmbuild` command from
`./install/linux/rpm-build` to `~/rpmbuild`. The main reason for this is
that we want a build directory that will not be mounted in the
container, since we've experienced issues with file permissions.

Regarding the choice of directories, we went with `~/rpmbuild` because
it's outside the Dangerzone source, and also because it's the default
choice in Fedora [1].

[1]: 3ae1eeafee/rpmdev-setuptree (L60)

Closes #727
2024-05-28 18:06:33 +03:00
Alex Pyrgiotis
a22f12ab6a
install: Detect bad file permissions in RPMs
When building the Dangerzone RPM package, detect if the files bundled in
it have any incorrect permissions. We have seen in the past that
building RPMs from the Dangerzone source, mounted to a macOS Docker
container, can lead to files readable only by the root user (600 /
rw-------).

Refs #727
2024-05-28 13:15:05 +03:00
Alex Pyrgiotis
d97d04b911
Inform readers about Dangerzone's security audit
Dangezone has received a security audit in December 2023, and published
on February 2024. It would be nice for people seeing this project to
learn about this audit.
2024-05-24 15:59:11 +03:00
Alex Pyrgiotis
b5d1681225
Add some articles about the Dangerzone project
Add some articles about the Dangerzone project that may be useful for
those evaluating this tool. This article list is not complete, and has
been sampled from various links we have encountered in the past.
2024-05-24 15:59:11 +03:00
178f94e612
docs: fix a typo, it's dev_scripts 2024-05-24 11:54:44 +02:00
Alex Pyrgiotis
76898471e7
Bump Python system path to 3.12 in Dockerfile
Alpine Linux 3.20 was released recently [1]. As a result, the
`alpine:latest` image ref, that our Dockerfile uses, switched from the
3.19 to the 3.20 Alpine Linux release. This release has Python 3.12,
meaning that the following line in our Dockerfile now fails:

    COPY --from=pymupdf-build /usr/lib/python3.11/site-packages/fitz/ /usr/lib/python3.11/site-packages/fitz

Bump the Python version in the Python system path to 3.12, so that we
can successfully build the container image.

[1]: https://alpinelinux.org/posts/Alpine-3.20.0-released.html
2024-05-23 12:14:00 +03:00
Alex Pyrgiotis
65776d8c05
Quote command in installation instructions
Zsh users that attempt to run the following command in our Ubuntu/Debian
installation instructions:

    echo deb [signed-by=/etc/apt/keyrings/fpf-apt-tools-archive-keyring.gpg] \
        https://packages.freedom.press/apt-tools-prod ${VERSION_CODENAME?} main \
            | sudo tee /etc/apt/sources.list.d/fpf-apt-tools.list

encounter the following error:

    zsh: no matches found:
    [signed-by=/etc/apt/keyrings/fpf-apt-tools-archive-keyring.gpg]

Quote this command to ensure compatibility with other shells, and update
our CI checks.

Fixes #805
2024-05-22 15:00:39 +03:00
Naglis Jonaitis
210405b9fd
Fix Qt QAction import
In PySide2 QAction is available under `PySide2.QtWidgets`[1] whereas in
PySide6 it resides under `PySide6.QtGui`[2].

Closes #788

[1]: https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QAction.html#PySide2.QtWidgets.PySide2.QtWidgets.QAction
[2]: https://doc.qt.io/qtforpython-6/PySide6/QtGui/QAction.html
2024-05-14 16:27:44 +03:00
Naglis Jonaitis
8694fb21ec
Use exec instead of exec_ for Qt dialogs
`exec_` is being deprecated in favor of `exec`.

Also use `launch()` helper method for `Dialog` subclasses.

Fixes #595
2024-05-14 16:23:20 +03:00
Alex Pyrgiotis
5dcccd1ced
ci: Test Fedora 40 and Ubuntu 24.04 installation instructions 2024-05-14 16:16:24 +03:00
Alex Pyrgiotis
aa8d00b328
Bump download links to 0.6.1 2024-05-13 19:25:59 +03:00
Alex Pyrgiotis
88a2d151ab
Update changelog entries 2024-05-09 17:36:05 +03:00
Alex Pyrgiotis
a8e51c17d9
Install Python from python.org
Add a note in our release instructions to install Python from
python.org. This should fix some incompatibilities with older macOS
versions.

Refs #471
2024-05-09 17:36:04 +03:00
Alex Pyrgiotis
8c59589be1
Inform users about Pyside6 and conmon packages
Inform users that for specific distros and versions, we install some
extra packages (PySide6, conmon), in order to fix some incompatibilities
between Dangerzone and the base system. Provide also a link to the
source / build instructions for the package, as well as any relevant
issues.

Fixes #767
2024-05-09 17:36:04 +03:00
Alex Pyrgiotis
341e29c0e3
Make our collapsible blocks more noticable
Make our collapsible blocks in our instructions more noticeable, by
enclosing them in an HTML table (<table>).
2024-05-09 17:36:04 +03:00
Alex Pyrgiotis
d55dee2f37
Add user instructions for verifying our signatures
Add a section for our end-users in INSTALL.md, that explains how to
verify that our Dangerzone assets have been signed by our advertised
signing key.

This section explains what are the .asc files that users see next to our
release assets, and how they can verify each asset individually using
GPG. It is heavily inspired by a similar section for OnionShare.

Closes #761
2024-05-09 17:36:04 +03:00
Alex Pyrgiotis
83c165ae33
dev_scripts: Sign our assets and calculate their hashes
Add a new script called `sign-assets.py`, which produces the hash of all
the Dangerzone assets for a release (Windows/macOS installers, container
image), and signs them individually.

Also update our RELEASE.md document, to incorporate this script into our
release workflow.
2024-05-09 17:32:07 +03:00
Alex Pyrgiotis
f6a39ec140
Add some extra entries to the 0.6.1 changelog 2024-05-09 16:46:16 +03:00
Alex Pyrgiotis
549ed23193
dev_scripts: Fix bug during env build
Create the build directory first, and then add the PySide6 package in
it.
2024-05-09 16:46:16 +03:00
Alex Pyrgiotis
b97e9540c1
Fix minor typos in RELEASE.md 2024-05-09 16:46:16 +03:00
Alex Pyrgiotis
ff25fa3045
Fix stuck conversion processes
Gracefully terminate certain conversion processes that may get stuck
when writing lots of data to stdout. Also, handle a race condition when
a conversion process terminates slightly after the associated container.

Fixes #791
2024-05-09 16:46:15 +03:00
Alex Pyrgiotis
0557e34429
Exclude Dangerzone from the discovered PDF viewers
We have recently [1] changed the name of the Dangerzone application to
capital-case "Dangerzone", but this breaks our PDF viewer detection
logic. Adjust our check to exclude Dangerzone from the list.

Fixes #790

[1]: See commit 3d426ed36b
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
37bf9badf4
Remove extraneous log sanitization
Remove an extra call to `replace_control_chars()`, as well as an
unnecessary method.
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
0b45360384
Keep newlines when reading debug logs
In d632908a44 we improved our
`replace_control_chars()` function, by replacing every control or
invalid Unicode character with a placeholder one. This change, however,
made our debug logs harder to read, since newlines were not preserved.

There are indeed various cases in which replacing newlines is wise
(e.g., in filenames), so we should keep this behavior by default.
However, specifically for reading debug logs, we add an option to keep
newlines to improve readability, at no expense to security.
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
e11aaec3ac
Always use sys.exit when exiting the application
The `exit()` [1] function is not necessarily present in every Python
environment, as it's added by the `site` module. Also, this function is
"[...] useful for the interactive interpreter shell and should not be
used in programs"

For this reason, we replace all such occurrences with `sys.exit()` [2],
which is the canonical function to exit Python programs.

[1]: https://docs.python.org/3/library/constants.html#exit
[2]: https://docs.python.org/3/library/sys.html#sys.exit
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
d6202cd028
Invoke external command on Windows properly
On Windows, if we don't use the `startupinfo=` argument of
subprocess.Popen, then a terminal window will flash while running the
command.

Use `startupinfo=` when killing a container, as we do for every other
command.
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
1c70ee6771
Fix archiving the same doc twice on Windows
On Windows, if we somehow attempt to archive the same document twice
(e.g, because it got archived once, and then we copy it back), we will
get an error, because Windows does not overwrite the target path, if it
already exists.

Fix this issue by always removing the previously archived version, when
performing the next archival action, and update our tests.
2024-05-09 15:57:42 +03:00
Alex Pyrgiotis
63b12abbdf
tests: Fix text sanitization tests on Windows
Fix a failing test case on Windows, due to a character that cannot
exist in a filename.
2024-05-09 15:57:42 +03:00
Naglis Jonaitis
ff1677672e
Bump pytest-cov package version
pytest-cov 3.0.0 running under pytest 7.2 produces warnings during CI
(see also pytest-dev/pytest-cov#561 [1]):

> PytestDeprecationWarning: The hookimpl CovPlugin.pytest_configure_node
> uses old-style configuration options (marks or attributes).

and

> PytestDeprecationWarning: The hookimpl CovPlugin.pytest_testnodedown
> uses old-style configuration options (marks or attributes).

The warnings were fixed in pytest-cov 4.0.0 [2].

[1]: https://github.com/pytest-dev/pytest-cov/issues/561
[2]: https://github.com/pytest-dev/pytest-cov/issues/561#issuecomment-1297143745
2024-05-08 15:40:14 +03:00
Naglis Jonaitis
5b6cc861d8
Don't use pytest-mock mocker.patch as context manager
Quote from `pytest-mock` docs [1]:

> The purpose of this plugin is to make the use of context managers and
> function decorators for mocking unnecessary, so it will emit a warning
> when used as such.

Thus using it as a context manager currently produces a warning during
test runs in CI which is extra noise that could make new (possibly more
important) warnings harder to spot.

[1]: https://pytest-mock.readthedocs.io/en/latest/usage.html#usage-as-context-manager
2024-05-08 15:40:14 +03:00
Naglis Jonaitis
c3a570eb7d
Use %F field code in .desktop entry
On Linux, the `%u` field code results in multiple Dangerzone instances
being launched when opening multiple documents with Dangerzone from
e.g. Nautilus, as `%u` signifies that the application (in this case -
Dangerzone) can only open a single file/URL at once.

This changes the field code to `%F` as Dangerzone (now) supports
converting multiple files at once. We use `%F` (multiple local files)
instead of `%U` (multiple files and/or URLs) since Dangerzone does not
support opening URLs.

See also the Desktop Entry Specification [1] for more information on the
field codes.

Fixes #797

[1]: https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html
2024-05-08 14:17:35 +03:00
Naglis Jonaitis
8cdb2d5720
Set the desktop filename and app name of the Qt application
Currently, the app ID of the Dangerzone GUI application when running
under Wayland is `python3`, which is not very useful if one wants to
automate some action related to the Dangerzone application window (e.g.
to always start Dangerzone window in floating mode under Sway WM).

Setting the desktop filename property also sets the app ID of the
application under Wayland. According to Qt documentation[1], the
property value should be the name of the application's .desktop file but
without the extension.

Qt documentation also states:

> This property gives a precise indication of what desktop entry
> represents the application and it is needed by the windowing system to
> retrieve such information without resorting to imprecise heuristics.

Therefore I also think that setting this property is needed to display
the correct application name and icon (taken from the .desktop entry)
when running under certain windowing systems (like Wayland)
(see also #402).

Note that this property is not enough, as we've encountered systems
where setting just the desktop file name does not alter the detected
application name by the window manager. For this reason, we also use
set the application name [2] to `dangerzone`, to remove any ambiguity.

[1]: https://doc.qt.io/qt-6/qguiapplication.html#desktopFileName-prop
[2]: https://doc.qt.io/qt-6/qcoreapplication.html#applicationName-prop

Fixes #402
2024-04-25 17:23:02 +03:00
Alex Pyrgiotis
307ecd495c
tests: Ignore a lint error found by mypy 1.9.0
Ignore a lint error that has started showing up since mypy 1.9.0. The
official docs show that the `.instance()` method does not accept a `cls`
argument [1], so either the stubs or mypy are wrong here.

[1]: https://doc.qt.io/qtforpython-6.5/PySide6/QtCore/QCoreApplication.html#PySide6.QtCore.PySide6.QtCore.QCoreApplication.instance
2024-04-25 16:23:39 +03:00
Alex Pyrgiotis
53062a9c36
Bump Poetry dependencies
Bump our poetry.lock file, to get the latest versions of our
dependencies. Note that we are aware that this bump does not bring in
the latest PySide6 version.

Refs #773
2024-04-25 16:23:39 +03:00
Alex Pyrgiotis
d54a152eeb
Update pre-release task for PySide6
Update the description in the pre-release task for PySide6, since a lot
has changed after writing this section. Now that `python3-pyside6` is in
the Fedora Rawhide repo, and will soon get backported in the stable
repos, we no longer check for newer upstream versions, but if Fedora
finally did the backport.

Refs freedomofpress/maint-dangerzone-pyside6#5
2024-04-25 16:23:39 +03:00
Alex Pyrgiotis
83265009a3
Small revamp in our release instructions
Reword, revise, remove release procedure steps, to better reflect what's
the proper time to perform a step.
2024-04-25 16:23:39 +03:00
Alex Pyrgiotis
2e3e3842df
Add entries to changelog for 0.6.1 2024-04-25 16:23:39 +03:00
Alex Pyrgiotis
bc36c97840
Bump version to 0.6.1 2024-04-25 16:23:39 +03:00
Naglis Jonaitis
d632908a44
Fix printing of filenames with surrogate escapes
On Unix systems a filename can be a sequence of bytes that is not valid
UTF-8. Python uses[1] surrogate escapes to allow to decode such
filenames to Unicode (bytes that cannot be decoded are replaced by a
surrogate; upon encoding the surrogate is converted to the original
byte).

From `click` docs[2]:

> Invalid bytes or surrogate escapes will raise an error when written
> to a stream with `errors="strict"`. This will typically happen with
> `stdout` when the locale is something like `en_GB.UTF-8`.

To fix that, we use `utils.replace_control_chars()` before printing the
filenames to `stdout` so that surrogate escapes are replaced by �.

Fixes #768
2024-04-25 14:11:25 +03:00
Naglis Jonaitis
52ced04507
Relax the restrictions of util.replace_control_chars
The `util.replace_control_chars()` function was overly strict, and
would replace every non-ASCII character with "_". This included both
control characters, as well as normal characters in a non-English
alphabet.

Relax these restrictions by checking each character and deciding if it's
a Unicode control character, using the `unicodedata` Python package.
With this change, emojis and non-English letters are now allowed.
2024-04-25 14:11:16 +03:00
Alex Pyrgiotis
2fa592eb69
tests: Add a fixture for uncommon filenames
Add a pytest fixture that crafts a filename with Unicode characters that
are not considered common for this use. By default, this fixture uses
an invalid Unicode character as well, but we strip it in case of macOS
(APFS) since filenames must be UTF-8 encoded.

[1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
2024-04-25 13:23:22 +03:00
Alex Pyrgiotis
94179a1d91
ci: Include test dependencies when linting
Include the test dependencies when linting, especially `pytest`. We need
this because `mypy` cannot understand the `pytest.raises` exception, and
specifically the fact that it catches exceptions. It assumes that the
next code block is unreachable, since it doesn't see any try ... except.
2024-04-24 16:27:14 +03:00