MCPcopy Create free account
hub / github.com/belak/gitdir / handlePublicKey

Method handlePublicKey

ssh_server.go:144–184  ·  view source on GitHub ↗
(ctx ssh.Context, incomingKey ssh.PublicKey)

Source from the content-addressed store, hash-verified

142}
143
144func (serv *Server) handlePublicKey(ctx ssh.Context, incomingKey ssh.PublicKey) bool {
145 slog := CtxLogger(ctx).With().
146 Str("remote_user", ctx.User()).
147 Str("remote_addr", ctx.RemoteAddr().String()).Logger()
148
149 remoteUser := ctx.User()
150
151 config := serv.GetAdminConfig()
152
153 pk := models.PublicKey{PublicKey: incomingKey}
154
155 /*
156 if strings.HasPrefix(remoteUser, settings.Options.InvitePrefix) {
157 invite := remoteUser[len(settings.Options.InvitePrefix):]
158
159 // Try to accept the invite. If this fails, bail out. Otherwise,
160 // continue looking up the user as normal.
161 if ok := serv.AcceptInvite(invite, models.PublicKey{incomingKey, ""}); !ok {
162 return false
163 }
164
165 // If it succeeded, we actually need to pull the refreshed admin config
166 // so the new user shows up.
167 settings = serv.GetAdminConfig()
168 }
169 */
170
171 user, err := config.LookupUserFromKey(pk, remoteUser)
172 if err != nil {
173 slog.Warn().Err(err).Msg("User not found")
174 return false
175 }
176
177 // Update the context with what we discovered
178 CtxSetUser(ctx, user)
179 CtxSetConfig(ctx, config)
180 CtxSetLogger(ctx, &slog)
181 CtxSetPublicKey(ctx, &pk)
182
183 return true
184}
185
186func (serv *Server) handleSession(s ssh.Session) {
187 var ctx context.Context = s.Context()

Callers

nothing calls this directly

Calls 8

GetAdminConfigMethod · 0.95
CtxLoggerFunction · 0.85
CtxSetUserFunction · 0.85
CtxSetConfigFunction · 0.85
CtxSetLoggerFunction · 0.85
CtxSetPublicKeyFunction · 0.85
LookupUserFromKeyMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected