pgpy has been using TZ-naive datetime objects, despite all OpenPGP
wire-format dates being essentially UTC.
Better to represent the datetime objects explicitly as UTC.
Closes: #401
In commit 08a76fdda9, distutils was
dropped. Before then, gpg_ver was a global mutable class instance,
mutated inside a function and then used. After then, it's a global
string that is... also modified inside a function and then used.
Strings cannot be modified inside functions like that. It shadows the
variable in the local scope, which means the global variable is
inaccessible now. In fact the global variable exists solely to be used
inside this function, but now it cannot be.
So, because it can be bound inside the function, it *must* be, but only
if python-gpg was installed did this actually occur. If not, we skipped
the integration tests and then tried to log the version, assuming that
the global default value of "unknown" was still bound, which is no
longer true.
As per RFC 4880 13.2, "Since TripleDES is the MUST-implement algorithm,
if it is not explicitly in the list, it is tacitly at the end."
Some keys in the wild do not have it explicitly in the list, so put it
there as a default.
distutils is going away in python 3.12. LooseVersion() wasn't really
being used for anything particularly useful. The strings that were
returned by the openssl backend for the cryptography module, or the
GPGME "engine" version were both just being replayed later as strings
anyway.
So, keep them in string form. If future work needs to do things like
compare them, apparently packaging.version contains classes that might
be better-maintained going forward.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
According to RFC 4880, 'an implementation MAY dash-escape any line,
SHOULD dash-escape lines commencing "From" followed by a space [...]'.
Therefore it is necessary to unescape all lines starting with dash-space
sequences, and not just these that have a dash following this sequence.
Fixes#341
Signed-off-by: Michał Górny <mgorny@gentoo.org>
There were issues in trying to do CPU tuning (see #279 and #157 for
examples).
The simpler approach, given the capacity of modern hardware and the
antiquity of OpenPGP's S2K parameters, is just to always use the
maximum S2K settings. This also saves us some CPU from running
calibration steps.
This commit also drops the test for #157 entirely, because that test
embeds assumptions about the way that calibration is done that are no
longer true.
If this is merged, we should close#279 without merging it.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
When the Signature Creation Time was supplied to the signing function,
we were ignoring the fact that it might have a different timezone than
UTC. But the stored timestamp is supposed to always be in UTC, so it
should roundtrip correctly.
This includes a test to ensure that we don't end up with a regression.
Closes: #291
This makes the No-modify flag for Key Server Preferences actionable,
by allowing the primary key holder the ability to indicate which
third-party certifications are acceptable for redistribution.
See https://gitlab.com/openpgp-wg/rfc4880bis/merge_requests/20 for
more details.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
In rfc4880bis version 08, we have a specification for the Intended
Recipients subpacket, which can help to defend against certain kinds
of subtle attacks that involve re-wrapping a signed message to encrypt
it to someone else.
See https://gitlab.com/openpgp-wg/rfc4880bis/merge_requests/19 and
https://0xacab.org/schleuder/schleuder/issues/158 for more details
about this subpacket.
Assuming that `alice` is the PGPKey of the sender, and `bob` is the
PGPKey of the recipient, The simplest way to use this when generating
a message in PGPy is:
```
msg = PGPMessage.new('test message')
msg |= alice.sign(msg, intended_recipients=[bob])
msg = bob.encrypt(msg)
```
And it can be checked on Bob's side with:
```
cleartext = bob.decrypt(msg)
for sigvfy in alice.verify(cleartext).good_signatures:
if bob.fingerprint in sigvfy.signature.intended_recipients:
print("meant for Bob")
```
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Key Server Preferences (RFC 4880 §5.2.3.17) is a bitfield, more like
Key Flags (RFC 4880 §5.2.3.21) than Preferred Hash Algorithms (RFC
4880 §5.2.3.8).
The caller should be able to invoke this as a set when calling
PGPKey.certify().
This patch also improves documentation for PGPKey.certify() to
indicate how to pass in these flags.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Some older versions of the python bindings for GPGME produce python
objects that reference the underlying gpg.Context objects.
When a gpg.Context is used in a "with" clause, it is disposed of at
the end, and any resulting objects that reference that context object
are dangling.
This doesn't seem to be a problem with gpgme 1.13.1 (the current
version), but i was seeing segfaults in the PGPy test suite when used
with gpgme 1.12.0 :(
These fixes should make PGPy's test suite more robust against this
kind of failure.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
- first pass super basic integration test separation
- BCPG decryption tests now pass so removed XFAIL marker
- remove unused imports
- added some warning filtering to reduce noise
This increases the versioned dependency on the cryptography module to
2.6, since that is the version that provides the necessary ed25519
functionality.
We also add a "pure" 25519 OpenPGP certificate for testing purposes.
Closes#221, #222, #247
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
This increases the minimum versioned dependency on the cryptography
module to 2.5, where the necessary features are exposed.
We also add a mixed RSA + ECDH OepnPGP certificate for testing
purposes.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
version 1.5 (released nearly 3 years ago, on 2016-08-26) introduced
sign() and verify() for all asymmetric algorithms.
Without this change, with modern versions of python-cryptography, we
see warnings like:
/usr/lib/python3/dist-packages/pgpy/packet/fields.py:1177: CryptographyDeprecationWarning: signer and verifier have been deprecated. Please use sign and verify instead.
The version of python-cryptography in debian stretch (oldstable) is
1.7.1, for point of reference.
Python strings don't use \ to escape either * or !. So the
declarations here were adding to the list of warnings during the run
of the test suite.
Declaring them as raw (unescaped) strings keeps the warnings more quiet.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
We were testing the wrong version of the curve string. With this
change on python-cryptography 2.6.1 and openssl 1.1.1c, we drop from
26 xfailed to 14 xfailed tests.
on Python 3.7 with a more modern version of python-cryptography, you
can pass a bytearray as a sessionkey object without a problem.
So this test was failing to raise an exception.
By passing an integer instead of a bytearray or a bytes, we can
re-induce the exception.
the reverted commit claimed impossible dynamic values for the
statically-stored creation date and expiration date.
What has changed, though, is that now() is after the expiration date,
so we do need to change expired to True.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>