diff --git a/lang/python/docs/dita/gpgme-python-howto.ditamap b/lang/python/docs/dita/gpgme-python-howto.ditamap index 1809acb3..10ba8a64 100644 --- a/lang/python/docs/dita/gpgme-python-howto.ditamap +++ b/lang/python/docs/dita/gpgme-python-howto.ditamap @@ -1,98 +1,98 @@ GPGME Python Bindings HOWTO Ben McGinnes - + diff --git a/lang/python/docs/dita/howto/part02/installing.dita b/lang/python/docs/dita/howto/part02/installing.dita index 879f6ca7..4ede496d 100644 --- a/lang/python/docs/dita/howto/part02/installing.dita +++ b/lang/python/docs/dita/howto/part02/installing.dita @@ -1,23 +1,23 @@ Installing

Installing the Python bindings is effectively achieved by compiling and installing GPGME itself.

Once SWIG is installed with Python and all the dependencies for GPGME are installed you only need to confirm that the version(s) of Python you want the bindings installed for are in your $PATH.

By default GPGME will attempt to install the bindings for the most recent or highest version number of Python 2 and Python 3 it detects in $PATH. It specifically checks for the python and python3 executables first and then checks for specific version numbers.

For Python 2 it checks for these executables in this order: python, python2 and python2.7.

For Python 3 it checks for these executables in this order: python3, - python3.6, python3.5 and - python3.4.

+ python3.6, python3.5, python3.4 + and python3.7.

diff --git a/lang/python/docs/dita/howto/part02/daesh.dita b/lang/python/docs/dita/howto/part02/isis-gnupg.dita similarity index 100% rename from lang/python/docs/dita/howto/part02/daesh.dita rename to lang/python/docs/dita/howto/part02/isis-gnupg.dita diff --git a/lang/python/docs/dita/howto/part03/exporting-pubkeys.dita b/lang/python/docs/dita/howto/part03/exporting-pubkeys.dita index 8ae4f5bd..f632eb6f 100644 --- a/lang/python/docs/dita/howto/part03/exporting-pubkeys.dita +++ b/lang/python/docs/dita/howto/part03/exporting-pubkeys.dita @@ -1,120 +1,120 @@ Exporting Public Keys

There are two methods of exporting public keys, both of which are very similar to the - other. The default method, key_export() will export a public key or keys + other. The default method, key_export(), will export a public key or keys matching a specified pattern as normal. The alternative, the - key_export_minimal() method will do the same thing except producing a + key_export_minimal() method, will do the same thing except producing a minimised output with extra signatures and third party signatures or certifications removed.

import gpg import os.path import sys print(""" This script exports one or more public keys. """) c = gpg.Context(armor=True) if len(sys.argv) >= 4: keyfile = sys.argv[1] logrus = sys.argv[2] homedir = sys.argv[3] elif len(sys.argv) == 3: keyfile = sys.argv[1] logrus = sys.argv[2] homedir = input("Enter the GPG configuration directory path (optional): ") elif len(sys.argv) == 2: keyfile = sys.argv[1] logrus = input("Enter the UID matching the key(s) to export: ") homedir = input("Enter the GPG configuration directory path (optional): ") else: keyfile = input("Enter the path and filename to save the secret key to: ") logrus = input("Enter the UID matching the key(s) to export: ") homedir = input("Enter the GPG configuration directory path (optional): ") if homedir.startswith("~"): if os.path.exists(os.path.expanduser(homedir)) is True: c.home_dir = os.path.expanduser(homedir) else: pass elif os.path.exists(homedir) is True: c.home_dir = homedir else: pass try: result = c.key_export(pattern=logrus) except: result = c.key_export(pattern=None) if result is not None: with open(keyfile, "wb") as f: f.write(result) else: pass

It is important to note that the result will only return None when a pattern has been entered for logrus, but it has not matched any keys. When the search pattern itself is set to None this triggers the exporting of the entire public keybox.

import gpg import os.path import sys print(""" This script exports one or more public keys in minimised form. """) c = gpg.Context(armor=True) if len(sys.argv) >= 4: keyfile = sys.argv[1] logrus = sys.argv[2] homedir = sys.argv[3] elif len(sys.argv) == 3: keyfile = sys.argv[1] logrus = sys.argv[2] homedir = input("Enter the GPG configuration directory path (optional): ") elif len(sys.argv) == 2: keyfile = sys.argv[1] logrus = input("Enter the UID matching the key(s) to export: ") homedir = input("Enter the GPG configuration directory path (optional): ") else: keyfile = input("Enter the path and filename to save the secret key to: ") logrus = input("Enter the UID matching the key(s) to export: ") homedir = input("Enter the GPG configuration directory path (optional): ") if homedir.startswith("~"): if os.path.exists(os.path.expanduser(homedir)) is True: c.home_dir = os.path.expanduser(homedir) else: pass elif os.path.exists(homedir) is True: c.home_dir = homedir else: pass try: result = c.key_export_minimal(pattern=logrus) except: result = c.key_export_minimal(pattern=None) if result is not None: with open(keyfile, "wb") as f: f.write(result) else: pass

diff --git a/lang/python/docs/dita/howto/part03/importing-eff-keys.dita b/lang/python/docs/dita/howto/part03/importing-eff-keys.dita new file mode 100644 index 00000000..124ebdac --- /dev/null +++ b/lang/python/docs/dita/howto/part03/importing-eff-keys.dita @@ -0,0 +1,74 @@ + + + + + Importing Keys + DRAFT VERSION + +

Importing keys is possible with the key_import() method and takes one + argument which is a bytes literal object containing either the binary or ASCII armoured key + data for one or more keys.

+

In the following example a key will be retrieved from the SKS keyservers via the web using + the requests module. Since requests returns the content as a bytes literal object, we can + then use that directly to import the resulting data into our keybox. In order to demonstrate + multiple imports this example searches for all the keys of users at a particular domain + name. This time we're using the EFF, since they've always been such good supporters of + strong encryption and good security practices.

+

If this holds true then I would expect that some keys I already have will be updated and + some others will be added. Most of the keys created most recently and belonging to still + active people within the EFF should, if they are following their own recent statements, be + revoked. If they are not revoked then it would be best left to the reader to determine + whether or not the change in leadership at that organisation indicates a change in their + policy of supporting good security practices.

+

+ import gpg +import requests + +c = gpg.Context() +url = "https://sks-keyservers.net/pks/lookup" +pattern = input("Enter the pattern to search for key or user IDs: ") +payload = { "op": "get", "search": pattern } + +r = requests.get(url, verify=True, params=payload) +k = c.key_import(r.content) + +summary = """ +Total number of keys: {0} +Total number imported: {1} +Number of version 3 keys ignored: {2} + +Number of imported key objects or updates: {3} +Number of unchanged keys: {4} +Number of new signatures: {5} +Number of revoked keys: {6} +""".format(k.considered, len(k.imports), k.skipped_v3_keys, k.imported, + k.unchanged, k.new_signatures, k.new_revocations) + +print(summary) +

+

The resulting output in that case, where the search pattern entered was + @eff.org was:

+

+ Total number of keys: 272 +Total number imported: 249 +Number of version 3 keys ignored: 23 + +Number of imported key objects or updates: 180 +Number of unchanged keys: 66 +Number of new signatures: 7 +Number of revoked keys: 0 +

+

The 23 skipped keys all date back to the 1990s, some of which were made very shortly after + PGP 2 was first released.

+

+ Pretty Good Privacy version 2 and above are the only versions with any widespread use. + Pretty Good Privacy version 1 had a number of serious security problems, not least of + which being that it relied on an encryption algorithm called Bass-O-Matic which was + written by Phil Zimmermann. Following feedback on this algorithm, Zimmermann withdrew + version 1 and re-implemented version 2 using RSA and IDEA, even though both were subject + to software patents at the time (both of those software patents have long since + expired). +

+ +
+
diff --git a/lang/python/docs/dita/howto/version-info.dita b/lang/python/docs/dita/howto/version-info.dita index f9bb42aa..f07c1362 100644 --- a/lang/python/docs/dita/howto/version-info.dita +++ b/lang/python/docs/dita/howto/version-info.dita @@ -1,16 +1,16 @@ Documentation Version -

Version: 0.1.2-DRAFT

+

Version: 0.1.3-DRAFT

Author: Ben McGinnes <ben@gnupg.org>

Author GPG Key ID: DB4724E6FA4286C92B4E55C4321E4E2373590E5D

Language: Australian English, British English