646 Commits

Author SHA1 Message Date
James Morris
ecd28311aa Documented SignatureType enum 2020-09-16 15:30:43 -04:00
James Morris
e73793a421 Added docstrings to constant enums 2020-09-15 23:54:00 -04:00
James Morris
f2dd02206e Tweaked docstring for PGPKey.encrypt() 2020-09-15 16:44:06 -04:00
James Morris
6e77edee8c Merge pull request #342 from mgorny/dashescape
Fix dash un-escaping to be applied unconditionally
2020-09-08 16:33:01 -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
Daniel Kahn Gillmor
9cd282479a PGPUID objects should be comparable when no selfsig exists.
In some cases, no selfsig will exist for PGPUID.  In the event that a
selfsig-less PGPUIDs is compared with one that has a selfsig, the
missing selfsig should be "less than" the other.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-08-31 19:09:12 -04:00
Daniel Kahn Gillmor
35a13a1ea7 PGPUID.is_primary should be False if no selfsig can be found
In some circumstances, no selfsig will be available.  This change
ensures that is_primary doesn't raise an exception in those
circumstances.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-08-31 19:09:12 -04:00
James Morris
8e1407de54 Added some more package metadata, bumped version in preparation of new release, tweaked setup.py 2020-07-28 14:26:31 -04:00
Karthikeyan Singaravelan
aa54624c5a Import ABC from collections.abc 2020-07-19 17:15:22 +00:00
Mac Malone
c885f7c4f7 Fixed the ordering of OnePassSignatures 2019-11-03 20:22:37 -05:00
Michael Greene
3c18597753 Merge pull request #301 from dkg/s2k-on-modern-hardware
Max out S2K parameters
2019-11-02 09:27:20 -07:00
Michael Greene
986f5d2722 try utf-8 first; fall back to charmap if that fails 2019-11-01 22:57:40 -07: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
2b9de7490c Merge pull request #280 from dkg/simplify-userid
User IDs: simplify, treat as UTF-8 strings
2019-11-01 16:36:37 -07: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
Daniel Kahn Gillmor
6e34a00a50 Avoid noisy warnings when generating messages
Similar to the concerns in #297, there are noisy warnings produced
when encrypting data to or signing data with a primary key, if a
subkey is ultimately what ends up being used:

```
./generate-test-vectors:279: UserWarning: Key F231550C4F47E38E does not have the required usage flag EncryptStorage, EncryptCommunications; using subkey 4766F6B9D5F21EB6
  encmsg = alice_key.pubkey.encrypt(payloadmsg, cipher=cipher, sessionkey=sessionkey)
```

This change converts these warnings to debug information.

In #298, we just removed the noisy warnings on consuming data -- the
caller really has no choice in how to consume the data, so there's no
point in sending them alerts.  Either we can decrypt or verify with
the primary key or one of the subkeys, or we can't.

But in the situation where the caller is producing data -- signing or
encrypting -- we might want be a little bit noisier, because the user
really might have some obscure reason that they prefer to use a
specific subkey that the library isn't in a position to understand.
So giving the user a hint at debug-level about what's going on is
probably reasonable.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-11-01 16:46:03 -04:00
Daniel Kahn Gillmor
2152e4b261 Removing warning about signature verification with subkey
Commod0re requested this change, in line with the change I requested
in #297 about decrypting with subkeys.  I think it's the right thing
to do.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-11-01 16:28:32 -04:00
Daniel Kahn Gillmor
14656c962f Drop noisy warning on decrypting with subkey
This warning doesn't appear to be actionable, and is likely to only
encourage users of PGPy to do extra gymnastics before calling
decrypt().

Closes #297

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-11-01 16:07:31 -04:00
Daniel Kahn Gillmor
a75e3a008a Fix up minor bug introduced in #286 2019-10-31 02:20:01 -04:00
Michael Greene
a3830cc831 Merge pull request #286 from dkg/specify-creation-time
specify creation time more completely
2019-10-26 10:10:57 -07:00
Michael Greene
43b4d4efe8 Merge pull request #284 from dkg/gen-issuer-fingerprint
PGPKey._sign: include hashed Issuer Fingerprint subpacket by default.
2019-10-26 10:10:09 -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
Michael Greene
c2bb150784 Merge pull request #292 from dkg/sigtime-utc
When Signature Creation Time is supplied, use UTC
2019-10-26 10:07:57 -07:00
Michael Greene
8de7c64ae6 passphrases should be unicode, not latin-1 2019-10-26 10:01:34 -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
c300d9b6f3 PGPUID: add convenience functions to retrieve attested 3PCs
These helper functions make it easy to verify which third-party
certifications are currently attested to by the primary key.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-09-18 19:28:28 -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
afb2aa103c SignatureV4: add canonical_bytes() function
This function allows the user to easily get the canonicalized
bytestring representation of the signature.  This is useful for making
third-party confirmation signatures (sig type 0x50), as well as
Signature Target subpackets (subpacket 31), and other pointers to
specific signatures.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-09-01 15:58:49 -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
ae1f29072f specify creation time
While #262 made it possible to set creation times in some places, it
missed some others.

This makes the created= argument functional in all the contexts where
it could be useful.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-28 01:34:22 -04:00
Daniel Kahn Gillmor
30eb24aaf7 PGPKey._sign: include hashed Issuer Fingerprint subpacket by default.
GnuPG has been including hashed Issuer Fingerprint subpackets by
default in signatures since 2016-10-08.  This subpacket makes it
possible to distinguish between a bad signature and a signature that
we happen to not have the issuer's key for.

We add it here for normal signature, certifications, and revocations,
unless the signer explicitly requests that it not be included.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-27 18:47:56 -04:00
Daniel Kahn Gillmor
df87950519 User IDs: simplify, treat as UTF-8 strings
Over in #271, we discussed simplifying the lower-level UserID packet
object, and moving the <name,comment,email> splitting logic up into
the higher-layer PGPUID API.

This patch does that work, and also exposes an additional
PGPUID.userid property, which is the full UTF-8 string.

If this gets merged, it will obsolete #271.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-27 16:52:33 -04:00
Daniel Kahn Gillmor
c639a03858 PGPKey.certify: document exportable flag
The exportable flag is already implemented, but it is not documented
in the docstring.  This addresses that concern.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-27 16:50:45 -04:00
Daniel Kahn Gillmor
75beb08733 types: Unarmor 76-character-long lines
When 76-char base64 lines were present, PGPy was failing to de-armor
them.

Closes: #276
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-27 11:54:10 -04:00
Michael Greene
9fc933834a Merge pull request #273 from dkg/issuer-fingerprint
IssuerFingerprint - include spec and update length for v5
2019-08-02 14:26:55 -07:00
Michael Greene
da1356b07f Merge pull request #272 from dkg/allow-skipping-cross-signing
Permit skipping cross-signing unless strictly required
2019-08-02 14:24:59 -07:00
Daniel Kahn Gillmor
138b0d555a Fix sphinx warnings about IDEA documentation
Without this change, the warning about IDEA is not properly rendered
in html, and ./setup.py build_sphinx itself produces a warning:

…/pgpy/constants.py:docstring of pgpy.constants.SymmetricKeyAlgorithm.IDEA:1: WARNING: Content block expected for the "warning" directive; none found.
…/pgpy/constants.py:docstring of pgpy.constants.SymmetricKeyAlgorithm.IDEA:2: WARNING: Explicit markup ends without a blank line; unexpected unindent.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-08-02 16:56:01 -04:00
Daniel Kahn Gillmor
c066719eb4 Permit skipping cross-signing unless strictly required
This is done by setting 'crosssign' to False in the prefs parameter to
the sign function.

You probably don't want to use this feature! It is likely to make
OpenPGP certificates without cross-signatures that some other
implementations will reject.
2019-08-02 15:53:23 -04:00
Daniel Kahn Gillmor
7df868e257 IssuerFingerprint - include spec and update length for v5
The spec comes from here:
https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-07#section-5.2.3.28

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorsemnan.net>
2019-08-02 13:37:35 -04:00
Michael Greene
6f4bb8d867 /facepalm 2019-08-01 19:32:31 -07:00
Michael Greene
e19e4181af ACTUAL fix for this bug 2019-08-01 19:24:36 -07:00
Michael Greene
3d653f4d9f v0.5.1 hotfix for type 0 signature subpackets 2019-08-01 17:51:18 -07:00
James Morris
47ecae30b2 Tweaked copyright notices 2019-08-01 20:45:02 -04:00
Michael Greene
e8c7dc5145 only raise once 2019-08-01 16:10:12 -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
f7ec8668bb fix collections.abc import under py27 2019-08-01 16:06:20 -07:00
Michael Greene
fc71db27d0 Merge pull request #270 from dkg/25519-from-rot42
ed25519 and Curve 25519 support from rot42
2019-08-01 14:15:00 -07:00
Michael Greene
58df467325 Merge pull request #269 from dkg/ecpoint-format-mismatch
Use dedicated exception class when ECPointFormat is wrong
2019-08-01 14:11:03 -07:00