From ffa39a17f48ee9847cc85819d8134b5eb9482b77 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 Oct 2021 08:31:26 +0300 Subject: explicitly use dlog.Server for server packages and dlog.Clent for client packages for logging --- internal/ssh/client/clientkeypair.go | 14 +++++++------- internal/ssh/client/knownhostscallback.go | 12 ++++++------ internal/ssh/server/hostkey.go | 10 +++++----- internal/ssh/server/publickeycallback.go | 10 +++++----- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'internal/ssh') diff --git a/internal/ssh/client/clientkeypair.go b/internal/ssh/client/clientkeypair.go index 0e21d0c..b35b25d 100644 --- a/internal/ssh/client/clientkeypair.go +++ b/internal/ssh/client/clientkeypair.go @@ -16,7 +16,7 @@ import ( // GeneratePrivatePublicKeyPairIfNotExists generates a SSH key pair (used by the integration tests) func GeneratePrivatePublicKeyPairIfNotExists(keyPath string, bitSize int) { if _, err := os.Stat(keyPath); err == nil { - dlog.Common.Debug("Private/public key pair already exists", keyPath) + dlog.Client.Debug("Private/public key pair already exists", keyPath) return } GeneratePrivatePublicKeyPair(keyPath, bitSize) @@ -27,27 +27,27 @@ func GeneratePrivatePublicKeyPair(keyPath string, bitSize int) { privateKeyPath := keyPath publicKeyPath := fmt.Sprintf("%s.pub", keyPath) - dlog.Common.Debug("Generating private/public key pair", privateKeyPath, publicKeyPath) + dlog.Client.Debug("Generating private/public key pair", privateKeyPath, publicKeyPath) privateKey, err := generatePrivateKey(bitSize) if err != nil { - dlog.Common.FatalPanic(err) + dlog.Client.FatalPanic(err) } publicKeyBytes, err := generatePublicKey(&privateKey.PublicKey) if err != nil { - dlog.Common.FatalPanic(err) + dlog.Client.FatalPanic(err) } privateKeyBytes := encodePrivateKeyToPEM(privateKey) err = writeKey(privateKeyBytes, privateKeyPath) if err != nil { - dlog.Common.FatalPanic(err) + dlog.Client.FatalPanic(err) } err = writeKey([]byte(publicKeyBytes), publicKeyPath) if err != nil { - dlog.Common.FatalPanic(err) + dlog.Client.FatalPanic(err) } - dlog.Common.Debug("Done generating private/public key pair", privateKeyPath, publicKeyPath) + dlog.Client.Debug("Done generating private/public key pair", privateKeyPath, publicKeyPath) } func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) { diff --git a/internal/ssh/client/knownhostscallback.go b/internal/ssh/client/knownhostscallback.go index dd58925..393c4c7 100644 --- a/internal/ssh/client/knownhostscallback.go +++ b/internal/ssh/client/knownhostscallback.go @@ -93,7 +93,7 @@ func (c KnownHostsCallback) Wrap() ssh.HostKeyCallback { ipLine: knownhosts.Line([]string{remote.String()}, key), responseCh: make(chan response), } - dlog.Common.Warn("Encountered unknown host", unknown) + dlog.Client.Warn("Encountered unknown host", unknown) // Notify user that there is an unknown host c.unknownCh <- unknown // Wait for user input. @@ -132,7 +132,7 @@ func (c KnownHostsCallback) PromptAddHosts(ctx context.Context) { hosts = []unknownHost{} } case <-ctx.Done(): - dlog.Common.Debug("Stopping goroutine prompting new hosts...") + dlog.Client.Debug("Stopping goroutine prompting new hosts...") return } } @@ -146,7 +146,7 @@ func (c KnownHostsCallback) promptAddHosts(hosts []unknownHost) { select { case <-c.trustAllHostsCh: - dlog.Common.Warn("Trusting host keys of servers", servers) + dlog.Client.Warn("Trusting host keys of servers", servers) c.trustHosts(hosts) return default: @@ -166,7 +166,7 @@ func (c KnownHostsCallback) promptAddHosts(hosts []unknownHost) { c.trustHosts(hosts) }, EndCallback: func() { - dlog.Common.Info("Added hosts to known hosts file", c.knownHostsPath) + dlog.Client.Info("Added hosts to known hosts file", c.knownHostsPath) }, } p.Add(a) @@ -179,7 +179,7 @@ func (c KnownHostsCallback) promptAddHosts(hosts []unknownHost) { c.trustHosts(hosts) }, EndCallback: func() { - dlog.Common.Info("Added hosts to known hosts file", c.knownHostsPath) + dlog.Client.Info("Added hosts to known hosts file", c.knownHostsPath) }, } p.Add(a) @@ -191,7 +191,7 @@ func (c KnownHostsCallback) promptAddHosts(hosts []unknownHost) { c.dontTrustHosts(hosts) }, EndCallback: func() { - dlog.Common.Info("Didn't add hosts to known hosts file", c.knownHostsPath) + dlog.Client.Info("Didn't add hosts to known hosts file", c.knownHostsPath) }, } p.Add(a) diff --git a/internal/ssh/server/hostkey.go b/internal/ssh/server/hostkey.go index 4844d36..be23d85 100644 --- a/internal/ssh/server/hostkey.go +++ b/internal/ssh/server/hostkey.go @@ -18,25 +18,25 @@ func PrivateHostKey() []byte { _, err := os.Stat(hostKeyFile) if os.IsNotExist(err) { - dlog.Common.Info("Generating private server RSA host key") + dlog.Server.Info("Generating private server RSA host key") privateKey, err := ssh.GeneratePrivateRSAKey(config.Server.HostKeyBits) if err != nil { - dlog.Common.FatalPanic("Failed to generate private server RSA host key", err) + dlog.Server.FatalPanic("Failed to generate private server RSA host key", err) } pem := ssh.EncodePrivateKeyToPEM(privateKey) if err := ioutil.WriteFile(hostKeyFile, pem, 0600); err != nil { - dlog.Common.Error("Unable to write private server RSA host key to file", + dlog.Server.Error("Unable to write private server RSA host key to file", hostKeyFile, err) } return pem } - dlog.Common.Info("Reading private server RSA host key from file", hostKeyFile) + dlog.Server.Info("Reading private server RSA host key from file", hostKeyFile) pem, err := ioutil.ReadFile(hostKeyFile) if err != nil { - dlog.Common.FatalPanic("Failed to load private server RSA host key", err) + dlog.Server.FatalPanic("Failed to load private server RSA host key", err) } return pem } diff --git a/internal/ssh/server/publickeycallback.go b/internal/ssh/server/publickeycallback.go index 585469f..c661419 100644 --- a/internal/ssh/server/publickeycallback.go +++ b/internal/ssh/server/publickeycallback.go @@ -23,9 +23,9 @@ func PublicKeyCallback(c gossh.ConnMetadata, return nil, err } - dlog.Common.Info(user, "Incoming authorization") + dlog.Server.Info(user, "Incoming authorization") if config.ServerRelaxedAuthEnable { - dlog.Common.Fatal(user, "Granting permissions via relaxed-auth") + dlog.Server.Fatal(user, "Granting permissions via relaxed-auth") return nil, nil } @@ -34,7 +34,7 @@ func PublicKeyCallback(c gossh.ConnMetadata, return nil, err } - dlog.Common.Info(user, "Reading", authorizedKeysFile) + dlog.Server.Info(user, "Reading", authorizedKeysFile) authorizedKeysBytes, err := ioutil.ReadFile(authorizedKeysFile) if err != nil { return nil, fmt.Errorf("Unable to read authorized keys file|%s|%s|%s", @@ -56,11 +56,11 @@ func verifyAuthorizedKeys(user *user.User, authorizedKeysBytes []byte, } authorizedKeysMap[string(authorizedPubKey.Marshal())] = true authorizedKeysBytes = restBytes - dlog.Common.Debug(user, "Authorized public key fingerprint", + dlog.Server.Debug(user, "Authorized public key fingerprint", gossh.FingerprintSHA256(authorizedPubKey)) } - dlog.Common.Debug(user, "Offered public key fingerprint", gossh.FingerprintSHA256(offeredPubKey)) + dlog.Server.Debug(user, "Offered public key fingerprint", gossh.FingerprintSHA256(offeredPubKey)) if authorizedKeysMap[string(offeredPubKey.Marshal())] { return &gossh.Permissions{ Extensions: map[string]string{"pubkey-fp": gossh.FingerprintSHA256(offeredPubKey)}, -- cgit v1.2.3