aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-06-01 01:22:16 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2011-06-01 01:22:16 -0400
commitd4ecf728109619d34c1781a069793a37c8d9b8e7 (patch)
tree8abd81609001b3305d20d4be2c6b27cf2742394b /server
parentcdc4ec8d31b826222d970fb37e3e101cd4f86a77 (diff)
downloadalias-d4ecf728109619d34c1781a069793a37c8d9b8e7.tar.gz
Fixes to handle alias queries on the server side
should work with code fixed by zaran, just need to build an user directory with the right objects.
Diffstat (limited to 'server')
-rw-r--r--server/alias_plugin.py29
-rw-r--r--server/object.py10
-rw-r--r--server/user.py3
3 files changed, 17 insertions, 25 deletions
diff --git a/server/alias_plugin.py b/server/alias_plugin.py
index 2001b1b..0b56438 100644
--- a/server/alias_plugin.py
+++ b/server/alias_plugin.py
@@ -14,11 +14,11 @@ from object import ObjectReader, ObjectError
from permission import PermissionError
class AliasQuery(ElementBase):
- namespace = 'alias:query'
+ namespace = 'alias:iq:object'
name = 'query'
plugin_attrib = 'alias'
interfaces = set(('node', 'type', 'content', 'permission', 'key'))
- sub_interfaces = set(('content', 'permission', 'key', 'salt'))
+ sub_interfaces = set(('content', 'permission', 'key'))
def addItem(self, node, key, permission = None):
item = AliasItem(None, self)
@@ -57,14 +57,6 @@ class AliasPlugin(base.base_plugin):
def handle_alias_query(self, iq):
caller = iq['from'].bare
-
- if iq['alias']['type'] == 'keys':
- key, salt = ObjectReader(caller).get_private_key();
- iq.reply()
- iq['alias']['type'] = 'keys'
- iq['alias']['key'] = key
- iq['alias']['salt'] = salt
- iq.send()
try:
callee = base64.b64decode(iq['to'].user)
@@ -72,24 +64,23 @@ class AliasPlugin(base.base_plugin):
logger.error("callee field not base64 encoded")
node = iq['alias']['node']
- node = ObjectReader(callee, node)
-
- if iq['alias']['type'] == 'items':
+ node = ObjectReader(node, callee)
+ if iq['alias']['type'] == 'get':
try:
- childs = node.get_child_list(caller)
+ content, key = node.get_content(caller)
except PermissionError:
self.send_permission_error(iq, 'Permission')
else:
iq.reply()
- iq['alias']['type'] = 'items'
+ iq['alias']['type'] = 'get'
iq['alias']['node'] = node.hash
- for name, perm, key in childs:
- iq['alias'].addItem(name, key, perm)
+ iq['alias']['content'] = content
+ iq['alias']['key'] = key
iq.send()
- if iq['alias']['type'] == 'content':
+ if iq['alias']['type'] == 'list':
try:
- content, key = node.get_content(caller)
+ list = node.get_children_list(caller)
except PermissionError:
self.send_permission_error(iq, 'Permission')
else:
diff --git a/server/object.py b/server/object.py
index 4c1e0c1..31de622 100644
--- a/server/object.py
+++ b/server/object.py
@@ -58,9 +58,9 @@ class ObjectReader(Object):
return (int(perm), key)
return (None, None)
- def get_child_list(self, user):
+ def get_children_list(self, user):
perm = self.get_permission(user)
- if not perm & LIST:
+ if not perm or (not perm & LIST):
logger.error("User {} doesn't have the list permission for object {}"
.format(user, self.hash))
raise PermissionError
@@ -84,7 +84,7 @@ class ObjectReader(Object):
def get_content(self, user):
"""Return object content and the user key to decrypt it."""
perm, key = self.get_permission_key(user)
- if not perm & READ :
+ if not perm or (not perm & READ) :
logger.error("User {} doesn't have read access to object {}"
.format(user, self.hash))
raise PermissionError
@@ -113,7 +113,7 @@ class ObjectWriter(ObjectReader):
def write(self, user, content):
perm = self.get_permission(user)
- if not perm & MODIFY:
+ if not perm or (not perm & MODIFY):
logger.error("User {} doesn't have the modify permission for object {}"
.format(user, self.hash))
raise PermissionError
@@ -123,7 +123,7 @@ class ObjectWriter(ObjectReader):
def append(self, user, content, parent):
parent_object = ObjectReader(parent, self.owner)
perm = parent_object.get_permission(user)
- if not perm & APPEND:
+ if not perm or (not perm & APPEND):
logger.error("User {} doesn't have the modify permission for object {}"
.format(user, parent))
raise PermissionError
diff --git a/server/user.py b/server/user.py
index 7f01149..2909c16 100644
--- a/server/user.py
+++ b/server/user.py
@@ -11,7 +11,8 @@ class User:
def __init__(self, jid):
self.jid = jid
- self.hash = hashlib.sha1(jid).hexdigest()
+ self.hash = hashlib.sha256(jid).hexdigest()
+ #self.hash = hashlib.md5(jid).hexdigest()
def register(self, registration):
ObjectWriter('pubkey', self.jid, split_name = False).write(self.jid, registration['pubkey'])