Changeset 1671:b32466ed1d77

Show
Ignore:
Timestamp:
06/25/08 14:42:29 (2 months ago)
Author:
klai@…
Branch:
default
Message:

Clean up reading of ssh keys

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Tycoon/AuctioneerClient.py

    r1561 r1671  
    5656    This class encapsulates an auctioneer client. 
    5757    """ 
     58    def __read_ssh_keys(self, file_name): 
     59        """ 
     60        """ 
     61        rfn = os.path.expanduser(file_name) 
     62        if not os.path.exists(rfn): 
     63            return 
     64        f = file(rfn, "r") 
     65        keys = "".join(f.readlines()) 
     66        if not DSA.is_key_ssh(keys): 
     67            return 
     68        key_string = self.__ssh_public_key_string 
     69        if (key_string != "" and key_string[-1] != "\n"): 
     70            key_string += "\n" 
     71        key_string += keys 
     72        self.__ssh_public_key_string = key_string 
     73 
    5874    def __init__( 
    5975        self, options, reactor, bank, host_name, bank_account_key=None, 
     
    6985        self.__remote_host_addr = host_name 
    7086         
     87        # Read in user ssh key information 
    7188        self.__ssh_public_key_string = ssh_public_key_string 
    72         # Check if the bank account key is also an ssh key 
    73         if not bank_account_key: 
    74             k = DSA() 
    75             if k.is_key_ssh(self.__options.PublicKeyFileName): 
    76                 if (self.__ssh_public_key_string != "" and 
    77                     self.__ssh_public_key_string[-1] != "\n"): 
    78                     self.__ssh_public_key_string += "\n" 
    79                 f = file(os.path.expanduser(self.__options.PublicKeyFileName), 
    80                          "r") 
    81                 self.__ssh_public_key_string += f.readline() 
    82                  
    83         # Read in user ssh key information 
    84         ssh_fns = self.__options.SSHPublicKeyFileNames 
    85         for fn in ssh_fns: 
    86             rfn = os.path.expanduser(fn) 
    87             if not os.path.exists(rfn): 
    88                 continue 
    89             f = file(rfn, "r") 
    90             keys = "".join(f.readlines()) 
    91             if (self.__ssh_public_key_string != "" and 
    92                 self.__ssh_public_key_string[-1] != "\n"): 
    93                 self.__ssh_public_key_string += "\n" 
    94             self.__ssh_public_key_string += keys 
    95             f.close() 
     89        ssh_fns = tuple(self.__options.SSHPublicKeyFileNames) 
     90        for fn in ssh_fns + (self.__options.PublicKeyFileName,): 
     91            self.__read_ssh_keys(fn) 
    9692        if self.__ssh_public_key_string == "": 
    97             raise Exception("SSH public key was not specified and could not be found: %s" % (ssh_fns,)) 
     93            raise Exception( 
     94                "SSH public key was not specified " 
     95                "and could not be found: %s" % (ssh_fns,)) 
    9896         
    9997        # Read in user key information