Browse Source

fixed pgp generation, work on onion

merge-requests/3/head
Kevin Froman 4 years ago
parent
commit
6a1a448eab
No known key found for this signature in database GPG Key ID: D414D0FE405B63B
  1. 2
      onionr/api.py
  2. 12
      onionr/communicator.py
  3. 12
      onionr/core.py
  4. 5
      onionr/onionr.py
  5. 17
      onionr/onionrutils.py
  6. 4
      readme.md

2
onionr/api.py

@ -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

12
onionr/communicator.py

@ -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:

12
onionr/core.py

@ -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=''):

5
onionr/onionr.py

@ -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)

17
onionr/onionrutils.py

@ -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):
@ -47,4 +47,17 @@ class OnionrUtils():
input()
else:
break
return pass1
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

4
readme.md

@ -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.

Loading…
Cancel
Save