Exemplo n.º 1
0
 def msg_received(self, conn, msg):
     """Handles messages received from the TI server.  Starts the
     TopologyInteractor command-line interface once authentication is complete."""
     if msg is not None:
         if msg.get_type() == VNSAuthRequest.get_type():
             print 'Authenticating as %s' % self.username
             sha1_of_salted_pw = hashlib.sha1(msg.salt +
                                              self.auth_key).digest()
             conn.send(VNSAuthReply(self.username, sha1_of_salted_pw))
         elif msg.get_type() == VNSAuthStatus.get_type():
             if msg.auth_ok:
                 print 'Authentication successful.'
                 conn.send(TIOpen(self.tid))
                 reactor.callInThread(TopologyInteractor(self).cmdloop)
             else:
                 print 'Authentication failed.'
         elif msg.get_type() == TIBadNodeOrPort.get_type():
             txt = str(msg)
             if self.prev_bn_msg == txt:
                 self.prev_bn_msg = None  # only stop it once
             else:
                 if self.prev_bn_msg != None:
                     print '***%s!=%s' % (self.prev_bn_msg, txt)
                 self.prev_bn_msg = txt
                 print '\n', txt
         elif msg.get_type() == TIBanner.get_type():
             print '\n', msg.msg
         elif msg.get_type() == TIPacket.get_type():
             self.got_tapped_packet(msg)
         else:
             print 'unexpected TI message received: %s' % msg
Exemplo n.º 2
0
 def msg_received(self, conn, msg):
     """Handles messages received from the TI server.  Starts the
     TopologyInteractor command-line interface once authentication is complete."""
     if msg is not None:
         if msg.get_type() == VNSAuthRequest.get_type():
             print 'Authenticating as %s' % self.username
             sha1_of_salted_pw = hashlib.sha1(msg.salt + self.auth_key).digest()
             conn.send(VNSAuthReply(self.username, sha1_of_salted_pw))
         elif msg.get_type() == VNSAuthStatus.get_type():
             if msg.auth_ok:
                 print 'Authentication successful.'
                 conn.send(TIOpen(self.tid))
                 reactor.callInThread(TopologyInteractor(self).cmdloop)
             else:
                 print 'Authentication failed.'
         elif msg.get_type() ==  TIBadNodeOrPort.get_type():
             txt = str(msg)
             if self.prev_bn_msg == txt:
                 self.prev_bn_msg = None # only stop it once
             else:
                 if self.prev_bn_msg != None:
                     print '***%s!=%s'%(self.prev_bn_msg,txt)
                 self.prev_bn_msg = txt
                 print '\n', txt
         elif msg.get_type() ==  TIBanner.get_type():
             print '\n', msg.msg
         elif msg.get_type() ==  TIPacket.get_type():
             self.got_tapped_packet(msg)
         else:
             print 'unexpected TI message received: %s' % msg
Exemplo n.º 3
0
    def handle_auth_reply(self, conn, ar, terminate_connection):
        if not conn.vns_auth_salt:
            msg = 'unexpectedly received authentication reply from conn_user=%s ar_user=%s at %s'
            terminate_connection(conn, msg % (conn.vns_user_profile, ar.username, conn))
            return

        try:
            up = db.UserProfile.objects.get(user__username=ar.username, retired=False)
        except db.UserProfile.DoesNotExist:
            logging.info('unrecognized username tried to login: %s' % ar.username)
            terminate_connection(conn, "authentication failed")
            return

        expected = hashlib.sha1(conn.vns_auth_salt + str(up.get_sim_auth_key())).digest()
        if ar.ssp != expected:
            logging.info('user %s provided an incorrect password' % ar.username)
            terminate_connection(conn, "authentication failed")
        else:
            conn.vns_auth_salt = None # only need one auth reply
            conn.vns_authorized = True
            conn.vns_user_profile = up
            msg = 'authenticated %s as %s' % (conn, ar.username)
            conn.send(VNSAuthStatus(True, msg))
Exemplo n.º 4
0
 def _handle_auth_reply(self, conn):
   # always authenticate
   msg = "authenticated %s as %s" % (conn, 'user')
   conn.send(VNSAuthStatus(True, msg))