From 26c1983a611ab9efd34dd4912a880001f06cb464 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 20 Jan 2018 11:59:44 -0600 Subject: [PATCH] hopefully fixed pgp test, added pgp export function --- onionr/onionrutils.py | 14 ++++++++++++-- onionr/tests.py | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 7a2f5413..15809828 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -18,10 +18,11 @@ along with this program. If not, see . ''' # Misc functions that do not fit in the main api, but are useful -import getpass, sys, requests, configparser, os, socket +import getpass, sys, requests, configparser, os, socket, gnupg class OnionrUtils(): '''Various useful functions''' def __init__(self): + self.fingerprintFile = 'data/own-fingerprint.txt' return def printErr(self, text='an error occured'): '''Print an error message to stderr with a new line''' @@ -60,4 +61,13 @@ class OnionrUtils(): retVal = True finally: sock.close() - return retVal \ No newline at end of file + return retVal + def exportMyPubkey(self): + '''Export our PGP key if it exists''' + if not os.path.exists(self.fingerprintFile): + raise Exception("No fingerprint found, cannot export our PGP key.") + gpg = gnupg.GPG(gnupghome='./data/pgp/') + with open(self.fingerprintFile,'r') as f: + fingerprint = f.read() + ascii_armored_public_keys = gpg.export_keys(fingerprint) + return ascii_armored_public_keys \ No newline at end of file diff --git a/onionr/tests.py b/onionr/tests.py index a893f096..7c4771ac 100755 --- a/onionr/tests.py +++ b/onionr/tests.py @@ -82,12 +82,13 @@ class OnionrTests(unittest.TestCase): def testPGPGen(self): print('--------------------------') print('Testing PGP key generation') + torID = open('data/hs/hostname').read() if os.path.exists('data/pgp/'): self.assertTrue(True) else: import core myCore = core.Core() - myCore.generateMainPGP() + myCore.generateMainPGP(torID) if os.path.exists('data/pgp/'): self.assertTrue(True) def testHMACGen(self):