Skip to content

Commit

Permalink
Merge #49
Browse files Browse the repository at this point in the history
enable connection using raw private key without file path
  • Loading branch information
melbahja authored Sep 22, 2023
2 parents b1f2e47 + 6562c21 commit d955155
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ func Key(prvFile string, passphrase string) (Auth, error) {
}, nil
}

func RawKey(privateKey string, passphrase string) (Auth, error) {
signer, err := GetSignerForRawKey([]byte(privateKey), passphrase)
if err != nil {
return nil, err
}

return Auth{
ssh.PublicKeys(signer),
}, nil
}

// HasAgent checks if ssh agent exists.
func HasAgent() bool {
return os.Getenv("SSH_AUTH_SOCK") != ""
Expand Down Expand Up @@ -96,3 +107,23 @@ func GetSigner(prvFile string, passphrase string) (ssh.Signer, error) {

return signer, err
}

// GetSignerForRawKey returns ssh signer from private key file.
func GetSignerForRawKey(privateKey []byte, passphrase string) (ssh.Signer, error) {

var (
err error
signer ssh.Signer
)

if passphrase != "" {

signer, err = ssh.ParsePrivateKeyWithPassphrase(privateKey, []byte(passphrase))

} else {

signer, err = ssh.ParsePrivateKey(privateKey)
}

return signer, err
}

0 comments on commit d955155

Please sign in to comment.