id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,branch,branch_author,launchpad_bug
5684,OpenSSL.SSL.Connection object has no getpeername attribute,nathanm,nathanm,"When reactor.connectSSL is used to create an SSL connection, the OpenSSL.SSL.Connection object has no getpeername attribute.

The following code sample can be used to reproduce the problem (change the connectSSL arguments to a valid IP and port where a secure server is accepting connections).

{{{
from OpenSSL import SSL
from twisted.internet import reactor, ssl
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver

class MyContextFactory(ssl.ClientContextFactory):

    def _verify(self, connection, x509, errnum, errdepth, ok):
        peername = connection.getpeername()
        print ""connected to"", peername
        return ok

    def getContext(self):
        ctx = ssl.ClientContextFactory.getContext(self)
        ctx.set_verify(SSL.VERIFY_PEER, self._verify)
        return ctx

class MyClient(LineReceiver):
    def connectionMade(self):
        return

    def lineReceived(self):
        return

class MyClientFactory(ClientFactory):
    protocol = MyClient

    def clientConnectionFailed(self, connector, reason):
        reactor.stop()

    def clientConnectionLost(self, connector, reason):
        reactor.stop()

if __name__ == ""__main__"":
    reactor.connectSSL('10.1.2.3', 12345, MyClientFactory(), MyContextFactory())
    reactor.run()
}}}

This produces an exception:

{{{
exceptions.AttributeError: 'NoneType' object has no attribute 'getpeername'
}}}

Yet this works...

{{{
from OpenSSL import SSL
import socket

context = SSL.Context(SSL.TLSv1_METHOD)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = SSL.Connection(context, s)
connection.connect(('10.1.2.3', 12345))
print ""connected to"", connection.getpeername()
}}}",defect,closed,normal,,core,wontfix,SSL Connection,,,,
