hopefully fixed pgp test, added pgp export function
This commit is contained in:
parent
0042e2fe51
commit
26c1983a61
@ -18,10 +18,11 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
# Misc functions that do not fit in the main api, but are useful
|
# 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():
|
class OnionrUtils():
|
||||||
'''Various useful functions'''
|
'''Various useful functions'''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.fingerprintFile = 'data/own-fingerprint.txt'
|
||||||
return
|
return
|
||||||
def printErr(self, text='an error occured'):
|
def printErr(self, text='an error occured'):
|
||||||
'''Print an error message to stderr with a new line'''
|
'''Print an error message to stderr with a new line'''
|
||||||
@ -61,3 +62,12 @@ class OnionrUtils():
|
|||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
return retVal
|
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
|
@ -82,12 +82,13 @@ class OnionrTests(unittest.TestCase):
|
|||||||
def testPGPGen(self):
|
def testPGPGen(self):
|
||||||
print('--------------------------')
|
print('--------------------------')
|
||||||
print('Testing PGP key generation')
|
print('Testing PGP key generation')
|
||||||
|
torID = open('data/hs/hostname').read()
|
||||||
if os.path.exists('data/pgp/'):
|
if os.path.exists('data/pgp/'):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
else:
|
else:
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
myCore.generateMainPGP()
|
myCore.generateMainPGP(torID)
|
||||||
if os.path.exists('data/pgp/'):
|
if os.path.exists('data/pgp/'):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
def testHMACGen(self):
|
def testHMACGen(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user