mirror of
https://github.com/golang/go
synced 2024-11-13 16:00:21 -07:00
exp/ssh: rename ClientAuthPublicKey helper ClientAuthKeyring
Also, rename ServerConfig.PubKeyCallback to PublicKeyCallback. R=rsc, agl CC=golang-dev https://golang.org/cl/5477059
This commit is contained in:
parent
17264df112
commit
fc6df2fdd8
@ -283,8 +283,8 @@ func (p *publickeyAuth) method() string {
|
|||||||
return "publickey"
|
return "publickey"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientAuthPublickey returns a ClientAuth using public key authentication.
|
// ClientAuthKeyring returns a ClientAuth using public key authentication.
|
||||||
func ClientAuthPublickey(impl ClientKeyring) ClientAuth {
|
func ClientAuthKeyring(impl ClientKeyring) ClientAuth {
|
||||||
return &publickeyAuth{impl}
|
return &publickeyAuth{impl}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ var (
|
|||||||
PasswordCallback: func(user, pass string) bool {
|
PasswordCallback: func(user, pass string) bool {
|
||||||
return user == "testuser" && pass == string(clientPassword)
|
return user == "testuser" && pass == string(clientPassword)
|
||||||
},
|
},
|
||||||
PubKeyCallback: func(user, algo string, pubkey []byte) bool {
|
PublicKeyCallback: func(user, algo string, pubkey []byte) bool {
|
||||||
key := clientKeychain.keys[0].(*rsa.PrivateKey).PublicKey
|
key := clientKeychain.keys[0].(*rsa.PrivateKey).PublicKey
|
||||||
expected := []byte(serializePublickey(key))
|
expected := []byte(serializePublickey(key))
|
||||||
algoname := algoName(key)
|
algoname := algoName(key)
|
||||||
@ -179,7 +179,7 @@ func TestClientAuthPublickey(t *testing.T) {
|
|||||||
config := &ClientConfig{
|
config := &ClientConfig{
|
||||||
User: "testuser",
|
User: "testuser",
|
||||||
Auth: []ClientAuth{
|
Auth: []ClientAuth{
|
||||||
ClientAuthPublickey(clientKeychain),
|
ClientAuthKeyring(clientKeychain),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c, err := Dial("tcp", newMockAuthServer(t), config)
|
c, err := Dial("tcp", newMockAuthServer(t), config)
|
||||||
@ -210,7 +210,7 @@ func TestClientAuthWrongPassword(t *testing.T) {
|
|||||||
User: "testuser",
|
User: "testuser",
|
||||||
Auth: []ClientAuth{
|
Auth: []ClientAuth{
|
||||||
ClientAuthPassword(wrongPw),
|
ClientAuthPassword(wrongPw),
|
||||||
ClientAuthPublickey(clientKeychain),
|
ClientAuthKeyring(clientKeychain),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ func TestClientAuthInvalidPublickey(t *testing.T) {
|
|||||||
config := &ClientConfig{
|
config := &ClientConfig{
|
||||||
User: "testuser",
|
User: "testuser",
|
||||||
Auth: []ClientAuth{
|
Auth: []ClientAuth{
|
||||||
ClientAuthPublickey(kc),
|
ClientAuthKeyring(kc),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ func TestClientAuthRSAandDSA(t *testing.T) {
|
|||||||
config := &ClientConfig{
|
config := &ClientConfig{
|
||||||
User: "testuser",
|
User: "testuser",
|
||||||
Auth: []ClientAuth{
|
Auth: []ClientAuth{
|
||||||
ClientAuthPublickey(kc),
|
ClientAuthKeyring(kc),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c, err := Dial("tcp", newMockAuthServer(t), config)
|
c, err := Dial("tcp", newMockAuthServer(t), config)
|
||||||
|
@ -50,7 +50,7 @@ func TestFuncPublickeyAuth(t *testing.T) {
|
|||||||
config := &ClientConfig{
|
config := &ClientConfig{
|
||||||
User: *sshuser,
|
User: *sshuser,
|
||||||
Auth: []ClientAuth{
|
Auth: []ClientAuth{
|
||||||
ClientAuthPublickey(kc),
|
ClientAuthKeyring(kc),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
conn, err := Dial("tcp", "localhost:22", config)
|
conn, err := Dial("tcp", "localhost:22", config)
|
||||||
|
@ -36,10 +36,10 @@ type ServerConfig struct {
|
|||||||
// several goroutines.
|
// several goroutines.
|
||||||
PasswordCallback func(user, password string) bool
|
PasswordCallback func(user, password string) bool
|
||||||
|
|
||||||
// PubKeyCallback, if non-nil, is called when a client attempts public
|
// PublicKeyCallback, if non-nil, is called when a client attempts public
|
||||||
// key authentication. It must return true iff the given public key is
|
// key authentication. It must return true iff the given public key is
|
||||||
// valid for the given user.
|
// valid for the given user.
|
||||||
PubKeyCallback func(user, algo string, pubkey []byte) bool
|
PublicKeyCallback func(user, algo string, pubkey []byte) bool
|
||||||
|
|
||||||
// Cryptographic-related configuration.
|
// Cryptographic-related configuration.
|
||||||
Crypto CryptoConfig
|
Crypto CryptoConfig
|
||||||
@ -359,7 +359,7 @@ func isAcceptableAlgo(algo string) bool {
|
|||||||
|
|
||||||
// testPubKey returns true if the given public key is acceptable for the user.
|
// testPubKey returns true if the given public key is acceptable for the user.
|
||||||
func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
|
func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
|
||||||
if s.config.PubKeyCallback == nil || !isAcceptableAlgo(algo) {
|
if s.config.PublicKeyCallback == nil || !isAcceptableAlgo(algo) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := s.config.PubKeyCallback(user, algo, pubKey)
|
result := s.config.PublicKeyCallback(user, algo, pubKey)
|
||||||
if len(s.cachedPubKeys) < maxCachedPubKeys {
|
if len(s.cachedPubKeys) < maxCachedPubKeys {
|
||||||
c := cachedPubKey{
|
c := cachedPubKey{
|
||||||
user: user,
|
user: user,
|
||||||
@ -425,7 +425,7 @@ userAuthLoop:
|
|||||||
break userAuthLoop
|
break userAuthLoop
|
||||||
}
|
}
|
||||||
case "publickey":
|
case "publickey":
|
||||||
if s.config.PubKeyCallback == nil {
|
if s.config.PublicKeyCallback == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
payload := userAuthReq.Payload
|
payload := userAuthReq.Payload
|
||||||
@ -499,7 +499,7 @@ userAuthLoop:
|
|||||||
if s.config.PasswordCallback != nil {
|
if s.config.PasswordCallback != nil {
|
||||||
failureMsg.Methods = append(failureMsg.Methods, "password")
|
failureMsg.Methods = append(failureMsg.Methods, "password")
|
||||||
}
|
}
|
||||||
if s.config.PubKeyCallback != nil {
|
if s.config.PublicKeyCallback != nil {
|
||||||
failureMsg.Methods = append(failureMsg.Methods, "publickey")
|
failureMsg.Methods = append(failureMsg.Methods, "publickey")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func dial(handler serverType, t *testing.T) *ClientConn {
|
|||||||
serverConfig.PasswordCallback = func(user, pass string) bool {
|
serverConfig.PasswordCallback = func(user, pass string) bool {
|
||||||
return user == "testuser" && pass == string(pw)
|
return user == "testuser" && pass == string(pw)
|
||||||
}
|
}
|
||||||
serverConfig.PubKeyCallback = nil
|
serverConfig.PublicKeyCallback = nil
|
||||||
|
|
||||||
l, err := Listen("tcp", "127.0.0.1:0", serverConfig)
|
l, err := Listen("tcp", "127.0.0.1:0", serverConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user