/usr/share/pyshared/MoinMoin/util/moinoid.py is in python-moinmoin 1.9.3-1ubuntu2.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | """
MoinMoin - OpenID utils
@copyright: 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
@license: GNU GPL, see COPYING for details.
"""
from random import randint
import time
from openid import oidutil
from openid.store.interface import OpenIDStore
from openid.association import Association
from openid.store import nonce
from MoinMoin import caching
from MoinMoin.support.python_compatibility import hash_new
from MoinMoin import log
logging = log.getLogger(__name__)
# redirect openid logging to moin log
def log(msg, level=0):
logging.log(level, msg)
oidutil.log = log
def strbase64(value):
from base64 import encodestring
return encodestring(str(value)).replace('\n', '')
def _cleanup_nonces(request):
cachelist = caching.get_cache_list(request, 'openid-nonce', 'farm')
# really openid should have a method to check this...
texpired = time.time() - nonce.SKEW
for name in cachelist:
entry = caching.CacheEntry(request, 'openid-nonce', name,
scope='farm', use_pickle=False)
try:
timestamp = int(entry.content())
if timestamp < texpired:
entry.remove()
except caching.CacheError:
pass
class MoinOpenIDStore(OpenIDStore):
'''OpenIDStore for MoinMoin'''
def __init__(self, request):
self.request = request
OpenIDStore.__init__(self)
def key(self, url):
'''return cache key'''
return hash_new('sha1', url).hexdigest()
def storeAssociation(self, server_url, association):
ce = caching.CacheEntry(self.request, 'openid', self.key(server_url),
scope='wiki', use_pickle=True)
if ce.exists():
assocs = ce.content()
else:
assocs = []
assocs += [association.serialize()]
ce.update(assocs)
def getAssociation(self, server_url, handle=None):
ce = caching.CacheEntry(self.request, 'openid', self.key(server_url),
scope='wiki', use_pickle=True)
if not ce.exists():
return None
assocs = ce.content()
found = False
for idx in xrange(len(assocs)-1, -1, -1):
assoc_str = assocs[idx]
association = Association.deserialize(assoc_str)
if association.getExpiresIn() == 0:
del assocs[idx]
else:
if handle is None or association.handle == handle:
found = True
break
ce.update(assocs)
if found:
return association
return None
def removeAssociation(self, server_url, handle):
ce = caching.CacheEntry(self.request, 'openid', self.key(server_url),
scope='wiki', use_pickle=True)
if not ce.exists():
return
assocs = ce.content()
for idx in xrange(len(assocs)-1, -1, -1):
assoc_str = assocs[idx]
association = Association.deserialize(assoc_str)
if association.handle == handle:
del assocs[idx]
if len(assocs):
ce.update(assocs)
else:
ce.remove()
def useNonce(self, server_url, timestamp, salt):
val = ''.join([str(server_url), str(timestamp), str(salt)])
csum = hash_new('sha1', val).hexdigest()
ce = caching.CacheEntry(self.request, 'openid-nonce', csum,
scope='farm', use_pickle=False)
if ce.exists():
# nonce already used!
return False
ce.update(str(timestamp))
if randint(0, 999) == 0:
self.request.add_finisher(_cleanup_nonces)
return True
|