fixed pgp generation, work on onion

This commit is contained in:
Kevin Froman 2018-01-20 01:23:09 -06:00
parent cb3de7056c
commit 6a1a448eab
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
6 changed files with 46 additions and 6 deletions

View File

@ -125,6 +125,8 @@ class API:
resp = Response("pong!")
elif action == 'setHMAC':
pass
elif action == 'getPGP':
ascii_armored_public_keys = gpg.export_keys('')
return resp

View File

@ -28,6 +28,18 @@ class OnionrCommunicate:
This class handles communication with nodes in the Onionr network.
'''
self._core = core.Core()
if debug:
print('Communicator debugging enabled')
torID = open('data/hs/hostname').read()
# get our own PGP fingerprint
fingerprintFile = 'data/own-fingerprint.txt'
if not os.path.exists(fingerprintFile):
self._core.generateMainPGP(torID)
with open(fingerprintFile,'r') as f:
self.pgpOwnFingerprint = f.read()
print('My PGP fingerprint is ' + self.pgpOwnFingerprint)
while True:
command = self._core.daemonQueue()
if debug:

View File

@ -29,17 +29,23 @@ class Core:
'''
self.queueDB = 'data/queue.db'
self.peerDB = 'data/peers.db'
self.ownPGPID = ''
#self.daemonQueue() # Call to create the DB if it doesn't exist
return
def generateMainPGP(self):
def generateMainPGP(self, myID):
''' Generate the main PGP key for our client. Should not be done often.
Uses own PGP home folder in the data/ directory. '''
# Generate main pgp key
gpg = gnupg.GPG(homedir='data/pgp/')
input_data = gpg.gen_key_input(key_type="RSA", key_length=2048, name_real='anon', name_comment='Onionr key', name_email='anon@onionr')
gpg = gnupg.GPG(gnupghome='./data/pgp/')
input_data = gpg.gen_key_input(key_type="RSA", key_length=2048, name_real=myID, name_email='anon@onionr')
#input_data = gpg.gen_key_input(key_type="RSA", key_length=1024)
key = gpg.gen_key(input_data)
# Write the key
myFingerpintFile = open('data/own-fingerprint.txt', 'w')
myFingerpintFile.write(key.fingerprint)
myFingerpintFile.close()
return
def addPeer(self, peerID, name=''):

View File

@ -78,7 +78,10 @@ class Onionr:
if self.debug:
randomPort = 8080
else:
randomPort = random.randint(1024, 65535)
while True:
randomPort = random.randint(1024, 65535)
if self.onionrUtils.checkPort(randomPort):
break
self.config['CLIENT'] = {'CLIENT HMAC': base64.b64encode(os.urandom(32)).decode('utf-8'), 'PORT': randomPort, 'API VERSION': '0.0.0'}
with open('data/config.ini', 'w') as configfile:
self.config.write(configfile)

View File

@ -18,7 +18,7 @@
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
import getpass, sys, requests, configparser, os
import getpass, sys, requests, configparser, os, socket
class OnionrUtils():
'''Various useful functions'''
def __init__(self):
@ -48,3 +48,16 @@ class OnionrUtils():
else:
break
return pass1
def checkPort(self, port):
'''Checks if a port is available, returns bool'''
# inspired by https://www.reddit.com/r/learnpython/comments/2i4qrj/how_to_write_a_python_script_that_checks_to_see/ckzarux/
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
retVal = False
try:
sock.bind(('', port))
except OSError as e:
if e.errno is 98:
retVal = True
finally:
sock.close()
return retVal

View File

@ -12,3 +12,7 @@ Major work in progress.
# Development
This software is in heavy development. If for some reason you want to get involved, get in touch first.
## Disclaimer
The Tor Project, I2P developers, and anyone else do not own, create, or endorse this project, and are not otherwise involved.