Пример #1
0
    def onJoin(self, details):
        print("joined")

        # setup application payload end-to-end encryption ("WAMP-cryptobox")
        # when a keyring was set, end-to-end encryption is performed automatically
        if True:
            keyring = KeyRing(PRIVKEY)
        else:
            # this works the same as in Component1, but the keys
            # loaded is different.
            keyring = KeyRing()

            # since we want to act as "callee" (and "subscriber"), we are thus a "responder"
            # and responders need the responder private key. however, we don't act as "callers"
            # (or "publishers"), and hence can get away with the public key for the originator only!
            key = Key(responder_priv=RESPONDER_PRIV, originator_pub=ORIGINATOR_PUB)
            keyring.set_key(u'com.myapp.encrypted.', key)

        self.set_keyring(keyring)

        # now start the testing ..

        def add2(a, b, details=None):
            print("call received: a={}, b={}, details={}".format(a, b, details))

            # when the procedure args were encrypted, the result will be always encrypted too!
            return a + b

        options = RegisterOptions(details_arg='details')
        reg1 = yield self.register(add2, u'com.myapp.add2', options=options)
        reg2 = yield self.register(add2, u'com.myapp.encrypted.add2', options=options)

        def failme(encrypted_error, details=None):
            # independent of whether the "failme" procedure args were encrypted or not,
            # an error returned to the caller will be encrypted or not depending soley
            # on the error URI
            if encrypted_error:
                raise ApplicationError(u"com.myapp.encrypted.error1", custom1=23, custom2=u'Hello')
            else:
                raise ApplicationError(u"com.myapp.error1", custom1=23, custom2=u'Hello')

        reg3 = yield self.register(failme, u'com.myapp.failme', options=options)
        reg4 = yield self.register(failme, u'com.myapp.encrypted.failme', options=options)

        def on_hello(msg, details=None):
            print("event received: msg='{}', details={}".format(msg, details))

        options = SubscribeOptions(details_arg='details')
        sub1 = yield self.subscribe(on_hello, u'com.myapp.hello', options=options)
        sub2 = yield self.subscribe(on_hello, u'com.myapp.encrypted.hello', options=options)

        print("ready!")
Пример #2
0
    def onJoin(self, details):
        print("joined")

        # setup application payload end-to-end encryption ("WAMP-cryptobox")
        # when a keyring was set, end-to-end encryption is performed automatically
        if True:
            # this is simplest keyring: for all URIs, use one key for both
            # originators and responders.
            keyring = KeyRing(PRIVKEY)
        else:
            # this is a more specialized keyring: we only make URIs starting
            # with "com.myapp.encrypted." encrypted, and only with private key
            # for originator (= this session, as it is "calling" and "publishing")

            # we need to have a keyring first. create an empty one.
            keyring = KeyRing()

            # since we want to act as "caller" (and "publisher"), we are thus a "originator"
            # and originators need the originator private key. however, we don't act as "callees"
            # (or "subscribers"), and hence can get away with the public key for the responder only!
            key = Key(originator_priv=ORIGINATOR_PRIV, responder_pub=RESPONDER_PUB)

            # we now associate URIs starting with "com.myapp.encrypted." with the
            # encryption keys ..
            keyring.set_key(u'com.myapp.encrypted.', key)

        # .. and finally set the keyring on the session. from now on, all calls (and event)
        # on URIs that start with "com.myapp.encrypted." will be encrypted. Calls (and events)
        # on URIs different from that will continue to travel unencrypted!
        self.set_keyring(keyring)

        # now start the testing ..

        yield self._test_rpc()
        yield self._test_rpc_errors()
        yield self._test_pubsub()

        print("done!")
        self.leave()
Пример #3
0
    def onJoin(self, details):
        print("joined")

        # setup application payload end-to-end encryption ("WAMP-cryptobox")
        # when a keyring was set, end-to-end encryption is performed automatically
        if True:
            # this is simplest keyring: for all URIs, use one key for both
            # originators and responders.
            keyring = KeyRing(PRIVKEY)
        else:
            # this is a more specialized keyring: we only make URIs starting
            # with "com.myapp.encrypted." encrypted, and only with private key
            # for originator (= this session, as it is "calling" and "publishing")

            # we need to have a keyring first. create an empty one.
            keyring = KeyRing()

            # since we want to act as "caller" (and "publisher"), we are thus a "originator"
            # and originators need the originator private key. however, we don't act as "callees"
            # (or "subscribers"), and hence can get away with the public key for the responder only!
            key = Key(originator_priv=ORIGINATOR_PRIV,
                      responder_pub=RESPONDER_PUB)

            # we now associate URIs starting with "com.myapp.encrypted." with the
            # encryption keys ..
            keyring.set_key(u'com.myapp.encrypted.', key)

        # .. and finally set the keyring on the session. from now on, all calls (and event)
        # on URIs that start with "com.myapp.encrypted." will be encrypted. Calls (and events)
        # on URIs different from that will continue to travel unencrypted!
        self.set_keyring(keyring)

        # now start the testing ..

        yield self._test_rpc()
        yield self._test_rpc_errors()
        yield self._test_pubsub()

        print("done!")
        self.leave()
Пример #4
0
    def onJoin(self, details):
        print("joined")

        # setup application payload end-to-end encryption ("WAMP-cryptobox")
        # when a keyring was set, end-to-end encryption is performed automatically
        if True:
            keyring = KeyRing(PRIVKEY)
        else:
            # this works the same as in Component1, but the keys
            # loaded is different.
            keyring = KeyRing()

            # since we want to act as "callee" (and "subscriber"), we are thus a "responder"
            # and responders need the responder private key. however, we don't act as "callers"
            # (or "publishers"), and hence can get away with the public key for the originator only!
            key = Key(responder_priv=RESPONDER_PRIV,
                      originator_pub=ORIGINATOR_PUB)
            keyring.set_key(u'com.myapp.encrypted.', key)

        self.set_keyring(keyring)

        # now start the testing ..

        def add2(a, b, details=None):
            print("call received: a={}, b={}, details={}".format(
                a, b, details))

            # when the procedure args were encrypted, the result will be always encrypted too!
            return a + b

        options = RegisterOptions(details_arg='details')
        reg1 = yield self.register(add2, u'com.myapp.add2', options=options)
        reg2 = yield self.register(add2,
                                   u'com.myapp.encrypted.add2',
                                   options=options)

        def failme(encrypted_error, details=None):
            # independent of whether the "failme" procedure args were encrypted or not,
            # an error returned to the caller will be encrypted or not depending soley
            # on the error URI
            if encrypted_error:
                raise ApplicationError(u"com.myapp.encrypted.error1",
                                       custom1=23,
                                       custom2=u'Hello')
            else:
                raise ApplicationError(u"com.myapp.error1",
                                       custom1=23,
                                       custom2=u'Hello')

        reg3 = yield self.register(failme,
                                   u'com.myapp.failme',
                                   options=options)
        reg4 = yield self.register(failme,
                                   u'com.myapp.encrypted.failme',
                                   options=options)

        def on_hello(msg, details=None):
            print("event received: msg='{}', details={}".format(msg, details))

        options = SubscribeOptions(details_arg='details')
        sub1 = yield self.subscribe(on_hello,
                                    u'com.myapp.hello',
                                    options=options)
        sub2 = yield self.subscribe(on_hello,
                                    u'com.myapp.encrypted.hello',
                                    options=options)

        print("ready!")