Philipp Hörist pushed to branch master at gajim / python-nbxmpp

Commits:

1 changed file:

Changes:

  • nbxmpp/modules/openpgp.py
    ... ... @@ -23,6 +23,7 @@ from nbxmpp.namespaces import Namespace
    23 23
     from nbxmpp.protocol import NodeProcessed
    
    24 24
     from nbxmpp.protocol import Node
    
    25 25
     from nbxmpp.protocol import StanzaMalformed
    
    26
    +from nbxmpp.protocol import JID
    
    26 27
     from nbxmpp.util import b64decode
    
    27 28
     from nbxmpp.util import b64encode
    
    28 29
     from nbxmpp.structs import StanzaHandler
    
    ... ... @@ -275,9 +276,17 @@ def parse_signcrypt(stanza):
    275 276
                 stanza.getNamespace() != Namespace.OPENPGP):
    
    276 277
             raise StanzaMalformed('Invalid signcrypt node')
    
    277 278
     
    
    278
    -    to = stanza.getTagAttr('to', 'jid')
    
    279
    -    if to is None:
    
    280
    -        raise StanzaMalformed('Invalid to attr')
    
    279
    +    to_nodes = stanza.getTags('to')
    
    280
    +    if not to_nodes:
    
    281
    +        raise StanzaMalformed('missing to nodes')
    
    282
    +
    
    283
    +    recipients = []
    
    284
    +    for to_node in to_nodes:
    
    285
    +        jid = to_node.getAttr('jid')
    
    286
    +        try:
    
    287
    +            recipients.append(JID.from_string(jid))
    
    288
    +        except Exception as error:
    
    289
    +            raise StanzaMalformed('Invalid jid: %s %s' % (jid, error))
    
    281 290
     
    
    282 291
         timestamp = stanza.getTagAttr('time', 'stamp')
    
    283 292
         if timestamp is None:
    
    ... ... @@ -286,10 +295,10 @@ def parse_signcrypt(stanza):
    286 295
         payload = stanza.getTag('payload')
    
    287 296
         if payload is None or payload.getChildren() is None:
    
    288 297
             raise StanzaMalformed('Invalid payload node')
    
    289
    -    return payload.getChildren(), to, timestamp
    
    298
    +    return payload.getChildren(), recipients, timestamp
    
    290 299
     
    
    291 300
     
    
    292
    -def create_signcrypt_node(stanza, not_encrypted_nodes):
    
    301
    +def create_signcrypt_node(stanza, recipients, not_encrypted_nodes):
    
    293 302
         '''
    
    294 303
         <signcrypt xmlns='urn:xmpp:openpgp:0'>
    
    295 304
           <to jid='juliet@example.org'/>
    
    ... ... @@ -314,7 +323,8 @@ def create_signcrypt_node(stanza, not_encrypted_nodes):
    314 323
                 stanza.delChild(node)
    
    315 324
     
    
    316 325
         signcrypt = Node('signcrypt', attrs={'xmlns': Namespace.OPENPGP})
    
    317
    -    signcrypt.addChild('to', attrs={'jid': str(stanza.getTo().bare)})
    
    326
    +    for recipient in recipients:
    
    327
    +        signcrypt.addChild('to', attrs={'jid': str(recipient)})
    
    318 328
     
    
    319 329
         timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
    
    320 330
         signcrypt.addChild('time', attrs={'stamp': timestamp})