+ added onionrpeers file
+ added onionrexceptions file + work on new communicator
This commit is contained in:
parent
d73b69c9b4
commit
b6da3385cb
23
onionr/communicator2.py
Normal file → Executable file
23
onionr/communicator2.py
Normal file → Executable file
@ -19,33 +19,20 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import core, config, onionrblockapi as block, requests, xml
|
||||
import sys, core, config, onionrblockapi as block, requests
|
||||
from defusedxml import minidom
|
||||
|
||||
class OnionrCommunicatorDaemon:
|
||||
def __init__(self, debug, developmentMode):
|
||||
self.timers = [] # list of tuples, function, time in seconds
|
||||
self._core = core.Core()
|
||||
|
||||
self.nistSalt = 0
|
||||
self.nistSaltTimestamp = 0
|
||||
self.powSalt = 0
|
||||
return
|
||||
|
||||
def getNistTimeStamp(self):
|
||||
curTime = self._core._utils.getCurrentHourEpoch
|
||||
data = doGetRequest('https://beacon.nist.gov/rest/record/' + str(curTime))
|
||||
|
||||
|
||||
def doGetRequest(self, url, port=sys.argv[2], proxyType='tor'):
|
||||
'''
|
||||
Do a get request through a local tor or i2p instance
|
||||
'''
|
||||
if proxyType == 'tor':
|
||||
proxies = {'http': 'socks5://127.0.0.1:' + str(port), 'https': 'socks5://127.0.0.1:' + str(port)}
|
||||
elif proxyType == 'i2p':
|
||||
proxies = {'http': 'http://127.0.0.1:4444'}
|
||||
else:
|
||||
return
|
||||
headers = {'user-agent': 'PyOnionr'}
|
||||
r = requests.get(url, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
||||
|
||||
shouldRun = False
|
||||
debug = True
|
||||
developmentMode = False
|
||||
|
@ -549,7 +549,7 @@ class Onionr:
|
||||
'''
|
||||
Starts the Onionr communication daemon
|
||||
'''
|
||||
|
||||
communicatorDaemon = './communicator.py'
|
||||
if not os.environ.get("WERKZEUG_RUN_MAIN") == "true":
|
||||
if self._developmentMode:
|
||||
logger.warn('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)', timestamp = False)
|
||||
@ -560,7 +560,13 @@ class Onionr:
|
||||
logger.info('Started .onion service: ' + logger.colors.underline + net.myID)
|
||||
logger.info('Our Public key: ' + self.onionrCore._crypto.pubKey)
|
||||
time.sleep(1)
|
||||
subprocess.Popen(["./communicator.py", "run", str(net.socksPort)])
|
||||
try:
|
||||
if config.get('newCommunicator'):
|
||||
communicatorDaemon = './communicator2.py'
|
||||
logger.info('Using new communicator')
|
||||
except NameError:
|
||||
pass
|
||||
subprocess.Popen([communicatorDaemon, "run", str(net.socksPort)])
|
||||
logger.debug('Started communicator')
|
||||
events.event('daemon_start', onionr = self)
|
||||
api.API(self.debug)
|
||||
|
22
onionr/onionrexceptions.py
Normal file
22
onionr/onionrexceptions.py
Normal file
@ -0,0 +1,22 @@
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network.
|
||||
|
||||
This file contains exceptions for onionr
|
||||
'''
|
||||
'''
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
class MissingPort(Exception):
|
||||
pass
|
19
onionr/onionrpeers.py
Normal file
19
onionr/onionrpeers.py
Normal file
@ -0,0 +1,19 @@
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network.
|
||||
|
||||
This file contains both the OnionrCommunicate class for communcating with peers
|
||||
'''
|
||||
'''
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
@ -21,6 +21,8 @@
|
||||
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii, time, base64, json, glob, shutil, math
|
||||
import nacl.signing, nacl.encoding
|
||||
from onionrblockapi import Block
|
||||
import onionrexceptions
|
||||
from defusedxml import minidom
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
try:
|
||||
@ -483,6 +485,44 @@ class OnionrUtils:
|
||||
'''returns epoch'''
|
||||
return math.floor(time.time())
|
||||
|
||||
def doGetRequest(self, url, port=0, proxyType='tor'):
|
||||
'''
|
||||
Do a get request through a local tor or i2p instance
|
||||
'''
|
||||
if proxyType == 'tor':
|
||||
if port == 0:
|
||||
raise onionrexceptions.MissingPort('Socks port required for Tor HTTP get request')
|
||||
proxies = {'http': 'socks5://127.0.0.1:' + str(port), 'https': 'socks5://127.0.0.1:' + str(port)}
|
||||
elif proxyType == 'i2p':
|
||||
proxies = {'http': 'http://127.0.0.1:4444'}
|
||||
else:
|
||||
return
|
||||
headers = {'user-agent': 'PyOnionr'}
|
||||
r = requests.get(url, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
||||
return r.text
|
||||
|
||||
def getNistBeaconSalt(self, torPort=0):
|
||||
'''
|
||||
Get the token for the current hour from the NIST randomness beacon
|
||||
'''
|
||||
if torPort == 0:
|
||||
try:
|
||||
sys.argv[2]
|
||||
except IndexError:
|
||||
raise onionrexceptions.MissingPort('Missing Tor socks port')
|
||||
retData = ''
|
||||
curTime = self._core._utils.getCurrentHourEpoch
|
||||
self.nistSaltTimestamp = curTime
|
||||
data = self.doGetRequest('https://beacon.nist.gov/rest/record/' + str(curTime), port=torPort)
|
||||
dataXML = minidom.parseString(data, forbid_dtd=True, forbid_entities=True, forbid_external=True)
|
||||
try:
|
||||
retData = dataXML.getElementsByTagName('outputValue')[0].childNodes[0].data
|
||||
except ValueError:
|
||||
logger.warn('Could not get NIST beacon value')
|
||||
else:
|
||||
self.powSalt = retData
|
||||
return retData
|
||||
|
||||
def size(path='.'):
|
||||
'''
|
||||
Returns the size of a folder's contents in bytes
|
||||
|
@ -23,5 +23,6 @@
|
||||
"allocations":{
|
||||
"disk": 1000000000,
|
||||
"netTotal": 1000000000
|
||||
}
|
||||
},
|
||||
"newCommunicator": false
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network. Run with 'help' for usage.
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
import hmac, base64, time, math
|
||||
|
||||
class TimedHMAC:
|
||||
def __init__(self, base64Key, data, hashAlgo):
|
||||
'''
|
||||
base64Key = base64 encoded key
|
||||
data = data to hash
|
||||
expire = time expiry in epoch
|
||||
hashAlgo = string in hashlib.algorithms_available
|
||||
|
||||
Maximum of 10 seconds grace period
|
||||
'''
|
||||
|
||||
self.data = data
|
||||
self.expire = math.floor(time.time())
|
||||
self.hashAlgo = hashAlgo
|
||||
self.b64Key = base64Key
|
||||
generatedHMAC = hmac.HMAC(base64.b64decode(base64Key).decode(), digestmod=self.hashAlgo)
|
||||
generatedHMAC.update(data + expire)
|
||||
self.HMACResult = generatedHMAC.hexdigest()
|
||||
|
||||
return
|
||||
|
||||
def check(self, data):
|
||||
'''
|
||||
Check a hash (and verify time is sane)
|
||||
'''
|
||||
|
||||
testHash = hmac.HMAC(base64.b64decode(base64Key).decode(), digestmod=self.hashAlgo)
|
||||
testHash.update(data + math.floor(time.time()))
|
||||
testHash = testHash.hexdigest()
|
||||
if hmac.compare_digest(testHash, self.HMACResult):
|
||||
return true
|
||||
|
||||
return false
|
@ -7,5 +7,6 @@ sha3==0.2.1
|
||||
simple_crypt==4.1.7
|
||||
ecdsa==0.13
|
||||
requests==2.12.4
|
||||
defusedxml==0.5.0
|
||||
SocksiPy_branch==1.01
|
||||
sphinx_rtd_theme==0.3.0
|
||||
|
Loading…
Reference in New Issue
Block a user