def _create_signature(self, jid, action): row = lookup_client_by_jid(jid) if not row: log_debug(3, 'no client found for jid', jid) if self.debug_level > 5: raise Exception(1) return None full_jid = row['jabber_id'] shared_key = row['shared_key'] attrs = { 'timestamp' : int(time.time()), 'serial' : self.get_unique_id(), 'action' : action, 'jid' : self.jid, } signing_comps = ['timestamp', 'serial', 'action', 'jid'] args = [shared_key, full_jid] for sc in signing_comps: args.append(attrs[sc]) log_debug(4, "Signature args", args) attrs['signature'] = jabber_lib.sign(*args) x = jabber_lib.jabber.xmlstream.Node('x') x.setNamespace(jabber_lib.NS_RHN_SIGNED) for k, v in attrs.items(): x.putAttr(k, v) return x
def _check_signature(self, stanza, actions=None): # Do we have this client in the table? jid = stanza.getFrom() if jid is None: log_debug(3, 'no from') return None jid = str(self._fix_jid(jid)) # Look for a <x> child that has our namespace xes = stanza.getTags('x') for x in xes: if x.getNamespace() != jabber_lib.NS_RHN_SIGNED: continue break else: #for log_debug(1, "No signature node found in stanza") return None # We now have our signature node x_client_id = x.getAttr('client-id') row = lookup_client_by_name(x_client_id) if not row: log_debug(3, 'no client found', x_client_id) if self.debug_level > 5: raise Exception(1) return None shared_key = row['shared_key'] timestamp = x.getAttr('timestap') serial = x.getAttr('serial') action = x.getAttr('action') if actions and action not in actions: log_debug(1, "action %s not allowed" % action) return None attrs = { 'client-id' : x_client_id, 'timestamp' : x.getAttr('timestamp'), 'serial' : x.getAttr('serial'), 'action' : x.getAttr('action'), 'jid' : jid, } signing_comps = ['client-id', 'timestamp', 'serial', 'action', 'jid'] args = [shared_key, self.jid] for sc in signing_comps: args.append(attrs[sc]) log_debug(4, "Signature args", args) signature = jabber_lib.sign(*args) x_signature = x.getAttr('signature') if signature != x_signature: log_debug(1, "Signatures do not match", signature, x_signature) if self.debug_level > 5: raise Exception(1) return None # Happy joy return x