621d920d05b0112e49409a48e84d53f8bb531cc0

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(ssh): check of empty pk and tidy context mw

Diff

 1diff --git a/pkg/ssh/middleware.go b/pkg/ssh/middleware.go
 2index 638e1f78a4e38513376423f8c8a7d9a4b4ab18b0..1bd93f99c0c81122f18c956056fa07cebaedee96 100644
 3--- a/pkg/ssh/middleware.go
 4+++ b/pkg/ssh/middleware.go
 5@@ -45,7 +45,7 @@ func AuthenticationMiddleware(sh ssh.Handler) ssh.Handler {
 6 
 7 			// Check if the key is the same as the one we have in context
 8 			fp := perms.Extensions["pubkey-fp"]
 9-			if fp != gossh.FingerprintSHA256(pk) {
10+			if fp == "" || fp != gossh.FingerprintSHA256(pk) {
11 				wish.Fatalln(s, ErrPermissionDenied)
12 				return
13 			}
14@@ -59,12 +59,13 @@ func AuthenticationMiddleware(sh ssh.Handler) ssh.Handler {
15 func ContextMiddleware(cfg *config.Config, dbx *db.DB, datastore store.Store, be *backend.Backend, logger *log.Logger) func(ssh.Handler) ssh.Handler {
16 	return func(sh ssh.Handler) ssh.Handler {
17 		return func(s ssh.Session) {
18-			s.Context().SetValue(sshutils.ContextKeySession, s)
19-			s.Context().SetValue(config.ContextKey, cfg)
20-			s.Context().SetValue(db.ContextKey, dbx)
21-			s.Context().SetValue(store.ContextKey, datastore)
22-			s.Context().SetValue(backend.ContextKey, be)
23-			s.Context().SetValue(log.ContextKey, logger.WithPrefix("ssh"))
24+			ctx := s.Context()
25+			ctx.SetValue(sshutils.ContextKeySession, s)
26+			ctx.SetValue(config.ContextKey, cfg)
27+			ctx.SetValue(db.ContextKey, dbx)
28+			ctx.SetValue(store.ContextKey, datastore)
29+			ctx.SetValue(backend.ContextKey, be)
30+			ctx.SetValue(log.ContextKey, logger.WithPrefix("ssh"))
31 			sh(s)
32 		}
33 	}