added 401 handler, work on storing/sending data

master
Kevin Froman 2018-01-21 20:49:11 -06:00
parent 5af2b99135
commit f46e7ea965
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 21 additions and 2 deletions

View File

@ -130,7 +130,10 @@ class API:
elif action == 'getPGP': elif action == 'getPGP':
resp = Response(self._utils.exportMyPubkey()) resp = Response(self._utils.exportMyPubkey())
elif action == 'setData': elif action == 'setData':
pass if data == None:
abort(401)
else:
self._core.setData(data)
elif action == 'getData': elif action == 'getData':
resp = Response(self._core.getData(data)) resp = Response(self._core.getData(data))
@ -147,6 +150,11 @@ class API:
self.requestFailed = True self.requestFailed = True
resp = Response("403") resp = Response("403")
return resp 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('Starting client on ' + self.host + ':' + str(bindPort))
print('Client token:', self.clientToken) print('Client token:', self.clientToken)

View File

@ -17,11 +17,18 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
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.Cipher import AES
from Crypto import Random from Crypto import Random
import netcontroller 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: class Core:
def __init__(self): def __init__(self):
''' '''
@ -125,6 +132,10 @@ class Core:
dataFile.close() dataFile.close()
return data return data
def setData(self, data):
'''set the data assciated with a hash'''
hasher = hashlib.sha3_256
def dataDirEncrypt(self, password): def dataDirEncrypt(self, password):
''' '''
Encrypt the data directory on Onionr shutdown Encrypt the data directory on Onionr shutdown