Adding digital signature check for SSE API
This commit is contained in:
parent
797d2b08a2
commit
b180e5aa85
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
wsgi.py
|
wsgi.py
|
||||||
*.swp
|
*.swp
|
||||||
|
config.py
|
||||||
|
.idea/
|
||||||
|
|||||||
2
config-example.py
Normal file
2
config-example.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dbfolder = ''
|
||||||
|
sse_pubKey = '<public key in the format of pybtc python library>'
|
||||||
@ -9,8 +9,10 @@ from quart_cors import cors
|
|||||||
import asyncio
|
import asyncio
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from pybtc import verify_signature
|
||||||
|
from config import *
|
||||||
|
|
||||||
|
|
||||||
dbfolder = ''
|
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
app = cors(app)
|
app = cors(app)
|
||||||
app.clients = set()
|
app.clients = set()
|
||||||
@ -436,10 +438,14 @@ async def index():
|
|||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
async def broadcast():
|
async def broadcast():
|
||||||
|
signature = request.headers.get('Signature')
|
||||||
data = await request.get_json()
|
data = await request.get_json()
|
||||||
for queue in app.clients:
|
if verify_signature(signature, sse_pubKey, data['message'].encode()):
|
||||||
await queue.put(data['message'])
|
for queue in app.clients:
|
||||||
return jsonify(True)
|
await queue.put(data['message'])
|
||||||
|
return jsonify(True)
|
||||||
|
else:
|
||||||
|
return jsonify(False)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/sse')
|
@app.route('/sse')
|
||||||
@ -467,7 +473,7 @@ async def sse():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=False, port=5010)
|
app.run(debug=True, port=5010)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user