40 lines
876 B
Python
Executable File
40 lines
876 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
## Single endpoint encrypted api
|
|
|
|
from flask import Flask
|
|
from flask import request
|
|
from hashlib import sha256
|
|
|
|
|
|
keys = {
|
|
'key1': 'user1',
|
|
'key2': 'user2'
|
|
}
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/<hex_hash>", methods=['post'])
|
|
def endpoint(hex_hash):
|
|
content_type = request.headers.get('content_type')
|
|
if content_type == 'application/json':
|
|
body = request.json
|
|
enc_data = body['foo']
|
|
|
|
## decrypt the enc_data
|
|
dec_data = enc_data
|
|
|
|
## Get checksum to compare against
|
|
dec_data_hash = sha256(dec_data.encode('utf-8')).hexdigest()
|
|
r_hash = hex_hash.encode('utf-8')
|
|
print('if', r_hash, '==', dec_data_hash)
|
|
|
|
response = "message: ", enc_data, "checksum: ", dec_data_hash
|
|
print(response)
|
|
return "YES"
|
|
else:
|
|
return 'Content-Type not supported'
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|