Commit 66fa2bf0 authored by user's avatar user
Browse files

ivrad

parent dc5e90f6
......@@ -2,6 +2,8 @@
*.tmp
*.swp
.gitmodules.bak
*.pid
*.pyc
gstreamer/
tmp/
ABBA Lay All Your Love On Me High Definition.
......@@ -26,3 +28,7 @@ sopel/sopel-ifmchat.pid
sopel/sopel-leftover.pid
sopel/sopel-sopel.pid
leftover/shouts.txt
sopel/bot_${ircprefix}_${hostname}-irc.indymedia.org.tell.db
sopel/indymedia.db
sopel/leftoverbot-irc.indymedia.org.tell.db
#from datetime import utcfromtimestamp
import datetime
from itsdangerous import TimestampSigner
from requests import RequestException
#from flask_unsign import logger, FlaskUnsignException
from itsdangerous import base64_decode, base64_encode, want_bytes
from itsdangerous.encoding import bytes_to_int, int_to_bytes, _base64_alphabet
from itsdangerous.signer import HMACAlgorithm
class CustomTimestampSigner(TimestampSigner):
"""
choose time
"""
def __init__(
self,
secret_key,
salt=None,
sep=".",
key_derivation=None,
digest_method=None,
algorithm=None,
timestamp=None,
**kwargs
):
self.secret_key = want_bytes(secret_key)
self.sep = want_bytes(sep)
self.timestamp = timestamp
if self.sep in _base64_alphabet:
raise ValueError(
"The given separator cannot be used because it may be"
" contained in the signature itself. Alphanumeric"
" characters and `-_=` must not be used."
)
self.salt = "itsdangerous.Signer" if salt is None else salt
print('incustomsigner')
if key_derivation is None:
key_derivation = self.default_key_derivation
self.key_derivation = key_derivation
if digest_method is None:
digest_method = self.default_digest_method
self.digest_method = digest_method
if algorithm is None:
algorithm = HMACAlgorithm(self.digest_method)
self.algorithm = algorithm
def get_timestamp(self):
#print('get_timestamp: ' + str(datetime.utcfromtimestamp(self.timestamp)))
return int(self.timestamp)
#
# def timestamp_to_datetime(self, ts):
# dt = datetime.utcfromtimestamp(timestamp)
# return dt
#!/usr/bin/env python
import hmac
from hashlib import sha512
import json
......@@ -12,6 +13,7 @@ from six import text_type
#from flask.json.tag import TaggedJSONSerializer
from tagjson import TaggedJSONSerializer
from itsdangerous.encoding import bytes_to_int, int_to_bytes
from signer import CustomTimestampSigner
from itsdangerous import base64_decode, base64_encode, want_bytes, URLSafeTimedSerializer, BadSignature, TimestampSigner
import hashlib
......@@ -78,40 +80,24 @@ class Shortly(object):
return payload
def get_serializer(self):
ts=1574108432
return URLSafeTimedSerializer(
secret_key='We are the world',
salt='cookie-session',
serializer=TaggedJSONSerializer(),
signer=TimestampSigner,
signer=CustomTimestampSigner,
signer_kwargs={
'key_derivation': 'hmac',
'timestamp': ts,
'digest_method': hashlib.sha1})
def dispatch_request(self, request):
print(request.cookies)
ra = self._get_remote_addr(request)
#print(ra)
ua = request.headers.get('User-Agent')
cookieid = self.create_identifier(ua, ra)
print('identifier: ' + cookieid)
session = dict()
session['_fresh'] = True
session['_id'] = cookieid
session['user_id'] = 26
#print('cookieid: ' + cookieid)
#print('session: ' + str(session))
#b64c = base64_encode(cookieid)
#b64d = self.get_serializer().dumps(session)
#return json.loads(data), timestamp
#print('session b64: ', str(b64d))
## try decoding
def test_decode(self, payload):
compressed = False
payload = self.get_serializer().dumps(session)
print('payload: ' + payload)
# rcvdpayload = self.get_serializer().dumps(session)
# print('rcvdpayload: ' + rcvdpayload)
if payload.startswith('.'):
print('compressed')
......@@ -119,7 +105,7 @@ class Shortly(object):
payload = payload[1:]
data = payload.split(".")[0]
print('dataaftersplit: ' + data)
data = base64_decode(data)
date64 = payload.split(".")[1]
......@@ -132,7 +118,37 @@ class Shortly(object):
data = data.decode("utf-8")
print('decoded: ' + data + ' ts: ' + str(timestamp) + ' digest: ' + str(sig64))
#print('decoded: ' + base64_decode(json.loads(b64d, object_hook=self.hook)))
return data
def dispatch_request(self, request):
rcvdcookie = request.cookies['session']
ra = self._get_remote_addr(request)
#print(ra)
ua = request.headers.get('User-Agent')
cookieid = self.create_identifier(ua, ra)
#print('identifier: ' + cookieid)
session = dict()
session['_fresh'] = True
session['_id'] = cookieid
session['user_id'] = 16
#print('cookieid: ' + cookieid)
#print('session: ' + str(session))
#b64c = base64_encode(cookieid)
#b64d = self.get_serializer().dumps(session)
#return json.loads(data), timestamp
#print('session b64: ', str(b64d))
payload = self.get_serializer().dumps(session)
#payload = rcvdcookie
print('payload: ' + payload)
self.test_decode(payload)
self.test_decode(rcvdcookie)
## try decoding
#print('decoded: ' + base64_decode(json.loads(b64d, object_hook=self.hook)))
#print('decoded: ' + base64_decode(json.loads(b64d, object_hook=self.hook)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment