Make Context conform to "x/crypto/ssh".ConnMetadata interface#124
Make Context conform to "x/crypto/ssh".ConnMetadata interface#124ransford-stripe wants to merge 1 commit intogliderlabs:masterfrom
Conversation
It's useful for this package's sshContext to implement ConnMetadata when you
want to authenticate user certificates from a PublicKeyHandler.
Somewhat realistic example of user certificate checking after this patch:
checker := gossh.CertChecker{
IsUserAuthority: func(pub gossh.PublicKey) bool {
// our own logic to check whether pub is acceptable
return true
}
}
func isUserCertOk(ctx ssh.Context, key ssh.PublicKey) bool {
if cert, ok := key.(*gossh.Certificate); ok {
_, err := checker.Authenticate(ctx, cert)
}
}
sshServer := &ssh.Server{
// ...
PublicKeyHandler: isUserCertOK,
}
|
Oof, yeah. I'm not sure what to do about this - lots of the things in this library were done for convenience and I assume the Good call-out and solid PR, but you're right that it is a breaking change... |
|
Better to have a robust user base and to wring hands about breaking changes than to have no users at all! FWIW, here is a minimal workaround that wraps this package's type gContext ssh.Context
type gContextWrapper struct{ gContext }
func (s *gContextWrapper) ClientVersion() []byte { return []byte(s.gContext.ClientVersion()) }
func (s *gContextWrapper) ServerVersion() []byte { return []byte(s.gContext.ServerVersion()) }
func (s *gContextWrapper) SessionID() []byte {
dec, _ := hex.DecodeString(s.gContext.SessionID())
return dec
}
// now when you need a ConnMetadata but have only a ssh.Context, you can call:
// wctx := &gContextWrapper{ctx}
// _, err := checker.Authenticate(wctx, cert) |
|
One upside of returning a []byte rather than a string is it makes it clearer that the data is not necessarily display-safe. It's easy to inject all kinds of escape codes and whatnot in there, so sanitization is required. |
|
@belak this seems like it would pair nicely with #122 in a breaking-changes release tagged 0.3. @progrium did you have an opinion on this PR per Kaleb's comment? |
|
Yes, that seems reasonable. I’ll try to take another look later today. |
|
Hi team, just wondering if there are any plans to update or revisit this PR? |
This package's
Contextinterface is almost, but not quite, identical to x/crypto/ssh'sConnMetadatainterface. Seeing how similar they are, I wonder if the differences are unintentional.I'm pretty sure anyone implementing certificate-based user authentication will run into this interface mismatch while trying to plumb connection details through to a
CertChecker, because code like the simple example below fails to typecheck:This PR slightly changes the
Contextinterface so that ansshContextconforms toConnMetadata. Specifically:ClientVersion(),ServerVersion(), andSessionID()return[]byteinstead ofstringcontext_test.goThis is a breaking change, so I'll leave it to the maintainers to decide if and when to merge.
Thanks for this great library!