Ignore:
Timestamp:
Jan 9, 2009, 11:42:17 AM (16 years ago)
Author:
quentin
Message:

Standalone VNC client fixes

  • Correct OpenSSL verification
  • Pass data after initial handshake (Oops!)
  • Find a free port to listen on, if one is not specified
  • Warn users when the authentication token expires
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/vnc-client/invirt-vnc-client

    r1969 r1972  
    11#!/usr/bin/python
    2 from twisted.internet import reactor, ssl, protocol
     2from twisted.internet import reactor, ssl, protocol, error
    33from OpenSSL import SSL
    44import base64, pickle
    5 import getopt, sys
     5import getopt, sys, os, time
    66
    77verbose = False
     
    2020
    2121    def _verify(self, connection, x509, errnum, errdepth, ok):
    22         print '_verify (ok=%d):' % ok
    23         print '  subject:', x509.get_subject()
    24         print '  issuer:', x509.get_issuer()
    25         print '  errnum %s, errdepth %d' % (errnum, errdepth)
     22        if verbose:
     23            print '_verify (ok=%d):' % ok
     24            print '  subject:', x509.get_subject()
     25            print '  issuer:', x509.get_issuer()
     26            print '  errnum %s, errdepth %d' % (errnum, errdepth)
     27        if errnum == 10:
     28            print 'The VNC server certificate has expired. Please contact xvm@mit.edu.'
    2629        return ok
    2730
     
    6063        if verbose: print "ProxyClient: connection made"
    6164    def dataReceived(self, data):
    62         if not ready:
     65        if not self.ready:
    6366            if verbose: print 'ProxyClient: received data "%s"' % data
    6467            if data.startswith("VNCProxy/1.0 200 "):
    65                 ready = True
     68                self.ready = True
    6669                if "\n" in data:
    67                     self.peer.transport.write(data[data.find("\n")+1:])
     70                    self.peer.transport.write(data[data.find("\n")+3:])
    6871                self.peer.transport.resumeProducing() # Allow reading
    6972            else:
    7073                print "Failed to connect: %s" % data
    7174                self.transport.loseConnection()
     75        else:
     76            self.peer.transport.write(data)
    7277
    7378class ProxyClientFactory(protocol.ClientFactory):
     
    183188   
    184189    if verbose: print "Will connect to %s:%s" % (connect_host, connect_port)
    185    
    186     listen[1] = 10003
    187     reactor.listenTCP(listen[1], ProxyFactory(connect_host, connect_port, authtoken, machine))
    188    
    189     print "Ready to connect. Connect to %s:%s now with your VNC client. The password is 'moocow'." % (listen[0], listen[1])
     190    if listen[1] is None:
     191        listen[1] = 5900
     192        ready = False
     193        while not ready:
     194            try:
     195                reactor.listenTCP(listen[1], ProxyFactory(connect_host, connect_port, authtoken, machine))
     196                ready = True
     197            except error.CannotListenError:
     198                listen[1] += 1
     199    else:
     200        reactor.listenTCP(listen[1], ProxyFactory(connect_host, connect_port, authtoken, machine))
     201   
     202    print "Ready to connect. Connect to %s:%s (display %d) now with your VNC client. The password is 'moocow'." % (listen[0], listen[1], listen[1]-5900)
     203    print "You must connect before your authentication token expires at %s." % \
     204          (time.ctime(token_expires))
    190205   
    191206    reactor.run()
Note: See TracChangeset for help on using the changeset viewer.