Example #1
0
 def pushMessage(self, message, args = None):
     if type(args) in (list, tuple):
         args = ','.join(args)
     if args:
         message = '%s|%s' % (message, args)
     log("TRYING TO WRITE:::", message)
     self.transport.write(str(message + self.delimiter))
Example #2
0
    def verify_certificate(self, conn, cert, errno, depth, retcode):
        # UNDOCUMENTED:
        # retcode is non-zero if the built in verification code would
        # succeed, false otherwise.
        # log("verify_certificate: ", cert, errno, depth, retcode)

        # UNDOCUMENTED:
        # See http://divmod.org/websvn/wsvn/Quotient/trunk/mantissa/sslverify.py?op=file&rev=0&sc=0
        # _errorcodes for errno descriptions. 
        if not retcode:
            log("VERIFICATION FAILED: ", errno)

        return retcode
Example #3
0
    def dataReceived(self, data):
        data = data.strip().split('\r\n')

        for chunk in data:
            _chunk = chunk.split(';')
            package = _chunk.pop(0)
            method = '' if not _chunk else _chunk.pop(0)
            args = _chunk

            log("PROCESSING: package, method, args:", package, method, args)
            if package == "HELLO":
                self.pushMessage("HELLO|HELLO")
            elif package == "HELLO|MY_NAME_IS":
                log("HAND_SHAKE suceeded with '%s'" % method)
                self.pushMessage("HELLO|AUTHORIZED")
            elif package in PACKAGES:
                self.pushMessage(chunk, PACKAGES[package].run(method, args))
            else:
                self.pushMessage("%s|NOT_IMPLEMENTED" % chunk)
Example #4
0
def ssl_info_callback(connection, where, ret):
    # ssl_conn = Connection.map()[ssl_ptr]
    # sys.stdout.write(ssl_ptr + ':' + str(sys.getrefcount(ssl_conn)) + '\n')
    # sys.stdout.flush()

    w = where & ~SSL_ST_MASK
    if (w & SSL_ST_CONNECT):
        state = "SSL connect"
    elif (w & SSL_ST_ACCEPT):
        state = "SSL accept"
    else:
        state = "SSL state unknown"

    if (where & SSL_CB_LOOP):
        # sys.stderr.write("LOOP: %s: %s\n" % (state, m2.ssl_get_state_v(ssl_ptr)))
        log("LOOP: %s: %s\n" % (state, connection.state_string()))
        return

    if (where & SSL_CB_EXIT):
        if not ret:
            log("FAILED: %s: %s\n" % (state, connection.state_string()))
        else:
            log("INFO: %s: %s\n" % (state, connection.state_string()))
        return

    # I don't think this code would ever execute under pyOpenSSL because
    # it handles alerts with exception, but I'm not sure.
    if (where & SSL_CB_ALERT):
        if (where & SSL_CB_READ):
            w = 'read'
        else:
            w = 'write'
        # sys.stderr.write("ALERT: %s: %s: %s\n" % \
        #     (w, m2.ssl_get_alert_type_v(ret), m2.ssl_get_alert_desc_v(ret)))
        log("ALERT: %s: DUNNO HOW TO GET ALERT INFO!\n" % w)
        return
Example #5
0
 def clientConnectionLost(self, connector, reason):
     log("Connection Lost:", reason.getErrorMessage())
     try:
         reactor.stop()
     except ReactorNotRunning:
         pass
Example #6
0
 def clientConnectionFailed(self, connector, reason):
     log("Connection Failed:", reason.getErrorMessage())
     reactor.stop()
Example #7
0
 def connectionLost(self, reason):
     log("Something Happened !")