Beispiel #1
0
    def remote_login(self, client):
        # print 'Remote login!'
        peerCertificate = Certificate.peerFromTransport(self.broker.transport)
        pdid = peerCertificate.getSubject().commonName.decode('utf-8')

        avatar, logout = yield self.portal.login(pdid, client)
        avatar = pb.AsReferenceable(avatar, "perspective")

        # Formerly in _cbLogin, moved here to make the deferred chain cleaner
        puid = avatar.processUniqueID()

        # only call logout once, whether the connection is dropped (disconnect)
        # or a logout occurs (cleanup), and be careful to drop the reference to
        # it in either case
        logout = [logout]

        def maybeLogout():
            if not logout:
                return
            fn = logout[0]
            del logout[0]
            fn()

        self.broker._localCleanup[puid] = maybeLogout
        self.broker.notifyOnDisconnect(maybeLogout)

        defer.returnValue(avatar)
Beispiel #2
0
 def startTLS(self, certificate, *verifyAuthorities):
     if self.hostCertificate is None:
         self.hostCertificate = certificate
         self._justStartedTLS = True
         self.transport.startTLS(certificate.options(*verifyAuthorities))
         stlsb = self._startingTLSBuffer
         if stlsb is not None:
             self._startingTLSBuffer = None
             for box in stlsb:
                 self.sendPacket(box)
     else:
         raise RuntimeError(
             "Previously authenticated connection between %s and %s "
             "is trying to re-establish as %s" % (
                 self.hostCertificate,
                 Certificate.peerFromTransport(self.transport),
                 (certificate, verifyAuthorities)))
Beispiel #3
0
 def startTLS(self, certificate, *verifyAuthorities):
     if self.hostCertificate is None:
         self.hostCertificate = certificate
         self._justStartedTLS = True
         self.transport.startTLS(certificate.options(*verifyAuthorities))
         stlsb = self._startingTLSBuffer
         if stlsb is not None:
             self._startingTLSBuffer = None
             for box in stlsb:
                 self.sendPacket(box)
     else:
         raise RuntimeError(
             "Previously authenticated connection between %s and %s "
             "is trying to re-establish as %s" %
             (self.hostCertificate,
              Certificate.peerFromTransport(self.transport),
              (certificate, verifyAuthorities)))
Beispiel #4
0
    def login2(self, portal):
        self.portal = portal

        # Returns a _RifflePortalWrapper remote reference. Set a timeout
        # in case the connection is down
        self.setTimeout(TIMEOUT)
        root = yield self.getRootObject()

        # Reset the timeout, indicating we've made the connection and are done waiting
        self.setTimeout(None)

        # Extract the name from credentials
        peerCertificate = Certificate.peerFromTransport(self._broker.transport)
        pdid = peerCertificate.getSubject().commonName.decode('utf-8')

        # Returns the server's avatar based on the client's interpretation
        # 'other' is the other end of the connection.
        other = self.portal.partialLogin(pdid)

        # Convert to remote referentiable for transmission
        referencibleOther = pb.AsReferenceable(other, "perspective")

        # Here is the problem. The login call triggers the init call, and that
        # starts the chain of riffle callbacks, but this object won't be back in time by then!

        # Avatar is the remotely described API object
        avatar = yield root.callRemote('login', referencibleOther)
        other.remote = Levy(avatar)

        # This is absolutely not needed. The point of this method is to registers
        # the new connections with the portal, but we already have all the pieces.
        # a, b = yield self.portal.login(pdid, avatar)

        # tttteeeemmmpppppoooorrraaaarrryyy
        realm = self.portal.findRealm(pdid)
        realm.attach(other, avatar)

        avatar.callRemote('handshake')
        other.perspective_handshake()

        defer.returnValue(avatar)
Beispiel #5
0
    def send_response(self):
        client = self.transport.getPeer()

        req_uri = self.lines[0].split(" ")[1]

        headers = {l.split(':')[0]:l.split(':')[1].strip() for l in self.lines[2:-1]}
        user_agent = headers.get('User-Agent', 'Unknown')

        try:
            peer_certificate = Certificate.peerFromTransport(self.transport)
            f = peer_certificate.digest()
            self.sendLine("HTTP/1.1 401 Unauthorized")
            self.sendLine(self.headers())
            self.sendLine("")
            self.transport.write(json.dumps(self.bodies['unauthorized']))
            self.transport.loseConnection()

            self.chirp({'f': f, 'tf': f.replace(":","")[:25].lower(), 'ip': client.host, 'useragent': user_agent, 'location': req_uri.split("?")[0]})

        except CertificateError as e:
            log.error("CertificateError Exception: {}".format(e))
            self.sendLine("HTTP/1.1 403 Forbidden")
            self.sendLine(self.headers())
            self.sendLine("")
            response = self.bodies['forbidden']
            response['message'] = response['message'].format(req_uri.split("?")[0])
            self.transport.write(json.dumps(response))
            self.transport.loseConnection()
        except Exception as e:
            log.error("Exception send_response: {}".format(e))
            self.sendLine("HTTP/1.1 400 Bad Request")
            self.sendLine(self.headers())
            self.sendLine("")
            self.transport.write(json.dumps(self.bodies['bad']))
            self.transport.loseConnection()

        d = defer.Deferred()
        d.callback("Success")
        return d
Beispiel #6
0
 def dataReceived(self, data):
     peerCertificate = Certificate.peerFromTransport(self.transport)
     print(peerCertificate.getSubject().commonName.decode('utf-8'))
     self.transport.loseConnection()