Example #1
0
// Convert simplified credentials into something useful for the ssh package
func get_auth(creds *Creds) ([]ssh.AuthMethod, error) {
	auth := []ssh.AuthMethod{}

	// Passwords. This isn't enough for a typical SSH server (which will usually
	// be configured for KeyboardInteractive, not Password) but fine for XR.
	if creds.Password != "" {
		auth = append(auth, ssh.Password(creds.Password))
	}

	// Keys
	if creds.Keypathname != "" {
		buf, err := ioutil.ReadFile(creds.Keypathname)
		if err != nil {
			return nil, errors.New("Can't read private key file: " + err.Error())
		}

		key, err := ssh.ParsePrivateKey(buf)
		if err != nil {
			return nil, errors.New("Can't parse private key: " + err.Error())
		}

		auth = append(auth, ssh.PublicKeys(key))
	}

	return auth, nil
}
Example #2
0
func (s *SftpSession) getKeyFile(fkey string) error {
	buf, err := ioutil.ReadFile(fkey)
	if err != nil {
		return err
	}
	s.sshkey, err = ssh.ParsePrivateKey(buf)
	if err != nil {
		return err
	}
	return nil
}