aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/examples
diff options
context:
space:
mode:
Diffstat (limited to 'lang/python/examples')
-rw-r--r--lang/python/examples/Makefile.am74
-rwxr-xr-xlang/python/examples/assuan.py28
-rwxr-xr-xlang/python/examples/decryption-filter.py33
-rwxr-xr-xlang/python/examples/delkey.py34
-rwxr-xr-xlang/python/examples/exportimport.py62
-rwxr-xr-xlang/python/examples/genkey.py45
-rw-r--r--lang/python/examples/howto/README.org58
-rwxr-xr-xlang/python/examples/howto/add-userid.py62
-rwxr-xr-xlang/python/examples/howto/advanced/cython/keycount.pyx26
-rw-r--r--lang/python/examples/howto/advanced/cython/requirements.txt1
-rw-r--r--lang/python/examples/howto/advanced/cython/setup.py6
-rwxr-xr-xlang/python/examples/howto/clear-sign-file.py56
-rwxr-xr-xlang/python/examples/howto/create-key.py95
-rwxr-xr-xlang/python/examples/howto/decrypt-file.py51
-rwxr-xr-xlang/python/examples/howto/detach-sign-file.py64
-rwxr-xr-xlang/python/examples/howto/encrypt-file.py71
-rwxr-xr-xlang/python/examples/howto/encrypt-sign-file.py70
-rwxr-xr-xlang/python/examples/howto/encrypt-to-group-gullible.py81
-rwxr-xr-xlang/python/examples/howto/encrypt-to-group-trustno1.py90
-rwxr-xr-xlang/python/examples/howto/encrypt-to-group.py91
-rwxr-xr-xlang/python/examples/howto/export-key.py87
-rwxr-xr-xlang/python/examples/howto/export-minimised-key.py87
-rwxr-xr-xlang/python/examples/howto/export-secret-key.py93
-rwxr-xr-xlang/python/examples/howto/export-secret-keys.py134
-rw-r--r--lang/python/examples/howto/groups.py62
-rwxr-xr-xlang/python/examples/howto/import-key.py93
-rwxr-xr-xlang/python/examples/howto/import-keybasekey.py80
-rwxr-xr-xlang/python/examples/howto/import-keys-hkp.py131
-rwxr-xr-xlang/python/examples/howto/import-keys.py70
-rwxr-xr-xlang/python/examples/howto/import-mailvelope-keys.py131
-rwxr-xr-xlang/python/examples/howto/keycount.py42
-rwxr-xr-xlang/python/examples/howto/local-sign-group.py183
-rwxr-xr-xlang/python/examples/howto/mutt-groups.py64
-rwxr-xr-xlang/python/examples/howto/pmkey-import-alt.py140
-rwxr-xr-xlang/python/examples/howto/pmkey-import-hkp-alt.py177
-rwxr-xr-xlang/python/examples/howto/pmkey-import-hkp.py140
-rwxr-xr-xlang/python/examples/howto/pmkey-import.py124
-rwxr-xr-xlang/python/examples/howto/post_installer.py151
-rw-r--r--lang/python/examples/howto/requirements.txt2
-rwxr-xr-xlang/python/examples/howto/revoke-userid.py62
-rwxr-xr-xlang/python/examples/howto/send-key-to-keyserver.py98
-rwxr-xr-xlang/python/examples/howto/sign-file.py64
-rwxr-xr-xlang/python/examples/howto/sign-key.py63
-rwxr-xr-xlang/python/examples/howto/symcrypt-file.py63
-rwxr-xr-xlang/python/examples/howto/temp-homedir-config.py133
-rwxr-xr-xlang/python/examples/howto/verify-signatures.py64
-rwxr-xr-xlang/python/examples/howto/verify-signed-file.py61
-rwxr-xr-xlang/python/examples/inter-edit.py55
-rwxr-xr-xlang/python/examples/low_level-encrypt_to_all.py54
-rwxr-xr-xlang/python/examples/sign.py29
-rwxr-xr-xlang/python/examples/signverify.py42
-rwxr-xr-xlang/python/examples/simple.py48
-rwxr-xr-xlang/python/examples/testCMSgetkey.py35
-rwxr-xr-xlang/python/examples/verifydetails.py82
54 files changed, 0 insertions, 4042 deletions
diff --git a/lang/python/examples/Makefile.am b/lang/python/examples/Makefile.am
deleted file mode 100644
index bd4319ee..00000000
--- a/lang/python/examples/Makefile.am
+++ /dev/null
@@ -1,74 +0,0 @@
-# Makefile.am for the Python bindings.
-# Copyright (C) 2019 g10 Code GmbH
-#
-# This file is part of GPGME.
-#
-# GPGME 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.
-#
-# GPGME 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 Lesser General
-# Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, see <https://gnu.org/licenses/>.
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-# Created by:
-# find . -type f -print | sed 's/^.\// /;$q;s/$/ \\/' | sort
-EXTRA_DIST = assuan.py \
- decryption-filter.py \
- delkey.py \
- exportimport.py \
- genkey.py \
- howto/add-userid.py \
- howto/advanced/cython/keycount.pyx \
- howto/advanced/cython/requirements.txt \
- howto/advanced/cython/setup.py \
- howto/clear-sign-file.py \
- howto/create-key.py \
- howto/decrypt-file.py \
- howto/detach-sign-file.py \
- howto/encrypt-file.py \
- howto/encrypt-sign-file.py \
- howto/encrypt-to-group-gullible.py \
- howto/encrypt-to-group.py \
- howto/encrypt-to-group-trustno1.py \
- howto/export-key.py \
- howto/export-minimised-key.py \
- howto/export-secret-key.py \
- howto/export-secret-keys.py \
- howto/groups.py \
- howto/import-keybasekey.py \
- howto/import-key.py \
- howto/import-keys-hkp.py \
- howto/import-keys.py \
- howto/import-mailvelope-keys.py \
- howto/keycount.py \
- howto/local-sign-group.py \
- howto/mutt-groups.py \
- howto/pmkey-import-alt.py \
- howto/pmkey-import-hkp-alt.py \
- howto/pmkey-import-hkp.py \
- howto/pmkey-import.py \
- howto/post_installer.py \
- howto/README.org \
- howto/requirements.txt \
- howto/revoke-userid.py \
- howto/send-key-to-keyserver.py \
- howto/sign-file.py \
- howto/sign-key.py \
- howto/symcrypt-file.py \
- howto/temp-homedir-config.py \
- howto/verify-signatures.py \
- howto/verify-signed-file.py \
- inter-edit.py \
- low_level-encrypt_to_all.py \
- sign.py \
- signverify.py \
- simple.py \
- testCMSgetkey.py \
- verifydetails.py
diff --git a/lang/python/examples/assuan.py b/lang/python/examples/assuan.py
deleted file mode 100755
index 84f5ff0a..00000000
--- a/lang/python/examples/assuan.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-"""Demonstrate the use of the Assuan protocol engine"""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-with gpg.Context(protocol=gpg.constants.protocol.ASSUAN) as c:
- # Invoke the pinentry to get a confirmation.
- err = c.assuan_transact(['GET_CONFIRMATION', 'Hello there'])
- print("You chose {}.".format("cancel" if err else "ok"))
diff --git a/lang/python/examples/decryption-filter.py b/lang/python/examples/decryption-filter.py
deleted file mode 100755
index d0fc3a4b..00000000
--- a/lang/python/examples/decryption-filter.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016, 2018 g10 Code GmbH
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-"""A decryption filter
-
-This demonstrates decryption using gpg in three lines of code. To
-be used like this:
-
-./decryption-filter.py < message.gpg > message.plain
-
-"""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-gpg.Context().decrypt(sys.stdin, sink=sys.stdout)
diff --git a/lang/python/examples/delkey.py b/lang/python/examples/delkey.py
deleted file mode 100755
index f0411f4d..00000000
--- a/lang/python/examples/delkey.py
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2004,2008 Igor Belyi <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-# Sample of key deletion
-# It deletes keys for [email protected] generated by genkey.py script
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-with gpg.Context() as c:
- # Note: We must not modify the key store during iteration,
- # therefore, we explicitly make a list.
- keys = list(c.keylist("[email protected]"))
-
- for k in keys:
- c.op_delete(k, True)
diff --git a/lang/python/examples/exportimport.py b/lang/python/examples/exportimport.py
deleted file mode 100755
index 235d5707..00000000
--- a/lang/python/examples/exportimport.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2004,2008 Igor Belyi <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-# Sample of export and import of keys
-# It uses keys for [email protected] generated by genkey.py script
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import os
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-
-with gpg.Context(armor=True) as c, gpg.Data() as expkey:
- print(" - Export %s's public keys - " % user)
- c.op_export(user, 0, expkey)
-
- # print out exported data to see how it looks in armor.
- expkey.seek(0, os.SEEK_SET)
- expstring = expkey.read()
- if expstring:
- sys.stdout.buffer.write(expstring)
- else:
- sys.exit("No %s's keys to export!" % user)
-
-# delete keys to ensure that they came from our imported data. Note
-# that if joe's key has private part as well we can only delete both
-# of them.
-with gpg.Context() as c:
- # Note: We must not modify the key store during iteration,
- # therefore, we explicitly make a list.
- keys = list(c.keylist(user))
-
- for k in keys:
- c.op_delete(k, True)
-
-with gpg.Context() as c:
- print(" - Import exported keys - ")
- c.op_import(expstring)
- result = c.op_import_result()
- if result:
- print(result)
- else:
- sys.exit(" - No import result - ")
diff --git a/lang/python/examples/genkey.py b/lang/python/examples/genkey.py
deleted file mode 100755
index 5df6476f..00000000
--- a/lang/python/examples/genkey.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2004 Igor Belyi <[email protected]>
-# Copyright (C) 2002 John Goerzen <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-# This is the example from the GPGME manual.
-
-parms = """<GnupgKeyParms format="internal">
-Key-Type: RSA
-Key-Length: 2048
-Subkey-Type: RSA
-Subkey-Length: 2048
-Name-Real: Joe Tester
-Name-Comment: with stupid passphrase
-Name-Email: [email protected]
-Passphrase: Crypt0R0cks
-Expire-Date: 2020-12-31
-</GnupgKeyParms>
-"""
-
-with gpg.Context() as c:
- c.set_progress_cb(gpg.callbacks.progress_stdout)
- c.op_genkey(parms, None, None)
- print("Generated key with fingerprint {0}.".format(
- c.op_genkey_result().fpr))
diff --git a/lang/python/examples/howto/README.org b/lang/python/examples/howto/README.org
deleted file mode 100644
index b74ae7e2..00000000
--- a/lang/python/examples/howto/README.org
+++ /dev/null
@@ -1,58 +0,0 @@
-#+TITLE: GPGME Python Bindings HOWTO Examples
-#+LATEX_COMPILER: xelatex
-#+LATEX_CLASS: article
-#+LATEX_CLASS_OPTIONS: [12pt]
-#+LATEX_HEADER: \usepackage{xltxtra}
-#+LATEX_HEADER: \usepackage[margin=1in]{geometry}
-#+LATEX_HEADER: \setmainfont[Ligatures={Common}]{Times New Roman}
-#+LATEX_HEADER: \author{Ben McGinnes <[email protected]>}
-
-
-* Examples
- :PROPERTIES:
- :CUSTOM_ID: gpgme-python3-examples
- :END:
-
- The contents of this directory are the examples included in the /GNU
- Privacy Guard (GnuPG) Made Easy Python Bindings HOWTO/ file. Each
- script is explicitly for Python 3 and specifically for Python 3.4 or
- later.
-
- Some of these scripts may work with Python 2.7, but there are no
- guarantees. They will include the relevant imports from the
- =__future__= module to facilitate that if possible.
-
-
-* Copyright and Licensing
- :PROPERTIES:
- :CUSTOM_ID: copyright-and-license
- :END:
-
- Unless otherwise stated, all the examples in this directory are
- released under the same terms as GPGME itself; that is they are dual
- licensed under the terms of both the GNU General Public License
- version 2.0 (or any later version) *and* the GNU Lesser General
- Public License version 2.1 (or any later version).
-
-
-** Copyright (C) The GnuPG Project, 2018
- :PROPERTIES:
- :CUSTOM_ID: copyright
- :END:
-
- Copyright © The GnuPG Project, 2018.
-
-
-** License GPL compatible
- :PROPERTIES:
- :CUSTOM_ID: license
- :END:
-
- This file is free software; as a special exception the author gives
- unlimited permission to copy and/or distribute it, with or without
- modifications, as long as this notice is preserved.
-
- This file is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, to the extent permitted by law; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE.
diff --git a/lang/python/examples/howto/add-userid.py b/lang/python/examples/howto/add-userid.py
deleted file mode 100755
index fce4acea..00000000
--- a/lang/python/examples/howto/add-userid.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import os.path
-
-print("""
-This script adds a new user ID to an existing key.
-
-The gpg-agent and pinentry are invoked to enter the passphrase.
-""")
-
-c = gpg.Context()
-
-homedir = input("Enter the GPG configuration directory path (optional): ")
-fpr0 = input("Enter the fingerprint of the key to modify: ")
-uid_name = input("Enter the name of the user ID: ")
-uid_email = input("Enter the email address of the user ID: ")
-uid_cmnt = input("Enter a comment to include (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
-
-fpr = "".join(fpr0.split())
-
-if uid_cmnt:
- userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
-else:
- userid = "{0} <{2}>".format(uid_name, uid_email)
-
-key = c.get_key(fpr, secret=True)
-c.key_add_uid(key, userid)
diff --git a/lang/python/examples/howto/advanced/cython/keycount.pyx b/lang/python/examples/howto/advanced/cython/keycount.pyx
deleted file mode 100755
index 2aa636d5..00000000
--- a/lang/python/examples/howto/advanced/cython/keycount.pyx
+++ /dev/null
@@ -1,26 +0,0 @@
-from __future__ import absolute_import
-
-import cython
-import gpg
-
-c = gpg.Context()
-seckeys = c.keylist(pattern=None, secret=True)
-pubkeys = c.keylist(pattern=None, secret=False)
-
-seclist = list(seckeys)
-secnum = len(seclist)
-
-publist = list(pubkeys)
-pubnum = len(publist)
-
-if cython.compiled is True:
- cc = "Powered by Cython compiled C code."
-else:
- cc = "Powered by Python."
-
-print("""
- Number of secret keys: {0}
- Number of public keys: {1}
-
- {2}
-""".format(secnum, pubnum, cc))
diff --git a/lang/python/examples/howto/advanced/cython/requirements.txt b/lang/python/examples/howto/advanced/cython/requirements.txt
deleted file mode 100644
index f6629e02..00000000
--- a/lang/python/examples/howto/advanced/cython/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-cython
diff --git a/lang/python/examples/howto/advanced/cython/setup.py b/lang/python/examples/howto/advanced/cython/setup.py
deleted file mode 100644
index 849639e2..00000000
--- a/lang/python/examples/howto/advanced/cython/setup.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from setuptools import setup
-from Cython.Build import cythonize
-
-setup(
- ext_modules = cythonize("keycount.pyx", annotate=True)
-)
diff --git a/lang/python/examples/howto/clear-sign-file.py b/lang/python/examples/howto/clear-sign-file.py
deleted file mode 100755
index 718ba026..00000000
--- a/lang/python/examples/howto/clear-sign-file.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import sys
-
-"""
-Clear-signs a file with a specified key. If entering both the key and the
-filename on the command line, the key must be entered first.
-"""
-
-if len(sys.argv) > 3:
- logrus = sys.argv[1]
- filename = " ".join(sys.argv[2:])
-elif len(sys.argv) == 3:
- logrus = sys.argv[1]
- filename = sys.argv[2]
-elif len(sys.argv) == 2:
- logrus = sys.argv[1]
- filename = input("Enter the path and filename to sign: ")
-else:
- logrus = input("Enter the fingerprint or key ID to sign with: ")
- filename = input("Enter the path and filename to sign: ")
-
-with open(filename, "rb") as f:
- text = f.read()
-
-key = list(gpg.Context().keylist(pattern=logrus))
-
-with gpg.Context(armor=True, signers=key) as c:
- signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
- with open("{0}.asc".format(filename), "wb") as f:
- f.write(signed_data)
diff --git a/lang/python/examples/howto/create-key.py b/lang/python/examples/howto/create-key.py
deleted file mode 100755
index fe1ea7b5..00000000
--- a/lang/python/examples/howto/create-key.py
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import os.path
-
-print("""
-This script generates a new key which does not expire.
-
-The gpg-agent and pinentry are invoked to set the passphrase.
-""")
-
-c = gpg.Context()
-
-homedir = input("Enter the GPG configuration directory path (optional): ")
-uid_name = input("Enter the name of the user ID: ")
-uid_email = input("Enter the email address of the user ID: ")
-uid_cmnt = input("Enter a comment to include (optional): ")
-key_algo = input("Enter the key algorithm, RSA or DSA (default is RSA): ")
-key_size = input("Enter the key size (2048-4096, default is 2048): ")
-
-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
-
-if uid_cmnt:
- userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
-else:
- userid = "{0} <{2}>".format(uid_name, uid_email)
-
-if key_algo.lower() == "dsa":
- ka = "dsa"
-else:
- ka = "rsa"
-
-if len(key_size) == 4:
- try:
- ks0 = int(key_size)
- except ValueError:
- ks0 = None
- if ks0 is None:
- ks = "2048"
- else:
- if ks0 < 2048:
- ks = "2048"
- elif ka == "dsa" and ks0 > 3072:
- ks = "3072"
- elif ka == "rsa" and ks0 > 4096:
- ks = "4096"
- else:
- ks = key_size
-else:
- ks = "2048"
-
-keyalgo = "{0}{1}".format(ka, ks)
-
-newkey = c.create_key(userid, algorithm=keyalgo, expires=False,
- passphrase=True, certify=True)
-key = c.get_key(newkey.fpr, secret=True)
-
-if ka == "rsa":
- newsub = c.create_subkey(key, algorithm=keyalgo, expires=False,
- passphrase=True, encrypt=True)
-else:
- newsub = c.create_subkey(key, expires=False, passphrase=True,
- encrypt=True)
diff --git a/lang/python/examples/howto/decrypt-file.py b/lang/python/examples/howto/decrypt-file.py
deleted file mode 100755
index a9c6cb76..00000000
--- a/lang/python/examples/howto/decrypt-file.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import sys
-
-if len(sys.argv) == 3:
- ciphertext = sys.argv[1]
- newfile = sys.argv[2]
-elif len(sys.argv) == 2:
- ciphertext = sys.argv[1]
- newfile = input("Enter path and filename to save decrypted data to: ")
-else:
- ciphertext = input("Enter path and filename of encrypted file: ")
- newfile = input("Enter path and filename to save decrypted data to: ")
-
-with open(ciphertext, "rb") as cfile:
- try:
- plaintext, result, verify_result = gpg.Context().decrypt(cfile)
- except gpg.errors.GPGMEError as e:
- plaintext = None
- print(e)
-
-if plaintext is not None:
- with open(newfile, "wb") as nfile:
- nfile.write(plaintext)
-else:
- pass
diff --git a/lang/python/examples/howto/detach-sign-file.py b/lang/python/examples/howto/detach-sign-file.py
deleted file mode 100755
index b9896ad1..00000000
--- a/lang/python/examples/howto/detach-sign-file.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import sys
-
-"""
-Signs a file with a specified key. If entering both the key and the filename
-on the command line, the key must be entered first.
-
-Will produce both an ASCII armoured and GPG binary format copy of the detached
-signature file.
-"""
-
-if len(sys.argv) > 3:
- logrus = sys.argv[1]
- filename = " ".join(sys.argv[2:])
-elif len(sys.argv) == 3:
- logrus = sys.argv[1]
- filename = sys.argv[2]
-elif len(sys.argv) == 2:
- logrus = sys.argv[1]
- filename = input("Enter the path and filename to sign: ")
-else:
- logrus = input("Enter the fingerprint or key ID to sign with: ")
- filename = input("Enter the path and filename to sign: ")
-
-with open(filename, "rb") as f:
- text = f.read()
-
-key = list(gpg.Context().keylist(pattern=logrus))
-
-with gpg.Context(armor=True, signers=key) as ca:
- signed_data, result = ca.sign(text, mode=gpg.constants.sig.mode.DETACH)
- with open("{0}.asc".format(filename), "wb") as fa:
- fa.write(signed_data)
-
-with gpg.Context(signers=key) as cb:
- signed_data, result = cb.sign(text, mode=gpg.constants.sig.mode.DETACH)
- with open("{0}.sig".format(filename), "wb") as fb:
- fb.write(signed_data)
diff --git a/lang/python/examples/howto/encrypt-file.py b/lang/python/examples/howto/encrypt-file.py
deleted file mode 100755
index 1e0c4712..00000000
--- a/lang/python/examples/howto/encrypt-file.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Encrypts a file to a specified key. If entering both the key and the filename
-on the command line, the key must be entered first.
-
-Will produce both an ASCII armoured and GPG binary format copy of the encrypted
-file.
-"""
-
-if len(sys.argv) > 3:
- a_key = sys.argv[1]
- filename = " ".join(sys.argv[2:])
-elif len(sys.argv) == 3:
- a_key = sys.argv[1]
- filename = sys.argv[2]
-elif len(sys.argv) == 2:
- a_key = sys.argv[1]
- filename = input("Enter the path and filename to encrypt: ")
-else:
- a_key = input("Enter the fingerprint or key ID to encrypt to: ")
- filename = input("Enter the path and filename to encrypt: ")
-
-rkey = list(gpg.Context().keylist(pattern=a_key, secret=False))
-with open(filename, "rb") as f:
- text = f.read()
-
-with gpg.Context(armor=True) as ca:
- try:
- ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,
- sign=False)
- with open("{0}.asc".format(filename), "wb") as fa:
- fa.write(ciphertext)
- except gpg.errors.InvalidRecipients as e:
- print(e)
-
-with gpg.Context() as cg:
- try:
- ciphertext, result, sign_result = cg.encrypt(text, recipients=rkey,
- sign=False)
- with open("{0}.gpg".format(filename), "wb") as fg:
- fg.write(ciphertext)
- except gpg.errors.InvalidRecipients as e:
- print(e)
diff --git a/lang/python/examples/howto/encrypt-sign-file.py b/lang/python/examples/howto/encrypt-sign-file.py
deleted file mode 100755
index f63644c3..00000000
--- a/lang/python/examples/howto/encrypt-sign-file.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Signs and encrypts a file to a specified key. If entering both the key and the
-filename on the command line, the key 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:
- a_key = sys.argv[1]
- filename = " ".join(sys.argv[2:])
-elif len(sys.argv) == 3:
- a_key = sys.argv[1]
- filename = sys.argv[2]
-elif len(sys.argv) == 2:
- a_key = sys.argv[1]
- filename = input("Enter the path and filename to encrypt: ")
-else:
- a_key = input("Enter the fingerprint or key ID to encrypt to: ")
- filename = input("Enter the path and filename to encrypt: ")
-
-rkey = list(gpg.Context().keylist(pattern=a_key, secret=False))
-with open(filename, "rb") as f:
- text = f.read()
-
-with gpg.Context(armor=True) as ca:
- ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,
- 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=rkey,
- always_trust=True,
- add_encrypt_to=True)
- with open("{0}.gpg".format(filename), "wb") as fg:
- fg.write(ciphertext)
diff --git a/lang/python/examples/howto/encrypt-to-group-gullible.py b/lang/python/examples/howto/encrypt-to-group-gullible.py
deleted file mode 100755
index d954ed3f..00000000
--- a/lang/python/examples/howto/encrypt-to-group-gullible.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-from groups import group_lists
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Uses the groups module to encrypt to multiple recipients.
-
-"""
-
-c = gpg.Context(armor=True)
-
-if len(sys.argv) > 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2:]
-elif len(sys.argv) == 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2]
-elif len(sys.argv) == 2:
- group_id = sys.argv[1]
- filepath = input("Enter the filename to encrypt: ")
-else:
- group_id = input("Enter the group name to encrypt to: ")
- filepath = input("Enter the filename to encrypt: ")
-
-with open(filepath, "rb") as f:
- text = f.read()
-
-for i in range(len(group_lists)):
- if group_lists[i][0] == group_id:
- klist = group_lists[i][1]
- else:
- klist = None
-
-logrus = []
-
-if klist is not None:
- for i in range(len(klist)):
- apattern = list(c.keylist(pattern=klist[i], secret=False))
- if apattern[0].can_encrypt == 1:
- logrus.append(apattern[0])
- else:
- pass
- try:
- ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
- add_encrypt_to=True)
- except:
- ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
- add_encrypt_to=True,
- always_trust=True)
- with open("{0}.asc".format(filepath), "wb") as f:
- f.write(ciphertext)
-else:
- pass
-
-# EOF
diff --git a/lang/python/examples/howto/encrypt-to-group-trustno1.py b/lang/python/examples/howto/encrypt-to-group-trustno1.py
deleted file mode 100755
index 758e8de6..00000000
--- a/lang/python/examples/howto/encrypt-to-group-trustno1.py
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-from groups import group_lists
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Uses the groups module to encrypt to multiple recipients.
-
-"""
-
-c = gpg.Context(armor=True)
-
-if len(sys.argv) > 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2:]
-elif len(sys.argv) == 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2]
-elif len(sys.argv) == 2:
- group_id = sys.argv[1]
- filepath = input("Enter the filename to encrypt: ")
-else:
- group_id = input("Enter the group name to encrypt to: ")
- filepath = input("Enter the filename to encrypt: ")
-
-with open(filepath, "rb") as f:
- text = f.read()
-
-for i in range(len(group_lists)):
- if group_lists[i][0] == group_id:
- klist = group_lists[i][1]
- else:
- klist = None
-
-logrus = []
-
-if klist is not None:
- for i in range(len(klist)):
- apattern = list(c.keylist(pattern=klist[i], secret=False))
- if apattern[0].can_encrypt == 1:
- logrus.append(apattern[0])
- else:
- pass
- try:
- ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
- add_encrypt_to=True)
- except gpg.errors.InvalidRecipients as e:
- for i in range(len(e.recipients)):
- for n in range(len(logrus)):
- if logrus[n].fpr == e.recipients[i].fpr:
- logrus.remove(logrus[n])
- else:
- pass
- try:
- ciphertext, result, sign_result = c.encrypt(text,
- recipients=logrus,
- add_encrypt_to=True)
- except:
- pass
- with open("{0}.asc".format(filepath), "wb") as f:
- f.write(ciphertext)
-else:
- pass
-
-# EOF
diff --git a/lang/python/examples/howto/encrypt-to-group.py b/lang/python/examples/howto/encrypt-to-group.py
deleted file mode 100755
index 514d6e0c..00000000
--- a/lang/python/examples/howto/encrypt-to-group.py
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-from groups import group_lists
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Uses the groups module to encrypt to multiple recipients.
-
-"""
-
-c = gpg.Context(armor=True)
-
-if len(sys.argv) > 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2:]
-elif len(sys.argv) == 3:
- group_id = sys.argv[1]
- filepath = sys.argv[2]
-elif len(sys.argv) == 2:
- group_id = sys.argv[1]
- filepath = input("Enter the filename to encrypt: ")
-else:
- group_id = input("Enter the group name to encrypt to: ")
- filepath = input("Enter the filename to encrypt: ")
-
-with open(filepath, "rb") as f:
- text = f.read()
-
-for i in range(len(group_lists)):
- if group_lists[i][0] == group_id:
- klist = group_lists[i][1]
- else:
- klist = None
-
-logrus = []
-
-if klist is not None:
- for i in range(len(klist)):
- apattern = list(c.keylist(pattern=klist[i], secret=False))
- if apattern[0].can_encrypt == 1:
- logrus.append(apattern[0])
- else:
- pass
- try:
- ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
- add_encrypt_to=True)
- except gpg.errors.InvalidRecipients as e:
- for i in range(len(e.recipients)):
- for n in range(len(logrus)):
- if logrus[n].fpr == e.recipients[i].fpr:
- logrus.remove(logrus[n])
- else:
- pass
- try:
- ciphertext, result, sign_result = c.encrypt(text,
- recipients=logrus,
- add_encrypt_to=True,
- always_trust=True)
- except:
- pass
- with open("{0}.asc".format(filepath), "wb") as f:
- f.write(ciphertext)
-else:
- pass
-
-# EOF
diff --git a/lang/python/examples/howto/export-key.py b/lang/python/examples/howto/export-key.py
deleted file mode 100755
index 18718d94..00000000
--- a/lang/python/examples/howto/export-key.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-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 key(s) to: ")
- logrus = input("Enter the UID matching the key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if len(homedir) == 0:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- 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
diff --git a/lang/python/examples/howto/export-minimised-key.py b/lang/python/examples/howto/export-minimised-key.py
deleted file mode 100755
index 3bf10963..00000000
--- a/lang/python/examples/howto/export-minimised-key.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-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 key(s) to: ")
- logrus = input("Enter the UID matching the key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if len(homedir) == 0:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- 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/examples/howto/export-secret-key.py b/lang/python/examples/howto/export-secret-key.py
deleted file mode 100755
index f04f716c..00000000
--- a/lang/python/examples/howto/export-secret-key.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os
-import os.path
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script exports one or more secret keys.
-
-The gpg-agent and pinentry are invoked to authorise the export.
-""")
-
-def open_0o600(path, flags):
- return os.open(path, flags, mode=0o600)
-
-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 secret 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 secret key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if len(homedir) == 0:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- c.home_dir = homedir
-else:
- pass
-
-try:
- result = c.key_export_secret(pattern=logrus)
-except:
- result = c.key_export_secret(pattern=None)
-
-if result is not None:
- with open(keyfile, "wb", opener=open_0o600) as f:
- f.write(result)
-else:
- pass
diff --git a/lang/python/examples/howto/export-secret-keys.py b/lang/python/examples/howto/export-secret-keys.py
deleted file mode 100755
index 08b165ed..00000000
--- a/lang/python/examples/howto/export-secret-keys.py
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os
-import os.path
-import subprocess
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script exports one or more secret keys as both ASCII armored and binary
-file formats, saved in files within the user's GPG home directory.
-
-The gpg-agent and pinentry are invoked to authorise the export.
-""")
-
-def open_0o600(path, flags):
- return os.open(path, flags, mode=0o600)
-
-if sys.platform == "win32":
- gpgconfcmd = "gpgconf.exe --list-dirs homedir"
-else:
- gpgconfcmd = "gpgconf --list-dirs homedir"
-
-a = gpg.Context(armor=True)
-b = gpg.Context()
-c = gpg.Context()
-
-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 secret key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-else:
- keyfile = input("Enter the filename to save the secret key to: ")
- logrus = input("Enter the UID matching the secret key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if len(homedir) == 0:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- c.home_dir = homedir
-else:
- pass
-
-if c.home_dir is not None:
- if c.home_dir.endswith("/"):
- gpgfile = "{0}{1}.gpg".format(c.home_dir, keyfile)
- ascfile = "{0}{1}.asc".format(c.home_dir, keyfile)
- else:
- gpgfile = "{0}/{1}.gpg".format(c.home_dir, keyfile)
- ascfile = "{0}/{1}.asc".format(c.home_dir, keyfile)
-else:
- if os.path.exists(os.environ["GNUPGHOME"]) is True:
- hd = os.environ["GNUPGHOME"]
- else:
- try:
- hd = subprocess.getoutput(gpgconfcmd)
- except:
- process = subprocess.Popen(gpgconfcmd.split(),
- stdout=subprocess.PIPE)
- procom = process.communicate()
- if sys.version_info[0] == 2:
- hd = procom[0].strip()
- else:
- hd = procom[0].decode().strip()
- gpgfile = "{0}/{1}.gpg".format(hd, keyfile)
- ascfile = "{0}/{1}.asc".format(hd, keyfile)
-
-try:
- a_result = a.key_export_secret(pattern=logrus)
- b_result = b.key_export_secret(pattern=logrus)
-except:
- a_result = a.key_export_secret(pattern=None)
- b_result = b.key_export_secret(pattern=None)
-
-if a_result is not None:
- with open(ascfile, "wb", opener=open_0o600) as f:
- f.write(a_result)
-else:
- pass
-
-if b_result is not None:
- with open(gpgfile, "wb", opener=open_0o600) as f:
- f.write(b_result)
-else:
- pass
diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py
deleted file mode 100644
index 17b7ab2f..00000000
--- a/lang/python/examples/howto/groups.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import subprocess
-import sys
-
-"""
-Intended for use with other scripts.
-
-Usage: from groups import group_lists
-"""
-
-if sys.platform == "win32":
- gpgconfcmd = "gpgconf.exe --list-options gpg"
-else:
- gpgconfcmd = "gpgconf --list-options gpg"
-
-process = subprocess.Popen(gpgconfcmd.split(), stdout=subprocess.PIPE)
-procom = process.communicate()
-
-if sys.version_info[0] == 2:
- lines = procom[0].splitlines()
-else:
- lines = procom[0].decode().splitlines()
-
-for line in lines:
- if line.startswith("group") is True:
- break
-
-groups = line.split(":")[-1].replace('"', '').split(',')
-
-group_lines = []
-group_lists = []
-
-for group in groups:
- group_lines.append(group.split("="))
- group_lists.append(group.split("="))
-
-for glist in group_lists:
- glist[1] = glist[1].split()
diff --git a/lang/python/examples/howto/import-key.py b/lang/python/examples/howto/import-key.py
deleted file mode 100755
index c1cb6c11..00000000
--- a/lang/python/examples/howto/import-key.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import sys
-
-del absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script imports one or more public keys from a single file.
-""")
-
-c = gpg.Context(armor=True)
-
-if len(sys.argv) >= 3:
- keyfile = sys.argv[1]
- homedir = sys.argv[2]
-elif len(sys.argv) == 2:
- keyfile = sys.argv[1]
- homedir = input("Enter the GPG configuration directory path (optional): ")
-else:
- keyfile = input("Enter the path and filename to import the key(s) from: ")
- 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
-
-if os.path.isfile(keyfile) is True:
- with open(keyfile, "rb") as f:
- incoming = f.read()
- result = c.key_import(incoming)
-else:
- result = None
-
-if result is not None and hasattr(result, "considered") is False:
- print(result)
-elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
- print("""
-The total number of keys considered for import was: {0}
-
- Number of keys revoked: {1}
- Number of new signatures: {2}
- Number of new subkeys: {3}
- Number of new user IDs: {4}
-Number of new secret keys: {5}
- Number of unchanged keys: {6}
-
-The key IDs for all considered keys were:
-""".format(num_keys, new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
-elif result is None:
- print("You must specify a key file to import.")
diff --git a/lang/python/examples/howto/import-keybasekey.py b/lang/python/examples/howto/import-keybasekey.py
deleted file mode 100755
index d6a42e9c..00000000
--- a/lang/python/examples/howto/import-keybasekey.py
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import requests
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script imports one or more public keys from keybase.io with the username
-of a keybase.io user.
-
-Multiple usernames may be provided, separated by spaces.
-""")
-
-c = gpg.Context()
-# https://keybase.io/<user>/pgp_keys.asc
-results = []
-
-if len(sys.argv) >= 2:
- keys = sys.argv[1:]
-else:
- keys = input("Enter the username(s) to get keys for: ")
-
-for key in keys:
- r = requests.get("https://keybase.io/{0}/pgp_keys.asc".format(key))
- import_result = c.key_import(r.content)
- results.append(import_result)
-
-for result in results:
- if result is not None and hasattr(result, "considered") is False:
- print(result)
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
- print("""
-The total number of keys considered for import was: {0}
-
- Number of keys revoked: {1}
- Number of new signatures: {2}
- Number of new subkeys: {3}
- Number of new user IDs: {4}
-Number of new secret keys: {5}
- Number of unchanged keys: {6}
-
-The key IDs for all considered keys were:
-""".format(num_keys, new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- else:
- print("No keys were imported or found.")
diff --git a/lang/python/examples/howto/import-keys-hkp.py b/lang/python/examples/howto/import-keys-hkp.py
deleted file mode 100755
index f0d79915..00000000
--- a/lang/python/examples/howto/import-keys-hkp.py
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import hkp4py
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script imports one or more public keys from the SKS keyservers.
-""")
-
-c = gpg.Context()
-server = hkp4py.KeyServer("hkps://hkps.pool.sks-keyservers.net")
-results = []
-keys = []
-
-if len(sys.argv) > 2:
- pattern = " ".join(sys.argv[1:])
-elif len(sys.argv) == 2:
- pattern = sys.argv[1]
-else:
- pattern = input("Enter the pattern to search for keys or user IDs: ")
-
-
-if pattern is not None:
- try:
- key = server.search(hex(int(pattern, 16)))
- keyed = True
- except ValueError as ve:
- key = server.search(pattern)
- keyed = False
-
- if key is not None:
- keys.append(key[0])
- if keyed is True:
- try:
- fob = server.search(pattern)
- except Exception as e:
- fob = None
- if fob is not None:
- keys.append(fob[0])
- else:
- pass
- else:
- pass
-
- for logrus in pattern.split():
- if logrus != pattern:
- try:
- key = server.search(hex(int(logrus, 16)))
- hexed = True
- except ValueError as ve:
- key = server.search(logrus)
- hexed = False
-
- if key is not None:
- keys.append(key[0])
- if hexed is True:
- try:
- fob = server.search(logrus)
- except Exception as e:
- fob = None
- if fob is not None:
- keys.append(fob[0])
- else:
- pass
- else:
- pass
- else:
- pass
- else:
- pass
-
-
-if len(keys) > 0:
- for key in keys:
- import_result = c.key_import(key.key_blob)
- results.append(import_result)
-
-for result in results:
- if result is not None and hasattr(result, "considered") is False:
- print(result)
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
- print("""
-The total number of keys considered for import was: {0}
-
- Number of keys revoked: {1}
- Number of new signatures: {2}
- Number of new subkeys: {3}
- Number of new user IDs: {4}
-Number of new secret keys: {5}
- Number of unchanged keys: {6}
-
-The key IDs for all considered keys were:
-""".format(num_keys, new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- else:
- print("No keys were imported or found.")
diff --git a/lang/python/examples/howto/import-keys.py b/lang/python/examples/howto/import-keys.py
deleted file mode 100755
index 798a4fcc..00000000
--- a/lang/python/examples/howto/import-keys.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import requests
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script imports one or more public keys from the SKS keyservers.
-""")
-
-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)
-result = c.key_import(r.content)
-
-if result is not None and hasattr(result, "considered") is False:
- print(result)
-elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
- print("""
-The total number of keys considered for import was: {0}
-
- Number of keys revoked: {1}
- Number of new signatures: {2}
- Number of new subkeys: {3}
- Number of new user IDs: {4}
-Number of new secret keys: {5}
- Number of unchanged keys: {6}
-
-The key IDs for all considered keys were:
-""".format(num_keys, new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
-else:
- pass
diff --git a/lang/python/examples/howto/import-mailvelope-keys.py b/lang/python/examples/howto/import-mailvelope-keys.py
deleted file mode 100755
index 9d57ff81..00000000
--- a/lang/python/examples/howto/import-mailvelope-keys.py
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import hkp4py
-import sys
-
-# Copyright (C) 2019 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script imports one or more public keys from the Mailvelope keyserver.
-""")
-
-c = gpg.Context()
-server = hkp4py.KeyServer("hkps://keys.mailvelope.com")
-results = []
-keys = []
-
-if len(sys.argv) > 2:
- pattern = " ".join(sys.argv[1:])
-elif len(sys.argv) == 2:
- pattern = sys.argv[1]
-else:
- pattern = input("Enter the pattern to search for keys or user IDs: ")
-
-
-if pattern is not None:
- try:
- key = server.search(hex(int(pattern, 16)))
- keyed = True
- except ValueError as ve:
- key = server.search(pattern)
- keyed = False
-
- if key is not None:
- keys.append(key[0])
- if keyed is True:
- try:
- fob = server.search(pattern)
- except Exception as e:
- fob = None
- if fob is not None:
- keys.append(fob[0])
- else:
- pass
- else:
- pass
-
- for logrus in pattern.split():
- if logrus != pattern:
- try:
- key = server.search(hex(int(logrus, 16)))
- hexed = True
- except ValueError as ve:
- key = server.search(logrus)
- hexed = False
-
- if key is not None:
- keys.append(key[0])
- if hexed is True:
- try:
- fob = server.search(logrus)
- except Exception as e:
- fob = None
- if fob is not None:
- keys.append(fob[0])
- else:
- pass
- else:
- pass
- else:
- pass
- else:
- pass
-
-
-if len(keys) > 0:
- for key in keys:
- import_result = c.key_import(key.key_blob)
- results.append(import_result)
-
-for result in results:
- if result is not None and hasattr(result, "considered") is False:
- print(result)
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
- print("""
-The total number of keys considered for import was: {0}
-
- Number of keys revoked: {1}
- Number of new signatures: {2}
- Number of new subkeys: {3}
- Number of new user IDs: {4}
-Number of new secret keys: {5}
- Number of unchanged keys: {6}
-
-The key IDs for all considered keys were:
-""".format(num_keys, new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- else:
- print("No keys were imported or found.")
diff --git a/lang/python/examples/howto/keycount.py b/lang/python/examples/howto/keycount.py
deleted file mode 100755
index 4599d485..00000000
--- a/lang/python/examples/howto/keycount.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-
-c = gpg.Context()
-seckeys = c.keylist(pattern=None, secret=True)
-pubkeys = c.keylist(pattern=None, secret=False)
-
-seclist = list(seckeys)
-secnum = len(seclist)
-
-publist = list(pubkeys)
-pubnum = len(publist)
-
-print("""
-Number of secret keys: {0}
-Number of public keys: {1}
-""".format(secnum, pubnum))
diff --git a/lang/python/examples/howto/local-sign-group.py b/lang/python/examples/howto/local-sign-group.py
deleted file mode 100755
index 321330f5..00000000
--- a/lang/python/examples/howto/local-sign-group.py
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import subprocess
-import sys
-
-from groups import group_lists
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script applies a local signature or certification to every key in a group.
-
-Usage: local-sign-group.py <group name> [signing keyid] [gnupg homedir]
-""")
-
-c = gpg.Context(armor=True)
-mkfpr = None
-defkey_fpr = None
-enckey_fpr = None
-to_certify = []
-
-if len(sys.argv) >= 4:
- clique = sys.argv[1]
- sigkey = sys.argv[2]
- homedir = sys.argv[3]
-elif len(sys.argv) == 3:
- clique = sys.argv[1]
- sigkey = sys.argv[2]
- homedir = input("Enter the GPG configuration directory path (optional): ")
-elif len(sys.argv) == 2:
- clique = sys.argv[1]
- sigkey = input("Enter the key ID to sign with (conditionally optional): ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-else:
- clique = input("Enter the group matching the key(s) to locally sign: ")
- sigkey = input("Enter the key ID to sign with (conditionally optional): ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if len(homedir) == 0:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- c.home_dir = homedir
-else:
- pass
-
-if len(sigkey) == 0:
- sigkey = None
-else:
- pass
-
-if sys.platform == "win32":
- gpgconfcmd = "gpgconf.exe --list-options gpg"
-else:
- gpgconfcmd = "gpgconf --list-options gpg"
-
-try:
- lines = subprocess.getoutput(gpgconfcmd).splitlines()
-except:
- process = subprocess.Popen(gpgconfcmd.split(), stdout=subprocess.PIPE)
- procom = process.communicate()
- if sys.version_info[0] == 2:
- lines = procom[0].splitlines()
- else:
- lines = procom[0].decode().splitlines()
-
-for i in range(len(lines)):
- if lines[i].startswith("default-key") is True:
- dline = lines[i]
- elif lines[i].startswith("encrypt-to") is True:
- eline = lines[i]
- else:
- pass
-
-defkey_fpr = dline.split(":")[-1].replace('"', '').split(',')[0].upper()
-enckey_fpr = eline.split(":")[-1].replace('"', '').split(',')[0].upper()
-
-try:
- dkey = c.keylist(pattern=defkey_fpr, secret=True)
- dk = list(dkey)
-except Exception as de:
- print(de)
- dk = None
- print("No valid default key.")
-
-try:
- ekey = c.keylist(pattern=defkey_fpr, secret=True)
- ek = list(ekey)
-except Exception as ee:
- print(ee)
- ek = None
- print("No valid always encrypt to key.")
-
-if sigkey is not None:
- mykey = c.keylist(pattern=sigkey, secret=True)
- mk = list(mykey)
- mkfpr = mk[0].fpr.upper()
- c.signers = mk
-else:
- if dk is None and ek is not None:
- c.signers = ek
- else:
- pass
-
-for group in group_lists:
- if group[0] == clique:
- for logrus in group[1]:
- khole = c.keylist(pattern=logrus)
- k = list(khole)
- to_certify.append(k[0].fpr.upper())
- else:
- pass
-
-if mkfpr is not None:
- if to_certify.count(mkfpr) > 0:
- for n in range(to_certify.count(mkfpr)):
- to_certify.remove(mkfpr)
- else:
- pass
-else:
- pass
-
-if defkey_fpr is not None:
- if to_certify.count(defkey_fpr) > 0:
- for n in range(to_certify.count(defkey_fpr)):
- to_certify.remove(defkey_fpr)
- else:
- pass
-else:
- pass
-
-if enckey_fpr is not None:
- if to_certify.count(enckey_fpr) > 0:
- for n in range(to_certify.count(enckey_fpr)):
- to_certify.remove(enckey_fpr)
- else:
- pass
-else:
- pass
-
-for fpr in to_certify:
- key = c.get_key(fpr)
- c.key_sign(key, uids=None, expires_in=False, local=True)
diff --git a/lang/python/examples/howto/mutt-groups.py b/lang/python/examples/howto/mutt-groups.py
deleted file mode 100755
index ed99eb26..00000000
--- a/lang/python/examples/howto/mutt-groups.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import sys
-from groups import group_lists
-
-"""
-Uses the groups module to generate Mutt crypt-hooks from gpg.conf.
-
-"""
-
-if len(sys.argv) >= 2:
- hook_file = sys.argv[1]
-else:
- hook_file = input("Enter the filename to save the crypt-hooks in: ")
-
-with open(hook_file, "w") as f:
- f.write("""# Change settings based upon message recipient
-#
-# send-hook [!]<pattern> <command>
-#
-# <command> is executed when sending mail to an address matching <pattern>
-#
-# crypt-hook regexp key-id
-# The crypt-hook command provides a method by which you can
-# specify the ID of the public key to be used when encrypting
-# messages to a certain recipient. The meaning of "key ID" is to
-# be taken broadly: This can be a different e-mail address, a
-# numerical key ID, or even just an arbitrary search string. You
-# may use multiple crypt-hooks with the same regexp; multiple
-# matching crypt-hooks result in the use of multiple key-ids for a
-# recipient.
-""")
-
-for n in range(len(group_lists)):
- rule = group_lists[n][0].replace(".", "\\\\.")
- with open(hook_file, "a") as f:
- f.write("\n")
- f.write("# {0}\n".format(group_lists[n][0]))
- for i in range(len(group_lists[n][1])):
- f.write("crypt-hook {0} {1}\n".format(rule, group_lists[n][1][i]))
diff --git a/lang/python/examples/howto/pmkey-import-alt.py b/lang/python/examples/howto/pmkey-import-alt.py
deleted file mode 100755
index 2212ea12..00000000
--- a/lang/python/examples/howto/pmkey-import-alt.py
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import os.path
-import requests
-import sys
-
-del absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script searches the ProtonMail key server for the specified key and
-imports it. Optionally enables specifying a different GnuPG home directory.
-
-Usage: pmkey-import-alt.py [search string] [homedir]
-""")
-
-c = gpg.Context(armor=True)
-url = "https://api.protonmail.ch/pks/lookup"
-ksearch = []
-
-if len(sys.argv) >= 3:
- keyterm = sys.argv[1]
- homedir = sys.argv[2]
-elif len(sys.argv) == 2:
- keyterm = sys.argv[1]
- homedir = input("Enter the GPG configuration directory path (optional): ")
-else:
- keyterm = input("Enter the key ID, UID or search string: ")
- 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
-
-if keyterm.count("@") == 2 and keyterm.startswith("@") is True:
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
-elif keyterm.count("@") == 1 and keyterm.startswith("@") is True:
- ksearch.append("{0}@protonmail.com".format(keyterm[1:]))
- ksearch.append("{0}@protonmail.ch".format(keyterm[1:]))
- ksearch.append("{0}@pm.me".format(keyterm[1:]))
-elif keyterm.count("@") == 0:
- ksearch.append("{0}@protonmail.com".format(keyterm))
- ksearch.append("{0}@protonmail.ch".format(keyterm))
- ksearch.append("{0}@pm.me".format(keyterm))
-elif keyterm.count("@") == 2 and keyterm.startswith("@") is False:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
-elif keyterm.count("@") > 2:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
-else:
- ksearch.append(keyterm)
-
-for k in ksearch:
- payload = {"op": "get", "search": k}
- try:
- r = requests.get(url, verify=True, params=payload)
- if r.ok is True:
- result = c.key_import(r.content)
- elif r.ok is False:
- result = r.content
- except Exception as e:
- result = None
-
- if result is not None and hasattr(result, "considered") is False:
- print("{0} for {1}".format(result.decode(), k))
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
-
- def knom():
- for ki in result.imports:
- for ku in c.get_key(ki.fpr).uids:
- return ku.uid
-
- print("""
-The total number of keys considered for import was: {0}
-
-With UIDs wholely or partially matching the following string:
-
- {1}
-
- Number of keys revoked: {2}
- Number of new signatures: {3}
- Number of new subkeys: {4}
- Number of new user IDs: {5}
-Number of new secret keys: {6}
- Number of unchanged keys: {7}
-
-The key IDs for all considered keys were:
-""".format(num_keys, knom(), new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- elif result is None:
- print(e)
diff --git a/lang/python/examples/howto/pmkey-import-hkp-alt.py b/lang/python/examples/howto/pmkey-import-hkp-alt.py
deleted file mode 100755
index 32553fbf..00000000
--- a/lang/python/examples/howto/pmkey-import-hkp-alt.py
+++ /dev/null
@@ -1,177 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import hkp4py
-import os.path
-import sys
-
-del absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script searches the ProtonMail key server for the specified key and
-imports it. Optionally enables specifying a different GnuPG home directory.
-
-Usage: pmkey-import-hkp.py [homedir] [search string]
- or: pmkey-import-hkp.py [search string]
-""")
-
-c = gpg.Context(armor=True)
-server = hkp4py.KeyServer("hkps://api.protonmail.ch")
-keyterms = []
-ksearch = []
-allkeys = []
-results = []
-paradox = []
-homeless = None
-
-if len(sys.argv) > 3:
- homedir = sys.argv[1]
- keyterms = sys.argv[2:]
-elif len(sys.argv) == 3:
- homedir = sys.argv[1]
- keyterm = sys.argv[2]
- keyterms.append(keyterm)
-elif len(sys.argv) == 2:
- homedir = ""
- keyterm = sys.argv[1]
- keyterms.append(keyterm)
-else:
- keyterm = input("Enter the key ID, UID or search string: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
- keyterms.append(keyterm)
-
-if len(homedir) == 0:
- homedir = None
- homeless = False
-
-if homedir is not None:
- if homedir.startswith("~"):
- if os.path.exists(os.path.expanduser(homedir)) is True:
- if os.path.isdir(os.path.expanduser(homedir)) is True:
- c.home_dir = os.path.realpath(os.path.expanduser(homedir))
- else:
- homeless = True
- else:
- homeless = True
- elif os.path.exists(os.path.realpath(homedir)) is True:
- if os.path.isdir(os.path.realpath(homedir)) is True:
- c.home_dir = os.path.realpath(homedir)
- else:
- homeless = True
- else:
- homeless = True
-
-# First check to see if the homedir really is a homedir and if not, treat it as
-# a search string.
-if homeless is True:
- keyterms.append(homedir)
- c.home_dir = None
-else:
- pass
-
-for keyterm in keyterms:
- if keyterm.count("@") == 2 and keyterm.startswith("@") is True:
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- elif keyterm.count("@") == 1 and keyterm.startswith("@") is True:
- ksearch.append("{0}@protonmail.com".format(keyterm[1:]))
- ksearch.append("{0}@protonmail.ch".format(keyterm[1:]))
- ksearch.append("{0}@pm.me".format(keyterm[1:]))
- elif keyterm.count("@") == 0:
- ksearch.append("{0}@protonmail.com".format(keyterm))
- ksearch.append("{0}@protonmail.ch".format(keyterm))
- ksearch.append("{0}@pm.me".format(keyterm))
- elif keyterm.count("@") == 2 and keyterm.startswith("@") is False:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
- elif keyterm.count("@") > 2:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
- else:
- ksearch.append(keyterm)
-
-for k in ksearch:
- print("Checking for key for: {0}".format(k))
- import_result = None
- keys = server.search(k)
- if isinstance(keys, list) is True:
- for key in keys:
- allkeys.append(key)
- try:
- import_result = c.key_import(key.key_blob)
- except Exception as e:
- import_result = c.key_import(key.key)
- else:
- paradox.append(keys)
- results.append(import_result)
-
-for result in results:
- if result is not None and hasattr(result, "considered") is False:
- print("{0} for {1}".format(result.decode(), k))
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
-
- def knom():
- for ki in result.imports:
- for ku in c.get_key(ki.fpr).uids:
- return ku.uid
-
- print("""
-The total number of keys considered for import was: {0}
-
-With UIDs wholely or partially matching the following string:
-
- {1}
-
- Number of keys revoked: {2}
- Number of new signatures: {3}
- Number of new subkeys: {4}
- Number of new user IDs: {5}
-Number of new secret keys: {6}
- Number of unchanged keys: {7}
-
-The key IDs for all considered keys were:
-""".format(num_keys, knom(), new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- elif result is None:
- pass
diff --git a/lang/python/examples/howto/pmkey-import-hkp.py b/lang/python/examples/howto/pmkey-import-hkp.py
deleted file mode 100755
index dff7dfa5..00000000
--- a/lang/python/examples/howto/pmkey-import-hkp.py
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import hkp4py
-import os.path
-import sys
-
-del absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script searches the ProtonMail key server for the specified key and
-imports it.
-
-Usage: pmkey-import-hkp.py [search strings]
-""")
-
-c = gpg.Context(armor=True)
-server = hkp4py.KeyServer("hkps://api.protonmail.ch")
-keyterms = []
-ksearch = []
-allkeys = []
-results = []
-paradox = []
-homeless = None
-
-if len(sys.argv) > 2:
- keyterms = sys.argv[1:]
-elif len(sys.argv) == 2:
- keyterm = sys.argv[1]
- keyterms.append(keyterm)
-else:
- key_term = input("Enter the key ID, UID or search string: ")
- keyterms = key_term.split()
-
-for keyterm in keyterms:
- if keyterm.count("@") == 2 and keyterm.startswith("@") is True:
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- elif keyterm.count("@") == 1 and keyterm.startswith("@") is True:
- ksearch.append("{0}@protonmail.com".format(keyterm[1:]))
- ksearch.append("{0}@protonmail.ch".format(keyterm[1:]))
- ksearch.append("{0}@pm.me".format(keyterm[1:]))
- elif keyterm.count("@") == 0:
- ksearch.append("{0}@protonmail.com".format(keyterm))
- ksearch.append("{0}@protonmail.ch".format(keyterm))
- ksearch.append("{0}@pm.me".format(keyterm))
- elif keyterm.count("@") == 2 and keyterm.startswith("@") is False:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
- elif keyterm.count("@") > 2:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
- else:
- ksearch.append(keyterm)
-
-for k in ksearch:
- print("Checking for key for: {0}".format(k))
- import_result = None
- keys = server.search(k)
- if isinstance(keys, list) is True:
- for key in keys:
- allkeys.append(key)
- try:
- import_result = c.key_import(key.key_blob)
- except Exception as e:
- import_result = c.key_import(key.key)
- else:
- paradox.append(keys)
- results.append(import_result)
-
-for result in results:
- if result is not None and hasattr(result, "considered") is False:
- print("{0} for {1}".format(result.decode(), k))
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
-
- def knom():
- for ki in result.imports:
- for ku in c.get_key(ki.fpr).uids:
- return ku.uid
-
- print("""
-The total number of keys considered for import was: {0}
-
-With UIDs wholely or partially matching the following string(s):
-
- {1}
-
- Number of keys revoked: {2}
- Number of new signatures: {3}
- Number of new subkeys: {4}
- Number of new user IDs: {5}
-Number of new secret keys: {6}
- Number of unchanged keys: {7}
-
-The key IDs for all considered keys were:
-""".format(num_keys, knom(), new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- elif result is None:
- pass
diff --git a/lang/python/examples/howto/pmkey-import.py b/lang/python/examples/howto/pmkey-import.py
deleted file mode 100755
index e95785b3..00000000
--- a/lang/python/examples/howto/pmkey-import.py
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import requests
-import sys
-
-del absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script searches the ProtonMail key server for the specified key and
-imports it.
-
-Usage: pmkey-import.py [search string]
-""")
-
-c = gpg.Context(armor=True)
-url = "https://api.protonmail.ch/pks/lookup"
-ksearch = []
-
-if len(sys.argv) >= 2:
- keyterm = sys.argv[1]
-else:
- keyterm = input("Enter the key ID, UID or search string: ")
-
-if keyterm.count("@") == 2 and keyterm.startswith("@") is True:
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
- ksearch.append(keyterm[1:])
-elif keyterm.count("@") == 1 and keyterm.startswith("@") is True:
- ksearch.append("{0}@protonmail.com".format(keyterm[1:]))
- ksearch.append("{0}@protonmail.ch".format(keyterm[1:]))
- ksearch.append("{0}@pm.me".format(keyterm[1:]))
-elif keyterm.count("@") == 0:
- ksearch.append("{0}@protonmail.com".format(keyterm))
- ksearch.append("{0}@protonmail.ch".format(keyterm))
- ksearch.append("{0}@pm.me".format(keyterm))
-elif keyterm.count("@") == 2 and keyterm.startswith("@") is False:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
-elif keyterm.count("@") > 2:
- uidlist = keyterm.split("@")
- for uid in uidlist:
- ksearch.append("{0}@protonmail.com".format(uid))
- ksearch.append("{0}@protonmail.ch".format(uid))
- ksearch.append("{0}@pm.me".format(uid))
-else:
- ksearch.append(keyterm)
-
-for k in ksearch:
- payload = {"op": "get", "search": k}
- try:
- r = requests.get(url, verify=True, params=payload)
- if r.ok is True:
- result = c.key_import(r.content)
- elif r.ok is False:
- result = r.content
- except Exception as e:
- result = None
-
- if result is not None and hasattr(result, "considered") is False:
- print("{0} for {1}".format(result.decode(), k))
- elif result is not None and hasattr(result, "considered") is True:
- num_keys = len(result.imports)
- new_revs = result.new_revocations
- new_sigs = result.new_signatures
- new_subs = result.new_sub_keys
- new_uids = result.new_user_ids
- new_scrt = result.secret_imported
- nochange = result.unchanged
-
- def knom():
- for ki in result.imports:
- for ku in c.get_key(ki.fpr).uids:
- return ku.uid
-
- print("""
-The total number of keys considered for import was: {0}
-
-With UIDs wholely or partially matching the following string:
-
- {1}
-
- Number of keys revoked: {2}
- Number of new signatures: {3}
- Number of new subkeys: {4}
- Number of new user IDs: {5}
-Number of new secret keys: {6}
- Number of unchanged keys: {7}
-
-The key IDs for all considered keys were:
-""".format(num_keys, knom(), new_revs, new_sigs, new_subs, new_uids, new_scrt,
- nochange))
- for i in range(num_keys):
- print(result.imports[i].fpr)
- print("")
- elif result is None:
- print(e)
diff --git a/lang/python/examples/howto/post_installer.py b/lang/python/examples/howto/post_installer.py
deleted file mode 100755
index b493f979..00000000
--- a/lang/python/examples/howto/post_installer.py
+++ /dev/null
@@ -1,151 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-# Copyright (C) 2016-2018 g10 Code GmbH
-# Copyright (C) 2015 Ben McGinnes <[email protected]>
-#
-# This library 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 library 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
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import glob
-import os
-import os.path
-import shutil
-import subprocess
-import sys
-import sysconfig
-
-from shutil import which
-
-del absolute_import, print_function, unicode_literals
-
-try:
- emacs = os.path.realpath(which("emacs"))
-except TypeError as e:
- emacs = None
-
-try:
- makeinfo = os.path.realpath(which("makeinfo"))
-except TypeError as e:
- makeinfo = None
-
-try:
- pandoc = os.path.realpath(which("pandoc"))
-except TypeError as e:
- pandoc = None
-
-try:
- texinfo = os.path.realpath(which("texinfo"))
-except TypeError as e:
- texinfo = None
-
-docsrc = glob.glob('doc/src/**/*', recursive=True)
-
-for srcdoc in docsrc:
- process = subprocess.Popen([emacs, srcdoc, "--batch", "-f",
- "org-texinfo-export-to-texinfo", "--kill"],
- stdout=subprocess.PIPE)
- procom = process.communicate()
-
-doctexi1 = glob.glob('doc/src/**/*.texi', recursive=True)
-doctexi2 = []
-doctexi3 = []
-
-for texi in doctexi1:
- doctexi2.append(os.path.realpath(texi))
-
-for texdoc in doctexi2:
- newtex = texdoc.replace("doc/src/", "doc/texinfo/")
- doctexi3.append(newtex)
- with open(texdoc, "r") as f:
- badtex = f.read()
- goodtex = badtex.replace("@documentencoding UTF-8\n",
- "@documentencoding utf-8\n")
- with open(newtex, "w") as f:
- f.write(goodtex)
-
-for srcdoc in docsrc:
- rstdoc = "{0}.rst".format(srcdoc.replace("doc/src/", "doc/rst/"))
- process = subprocess.Popen([pandoc, "-f", "org", "-t", "rst+smart", "-o",
- rstdoc, srcdoc], stdout=subprocess.PIPE)
- procom = process.communicate()
-
-with open("doc/rst/index.rst", "r") as f:
- genindex = f.readlines()
-
-indextop = ['.. GPGME Python Bindings documentation master file, created by\n',
- ' sphinx-quickstart on Wed Dec 5 09:04:47 2018.\n',
- ' You can adapt this file completely to your liking, but it should at least\n',
- ' contain the root `toctree` directive.\n', '\n',
- 'GPGME Python Bindings\n', '=====================\n', '\n',
- '.. toctree::\n', ' :maxdepth: 3\n', ' :caption: Contents:\n',
- '\n']
-
-with open("doc/rst/index.rst", "w") as f:
- for line in indextop:
- f.write(line)
- for line in genindex[5:]:
- f.write(line)
-
-with open("doc/rst/Makefile", "w") as f:
- f.write("""# Minimal makefile for Sphinx documentation
-#
-
-# You can set these variables from the command line.
-SPHINXOPTS =
-SPHINXBUILD = sphinx-build
-SOURCEDIR = .
-BUILDDIR = _build
-
-# Put it first so that "make" without argument is like "make help".
-help:
- @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
-
-.PHONY: help Makefile
-
-# Catch-all target: route all unknown targets to Sphinx using the new
-# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
-%: Makefile
- @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
-""")
-
-info_path = os.path.realpath(sysconfig._PREFIX + "/share/info")
-info_paths = os.environ["INFOPATH"].split(":")
-
-if info_paths.count(info_path) == 0:
- info_paths.insert(0, info_path)
-else:
- pass
-
-for ipath in info_paths:
- if os.path.exists(os.path.realpath(ipath)) is False:
- info_paths.remove(ipath)
- else:
- pass
-
-# Remove the old generated .texi files from the org source directory.
-for texifile in doctexi2:
- os.remove(texifile)
-
-print("""
-You may now build your preferred documentation format using either:
-
- 1. Sphinx in the doc/rst/ directory; and/or
- 2. Texinfo or Makeinfo in the doc/texinfo/ directory.
-
-Alternatively the original Org mode source files can be found in the doc/src/
-directory.
-""")
diff --git a/lang/python/examples/howto/requirements.txt b/lang/python/examples/howto/requirements.txt
deleted file mode 100644
index 8f6e1e15..00000000
--- a/lang/python/examples/howto/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-hkp4py
-requests
diff --git a/lang/python/examples/howto/revoke-userid.py b/lang/python/examples/howto/revoke-userid.py
deleted file mode 100755
index 70ed79a6..00000000
--- a/lang/python/examples/howto/revoke-userid.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import os.path
-
-print("""
-This script revokes a user ID on an existing key.
-
-The gpg-agent and pinentry are invoked to enter the passphrase.
-""")
-
-c = gpg.Context()
-
-homedir = input("Enter the GPG configuration directory path (optional): ")
-fpr0 = input("Enter the fingerprint of the key to modify: ")
-uid_name = input("Enter the name of the user ID: ")
-uid_email = input("Enter the email address of the user ID: ")
-uid_cmnt = input("Enter a comment to include (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
-
-fpr = "".join(fpr0.split())
-
-if uid_cmnt:
- userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
-else:
- userid = "{0} <{2}>".format(uid_name, uid_email)
-
-key = c.get_key(fpr, secret=True)
-c.key_revoke_uid(key, userid)
diff --git a/lang/python/examples/howto/send-key-to-keyserver.py b/lang/python/examples/howto/send-key-to-keyserver.py
deleted file mode 100755
index 5f3eba70..00000000
--- a/lang/python/examples/howto/send-key-to-keyserver.py
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import hkp4py
-import os.path
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-print("""
-This script sends one or more public keys to the SKS keyservers and is
-essentially a slight variation on the export-key.py script.
-
-The default is to send all keys if there is no pattern or search term.
-""")
-
-c = gpg.Context(armor=True)
-server = hkp4py.KeyServer("hkps://hkps.pool.sks-keyservers.net")
-
-if len(sys.argv) >= 3:
- logrus = sys.argv[1]
- homedir = sys.argv[2]
-elif len(sys.argv) == 2:
- logrus = sys.argv[1]
- homedir = input("Enter the GPG configuration directory path (optional): ")
-else:
- logrus = input("Enter the UID matching the key(s) to export: ")
- homedir = input("Enter the GPG configuration directory path (optional): ")
-
-if not homedir:
- homedir = None
-elif homedir.startswith("~"):
- userdir = os.path.expanduser(homedir)
- if os.path.exists(userdir) is True:
- homedir = os.path.realpath(userdir)
- else:
- homedir = None
-else:
- homedir = os.path.realpath(homedir)
-
-if homedir is not None and os.path.exists(homedir) is False:
- homedir = None
-elif homedir is not None and os.path.exists(homedir) is True:
- if os.path.isdir(homedir) is False:
- homedir = None
- else:
- pass
-
-if homedir is not None:
- c.home_dir = homedir
-else:
- pass
-
-if logrus:
- try:
- export_result = c.key_export(pattern=logrus)
- except Exception as e:
- print(e)
- export_result = None
-else:
- export_result = c.key_export(pattern=None)
-
-if export_result is not None:
- try:
- try:
- send_result = server.add(export_result)
- except:
- send_result = server.add(export_result.decode())
- if send_result is not None:
- print(send_result)
- else:
- pass
- except Exception as e:
- print(e)
-else:
- pass
diff --git a/lang/python/examples/howto/sign-file.py b/lang/python/examples/howto/sign-file.py
deleted file mode 100755
index 5fbce5a3..00000000
--- a/lang/python/examples/howto/sign-file.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import sys
-
-"""
-Signs a file with a specified key. If entering both the key and the filename
-on the command line, the key must be entered first.
-
-Will produce both an ASCII armoured and GPG binary format copy of the signed
-file.
-"""
-
-if len(sys.argv) > 3:
- logrus = sys.argv[1]
- filename = " ".join(sys.argv[2:])
-elif len(sys.argv) == 3:
- logrus = sys.argv[1]
- filename = sys.argv[2]
-elif len(sys.argv) == 2:
- logrus = sys.argv[1]
- filename = input("Enter the path and filename to sign: ")
-else:
- logrus = input("Enter the fingerprint or key ID to sign with: ")
- filename = input("Enter the path and filename to sign: ")
-
-with open(filename, "rb") as f:
- text = f.read()
-
-key = list(gpg.Context().keylist(pattern=logrus))
-
-with gpg.Context(armor=True, signers=key) as ca:
- signed_data, result = ca.sign(text, mode=gpg.constants.sig.mode.NORMAL)
- with open("{0}.asc".format(filename), "wb") as fa:
- fa.write(signed_data)
-
-with gpg.Context(signers=key) as cg:
- signed_data, result = cg.sign(text, mode=gpg.constants.sig.mode.NORMAL)
- with open("{0}.gpg".format(filename), "wb") as fg:
- fg.write(signed_data)
diff --git a/lang/python/examples/howto/sign-key.py b/lang/python/examples/howto/sign-key.py
deleted file mode 100755
index 82e96f88..00000000
--- a/lang/python/examples/howto/sign-key.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-import gpg
-import os.path
-
-print("""
-This script signs or certifies a key.
-
-The gpg-agent and pinentry are invoked to enter the passphrase.
-""")
-
-c = gpg.Context()
-
-homedir = input("Enter the GPG configuration directory path (optional): ")
-fpr0 = input("Enter the fingerprint of the key to sign: ")
-userid = input("Enter the UID to sign (case sensitive, optional): ")
-sig_type = input("Enter the certification type (local or normal): ")
-
-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
-
-fpr = "".join(fpr0.split())
-key = c.get_key(fpr, secret=False)
-
-if userid and sig_type.lower() == "local":
- c.key_sign(key, uids=userid, local=True)
-elif userid and sig_type.lower() != "local":
- c.key_sign(key, uids=userid)
-elif not userid and sig_type.lower() == "local":
- c.key_sign(key, local=True)
-else:
- c.key_sign(key)
diff --git a/lang/python/examples/howto/symcrypt-file.py b/lang/python/examples/howto/symcrypt-file.py
deleted file mode 100755
index eeeac991..00000000
--- a/lang/python/examples/howto/symcrypt-file.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import gpg
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-"""
-Symmetrically encrypts a file. Passphrase will be prompted for via Pinentry.
-
-Will produce both an ASCII armoured and GPG binary format copy of the encrypted
-file.
-"""
-
-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 encrypt: ")
-
-with open(filename, "rb") as f:
- text = f.read()
-
-with gpg.Context(armor=True) as ca:
- try:
- ciphertext, result, sign_result = ca.encrypt(text, passphrase=None,
- sign=False)
- with open("{0}.asc".format(filename), "wb") as fa:
- fa.write(ciphertext)
- except gpg.errors.GPGMEError as e:
- print(e)
-
-with gpg.Context() as cg:
- try:
- ciphertext, result, sign_result = cg.encrypt(text, passphrase=None,
- sign=False)
- with open("{0}.gpg".format(filename), "wb") as fg:
- fg.write(ciphertext)
- except gpg.errors.GPGMEError as e:
- print(e)
diff --git a/lang/python/examples/howto/temp-homedir-config.py b/lang/python/examples/howto/temp-homedir-config.py
deleted file mode 100755
index cb968d3d..00000000
--- a/lang/python/examples/howto/temp-homedir-config.py
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-import os
-import os.path
-import sys
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://www.gnu.org/licenses/>.
-
-intro = """
-This script creates a temporary directory to use as a homedir for
-testing key generation tasks with the correct permissions, along
-with a gpg.conf file containing the same configuration options
-listed in the HOWTO.
-
-You may wish to change the order of the cipher preferences or
-remove those not relevant to your installation. These
-configuration parameters assume that all ciphers and digests are
-installed and available rather than limiting to the default
-ciphers and digests.
-
-The script prompts for a directory name to be installed as a hidden
-directory in the user's home directory on POSIX systems. So if you
-enter "gnupg-temp" on a Linux, BSD or OS X system, it will create
-"~/.gnupg-temp" (you do not need to enter the leading dot).
-
-This script has not been tested on Windows systems and may have
-unpredictable results. That said, it will not delete or copy over
-existing data.
-
-If the directory already exists, the script will terminate with a
-message telling you to specify a new directory name. There is no
-default directory name.
-"""
-
-ciphers256 = "TWOFISH CAMELLIA256 AES256"
-ciphers192 = "CAMELLIA192 AES192"
-ciphers128 = "CAMELLIA128 AES"
-ciphersBad = "BLOWFISH IDEA CAST5 3DES"
-digests = "SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1"
-compress = "ZLIB BZIP2 ZIP Uncompressed"
-
-gpgconf = """# gpg.conf settings for key generation:
-expert
-allow-freeform-uid
-allow-secret-key-import
-trust-model tofu+pgp
-tofu-default-policy unknown
-enable-large-rsa
-enable-dsa2
-cert-digest-algo SHA512
-default-preference-list {0} {1} {2} {3} {4} {5}
-personal-cipher-preferences {0} {1} {2} {3}
-personal-digest-preferences {4}
-personal-compress-preferences {5}
-""".format(ciphers256, ciphers192, ciphers128, ciphersBad, digests, compress)
-
-agentconf = """# gpg-agent.conf settings for key generation:
-default-cache-ttl 300
-"""
-
-if len(sys.argv) == 1:
- print(intro)
- new_homedir = input("Enter the temporary gnupg homedir name: ")
-elif len(sys.argv) == 2:
- new_homedir = sys.argv[1]
-else:
- new_homedir = " ".join(sys.argv[1:])
-
-userdir = os.path.expanduser("~")
-
-if new_homedir.startswith("~"):
- new_homedir.replace("~", "")
-else:
- pass
-
-if new_homedir.startswith("/"):
- new_homedir.replace("/", "")
-else:
- pass
-
-if new_homedir.startswith("."):
- new_homedir.replace(".", "_")
-else:
- pass
-
-if new_homedir.count(" ") > 0:
- new_homedir.replace(" ", "_")
-else:
- pass
-
-nh = "{0}/.{1}".format(userdir, new_homedir)
-
-def open_0o600(path, flags):
- return os.open(path, flags, mode=0o600)
-
-if os.path.exists(nh) is True:
- print("The {0} directory already exists.".format(nh))
-else:
- print("Creating the {0} directory.".format(nh))
- os.mkdir(nh, 0o700)
- with open("{0}/{1}".format(nh, "gpg.conf"), "w", opener=open_0o600) as f1:
- f1.write(gpgconf)
- with open("{0}/{1}".format(nh, "gpg-agent.conf"), "w", opener=open_0o600) as f2:
- f2.write(gpgconf)
- print("""You may now use the {0} directory as an alternative GPG homedir:
-
-gpg --homedir {0}
-gpg --homedir --full-gen-key
-
-Or with GPGME scripts, including the GPGME Python bindings.
-""")
diff --git a/lang/python/examples/howto/verify-signatures.py b/lang/python/examples/howto/verify-signatures.py
deleted file mode 100755
index 9c838f85..00000000
--- a/lang/python/examples/howto/verify-signatures.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://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
diff --git a/lang/python/examples/howto/verify-signed-file.py b/lang/python/examples/howto/verify-signed-file.py
deleted file mode 100755
index a7714309..00000000
--- a/lang/python/examples/howto/verify-signed-file.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import, division, unicode_literals
-
-# Copyright (C) 2018 Ben McGinnes <[email protected]>
-#
-# 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 License for more details.
-#
-# You should have received a copy of the GNU General Public License and the GNU
-# Lesser General Public License along with this program; if not, see
-# <https://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
diff --git a/lang/python/examples/inter-edit.py b/lang/python/examples/inter-edit.py
deleted file mode 100755
index 2fd74c29..00000000
--- a/lang/python/examples/inter-edit.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2005 Igor Belyi <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-"""Simple interactive editor to test editor scripts"""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-if len(sys.argv) != 2:
- sys.exit("Usage: %s <Gpg key pattern>\n" % sys.argv[0])
-
-name = sys.argv[1]
-
-with gpg.Context() as c:
- keys = list(c.keylist(name))
- if len(keys) == 0:
- sys.exit("No key matching {}.".format(name))
- if len(keys) > 1:
- sys.exit("More than one key matching {}.".format(name))
-
- key = keys[0]
- print("Editing key {} ({}):".format(key.uids[0].uid, key.subkeys[0].fpr))
-
- def edit_fnc(keyword, args):
- print("Status: {}, args: {} > ".format(keyword, args), end="")
-
- if 'GET' not in keyword:
- # no prompt
- print()
- return None
-
- try:
- return input()
- except EOFError:
- return "quit"
-
- c.interact(key, edit_fnc, sink=sys.stdout)
diff --git a/lang/python/examples/low_level-encrypt_to_all.py b/lang/python/examples/low_level-encrypt_to_all.py
deleted file mode 100755
index edd01974..00000000
--- a/lang/python/examples/low_level-encrypt_to_all.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2008 Igor Belyi <[email protected]>
-# Copyright (C) 2002 John Goerzen <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-"""
-This program will try to encrypt a simple message to each key on your
-keyring. If your keyring has any invalid keys on it, those keys will
-be skipped and it will re-try the encryption."""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-with gpg.Context(armor=True) as c:
- recipients = list()
- for key in c.keylist():
- valid = 0
- if any(sk.can_encrypt for sk in key.subkeys):
- recipients.append(key)
- print("Adding recipient {0}.".format(key.uids[0].uid))
-
- ciphertext = None
- while not ciphertext:
- print("Encrypting to %d recipients" % len(recipients))
- try:
- ciphertext, _, _ = c.encrypt(
- b'This is my message.', recipients=recipients)
- except gpg.errors.InvalidRecipients as e:
- print("Encryption failed for these keys:\n{0!s}".format(e))
-
- # filter out the bad keys
- bad_keys = {bad.fpr for bad in e.recipients}
- recipients = [
- r for r in recipients if not r.subkeys[0].fpr in bad_keys
- ]
-
- sys.stdout.buffer.write(ciphertext)
diff --git a/lang/python/examples/sign.py b/lang/python/examples/sign.py
deleted file mode 100755
index 079ccdef..00000000
--- a/lang/python/examples/sign.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2002 John Goerzen <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-from gpg.constants.sig import mode
-
-del absolute_import, print_function, unicode_literals
-
-with gpg.Context() as c:
- signed, _ = c.sign(b"Test message", mode=mode.CLEAR)
- sys.stdout.buffer.write(signed)
diff --git a/lang/python/examples/signverify.py b/lang/python/examples/signverify.py
deleted file mode 100755
index c9c6edd5..00000000
--- a/lang/python/examples/signverify.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2004,2008 Igor Belyi <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-# Sample of unattended signing/verifying of a message.
-# It uses keys for [email protected] generated by genkey.py script
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-from gpg.constants.sig import mode
-
-del absolute_import, print_function, unicode_literals
-
-user = "joe+gpg"
-
-with gpg.Context(pinentry_mode=gpg.constants.PINENTRY_MODE_LOOPBACK) as c:
- keys = list(c.keylist(user))
- if len(keys) == 0:
- sys.exit("No key matching {}.".format(user))
-
- c.signers = keys[:1]
- c.set_passphrase_cb(lambda *args: "Crypt0R0cks")
- signed_data, _ = c.sign(b"Test message", mode=mode.CLEAR)
-
- data, result = c.verify(signed_data, verify=keys[:1])
- print("Data: {!r}\nSignature: {!s}".format(data, result.signatures[0]))
diff --git a/lang/python/examples/simple.py b/lang/python/examples/simple.py
deleted file mode 100755
index d2e7c07d..00000000
--- a/lang/python/examples/simple.py
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2005 Igor Belyi <[email protected]>
-# Copyright (C) 2002 John Goerzen <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-with gpg.Context(armor=True) as c:
- recipients = []
- print("Enter name of your recipient(s), end with a blank line.")
- while True:
- line = input()
- if not line:
- break
- new = list(c.keylist(line))
- if not new:
- print("Matched no known keys.")
- else:
- print("Adding {}.".format(", ".join(k.uids[0].name for k in new)))
- recipients.extend(new)
-
- if not recipients:
- sys.exit("No recipients.")
-
- print("Encrypting for {}.".format(", ".join(
- k.uids[0].name for k in recipients)))
-
- ciphertext, _, _ = c.encrypt(b"This is my message,", recipients)
- sys.stdout.buffer.write(ciphertext)
diff --git a/lang/python/examples/testCMSgetkey.py b/lang/python/examples/testCMSgetkey.py
deleted file mode 100755
index 9b5a5265..00000000
--- a/lang/python/examples/testCMSgetkey.py
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2008 Bernhard Reiter <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-"""A test applicaton for the CMS protocol."""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-if len(sys.argv) != 2:
- sys.exit("fingerprint or unique key ID for gpgme_get_key()")
-
-with gpg.Context(protocol=gpg.constants.protocol.CMS) as c:
- key = c.get_key(sys.argv[1])
-
- print("got key: ", key.subkeys[0].fpr)
- for uid in key.uids:
- print(uid.uid)
diff --git a/lang/python/examples/verifydetails.py b/lang/python/examples/verifydetails.py
deleted file mode 100755
index 37334868..00000000
--- a/lang/python/examples/verifydetails.py
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2016 g10 Code GmbH
-# Copyright (C) 2004,2008 Igor Belyi <[email protected]>
-# Copyright (c) 2008 Bernhard Reiter <[email protected]>
-#
-# 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 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 for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <https://www.gnu.org/licenses/>.
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import sys
-import gpg
-
-del absolute_import, print_function, unicode_literals
-
-
-def print_engine_infos():
- print("gpgme version:", gpg.core.check_version(None))
- print("engines:")
-
- for engine in gpg.core.get_engine_info():
- print(engine.file_name, engine.version)
-
- for proto in [gpg.constants.protocol.OpenPGP, gpg.constants.protocol.CMS]:
- print("Have {}? {}".format(
- gpg.core.get_protocol_name(proto),
- gpg.core.engine_check_version(proto)))
-
-
-def verifyprintdetails(filename, detached_sig_filename=None):
- """Verify a signature, print a lot of details."""
- with gpg.Context() as c:
-
- # Verify.
- data, result = c.verify(
- open(filename),
- open(detached_sig_filename) if detached_sig_filename else None)
-
- # List results for all signatures. Status equal 0 means "Ok".
- for index, sign in enumerate(result.signatures):
- print("signature", index, ":")
- print(" summary: %#0x" % (sign.summary))
- print(" status: %#0x" % (sign.status))
- print(" timestamp: ", sign.timestamp)
- print(" fingerprint:", sign.fpr)
- print(" uid: ", c.get_key(sign.fpr).uids[0].uid)
-
- # Print "unsigned" text if inline signature
- if data:
- sys.stdout.buffer.write(data)
-
-
-def main():
- print_engine_infos()
- print()
-
- argc = len(sys.argv)
- if argc < 2 or argc > 3:
- sys.exit("Usage: {} <filename>[ <detached_signature_filename>]".format(
- sys.argv[0]))
-
- if argc == 2:
- print("trying to verify file {}.".format(sys.argv[1]))
- verifyprintdetails(sys.argv[1])
- if argc == 3:
- print("trying to verify signature {1} for file {0}.".format(*sys.argv))
- verifyprintdetails(sys.argv[1], sys.argv[2])
-
-
-if __name__ == "__main__":
- main()