From 268325c07d2904426900d469174be2d1f6812b8c Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 12 Jun 2019 15:12:56 -0500 Subject: [PATCH] - removed simplecache for now * fixed existingRand bytes check in announce in onionrdaemontools * moved openhome to its own file * slight comment and boilerplate changes + added more readme files for subdirectories --- onionr/api.py | 3 +- onionr/communicatorutils/onionrdaemontools.py | 7 +- onionr/etc/README.md | 5 ++ onionr/etc/onionrvalues.py | 2 +- onionr/etc/pgpwords.py | 2 +- onionr/httpapi/README.md | 13 ++++ onionr/httpapi/configapi/__init__.py | 2 +- onionr/httpapi/friendsapi/__init__.py | 2 +- onionr/httpapi/miscpublicapi/__init__.py | 19 +++++ onionr/httpapi/miscpublicapi/announce.py | 2 +- onionr/httpapi/miscpublicapi/getblocks.py | 2 +- onionr/httpapi/miscpublicapi/upload.py | 2 +- onionr/httpapi/profilesapi/__init__.py | 2 +- onionr/onionr.py | 2 +- onionr/onionrcommands/README.md | 25 +++++++ onionr/onionrcommands/__init__.py | 13 +--- onionr/onionrcommands/banblocks.py | 2 +- onionr/onionrcommands/daemonlaunch.py | 2 +- onionr/onionrcommands/filecommands.py | 20 +++++ onionr/onionrcommands/keyadders.py | 2 +- onionr/onionrcommands/onionrstatistics.py | 2 +- .../openwebinterface.py} | 27 ++++--- onionr/onionrcommands/plugincommands.py | 3 +- onionr/onionrcommands/pubkeymanager.py | 15 ++-- onionr/onionrfragment/__init__.py | 73 ------------------- onionr/onionrservices/__init__.py | 2 +- onionr/onionrservices/bootstrapservice.py | 2 +- onionr/onionrservices/httpheaders.py | 2 +- 28 files changed, 126 insertions(+), 129 deletions(-) create mode 100644 onionr/etc/README.md create mode 100644 onionr/httpapi/README.md create mode 100644 onionr/onionrcommands/README.md rename onionr/{httpapi/simplecache/__init__.py => onionrcommands/openwebinterface.py} (55%) mode change 100755 => 100644 delete mode 100755 onionr/onionrfragment/__init__.py diff --git a/onionr/api.py b/onionr/api.py index 66464e9b..daefd6ef 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -26,7 +26,7 @@ import core from onionrblockapi import Block import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config import httpapi -from httpapi import friendsapi, simplecache, profilesapi, configapi, miscpublicapi +from httpapi import friendsapi, profilesapi, configapi, miscpublicapi from onionrservices import httpheaders import onionr @@ -199,7 +199,6 @@ class API: self.queueResponse = {} onionrInst.setClientAPIInst(self) app.register_blueprint(friendsapi.friends) - app.register_blueprint(simplecache.simplecache) app.register_blueprint(profilesapi.profile_BP) app.register_blueprint(configapi.config_BP) httpapi.load_plugin_blueprints(app) diff --git a/onionr/communicatorutils/onionrdaemontools.py b/onionr/communicatorutils/onionrdaemontools.py index 78e1f3dd..b18edd87 100755 --- a/onionr/communicatorutils/onionrdaemontools.py +++ b/onionr/communicatorutils/onionrdaemontools.py @@ -67,9 +67,9 @@ class DaemonTools: combinedNodes = ourID + peer if ourID != 1: #TODO: Extend existingRand for i2p - existingRand = self.daemon._core.getAddressInfo(peer, 'powValue') + existingRand = self.daemon._core._utils.bytesToStr(self.daemon._core.getAddressInfo(peer, 'powValue')) # Reset existingRand if it no longer meets the minimum POW - if type(existingRand) is type(None) or not existingRand.endswith(b'0' * ov.announce_pow): + if type(existingRand) is type(None) or not existingRand.endswith('0' * ov.announce_pow): existingRand = '' if peer in self.announceCache: @@ -216,5 +216,4 @@ class DaemonTools: fakePeer = 'OVPCZLOXD6DC5JHX4EQ3PSOGAZ3T24F75HQLIUZSDSMYPEOXCPFA====' data = secrets.token_hex(secrets.randbelow(1024) + 1) self.daemon._core.insertBlock(data, header='pm', encryptType='asym', asymPeer=fakePeer, meta={'subject': 'foo'}) - self.daemon.decrementThreadCount('insertDeniableBlock') - return \ No newline at end of file + self.daemon.decrementThreadCount('insertDeniableBlock') \ No newline at end of file diff --git a/onionr/etc/README.md b/onionr/etc/README.md new file mode 100644 index 00000000..c5c054ea --- /dev/null +++ b/onionr/etc/README.md @@ -0,0 +1,5 @@ +# etc + +pgpwords.py: represent data using the pgp word list: https://en.wikipedia.org/wiki/PGP_word_list + +onionrvalues.py: spec values for onionr blocks and other things \ No newline at end of file diff --git a/onionr/etc/onionrvalues.py b/onionr/etc/onionrvalues.py index f55f5ac4..e3e1421d 100755 --- a/onionr/etc/onionrvalues.py +++ b/onionr/etc/onionrvalues.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication This file defines values and requirements used by Onionr ''' diff --git a/onionr/etc/pgpwords.py b/onionr/etc/pgpwords.py index 8e4ddb8e..d045b65a 100755 --- a/onionr/etc/pgpwords.py +++ b/onionr/etc/pgpwords.py @@ -4,7 +4,7 @@ '''This file is adapted from https://github.com/thblt/pgp-words by github user 'thblt' ('Thibault Polge), GPL v3 license''' ''' -Changes made for Onionr: +Changes made for Onionr by Kevin Froman in 2018-2019: Minor changes such as slight word adjustment, line breaks CLI commands/usage function removed diff --git a/onionr/httpapi/README.md b/onionr/httpapi/README.md new file mode 100644 index 00000000..b048b2c3 --- /dev/null +++ b/onionr/httpapi/README.md @@ -0,0 +1,13 @@ +# httpapi + +The httpapi contains collections of endpoints for the client API server. + +## Files: + +configapi: manage onionr configuration from the client http api + +friendsapi: add, remove and list friends from the client http api + +miscpublicapi: misculanious onionr network interaction from the **public** httpapi, such as announcements, block fetching and uploading. + +profilesapi: work in progress in returning a profile page for an Onionr user \ No newline at end of file diff --git a/onionr/httpapi/configapi/__init__.py b/onionr/httpapi/configapi/__init__.py index 3f5484f8..d760ff7b 100644 --- a/onionr/httpapi/configapi/__init__.py +++ b/onionr/httpapi/configapi/__init__.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This file handles configuration setting and getting from the HTTP API ''' diff --git a/onionr/httpapi/friendsapi/__init__.py b/onionr/httpapi/friendsapi/__init__.py index c935ded5..8d6b4122 100755 --- a/onionr/httpapi/friendsapi/__init__.py +++ b/onionr/httpapi/friendsapi/__init__.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This file creates http endpoints for friend management ''' diff --git a/onionr/httpapi/miscpublicapi/__init__.py b/onionr/httpapi/miscpublicapi/__init__.py index f03d3808..b29454f7 100644 --- a/onionr/httpapi/miscpublicapi/__init__.py +++ b/onionr/httpapi/miscpublicapi/__init__.py @@ -1,3 +1,22 @@ +''' + Onionr - Private P2P Communication + + Public endpoints to do various block sync actions and announcement +''' +''' + 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 . +''' from . import announce, upload, getblocks announce = announce.handle_announce # endpoint handler for accepting peer announcements diff --git a/onionr/httpapi/miscpublicapi/announce.py b/onionr/httpapi/miscpublicapi/announce.py index a6d9513f..8a25b635 100644 --- a/onionr/httpapi/miscpublicapi/announce.py +++ b/onionr/httpapi/miscpublicapi/announce.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Handle announcements to the public API server ''' diff --git a/onionr/httpapi/miscpublicapi/getblocks.py b/onionr/httpapi/miscpublicapi/getblocks.py index 1ab8f949..fa9dde14 100644 --- a/onionr/httpapi/miscpublicapi/getblocks.py +++ b/onionr/httpapi/miscpublicapi/getblocks.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Public endpoints to get block data and lists ''' diff --git a/onionr/httpapi/miscpublicapi/upload.py b/onionr/httpapi/miscpublicapi/upload.py index 0561ed08..5fd0f32c 100644 --- a/onionr/httpapi/miscpublicapi/upload.py +++ b/onionr/httpapi/miscpublicapi/upload.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Accept block uploads to the public API server ''' diff --git a/onionr/httpapi/profilesapi/__init__.py b/onionr/httpapi/profilesapi/__init__.py index f3c3ba2f..681212be 100644 --- a/onionr/httpapi/profilesapi/__init__.py +++ b/onionr/httpapi/profilesapi/__init__.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This file creates http endpoints for user profile pages ''' diff --git a/onionr/onionr.py b/onionr/onionr.py index a12250cc..c73edb4b 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -208,7 +208,7 @@ class Onionr: commands.onionrstatistics.show_details(self) def openHome(self): - commands.open_home(self) + commands.openwebinterface.open_home(self) def addID(self): commands.pubkeymanager.add_ID(self) diff --git a/onionr/onionrcommands/README.md b/onionr/onionrcommands/README.md new file mode 100644 index 00000000..a817cc7f --- /dev/null +++ b/onionr/onionrcommands/README.md @@ -0,0 +1,25 @@ +# onionrcommands + +This module contains handlers/functions for Onionr cli interface commands. + +## Files + +__init__.py: stores the command references (aside from plugins) and help info. + +banblocks.py: command handler for manually removing blocks from one's node + +daemonlaunch.py: command to run Onionr (start the api servers, tor and communicator) + +exportblocks.py: command to export an onionr block to the export folder. Exported blocks can be manually shared outside of the Onionr network + +filecommands.py commands to insert and fetch files from the Onionr network + +keyadders.py: commands to add an onionr user key or transport address + +onionrstatistics.py: commands to print out various information about one's Onionr node + +openwebinterface.py: command to open the web interface (useful because it requires a randomly generated token) + +plugincommands.py: commands to enable/disable/reload plugins + +pubkeymanager.py: commands to generate a new onionr user id, change the active id, or add/remove/list friends \ No newline at end of file diff --git a/onionr/onionrcommands/__init__.py b/onionr/onionrcommands/__init__.py index e929499f..e561292c 100644 --- a/onionr/onionrcommands/__init__.py +++ b/onionr/onionrcommands/__init__.py @@ -20,7 +20,8 @@ import webbrowser, sys import logger -from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders, banblocks, exportblocks +from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders +from . import banblocks, exportblocks, openwebinterface def show_help(o_inst, command): @@ -39,16 +40,6 @@ def show_help(o_inst, command): for command, helpmessage in helpmenu.items(): o_inst.showHelp(command) -def open_home(o_inst): - try: - url = o_inst.onionrUtils.getClientAPIServer() - except FileNotFoundError: - logger.error('Onionr seems to not be running (could not get api host)') - else: - url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword')) - print('If Onionr does not open automatically, use this URL:', url) - webbrowser.open_new_tab(url) - def get_commands(onionr_inst): return {'': onionr_inst.showHelpSuggestion, 'help': onionr_inst.showHelp, diff --git a/onionr/onionrcommands/banblocks.py b/onionr/onionrcommands/banblocks.py index 474353f6..a9caa867 100644 --- a/onionr/onionrcommands/banblocks.py +++ b/onionr/onionrcommands/banblocks.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This file contains the command for banning blocks from the node ''' diff --git a/onionr/onionrcommands/daemonlaunch.py b/onionr/onionrcommands/daemonlaunch.py index 98708258..4b343ede 100644 --- a/onionr/onionrcommands/daemonlaunch.py +++ b/onionr/onionrcommands/daemonlaunch.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication launch the api server and communicator ''' diff --git a/onionr/onionrcommands/filecommands.py b/onionr/onionrcommands/filecommands.py index f9d05f01..444fd147 100644 --- a/onionr/onionrcommands/filecommands.py +++ b/onionr/onionrcommands/filecommands.py @@ -1,3 +1,23 @@ +''' + Onionr - Private P2P Communication + + This file handles the commands for adding and getting files from the Onionr network +''' +''' + 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 . +''' + import base64, sys, os import logger from onionrblockapi import Block diff --git a/onionr/onionrcommands/keyadders.py b/onionr/onionrcommands/keyadders.py index d52b81f9..0edda6b0 100644 --- a/onionr/onionrcommands/keyadders.py +++ b/onionr/onionrcommands/keyadders.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication add keys (transport and pubkey) ''' diff --git a/onionr/onionrcommands/onionrstatistics.py b/onionr/onionrcommands/onionrstatistics.py index 8430a524..0974b290 100644 --- a/onionr/onionrcommands/onionrstatistics.py +++ b/onionr/onionrcommands/onionrstatistics.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This module defines commands to show stats/details about the local node ''' diff --git a/onionr/httpapi/simplecache/__init__.py b/onionr/onionrcommands/openwebinterface.py old mode 100755 new mode 100644 similarity index 55% rename from onionr/httpapi/simplecache/__init__.py rename to onionr/onionrcommands/openwebinterface.py index 75a645a0..823703a0 --- a/onionr/httpapi/simplecache/__init__.py +++ b/onionr/onionrcommands/openwebinterface.py @@ -1,7 +1,7 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication - This file creates http endpoints for friend management + Open the web interface properly into a web browser ''' ''' This program is free software: you can redistribute it and/or modify @@ -17,15 +17,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import core -from flask import Blueprint, Response, request, abort - -simplecache = Blueprint('simplecache', __name__) - -@simplecache.route('/get/') -def get_key(key): - return - -@simplecache.route('/set/', methods=['POST']) -def set_key(key): - return \ No newline at end of file +import webbrowser +import logger +def open_home(o_inst): + try: + url = o_inst.onionrUtils.getClientAPIServer() + except FileNotFoundError: + logger.error('Onionr seems to not be running (could not get api host)') + else: + url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword')) + print('If Onionr does not open automatically, use this URL:', url) + webbrowser.open_new_tab(url) \ No newline at end of file diff --git a/onionr/onionrcommands/plugincommands.py b/onionr/onionrcommands/plugincommands.py index c357956f..e4f88d96 100644 --- a/onionr/onionrcommands/plugincommands.py +++ b/onionr/onionrcommands/plugincommands.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication plugin CLI commands ''' @@ -30,7 +30,6 @@ def enable_plugin(o_inst): logger.info('%s %s ' % (sys.argv[0], sys.argv[1])) def disable_plugin(o_inst): - if len(sys.argv) >= 3: plugin_name = sys.argv[2] logger.info('Disabling plugin "%s"...' % plugin_name) diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py index 00d17175..a294396b 100644 --- a/onionr/onionrcommands/pubkeymanager.py +++ b/onionr/onionrcommands/pubkeymanager.py @@ -1,7 +1,7 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication - This module defines ID-related CLI commands + This module defines user ID-related CLI commands ''' ''' This program is free software: you can redistribute it and/or modify @@ -51,7 +51,7 @@ def change_ID(o_inst): try: key = sys.argv[2] except IndexError: - logger.error('Specify pubkey to use') + logger.warn('Specify pubkey to use') else: if o_inst.onionrUtils.validatePubKey(key): if key in o_inst.onionrCore._crypto.keyManager.getPubkeyList(): @@ -60,9 +60,9 @@ def change_ID(o_inst): logger.info('Set active key to: %s' % (key,)) logger.info('Restart Onionr if it is running.') else: - logger.error('That key does not exist') + logger.warn('That key does not exist') else: - logger.error('Invalid key %s' % (key,)) + logger.warn('Invalid key %s' % (key,)) def friend_command(o_inst): friend = '' @@ -86,7 +86,8 @@ def friend_command(o_inst): raise onionrexceptions.KeyNotKnown friend = onionrusers.OnionrUser(o_inst.onionrCore, friend) except IndexError: - logger.error('Friend ID is required.') + logger.warn('Friend ID is required.') + action = 'error' # set to 'error' so that the finally block does not process anything except onionrexceptions.KeyNotKnown: o_inst.onionrCore.addPeer(friend) friend = onionrusers.OnionrUser(o_inst.onionrCore, friend) @@ -94,7 +95,7 @@ def friend_command(o_inst): if action == 'add': friend.setTrust(1) logger.info('Added %s as friend.' % (friend.publicKey,)) - else: + elif action == 'remove': friend.setTrust(0) logger.info('Removed %s as friend.' % (friend.publicKey,)) else: diff --git a/onionr/onionrfragment/__init__.py b/onionr/onionrfragment/__init__.py deleted file mode 100755 index c8386465..00000000 --- a/onionr/onionrfragment/__init__.py +++ /dev/null @@ -1,73 +0,0 @@ -''' - Onionr - P2P Anonymous Storage Network - - This file contains the OnionrFragment class which implements the fragment system -''' -''' - 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 . -''' - -# onionr:10ch+10ch+10chgdecryptionkey -import core, sys, binascii, os - -FRAGMENT_SIZE = 0.25 -TRUNCATE_LENGTH = 30 - -class OnionrFragment: - def __init__(self, uri=None): - uri = uri.replace('onionr:', '') - count = 0 - blocks = [] - appendData = '' - key = '' - for x in uri: - if x == 'k': - key = uri[uri.index('k') + 1:] - appendData += x - if count == TRUNCATE_LENGTH: - blocks.append(appendData) - appendData = '' - count = 0 - count += 1 - self.key = key - self.blocks = blocks - return - - @staticmethod - def generateFragments(data=None, coreInst=None): - if coreInst is None: - coreInst = core.Core() - - key = os.urandom(32) - data = coreInst._crypto.symmetricEncrypt(data, key).decode() - blocks = [] - blockData = b"" - uri = "onionr:" - total = sys.getsizeof(data) - for x in data: - blockData += x.encode() - if round(len(blockData) / len(data), 3) > FRAGMENT_SIZE: - blocks.append(core.Core().insertBlock(blockData)) - blockData = b"" - - for bl in blocks: - uri += bl[:TRUNCATE_LENGTH] - uri += "k" - uri += binascii.hexlify(key).decode() - return (uri, key) - -if __name__ == '__main__': - uri = OnionrFragment.generateFragments("test")[0] - print(uri) - OnionrFragment(uri) \ No newline at end of file diff --git a/onionr/onionrservices/__init__.py b/onionr/onionrservices/__init__.py index 2faa4cdd..2792f7e3 100644 --- a/onionr/onionrservices/__init__.py +++ b/onionr/onionrservices/__init__.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication Onionr services provide the server component to direct connections ''' diff --git a/onionr/onionrservices/bootstrapservice.py b/onionr/onionrservices/bootstrapservice.py index 160b716d..077b4657 100644 --- a/onionr/onionrservices/bootstrapservice.py +++ b/onionr/onionrservices/bootstrapservice.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication Bootstrap onion direct connections for the clients ''' diff --git a/onionr/onionrservices/httpheaders.py b/onionr/onionrservices/httpheaders.py index 2b2c1770..63c4a6ad 100644 --- a/onionr/onionrservices/httpheaders.py +++ b/onionr/onionrservices/httpheaders.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication Set default onionr http headers '''