[git] GPGME - branch, ben/docs/2018-03, updated. gpgme-1.10.0-137-gc6a0395

by Ben McGinnes cvs at cvs.gnupg.org
Wed Mar 21 19:56:36 CET 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, ben/docs/2018-03 has been updated
       via  c6a0395f0a3a57071f0c943f7815f58a02f9d2f3 (commit)
       via  0a0d57fd41380cd797d29e11cec8a77c7404e960 (commit)
       via  0ccc57c9512246d82d46e7732bfb0f95c18ca9d3 (commit)
       via  8b401bfc76eac762553f76faab53c2f4cd117a8d (commit)
       via  6c6af9a7b0ae4e7182d669bec282c6edaaa7eaa1 (commit)
       via  a4e3f827652c59d850b4e5506a92c1ecd190c1bb (commit)
       via  ad6cb4f9b8b97a2bc501c17fc542a84b725dedea (commit)
       via  ae2767eb27b6a76284ee4403e575869afe2e80a8 (commit)
       via  e57388a69f61d14e3df3c842d227fb450c96c807 (commit)
      from  ac6a552c37147a000de74f49d1bff34dad52252e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c6a0395f0a3a57071f0c943f7815f58a02f9d2f3
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 05:55:53 2018 +1100

    example: key selection
    
    * Removed extraneous blank line.

diff --git a/lang/python/examples/howto/key-selection.py b/lang/python/examples/howto/key-selection.py
index 8c2d7b5..a007219 100755
--- a/lang/python/examples/howto/key-selection.py
+++ b/lang/python/examples/howto/key-selection.py
@@ -49,4 +49,3 @@ keys = []
 for i in range(len(key_ids)):
     logrus = key_ids[i]
     keys.append(gpg.Context().keylist(pattern=logrus))
-

commit 0a0d57fd41380cd797d29e11cec8a77c7404e960
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 05:52:55 2018 +1100

    example: key selection
    
    * Similar to group-key-selection.py, but does not use an existing
      group from gpg.conf; instead takes multiple key IDs, fingerprints or
      patterns on the command line and adds them to a keylist object.

diff --git a/lang/python/examples/howto/key-selection.py b/lang/python/examples/howto/key-selection.py
new file mode 100755
index 0000000..8c2d7b5
--- /dev/null
+++ b/lang/python/examples/howto/key-selection.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Uses key IDs, fingerprints or other patterns as space separated input and
+creates a keylist object for use by the gpg module.
+
+Similar to the group-key-selection.py script, but does not require an existing
+group in the gpg.conf file.
+"""
+
+if len(sys.argv) < 2:
+    key_ids_str = sys.argv[1:]
+elif len(sys.argv) == 2:
+    key_ids_str = sys.argv[1]
+elif len(sys.argv) == 1:
+    key_ids_str = input("Enter the keys to select by key ID or fingerprint: ")
+else:
+    key_ids_str = input("Enter the keys to select by key ID or fingerprint: ")
+
+key_ids = key_ids_str.split()
+keys = []
+for i in range(len(key_ids)):
+    logrus = key_ids[i]
+    keys.append(gpg.Context().keylist(pattern=logrus))
+

commit 0ccc57c9512246d82d46e7732bfb0f95c18ca9d3
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 05:40:02 2018 +1100

    example: sign and encrypt to group
    
    * Begins to string together some of the simpler examples to do more
      useful things.
    * Signs and encrypts a file while encrypting to every key in a group
      specified in the gpg.conf file.

diff --git a/lang/python/examples/howto/group-encrypt-sign-file.py b/lang/python/examples/howto/group-encrypt-sign-file.py
new file mode 100755
index 0000000..920e50d
--- /dev/null
+++ b/lang/python/examples/howto/group-encrypt-sign-file.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+from groups import group_lists
+
+"""
+Signs and encrypts a file to a specified group of keys.  If entering both the
+group and the filename on the command line, the group must be entered first.
+
+Signs with and also encrypts to the default key of the user invoking the
+script.  Will treat all recipients as trusted to permit encryption.
+
+Will produce both an ASCII armoured and GPG binary format copy of the signed
+and encrypted file.
+"""
+
+if len(sys.argv) > 3:
+    group = sys.argv[1]
+    filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+    group = sys.argv[1]
+    filename = sys.argv[2]
+elif len(sys.argv) == 2:
+    group = sys.argv[1]
+    filename = input("Enter the path and filename to encrypt: ")
+else:
+    group = input("Enter the name of the group to select keys for: ")
+    filename = input("Enter the path and filename to encrypt: ")
+
+keys = []
+a = []
+
+for i in range(len(group_lists)):
+    a.append(group_lists[i][0])
+
+b = a.index(group)
+
+for i in range(len(group_lists[b][1])):
+    logrus = group_lists[b][1][i]
+    keys.append(gpg.Context().keylist(pattern=logrus))
+
+with open(filename, "rb") as f:
+    text = f.read()
+
+with gpg.Context(armor=True) as ca:
+    ciphertext, result, sign_result = ca.encrypt(text, recipients=keys,
+                                                 always_trust=True,
+                                                     add_encrypt_to=True)
+    with open("{0}.asc".format(filename), "wb") as fa:
+        fa.write(ciphertext)
+
+with gpg.Context() as cg:
+    ciphertext, result, sign_result = cg.encrypt(text, recipients=keys,
+                                                 always_trust=True,
+                                                     add_encrypt_to=True)
+    with open("{0}.gpg".format(filename), "wb") as fg:
+        fg.write(ciphertext)

commit 8b401bfc76eac762553f76faab53c2f4cd117a8d
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 05:20:51 2018 +1100

    example: group key selection
    
    * Example of preparing a keylist object using an existing group line
      from the gpg.conf file.

diff --git a/lang/python/examples/howto/group-key-selection.py b/lang/python/examples/howto/group-key-selection.py
new file mode 100755
index 0000000..2e3d2eb
--- /dev/null
+++ b/lang/python/examples/howto/group-key-selection.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+from groups import group_lists
+
+"""
+Takes an existing group specified as a command line parameter and converts it
+to a list object 'keys' as expected by the gpg module.
+
+Requires the groups module in this directory.
+"""
+
+if len(sys.argv) == 2:
+    group = sys.argv[1]
+elif len(sys.argv) == 1:
+    group = input("Enter the name of the group to select keys for: ")
+else:
+    group = input("Enter the name of the group to select keys for: ")
+
+keys = []
+a = []
+
+for i in range(len(group_lists)):
+    a.append(group_lists[i][0])
+
+b = a.index(group)
+
+for i in range(len(group_lists[b][1])):
+    logrus = group_lists[b][1][i]
+    keys.append(gpg.Context().keylist(pattern=logrus))

commit 6c6af9a7b0ae4e7182d669bec282c6edaaa7eaa1
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 05:07:56 2018 +1100

    example groups work around
    
    * Updated usage so it only references importing the final list of
      lists produced.  Trying to use some of the mid-points can have
      unpredictable results (this is part of the problem with work
      arounds).

diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py
index e7adc44..5e7fdf6 100644
--- a/lang/python/examples/howto/groups.py
+++ b/lang/python/examples/howto/groups.py
@@ -28,7 +28,7 @@ import subprocess
 """
 Intended for use with other scripts.
 
-Usage: from groups import group_lines, group_lists
+Usage: from groups import group_lists
 """
 
 lines = subprocess.getoutput("gpgconf --list-options gpg").splitlines()

commit a4e3f827652c59d850b4e5506a92c1ecd190c1bb
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 04:04:05 2018 +1100

    example: groups
    
    * Added a docstring.

diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py
index 67fd783..e7adc44 100644
--- a/lang/python/examples/howto/groups.py
+++ b/lang/python/examples/howto/groups.py
@@ -25,6 +25,12 @@ from __future__ import absolute_import, division, unicode_literals
 
 import subprocess
 
+"""
+Intended for use with other scripts.
+
+Usage: from groups import group_lines, group_lists
+"""
+
 lines = subprocess.getoutput("gpgconf --list-options gpg").splitlines()
 
 for i in range(len(lines)):

commit ad6cb4f9b8b97a2bc501c17fc542a84b725dedea
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 03:58:58 2018 +1100

    example: verify signatures
    
    * Added example for verifying detached signatures against the files
      they're the signatures for.

diff --git a/lang/python/examples/howto/verify-signatures.py b/lang/python/examples/howto/verify-signatures.py
new file mode 100755
index 0000000..8aafc3b
--- /dev/null
+++ b/lang/python/examples/howto/verify-signatures.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+import time
+
+"""
+Verifies a signed file which has been signed with a detached signature.
+"""
+
+if len(sys.argv) > 2:
+    filename = sys.argv[1]
+    sig_file = sys.argv[2]
+elif len(sys.argv) == 2:
+    filename = sys.argv[1]
+    sig_file = input("Enter the path and filename of the detached signature: ")
+else:
+    filename = input("Enter the path and filename to verify: ")
+    sig_file = input("Enter the path and filename of the detached signature: ")
+
+c = gpg.Context()
+
+try:
+    data, result = c.verify(open(filename), open(sig_file))
+    verified = True
+except gpg.errors.BadSignatures as e:
+    verified = False
+    print(e)
+
+if verified is True:
+    for i in range(len(result.signatures)):
+        sign = result.signatures[i]
+        print("""Good signature from:
+{0}
+with key {1}
+made at {2}
+""".format(c.get_key(sign.fpr).uids[0].uid, sign.fpr,
+           time.ctime(sign.timestamp)))
+else:
+    pass

commit ae2767eb27b6a76284ee4403e575869afe2e80a8
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 01:50:08 2018 +1100

    example: verify signed file
    
    * Added example to verify normal and clearsigned files.

diff --git a/lang/python/examples/howto/verify-signed-file.py b/lang/python/examples/howto/verify-signed-file.py
new file mode 100755
index 0000000..9f8702f
--- /dev/null
+++ b/lang/python/examples/howto/verify-signed-file.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+import time
+
+"""
+Verifies a signed file which has been signed with either NORMAL or CLEAR modes.
+"""
+
+if len(sys.argv) > 2:
+    filename = " ".join(sys.argv[1:])
+elif len(sys.argv) == 2:
+    filename = sys.argv[1]
+else:
+    filename = input("Enter the path and filename to sign: ")
+
+c = gpg.Context()
+
+try:
+    data, result = c.verify(open(filename))
+    verified = True
+except gpg.errors.BadSignatures as e:
+    verified = False
+    print(e)
+
+if verified is True:
+    for i in range(len(result.signatures)):
+        sign = result.signatures[i]
+        print("""Good signature from:
+{0}
+with key {1}
+made at {2}
+""".format(c.get_key(sign.fpr).uids[0].uid, sign.fpr,
+           time.ctime(sign.timestamp)))
+else:
+    pass

commit e57388a69f61d14e3df3c842d227fb450c96c807
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 01:48:41 2018 +1100

    doc: python bindings howto
    
    * Fixed minor error in one of the verification examples.

diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org
index 0c15149..655209a 100644
--- a/lang/python/docs/GPGMEpythonHOWTOen.org
+++ b/lang/python/docs/GPGMEpythonHOWTOen.org
@@ -898,7 +898,7 @@
      """.format(c.get_key(sign.fpr).uids[0].uid,
 		sign.fpr, time.ctime(sign.timestamp)))
      else:
-	 pass(e)
+	 pass
    #+end_src
 
    Whereas this next example, which is almost identical would work

-----------------------------------------------------------------------

Summary of changes:
 lang/python/docs/GPGMEpythonHOWTOen.org            |  2 +-
 ...ypt-sign-file.py => group-encrypt-sign-file.py} | 31 ++++++++++-----
 .../{decrypt-file.py => group-key-selection.py}    | 36 +++++++++++------
 lang/python/examples/howto/groups.py               |  6 +++
 .../howto/{decrypt-file.py => key-selection.py}    | 31 +++++++++------
 .../{clear-sign-file.py => verify-signatures.py}   | 46 +++++++++++++---------
 .../{decrypt-file.py => verify-signed-file.py}     | 39 ++++++++++++------
 7 files changed, 127 insertions(+), 64 deletions(-)
 copy lang/python/examples/howto/{encrypt-sign-file.py => group-encrypt-sign-file.py} (80%)
 copy lang/python/examples/howto/{decrypt-file.py => group-key-selection.py} (63%)
 copy lang/python/examples/howto/{decrypt-file.py => key-selection.py} (64%)
 copy lang/python/examples/howto/{clear-sign-file.py => verify-signatures.py} (58%)
 copy lang/python/examples/howto/{decrypt-file.py => verify-signed-file.py} (63%)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list