diff --git a/onionr/api.py b/onionr/api.py index 29f8282f..6b45f97e 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -130,7 +130,10 @@ class API: elif action == 'getPGP': resp = Response(self._utils.exportMyPubkey()) elif action == 'setData': - pass + if data == None: + abort(401) + else: + self._core.setData(data) elif action == 'getData': resp = Response(self._core.getData(data)) @@ -147,6 +150,11 @@ class API: self.requestFailed = True resp = Response("403") return resp + @app.errorhandler(401) + def clientError(err): + self.requestFailed = True + resp = Response("Invalid request") + return resp print('Starting client on ' + self.host + ':' + str(bindPort)) print('Client token:', self.clientToken) diff --git a/onionr/core.py b/onionr/core.py index 0c476217..0264c13a 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -17,11 +17,18 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import sqlite3, os, time, math, gnupg, base64, tarfile, getpass, simplecrypt +import sqlite3, os, time, math, gnupg, base64, tarfile, getpass, simplecrypt, hashlib from Crypto.Cipher import AES from Crypto import Random import netcontroller +if sys.version_info < (3, 6): + try: + import sha3 + except ModuleNotFoundError: + sys.stderr.write('On Python 3 versions prior to 3.6.x, you need the sha3 module') + sys.exit(1) + class Core: def __init__(self): ''' @@ -125,6 +132,10 @@ class Core: dataFile.close() return data + def setData(self, data): + '''set the data assciated with a hash''' + hasher = hashlib.sha3_256 + def dataDirEncrypt(self, password): ''' Encrypt the data directory on Onionr shutdown