Commit Graph

264 Commits

Author SHA1 Message Date
Michael Greene
eb99007b3a big PEP8 pass 2022-11-23 17:15:45 -08:00
Michael Greene
dd85906b50 fix last test 2022-11-23 16:32:15 -08:00
Michael Greene
696e24b800 fix warning formatting and try to get everything using the same kind of string formatting 2022-11-23 16:18:04 -08:00
Michael Greene
25d2c12718 fix this weirdness 2022-11-23 15:44:04 -08:00
Michael Greene
c10439f74b this fixes EdDSA 2022-11-23 15:43:51 -08:00
Michael Greene
3aa0acbce5 oops 2022-11-23 15:35:08 -08:00
Michael Greene
0f574f5ba8 fix expires_at 2022-11-23 15:34:30 -08:00
Michael Greene
eead880d09 - move FlagEnum and FlagEnumMeta back into types.py where they belong
- fix capitalization and spelling of SecurityIssues flag members
- pythonize the names of SAFE_CURVES and MINIMUM_ASYMMETRIC_KE?Y_LENGTHS
- move the functionality of is_hash_considered_secure into a HashAlgorithm property called is_considered_secure where it always should have been
- move the functionality of check_assymetric_algo_and_its_parameters into a PubKeyAlgorithm function called validate_params like it always should have been
2022-11-23 15:33:36 -08:00
Michael Greene
0965434d9d fix PGPUID.selfsig 2022-11-23 11:04:05 -08:00
Michael Greene
937f36bd62 fix typo 2022-11-23 10:47:09 -08:00
KOLANICH
a23dccef97 Got rid of six. 2022-11-11 17:39:38 +03:00
KOLANICH
b8c28c5a46 Added some security checks: * a check of self-signatures (doesn't work - no self-signatures are detected on primary key (_signatures is empty), BouncyCastle detects them fine) * a check of cryptoprimitives used 2022-11-10 17:23:27 +03:00
Michael Greene
b5cc2f353b Merge pull request #415 from dkg/tz-aware-datetime 2022-11-09 14:50:16 -08: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
Daniel Kahn Gillmor
82614f8019 Ignore unrecognized signature versions
As new versions of OpenPGP signatures are defined, implementations may
provide multiple signatures, one of an older version for legacy
clients and one of a new version for clients that can read the new
signature form.

PGPy should skip over any signature whose version is not recognized.
2022-11-09 07:49:01 -05:00
Michael Greene
473d3651e2 Merge pull request #313 from prebuilder/genExprs
Refactoring the generator expressions for better readability and possibility to add debug output
2022-11-02 21:36:08 -07: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
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
James Morris
abcf2ae300 Fixed docstring for PGPKey.add_subkey() 2021-01-26 10:36:31 -05:00
KOLANICH
3d34eba1b4 Refactoring the generator expressions for better readability and possibility to add debug output 2021-01-12 19:34:15 +03:00
James Morris
3a1f7bf3db Merge branch 'master' into master 2020-09-24 17:38:54 -04:00
James Morris
1b2b52adfd More documentation fixups 2020-09-18 17:48: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
Mac Malone
c885f7c4f7 Fixed the ordering of OnePassSignatures 2019-11-03 20:22:37 -05:00
Michael Greene
986f5d2722 try utf-8 first; fall back to charmap if that fails 2019-11-01 22:57:40 -07: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
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
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
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
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
Michael Greene
3d653f4d9f v0.5.1 hotfix for type 0 signature subpackets 2019-08-01 17:51:18 -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