399 Commits

Author SHA1 Message Date
Michael Greene
eb99007b3a big PEP8 pass 2022-11-23 17:15:45 -08:00
Michael Greene
3f55a53255 fix this test 2022-11-23 16:23:15 -08:00
Michael Greene
18bc63d856 - explicitly define which security issues can cause signature verify to fail
- improve implementation of SignatureVerify.bad_signatures
- improve implementation of SignatureVerify.good_signatures
- fix implementation of SignatureVerify.__bool__
2022-11-23 16:05:33 -08:00
Michael Greene
5c029ba215 fix all these tests 2022-11-23 11:04:15 -08:00
KOLANICH
a23dccef97 Got rid of six. 2022-11-11 17:39:38 +03:00
KOLANICH
d0cea0a4e1 Fixed gpg_ver initialization in conftest.py.
It should be a global variable in order to be imported
2022-11-10 17:28:48 +03:00
Daniel Kahn Gillmor
c880d72902 Generate and use TZ-aware datetime objects
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
2022-11-09 07:52:28 -05:00
Michael Greene
10f7d765e3 Merge pull request #394 from ignaloidas/default-to-3DES
Default to 3DES when preferred algorithms don't have any supporting algorithm
2022-11-02 21:24:56 -07:00
Michael Greene
4f133bbd15 Merge pull request #404 from kianmeng/fix-typos
Fix typos
2022-11-02 21:21:19 -07:00
Eli Schwartz
383a3c9e64 fix testsuite regression that immediately crashed without integration tests
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.
2022-10-26 20:57:16 -04:00
Kian-Meng Ang
6e5b685be3 Fix typos
Found via `codespell -L nd,wth,te,useg,bu,fpr,fo,clen,varius,unce`
2022-10-10 17:13:41 +08:00
Ignas Kiela
e0eb8fb4a5 Default to 3DES when preferred algorithms don't have any supporting algorithm
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.
2022-04-20 17:53:29 +03:00
Daniel Kahn Gillmor
08a76fdda9 tests: drop distutils
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>
2022-01-31 19:51:12 -05:00
James Morris
6e6da41406 Error if we are running on GitHub CI without integration tests 2021-09-24 10:44:50 -04:00
James Morris
2536f36067 Fix mispelled tests messing with ordering 2021-09-23 18:59:41 -04:00
Gabriel Cruz
50ef17a9b1 Feature:: Support for keys without usage flags (#371)
Co-authored-by: James Morris <jmorris@securityinnovation.com>
2021-07-08 15:52:09 -04:00
Paul Mulders
e2f427ea5c Port tests/test_05_actions.py to pytest-order 2021-06-23 17:58:34 +02:00
James Morris
3a1f7bf3db Merge branch 'master' into master 2020-09-24 17:38:54 -04:00
Michał Górny
59c4050088 Fix dash escaping to be applied unconditionally
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>
2020-09-08 19:37:37 +02:00
James Morris
feabf6c2fd Fixed import try/except in tests so that pypy doesn't immediately choke 2020-07-16 16:37:46 -04:00
Mac Malone
26f5b358ee Added one-pass signature order regression test 2019-12-02 16:45:17 -05:00
Daniel Kahn Gillmor
777faa8343 Max out S2K parameters
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>
2019-11-02 00:19:03 -04:00
Michael Greene
d32aebe19f Merge branch 'master' into intended-recipient 2019-11-01 16:35:34 -07:00
Michael Greene
1324e0ac79 Merge pull request #287 from dkg/attested-certifications
Implement First-Party Attested Third-Party Certifications (1PA3PC)
2019-11-01 16:33:10 -07:00
Michael Greene
445f912ce1 Merge pull request #282 from dkg/keyserver-prefs
KeyServerPreferences is a bitfield, not a list
2019-10-26 10:09:33 -07:00
Daniel Kahn Gillmor
494e88473d When Signature Creation Time is supplied, use UTC
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
2019-10-21 13:13:04 -04:00
Daniel Kahn Gillmor
1c9b55a0df Implement Attested Certifications
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>
2019-09-18 19:28:28 -04:00
Daniel Kahn Gillmor
f623661d99 handle and generate Intended Recipient subpackets
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>
2019-09-11 21:55:36 -04:00
Daniel Kahn Gillmor
6d7877d167 KeyServerPreferences is a bitfield, not a list
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>
2019-08-28 02:09:55 -04:00
Daniel Kahn Gillmor
a972df5672 tests: avoid references to gpg.Context after deletion
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>
2019-08-27 11:15:50 -04:00
Michael Greene
e19e4181af ACTUAL fix for this bug 2019-08-01 19:24:36 -07:00
Michael Greene
15c90e2513 - correct missed copyright notices (need to add more of these)
- bump version string to 0.5.0
- change a list to a set
2019-08-01 16:09:13 -07:00
Michael Greene
824f2649fb soft unit test update pass:
- 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
2019-08-01 15:45:47 -07:00
Michael Greene
2bd4054674 fix failing test and resolve deprecation warning 2019-08-01 14:24:27 -07:00
rot42
d601655c27 support for Ed25519 signatures
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>
2019-08-01 15:57:48 -04:00
rot42
53c6c3ba94 support for ECDH encryption using Curve25519 (cv25519)
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>
2019-08-01 15:54:06 -04:00
Michael Greene
c740bc8453 Merge pull request #253 from rot42/ft-s2k-gnu-extensions
Support for S2K GNU extensions
2019-07-31 09:31:03 -07:00
Michael Greene
b0132fcd86 Merge pull request #258 from dkg/cleanup-tests
tests/test_03_armor.py: fix syntax
2019-07-31 09:09:25 -07:00
Michael Greene
fbd2796863 Merge pull request #259 from dkg/cryptography-1.5
move to python-cryptography v1.5
2019-07-31 09:08:40 -07:00
Michael Greene
00a50fcf5f Merge pull request #265 from dkg/cleanup-escapes
Avoid warnings about bad escape characters
2019-07-31 09:07:09 -07:00
Daniel Kahn Gillmor
d281d6ec17 move to python-cryptography v1.5
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.
2019-07-17 04:41:27 -04:00
Daniel Kahn Gillmor
148fbf6948 Avoid warnings about bad escape characters
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>
2019-07-17 02:58:47 -04:00
Daniel Kahn Gillmor
e0e516ed7f test the names of the curves against the stored list
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.
2019-07-17 02:49:29 -04:00
Daniel Kahn Gillmor
f18cbbca84 try passing a non-bytes-like object as a session key to elicit TypeError
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.
2019-07-17 01:03:48 -04:00
Daniel Kahn Gillmor
12ed9b3b71 fix e163a0cf22
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>
2019-07-17 01:02:41 -04:00
Daniel Kahn Gillmor
5f8c855e4f tests/test_03_armor.py: fix syntax
Without this fix, there is an immediate failure when running pytest-3.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-07-17 00:22:41 -04:00
Michael Greene
35d505c5f8 Merge pull request #244 from Wolf480pl/preference-list
#243 - Pick first _supported_ algorithm from preference list
2019-06-07 14:55:13 -07:00
Michael Greene
db7d00fc3f Merge pull request #207 from J08nY/feature/key-revocations
Add revocation_signatures property to PGPKey.
2019-06-07 14:45:42 -07:00
Michael Greene
77f3c20ebe Merge pull request #205 from J08nY/feature/issuer-fingerprint
Support IssuerFingerprint subpacket.
2019-06-07 14:35:58 -07:00
Michael Greene
c8ebbae059 Merge pull request #180 from J08nY/feature/keyring-add
Add PGPKeyring.load() for PGPKey instance param.
2019-06-07 14:33:46 -07:00