summaryrefslogtreecommitdiff
path: root/internal/ssh/server/publickeycallback.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-09 21:10:29 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 13:36:41 +0300
commit97747ea0f3178f7f5890512d483fdccaa82846b0 (patch)
tree9ff1335ca26afc90e55fd6de416457e252d75a35 /internal/ssh/server/publickeycallback.go
parent7a7169791a64190e1002e38bc9c04ad0d5c1ce1f (diff)
vetting and linting and some code restyling
Diffstat (limited to 'internal/ssh/server/publickeycallback.go')
-rw-r--r--internal/ssh/server/publickeycallback.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/internal/ssh/server/publickeycallback.go b/internal/ssh/server/publickeycallback.go
index 59d1f31..ebc428a 100644
--- a/internal/ssh/server/publickeycallback.go
+++ b/internal/ssh/server/publickeycallback.go
@@ -13,25 +13,28 @@ import (
gossh "golang.org/x/crypto/ssh"
)
-// PublicKeyCallback is for the server to check whether a public SSH key is authorized ot not.
-func PublicKeyCallback(c gossh.ConnMetadata, offeredPubKey gossh.PublicKey) (*gossh.Permissions, error) {
+// PublicKeyCallback is for the server to check whether a public SSH key is
+// authorized ot not.
+func PublicKeyCallback(c gossh.ConnMetadata,
+ offeredPubKey gossh.PublicKey) (*gossh.Permissions, error) {
+
user, err := user.New(c.User(), c.RemoteAddr().String())
if err != nil {
return nil, err
}
- dlog.Common.Info(user, "Incoming authorization")
+ dlog.Common.Info(user, "Incoming authorization")
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("Unable to get current working directory|%s|", err.Error())
}
-
if config.ServerRelaxedAuthEnable {
dlog.Common.Fatal(user, "Granting permissions via relaxed-auth")
return nil, nil
}
- authorizedKeysFile := fmt.Sprintf("%s/%s/%s.authorized_keys", cwd, config.Common.CacheDir, user.Name)
+ authorizedKeysFile := fmt.Sprintf("%s/%s/%s.authorized_keys", cwd,
+ config.Common.CacheDir, user.Name)
if _, err := os.Stat(authorizedKeysFile); os.IsNotExist(err) {
user, err := osUser.Lookup(user.Name)
if err != nil {
@@ -44,23 +47,25 @@ func PublicKeyCallback(c gossh.ConnMetadata, offeredPubKey gossh.PublicKey) (*go
dlog.Common.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", authorizedKeysFile, user, err.Error())
+ return nil, fmt.Errorf("Unable to read authorized keys file|%s|%s|%s",
+ authorizedKeysFile, user, err.Error())
}
authorizedKeysMap := map[string]bool{}
for len(authorizedKeysBytes) > 0 {
authorizedPubKey, _, _, restBytes, err := gossh.ParseAuthorizedKey(authorizedKeysBytes)
if err != nil {
- return nil, fmt.Errorf("Unable to parse authorized keys bytes|%s|%s", user, err.Error())
+ return nil, fmt.Errorf("Unable to parse authorized keys bytes|%s|%s",
+ user, err.Error())
}
authorizedKeysMap[string(authorizedPubKey.Marshal())] = true
authorizedKeysBytes = restBytes
-
- dlog.Common.Debug(user, "Authorized public key fingerprint", gossh.FingerprintSHA256(authorizedPubKey))
+ dlog.Common.Debug(user, "Authorized public key fingerprint",
+ gossh.FingerprintSHA256(authorizedPubKey))
}
- dlog.Common.Debug(user, "Offered public key fingerprint", gossh.FingerprintSHA256(offeredPubKey))
-
+ dlog.Common.Debug(user, "Offered public key fingerprint",
+ gossh.FingerprintSHA256(offeredPubKey))
if authorizedKeysMap[string(offeredPubKey.Marshal())] {
return &gossh.Permissions{
Extensions: map[string]string{