Merge branch 'crypto' of github.com:beardog108/onionr into crypto
This commit is contained in:
commit
417b2d7a79
@ -215,7 +215,7 @@ class API:
|
||||
|
||||
return resp
|
||||
if not os.environ.get("WERKZEUG_RUN_MAIN") == "true":
|
||||
logger.info('Starting client on ' + self.host + ':' + str(bindPort) + '...')
|
||||
logger.info('Starting client on ' + self.host + ':' + str(bindPort) + '...', timestamp=True)
|
||||
|
||||
try:
|
||||
app.run(host=self.host, port=bindPort, debug=True, threaded=True)
|
||||
|
@ -36,12 +36,12 @@ class OnionrCommunicate:
|
||||
|
||||
self.highFailureAmount = 7
|
||||
'''
|
||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]))
|
||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]), timestamp=True)
|
||||
try:
|
||||
self.bitcoin = btc.OnionrBTC(torP=int(sys.argv[2]))
|
||||
except _gdbm.error:
|
||||
pass
|
||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()))
|
||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()), timestamp=True)
|
||||
'''
|
||||
#except:
|
||||
#logger.fatal('Failed to start Bitcoin Node, exiting...')
|
||||
@ -89,13 +89,13 @@ class OnionrCommunicate:
|
||||
blockProcessTimer = 0
|
||||
if command != False:
|
||||
if command[0] == 'shutdown':
|
||||
logger.info('Daemon recieved exit command.')
|
||||
logger.info('Daemon recieved exit command.', timestamp=True)
|
||||
break
|
||||
elif command[0] == 'anounceNode':
|
||||
announceAmount = 1
|
||||
announceVal = False
|
||||
for i in command[1]:
|
||||
logger.info('Announcing our node to ' + command[1][i])
|
||||
logger.info('Announcing our node to ' + command[1][i], timestamp=True)
|
||||
while not announceVal:
|
||||
announceVal = self.performGet('announce', command[1][i], data=self._core.hsAdder, skipHighFailureAddress=True)
|
||||
|
||||
@ -123,14 +123,14 @@ class OnionrCommunicate:
|
||||
|
||||
while peersCheck > peersChecked:
|
||||
i = random.randint(0, maxN)
|
||||
logger.info('Using ' + peerList[i] + ' to find new peers')
|
||||
logger.info('Using ' + peerList[i] + ' to find new peers', timestamp=True)
|
||||
try:
|
||||
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
|
||||
logger.debug('Attempting to merge address: ')
|
||||
logger.debug(newAdders)
|
||||
self._utils.mergeAdders(newAdders)
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.info(peerList[i] + ' connection failed')
|
||||
logger.info(peerList[i] + ' connection failed', timestamp=True)
|
||||
continue
|
||||
else:
|
||||
try:
|
||||
@ -141,7 +141,7 @@ class OnionrCommunicate:
|
||||
# TODO: Require keys to come with POW token (very large amount of POW)
|
||||
self._utils.mergeKeys(newKeys)
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.info(peerList[i] + ' connection failed')
|
||||
logger.info(peerList[i] + ' connection failed', timestamp=True)
|
||||
continue
|
||||
else:
|
||||
peersChecked += 1
|
||||
@ -226,7 +226,7 @@ class OnionrCommunicate:
|
||||
self._core.setData(data)
|
||||
if data.startswith('-txt-'):
|
||||
self._core.setBlockType(hash, 'txt')
|
||||
logger.info('Successfully obtained data for ' + hash)
|
||||
logger.info('Successfully obtained data for ' + hash, timestamp=True)
|
||||
if len(data) < 120:
|
||||
logger.debug('Block text:\n' + data)
|
||||
else:
|
||||
|
@ -24,12 +24,12 @@ class OnionrCryptoTests(unittest.TestCase):
|
||||
crypto = onionrcrypto.OnionrCrypto(myCore)
|
||||
key = key = b"tttttttttttttttttttttttttttttttt"
|
||||
|
||||
logger.info("Encrypting: " + dataString)
|
||||
logger.info("Encrypting: " + dataString, timestamp=True)
|
||||
encrypted = crypto.symmetricEncrypt(dataString, key, returnEncoded=True)
|
||||
logger.info(encrypted)
|
||||
logger.info('Decrypting encrypted string:')
|
||||
logger.info(encrypted, timestamp=True)
|
||||
logger.info('Decrypting encrypted string:', timestamp=True)
|
||||
decrypted = crypto.symmetricDecrypt(encrypted, key, encodedMessage=True)
|
||||
logger.info(decrypted)
|
||||
logger.info(decrypted, timestamp=True)
|
||||
self.assertTrue(True)
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -141,11 +141,11 @@ def log(prefix, data, color = '', timestamp=True):
|
||||
data : The actual data to output
|
||||
color : The color to output before the data
|
||||
'''
|
||||
curTime = ''
|
||||
if timestamp:
|
||||
curTime = time.strftime("%m-%d %H:%M:%S")
|
||||
else:
|
||||
curTime = ''
|
||||
output = colors.reset + str(color) + '[' + colors.bold + str(prefix) + colors.reset + str(color) + '] ' + curTime + ' ' + str(data) + colors.reset
|
||||
curTime = time.strftime("%m-%d %H:%M:%S") + ' '
|
||||
|
||||
output = colors.reset + str(color) + '[' + colors.bold + str(prefix) + colors.reset + str(color) + '] ' + curTime + str(data) + colors.reset
|
||||
if not get_settings() & USE_ANSI:
|
||||
output = colors.filter(output)
|
||||
|
||||
@ -201,26 +201,28 @@ def confirm(default = 'y', message = 'Are you sure %s? '):
|
||||
return default == 'y'
|
||||
|
||||
# debug: when there is info that could be useful for debugging purposes only
|
||||
def debug(data):
|
||||
def debug(data, timestamp=True):
|
||||
if get_level() <= LEVEL_DEBUG:
|
||||
log('/', data)
|
||||
log('/', data, timestamp=timestamp)
|
||||
|
||||
# info: when there is something to notify the user of, such as the success of a process
|
||||
def info(data):
|
||||
def info(data, timestamp=False):
|
||||
if get_level() <= LEVEL_INFO:
|
||||
log('+', data, colors.fg.green)
|
||||
log('+', data, colors.fg.green, timestamp=timestamp)
|
||||
|
||||
# warn: when there is a potential for something bad to happen
|
||||
def warn(data):
|
||||
def warn(data, timestamp=True):
|
||||
if get_level() <= LEVEL_WARN:
|
||||
log('!', data, colors.fg.orange)
|
||||
log('!', data, colors.fg.orange, timestamp=timestamp)
|
||||
|
||||
# error: when only one function, module, or process of the program encountered a problem and must stop
|
||||
def error(data):
|
||||
def error(data, error=None, timestamp=True):
|
||||
if get_level() <= LEVEL_ERROR:
|
||||
log('-', data, colors.fg.red)
|
||||
log('-', data, colors.fg.red, timestamp=timestamp)
|
||||
if not error is None:
|
||||
debug('Error details: ' + str(error))
|
||||
|
||||
# fatal: when the something so bad has happened that the prorgam must stop
|
||||
def fatal(data):
|
||||
def fatal(data, timestamp=True):
|
||||
if get_level() <= LEVEL_FATAL:
|
||||
log('#', data, colors.bg.red + colors.fg.green + colors.bold)
|
||||
log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp)
|
||||
|
@ -97,7 +97,7 @@ HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
|
||||
logger.fatal('Failed to start Tor. Try killing any other Tor processes owned by this user.')
|
||||
return False
|
||||
|
||||
logger.info('Finished starting Tor')
|
||||
logger.info('Finished starting Tor', timestamp=True)
|
||||
self.readyState = True
|
||||
|
||||
myID = open('data/hs/hostname', 'r')
|
||||
|
@ -158,6 +158,8 @@ class Onionr:
|
||||
'addpeer': self.addPeer,
|
||||
'add-peer': self.addPeer,
|
||||
'add-address': self.addAddress,
|
||||
'add-addr': self.addAddress,
|
||||
'addaddr': self.addAddress,
|
||||
'addaddress': self.addAddress,
|
||||
|
||||
'connect': self.addAddress
|
||||
@ -173,12 +175,12 @@ class Onionr:
|
||||
'enable-plugin': 'Enables and starts a plugin',
|
||||
'disable-plugin': 'Disables and stops a plugin',
|
||||
'reload-plugin': 'Reloads a plugin',
|
||||
'list-peers': 'Displays a list of peers',
|
||||
'add-peer': 'Adds a peer (?)',
|
||||
'list-peers': 'Displays a list of peers',
|
||||
'add-msg': 'Broadcasts a message to the Onionr network',
|
||||
'pm': 'Adds a private message to block',
|
||||
'gui': 'Opens a graphical interface for Onionr',
|
||||
'getpms': 'Shows private messages sent to you'
|
||||
'get-pms': 'Shows private messages sent to you',
|
||||
'gui': 'Opens a graphical interface for Onionr'
|
||||
}
|
||||
|
||||
command = ''
|
||||
@ -312,7 +314,9 @@ class Onionr:
|
||||
return
|
||||
|
||||
def addAddress(self):
|
||||
'''Adds a Onionr node address'''
|
||||
'''
|
||||
Adds a Onionr node address
|
||||
'''
|
||||
try:
|
||||
newAddress = sys.argv[2]
|
||||
except:
|
||||
@ -320,9 +324,9 @@ class Onionr:
|
||||
else:
|
||||
logger.info("Adding address: " + logger.colors.underline + newAddress)
|
||||
if self.onionrCore.addAddress(newAddress):
|
||||
logger.info("Successfully added address")
|
||||
logger.info("Successfully added address.")
|
||||
else:
|
||||
logger.warn("Unable to add address")
|
||||
logger.warn("Unable to add address.")
|
||||
|
||||
return
|
||||
|
||||
|
@ -47,8 +47,8 @@ class POW:
|
||||
if iFound:
|
||||
endTime = math.floor(time.time())
|
||||
if self.reporting:
|
||||
logger.info('Found token ' + token)
|
||||
logger.info('took ' + str(endTime - startTime))
|
||||
logger.info('Found token ' + token, timestamp=True)
|
||||
logger.info('took ' + str(endTime - startTime), timestamp=True)
|
||||
self.result = token
|
||||
|
||||
def __init__(self, difficulty, bitcoinNode):
|
||||
|
@ -46,12 +46,10 @@ class OnionrUtils:
|
||||
self.timingToken = bypass.read()
|
||||
|
||||
def sendPM(self, pubkey, message):
|
||||
'''High level function to encrypt a message to a peer and insert it as a block'''
|
||||
'''
|
||||
High level function to encrypt a message to a peer and insert it as a block
|
||||
'''
|
||||
|
||||
#forwardKey = self._core.getPeerInfo(pubkey, 'forwardKey')
|
||||
|
||||
#if self._core.getPeerInfo(pubkey, 'pubkeyExchanged') == 1:
|
||||
# pass
|
||||
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
||||
block = self._core.insertBlock(encrypted, header='pm')
|
||||
|
||||
@ -63,19 +61,25 @@ class OnionrUtils:
|
||||
return
|
||||
|
||||
def incrementAddressSuccess(self, address):
|
||||
'''Increase the recorded sucesses for an address'''
|
||||
'''
|
||||
Increase the recorded sucesses for an address
|
||||
'''
|
||||
increment = self._core.getAddressInfo(address, 'success') + 1
|
||||
self._core.setAddressInfo(address, 'success', increment)
|
||||
return
|
||||
|
||||
def decrementAddressSuccess(self, address):
|
||||
'''Decrease the recorded sucesses for an address'''
|
||||
'''
|
||||
Decrease the recorded sucesses for an address
|
||||
'''
|
||||
increment = self._core.getAddressInfo(address, 'success') - 1
|
||||
self._core.setAddressInfo(address, 'success', increment)
|
||||
return
|
||||
|
||||
def mergeKeys(self, newKeyList):
|
||||
'''Merge ed25519 key list to our database'''
|
||||
'''
|
||||
Merge ed25519 key list to our database
|
||||
'''
|
||||
retVal = False
|
||||
if newKeyList != False:
|
||||
for key in newKeyList.split(','):
|
||||
@ -86,13 +90,15 @@ class OnionrUtils:
|
||||
|
||||
|
||||
def mergeAdders(self, newAdderList):
|
||||
'''Merge peer adders list to our database'''
|
||||
'''
|
||||
Merge peer adders list to our database
|
||||
'''
|
||||
retVal = False
|
||||
if newAdderList != False:
|
||||
for adder in newAdderList.split(','):
|
||||
if not adder in self._core.listAdders(randomOrder=False) and adder.strip() != self.getMyAddress():
|
||||
if self._core.addAddress(adder):
|
||||
logger.info('added ' + adder + ' to db')
|
||||
logger.info('Added ' + adder + ' to db.', timestamp=True)
|
||||
input()
|
||||
retVal = True
|
||||
else:
|
||||
@ -285,15 +291,18 @@ class OnionrUtils:
|
||||
for i in blocks:
|
||||
if len (i) == 0:
|
||||
continue
|
||||
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
|
||||
message = potentialMessage.read()
|
||||
if message.startswith('-pm-'):
|
||||
try:
|
||||
message = self._core._crypto.pubKeyDecrypt(message.replace('-pm-', ''), encodedData=True, anonymous=True)
|
||||
except nacl.exceptions.CryptoError as e:
|
||||
#logger.debug('Unable to decrypt ' + i)
|
||||
#logger.debug(str(e))
|
||||
pass
|
||||
else:
|
||||
logger.info('Recieved message: ' + message.decode())
|
||||
try:
|
||||
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
|
||||
message = potentialMessage.read()
|
||||
if message.startswith('-pm-'):
|
||||
try:
|
||||
message = self._core._crypto.pubKeyDecrypt(message.replace('-pm-', ''), encodedData=True, anonymous=True)
|
||||
except nacl.exceptions.CryptoError as e:
|
||||
#logger.debug('Unable to decrypt ' + i)
|
||||
#logger.debug(str(e))
|
||||
pass
|
||||
else:
|
||||
logger.info('Recieved message: ' + message.decode())
|
||||
except Exception as error:
|
||||
logger.error('Failed to open block ' + str(i) + '.', error=error)
|
||||
return
|
Loading…
Reference in New Issue
Block a user