aboutsummaryrefslogtreecommitdiff
path: root/lib/ssh
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-26 18:41:13 +0700
committerShulhan <ms@kilabit.info>2023-09-26 18:41:13 +0700
commit8d0720f6f9406262868e2efa0d757ec27ef7119d (patch)
treec30fed676692f599834c991e69fb200c745d8c0c /lib/ssh
parent410ab868afb9bfc8c02cba67ca6e9c436b44061b (diff)
downloadpakakeh.go-8d0720f6f9406262868e2efa0d757ec27ef7119d.tar.xz
go.mod: remove replace directive for golang.org/x/crypto
Using replace directive does not works well if we install binary using "go install". One of the case that we found is when user installing awwan [1] that use "share" module [2] with replace directive, the binary is not build with git.sr.ht/~shulhan/go-x-crypto. /Users/xxx/go/bin/awwan: go1.21.0 path git.sr.ht/~shulhan/awwan/cmd/awwan mod git.sr.ht/~shulhan/awwan v0.7.1-0.20230925173020-40b9fe9b854c h1:629djcSfqM8ITX+CtgGyrybPnKQPpwJ/EceN967bKps= dep git.sr.ht/~shulhan/asciidoctor-go v0.5.0 h1:TfcAjv+7EwBZ83ef8OhX9vfQ4vRFcaJh0P1XXgbsJv0= dep git.sr.ht/~shulhan/ciigo v0.10.0 h1:s1SJ3/NzBcbOLmEZ4z1Cx9Vf7ZdDIvm45b7KMCZKzEY= dep github.com/evanw/esbuild v0.19.3 h1:foPr0xwQM3lBWKBtscauTN9FrmJzRDVI2+EGOs82H/I= dep github.com/shuLhan/share v0.49.2-0.20230923081600-77c41ce992e6 h1:REQDC2UKLaWT1WGd/Iw/rfKLkXb7vtKtyObkeZeHZRk= dep github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA= dep github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= dep golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= dep golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= dep golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= dep golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= dep gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= build -buildmode=exe build -compiler=gc build DefaultGODEBUG=panicnil=1 build CGO_ENABLED=1 build CGO_CFLAGS= build CGO_CPPFLAGS= build CGO_CXXFLAGS= build CGO_LDFLAGS= build GOARCH=arm64 build GOOS=darwin This changes require use to modify lib/cryto and lib/ssh that depends on our patches. [1] https://git.sr.ht/~shulhan/awwan [2] https://github.com/shuLhan/share/commit/77c41ce992e6
Diffstat (limited to 'lib/ssh')
-rw-r--r--lib/ssh/client.go26
-rw-r--r--lib/ssh/client_test.go23
2 files changed, 26 insertions, 23 deletions
diff --git a/lib/ssh/client.go b/lib/ssh/client.go
index ae70163a..0f1ed680 100644
--- a/lib/ssh/client.go
+++ b/lib/ssh/client.go
@@ -5,13 +5,13 @@
package ssh
import (
- "errors"
"fmt"
"io"
"log"
"net"
"os"
"os/exec"
+ "strings"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
@@ -111,8 +111,7 @@ func NewClientInteractive(section *config.Section) (cl *Client, err error) {
return cl, nil
}
- var errKey *knownhosts.KeyError
- if errors.As(err, &errKey) {
+ if strings.Contains(err.Error(), `knownhosts`) {
// Host key is either unknown or mismatch with one
// of known_hosts files, so no need to continue with
// dialWithPrivateKeys.
@@ -175,19 +174,16 @@ func (cl *Client) setConfigHostKeyCallback() (err error) {
// dialError return the error with clear information when the host key is
// missing or mismatch from known_hosts files.
func (cl *Client) dialError(logp string, errDial error) (err error) {
- var (
- errKey *knownhosts.KeyError
- )
- if errors.As(errDial, &errKey) {
- if len(errKey.Want) == 0 {
- err = fmt.Errorf(`%s: %w: server host key is missing from %+v`, logp, errDial, cl.listKnownHosts)
- } else {
- err = fmt.Errorf(`%s: %w: server host key mismatch in %+v`, logp, errDial, cl.listKnownHosts)
- }
- } else {
- err = fmt.Errorf(`%s: %w`, logp, errDial)
+ var errDialString = errDial.Error()
+
+ if strings.Contains(errDialString, `key is unknown`) {
+ return fmt.Errorf(`%s: %w from known_hosts files %+v`, logp, errDial, cl.listKnownHosts)
}
- return err
+ if strings.Contains(errDialString, `key mismatch`) {
+ return fmt.Errorf(`%s: %w with known_hosts files %+v`, logp, errDial, cl.listKnownHosts)
+ }
+
+ return fmt.Errorf(`%s: %w`, logp, errDial)
}
// dialWithSigners connect to the remote machine using AuthMethod PublicKeys
diff --git a/lib/ssh/client_test.go b/lib/ssh/client_test.go
index ede94591..062a32cc 100644
--- a/lib/ssh/client_test.go
+++ b/lib/ssh/client_test.go
@@ -5,11 +5,13 @@
package ssh
import (
+ "fmt"
"os"
"path/filepath"
"testing"
"github.com/shuLhan/share/lib/ssh/config"
+ "github.com/shuLhan/share/lib/test"
)
// TestNewClient_KeyError test SSH to server with host key does not exist in
@@ -20,9 +22,8 @@ func TestNewClient_KeyError_notExist(t *testing.T) {
var (
section = config.NewSection(`localhost`)
- wd string
- pathFile string
- err error
+ wd string
+ err error
)
wd, err = os.Getwd()
@@ -39,20 +40,26 @@ func TestNewClient_KeyError_notExist(t *testing.T) {
t.Fatal(err)
}
- pathFile = filepath.Join(wd, `testdata/localhost/known_hosts_empty`)
- err = section.Set(config.KeyUserKnownHostsFile, pathFile)
+ var knownHostsFile = filepath.Join(wd, `testdata/localhost/known_hosts_empty`)
+ err = section.Set(config.KeyUserKnownHostsFile, knownHostsFile)
if err != nil {
t.Fatal(err)
}
- pathFile = filepath.Join(wd, `testdata/localhost/client.key`)
- err = section.Set(config.KeyIdentityFile, pathFile)
+ var pkeyFile = filepath.Join(wd, `testdata/localhost/client.key`)
+ err = section.Set(config.KeyIdentityFile, pkeyFile)
if err != nil {
t.Fatal(err)
}
+ var (
+ expError = fmt.Sprintf(`NewClientInteractive: dialWithSigners: ssh: handshake failed: knownhosts: key is unknown from known_hosts files [%s]`, knownHostsFile)
+ gotError string
+ )
+
_, err = NewClientInteractive(section)
if err != nil {
- t.Fatal(err)
+ gotError = err.Error()
}
+ test.Assert(t, `NewClientInteractive: error`, expError, gotError)
}