[gnome-keysign: 5/11] tests: add scripts for testing
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign: 5/11] tests: add scripts for testing
- Date: Wed, 7 Oct 2020 18:17:03 +0000 (UTC)
commit 2128e27dc89be033e985b6555d31195acf417540
Author: Tobias Mueller <muelli cryptobitch de>
Date: Fri Sep 11 21:51:42 2020 +0200
tests: add scripts for testing
This allows to reproduce a testing environment more easily. Of course,
the scripts are not the most beautiful ones you've ever seen, but they
have served me well enough.
keysign/sign_and_encrypt.py | 58 +++++++++++++++++++++++++++++++++++++++++++++
tests/create_attestee.sh | 11 +++++++++
tests/create_attestor.sh | 12 ++++++++++
3 files changed, 81 insertions(+)
---
diff --git a/keysign/sign_and_encrypt.py b/keysign/sign_and_encrypt.py
new file mode 100644
index 0000000..e1092b1
--- /dev/null
+++ b/keysign/sign_and_encrypt.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# Copyright 2020 Tobias Mueller <tobi cryptobit ch>
+#
+# This file is part of GNOME Keysign.
+#
+# GNOME Keysign 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 3 of the License, or
+# (at your option) any later version.
+#
+# GNOME Keysign 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 GNOME Keysign. If not, see <http://www.gnu.org/licenses/>.
+
+import argparse
+
+import logging
+import sys
+
+from .gpgmeh import sign_keydata_and_encrypt, fingerprint_from_keydata
+
+def main():
+ import argparse
+ parser = argparse.ArgumentParser(description="Sign an OpenPGP key from a file. "
+ "The program will open each file, extract exactly one OpenPGP key, "
+ "sign each UID separately, encrypt and write the result out to a file.")
+ parser.add_argument('-v', '--verbose', action='count', default=0,
+ help="Increase detail of logging")
+ parser.add_argument("file", nargs='+', type=argparse.FileType('rb'),
+ help="File containing OpenPGP keys")
+ args = parser.parse_args()
+
+ log_levels = [logging.WARNING, logging.INFO, logging.DEBUG]
+ log_level = log_levels[min(len(log_levels)-1, args.verbose)]
+ logging.basicConfig(level=log_level)
+
+ log = logging.getLogger(__name__)
+ log.debug('Running main with args: %s', args)
+
+ for fhandle in args.file:
+ data = fhandle.read()
+ fingerprint = fingerprint_from_keydata(data)
+ for i, (uid, ciphertext, plaintext) in enumerate(sign_keydata_and_encrypt(keydata=data)):
+ fname = "%s-%d.pgp" % (fingerprint, i)
+ with open(fname, 'wb') as outfile:
+ outfile.write(ciphertext)
+ print ("Written to %s \t for UID %s" % (fname, uid))
+
+
+
+if __name__ == '__main__':
+ logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
+ format='%(name)s (%(levelname)s): %(message)s')
+ sys.exit(main())
diff --git a/tests/create_attestee.sh b/tests/create_attestee.sh
new file mode 100755
index 0000000..4120831
--- /dev/null
+++ b/tests/create_attestee.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -ex
+# A simple helper for creating an environment for the receiver of the newly produced certification
+
+ATTESTEE_DIR=/tmp/gks-attestee
+
+rm -rf "${ATTESTEE_DIR}.bak"
+mv -f "$ATTESTEE_DIR" "${ATTESTEE_DIR}.bak"
+mkdir -p $ATTESTEE_DIR
+echo -n | env GNUPGHOME=${ATTESTEE_DIR} gpg --pinentry-mode loopback --batch --no-tty --yes --passphrase-fd
0 --quick-generate-key attestee example com
+env GNUPGHOME=${ATTESTEE_DIR} gpg --armor --export attestee example com > ${ATTESTEE_DIR}/attestee.pgp.asc
+echo \"GNUPGHOME=${ATTESTEE_DIR}\" python3 -m keysign.sign_and_encrypt ${ATTESTEE_DIR}/attestee.pgp.asc
diff --git a/tests/create_attestor.sh b/tests/create_attestor.sh
new file mode 100755
index 0000000..12e1e1c
--- /dev/null
+++ b/tests/create_attestor.sh
@@ -0,0 +1,12 @@
+#!/bin/bash -ex
+# A simple helper for creating an environment for the producer of a certification
+
+ATTESTOR_DIR=/tmp/gks-attestor
+
+rm -rf "${ATTESTOR_DIR}.bak"
+mv -f "$ATTESTOR_DIR" "${ATTESTOR_DIR}.bak"
+mkdir -p $ATTESTOR_DIR
+echo -n | env GNUPGHOME=${ATTESTOR_DIR} gpg --pinentry-mode loopback --batch --no-tty --yes --passphrase-fd
0 --quick-generate-key attestor example com
+env GNUPGHOME=${ATTESTOR_DIR} gpg --armor --export attestor example com > ${ATTESTOR_DIR}/attestor.pgp.asc
+
+echo env \"GNUPGHOME=${ATTESTOR_DIR}\" python3 -m keysign.sign_and_encrypt ATTESTEE_DIR/attestee.pgp.asc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]