Skip to content

Commit

Permalink
fix add key to ssh-agent if password is provided, but key is not encr…
Browse files Browse the repository at this point in the history
…ypted (#1)

* bug fixing during add key to ssh-agent if password is provided, but key is not encrypted

* goreleaser add flag --auto-snapshot

* goreleaser release --clean --skip-validate
  • Loading branch information
revengel authored Feb 21, 2023
1 parent cda8315 commit 0157bb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: goreleaser/[email protected]
with:
version: latest
args: release --clean
args: release --clean --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
GOPATH: /home/runner/go
10 changes: 9 additions & 1 deletion ssh-agent.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -34,7 +37,12 @@ func (sa sshAgent) list() (o []string, err error) {
func (sa *sshAgent) add(privateKeyB []byte, password, comment string, lifetime uint32) (err error) {
var privateKey interface{}

if len(password) > 0 {
decodedPem, _ := pem.Decode(privateKeyB)

if x509.IsEncryptedPEMBlock(decodedPem) {
if len(password) == 0 {
return errors.New("private ssh-key is encrypted but provided password is empty")
}
privateKey, err = ssh.ParseRawPrivateKeyWithPassphrase(privateKeyB, []byte(password))
} else {
privateKey, err = ssh.ParseRawPrivateKey(privateKeyB)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func getVersion() semver.Version {
return semver.Version{
Major: 0,
Minor: 1,
Patch: 0,
Patch: 1,
Pre: []semver.PRVersion{
{VersionStr: "git"},
},
Expand Down

0 comments on commit 0157bb1

Please sign in to comment.