[Twisted-Python] SSL and Perspective Broker

Edmund Dengler edmundd at eSentire.com
Mon Aug 4 16:52:33 MDT 2003


Greetings!

Okay, tried something a bit more complicated, basically it is a modified
version of pb6server/pb6client code from the documentation.

I'm locking up again. It looks like it gets further than when I had my
problems with 1.0.5. The client claims to have gotten a root reference
(good, this is further), but the server does not show the attaching
client. It looks like the client is blocking in the pb.logIn method.

Twisted Version: 1.0.7alpha2

Note: I did have this working with a hacked up 1.0.5.

SERVER SIDE
-----------

#! /usr/bin/python

from twisted.spread import pb
from twisted.cred.authorizer import DefaultAuthorizer
import twisted.internet.app

from OpenSSL import SSL
from twisted.internet import ssl

import os

class TransferClientPerspective(pb.Perspective):

    def attached(self, clientref, identity):
        print "client attached! they are:", identity
        return self

    def detached(self, ref, identity):
        print "client detached! they were:", identity

    def perspective_transferEvent(self, event):
        print "I am %s, transferEvent(%s) called on %s" % (self.myname, event, self)
        return true



class ServerContextFactory:

    def getContext(self):
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_certificate_file('server.pem')
        ctx.use_privatekey_file('server.pem')
        return ctx


class TransferServer:
    def __init__(self):
        pass

    def run(self):
        print "TransferServer.run() called"

        app = twisted.internet.app.Application("TransferServer")
        auth = DefaultAuthorizer(app)

        service = pb.Service("TransferService", app, auth)
        service.perspectiveClass = TransferClientPerspective

        client1 = service.createPerspective("perspective1")
        client1.myname = "client1"

        identity1 = auth.createIdentity("user1")
        identity1.setPassword("pass1")
        identity1.addKeyByString("TransferService", "perspective1")
        auth.addIdentity(identity1)

        print "Starting service listening now"
        app.listenSSL(8800, pb.BrokerFactory(pb.AuthRoot(auth)), ServerContextFactory())
        app.run(save=0)

server = TransferServer()
server.run()



CLIENT SIDE
-----------

#! /usr/bin/python

from twisted.spread import pb
from twisted.internet import reactor, ssl
from twisted.internet.protocol import ClientFactory
import pdb


class TransferClient:
    def __init__(self):
        pass

    def go(self):
        def1 = pb.getObjectAtSSL("crete.internal", 8800, 15)
        def1.addCallbacks(self.logIn,self.unable)
        print "finishing main()"
        reactor.run()

    def logIn(self, root):
        print "TransferClient.login() called"
        print "Got root reference: %s" % root
        def2 = pb.logIn(root, service="TransferService", username="user1", password="pass1", perspective="perspective1")
        def2.addCallbacks(self.startTransfer,self.unable)


    def startTransfer(self, perspective):
        print "TransferClient.startTransfer() called"
        print "Got perspective1 reference: %s" % perspective
        print "Asking it to transferEvent(13)"
        perspective.callRemote("transferEvent", 13)

    def unable(self, error):
        print "TransferClient.unable() called"
        error.printTraceback()

client = TransferClient()
client.go()




On Mon, 4 Aug 2003, Itamar Shtull-Trauring wrote:

> On Mon, 4 Aug 2003 17:02:42 -0400 (EDT)
> Edmund Dengler <edmundd at eSentire.com> wrote:
>
> > a bit of time to go digging, but I believe the context was before the
> > timeout previously as I based my hacked version on the 1.0.5 code).
>
> As of 1.0.7 you shouldn't need to do this. If you *do* end up hacking PB
> please do tell us so we can fix it so it's not necessary. What are you
> using PB for, by the way?
>
> --
> Itamar Shtull-Trauring    http://itamarst.org/
> Available for Python & Twisted consulting
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>





More information about the Twisted-Python mailing list