예제 #1
0
def read_provided_ssh_key():
    from src.SSH import read_private_key_from_file
    #print 'Look for preconfigured SSH key.'

    f = resource_path('resources', 'ssh.key')
    #print '> at %s' % f
    if not f or not os.path.isfile(f):
        #print '> not found'
        return None
    if os.path.getsize(f) < 1:
        #print '> empty'
        return None

    # Read preconfigured SSH key.
    try:
        #print '> read key'
        pwd = get_configuration('settings', 'ssh-provided-key-password', '')
        key = read_private_key_from_file(f, pwd)
    except:
        print 'Preconfigured SSH key is not readable!'
        print traceback.format_exc()
        key = None

    # If the program was started from a binary executable,
    # the SSH key is removed from the temporary application folder after it was read.
    # Hopefully this makes it a bit more difficult to extract the SSH key from an application binary.
    if is_executed_from_binary():
        #print '> remove key file from local disk'
        os.remove(f)

    return key
예제 #2
0
    def validate(self, messages):
        count = len(messages)

        # validate VNC application
        if not self.is_custom_vnc_app():
            vnc = self.settings.get_vnc_application(default=None)
            if vnc is None or vnc == '':
                messages.append(_('No VNC application was specified.'))
            elif not os.path.isfile(vnc):
                messages.append(_('The VNC application does not point to a file.'))

        # validate SSH user
        user = self.settings.get_ssh_user(default=None)
        if user is None:
            messages.append(_('No SSH user name was specified.'))

        # validate SSH keyfile
        if not self.settings.is_ssh_use_provided_key():
            password = self.settings.get_ssh_password()
            keyfile = self.settings.get_ssh_keyfile(default=None)
            if not keyfile is None:
                if not os.path.isfile(keyfile):
                    messages.append(_('The private key file is invalid.'))
                else:
                    try:
                        read_private_key_from_file(keyfile, password=password)
                    except:
                        print traceback.format_exc()
                        messages.append(_('Can\'t open private key with the provided password.'))

        # validate SSH port
        port = self.settings.get_ssh_port(default=None)
        if port is None:
            messages.append(_('The SSH port number is invalid.'))
        elif port < 0 or port > 65535:
            messages.append(_('The SSH port number is not in the interval from {0} to {1}.').format(1, 65535))

        return len(messages) > count