How to use the nbxmpp.c14n.c14n function in nbxmpp

To help you get started, we’ve selected a few nbxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajim / gajim / gajim / common / stanza_session.py View on Github external
self.n_s = crypto.generate_nonce()

        x.addChild(node=nbxmpp.DataField(name='my_nonce',
            value=base64.b64encode(self.n_s).decode('utf-8'), typ='hidden'))

        modp_options = [ int(g) for g in app.config.get('esession_modp').split(
            ',') ]

        x.addChild(node=nbxmpp.DataField(name='modp', typ='list-single',
            options=[[None, y] for y in modp_options]))

        x.addChild(node=self.make_dhfield(modp_options, sigmai))
        self.sigmai = sigmai

        self.form_s = ''.join(nbxmpp.c14n.c14n(el, self._is_buggy_gajim()) for \
            el in x.getChildren())

        feature.addChild(node=x)

        self.status = 'requested-e2e'

        self.send(request)
github gajim / gajim / gajim / common / stanza_session.py View on Github external
def make_identity(self, form, dh_i):
        if self.negotiated['send_pubkey']:
            if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'):
                pubkey = secrets.secrets().my_pubkey(self.conn.name)
                fields = (pubkey.n, pubkey.e)

                cb_fields = [base64.b64encode(crypto.encode_mpi(f)) for f in
                    fields]

                pubkey_s = b'%s%s' % \
                    tuple(cb_fields)
        else:
            pubkey_s = b''

        form_s2 = ''.join(nbxmpp.c14n.c14n(el, self._is_buggy_gajim()) for el \
            in form.getChildren())

        old_c_s = self.c_s
        content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_s + \
            self.form_s.encode('utf-8') + form_s2.encode('utf-8')

        mac_s = self.hmac(self.ks_s, content)

        if self.negotiated['send_pubkey']:
            signature = self.sign(mac_s)

            sign_s = ''
            '%s' % base64.b64encode(signature)

            if self.negotiated['send_pubkey'] == 'hash':
                b64ed = base64.b64encode(self.hash(pubkey_s))
github gajim / gajim / gajim / common / stanza_session.py View on Github external
plaintext = self.decrypt(id_o)
            parsed = nbxmpp.Node(node='' + plaintext + '')

            if self.negotiated['recv_pubkey'] == 'hash':
                # fingerprint = parsed.getTagData('fingerprint')
                # FIXME find stored pubkey or terminate session
                raise NotImplementedError()
            else:
                if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'):
                    keyvalue = parsed.getTag(name='RSAKeyValue', namespace=XmlDsig)

                    n, e = (crypto.decode_mpi(base64.b64decode(
                            keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent'))
                    eir_pubkey = RSA.construct((n, int(e)))

                    pubkey_o = nbxmpp.c14n.c14n(keyvalue, self._is_buggy_gajim())
                else:
                    # FIXME DSA, etc.
                    raise NotImplementedError()

            enc_sig = parsed.getTag(name='SignatureValue',
                    namespace=XmlDsig).getData()
            signature = (crypto.decode_mpi(base64.b64decode(enc_sig)), )
        else:
            mac_o = self.decrypt(id_o)
            pubkey_o = b''

        c7l_form = self.c7lize_mac_id(form)

        content = self.n_s + self.n_o + crypto.encode_mpi(dh_i) + pubkey_o

        if sigmai:
github gajim / gajim / gajim / common / stanza_session.py View on Github external
self.jid.getStripped())
            rshashes = [self.hmac(self.n_s, rs[0]) for rs in srses]

            if not rshashes:
                # we've never spoken before, but we'll pretend we have
                rshash_size = self.hash_alg().digest_size
                rshashes.append(crypto.random_bytes(rshash_size))

            rshashes = [base64.b64encode(rshash).decode('utf-8') for rshash in \
                rshashes]
            result.addChild(node=nbxmpp.DataField(name='rshashes',
                value=rshashes))
            result.addChild(node=nbxmpp.DataField(name='dhkeys',
                value=base64.b64encode(crypto.encode_mpi(e)).decode('utf-8')))

            self.form_o = ''.join(nbxmpp.c14n.c14n(el, self._is_buggy_gajim()) \
                for el in form.getChildren())

        # MUST securely destroy K unless it will be used later to generate the
        # final shared secret

        for datafield in self.make_identity(result, e):
            result.addChild(node=datafield)

        feature.addChild(node=result)
        self.send(accept)

        if self.sigmai:
            self.status = 'active'
            self.enable_encryption = True
        else:
            self.status = 'identified-alice'
github gajim / gajim / gajim / common / stanza_session.py View on Github external
def c7lize_mac_id(self, form):
        kids = form.getChildren()
        macable = [x for x in kids if x.getVar() not in ('mac', 'identity')]
        return ''.join(nbxmpp.c14n.c14n(el, self._is_buggy_gajim()) for el in \
                macable)