'L{TLSMemoryBIOProtocol.getPeerCertificate} returns the
L{OpenSSL.crypto.X509Type} instance representing the peer\'s
certificate.'

def test_getPeerCertificate(self):

    clientFactory = ClientFactory()
    clientFactory.protocol = Protocol
    (clientContextFactory, handshakeDeferred) = HandshakeCallbackContextFactory.factoryAndDeferred()
    wrapperFactory = TLSMemoryBIOFactory(clientContextFactory, True, clientFactory)
    sslClientProtocol = wrapperFactory.buildProtocol(None)
    serverFactory = ServerFactory()
    serverFactory.protocol = Protocol
    serverContextFactory = ServerTLSContext()
    wrapperFactory = TLSMemoryBIOFactory(serverContextFactory, False, serverFactory)
    sslServerProtocol = wrapperFactory.buildProtocol(None)
    loopbackAsync(sslServerProtocol, sslClientProtocol)
    def cbHandshook(ignored):
        cert = sslClientProtocol.getPeerCertificate()
        self.assertIsInstance(cert, X509Type)
        self.assertEqual(cert.digest('sha1'), '45:DD:FD:E2:BD:BF:8B:D0:00:B7:D2:7A:BB:20:F5:34:05:4B:15:80')
    handshakeDeferred.addCallback(cbHandshook)
    return handshakeDeferred
