aboutsummaryrefslogtreecommitdiff
path: root/ssh/client_auth.go
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2013-09-13 14:25:14 -0400
committerAdam Langley <agl@golang.org>2013-09-13 14:25:14 -0400
commite62b2aead43494d8abe8c8be4cf9993beb379779 (patch)
tree2ebfc6dbd5c8f6c80439d5d308158fb278164f90 /ssh/client_auth.go
parent6a743c56c79964532cf81eb3e71013c7eaf286bc (diff)
downloadgo-x-crypto-e62b2aead43494d8abe8c8be4cf9993beb379779.tar.xz
go.crypto/ssh: introduce PublicKey interface type.
Public functions affected: -AgentKey.Key -AgentClient.SignRequest -ClientKeyring.Key -MarshalPublicKey -ParsePublicKey R=agl, jpsugar, jmpittman CC=golang-dev https://golang.org/cl/13642043
Diffstat (limited to 'ssh/client_auth.go')
-rw-r--r--ssh/client_auth.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/ssh/client_auth.go b/ssh/client_auth.go
index 7946843..31a5e09 100644
--- a/ssh/client_auth.go
+++ b/ssh/client_auth.go
@@ -155,9 +155,8 @@ func ClientAuthPassword(impl ClientPassword) ClientAuth {
// ClientKeyring implements access to a client key ring.
type ClientKeyring interface {
- // Key returns the i'th *rsa.Publickey or *dsa.Publickey, or nil if
- // no key exists at i.
- Key(i int) (key interface{}, err error)
+ // Key returns the i'th Publickey, or nil if no key exists at i.
+ Key(i int) (key PublicKey, err error)
// Sign returns a signature of the given data using the i'th key
// and the supplied random source.
@@ -190,7 +189,7 @@ func (p *publickeyAuth) auth(session []byte, user string, t *transport, rand io.
var index int
// a map of public keys to their index in the keyring
- validKeys := make(map[int]interface{})
+ validKeys := make(map[int]PublicKey)
for {
key, err := p.Key(index)
if err != nil {
@@ -214,8 +213,8 @@ func (p *publickeyAuth) auth(session []byte, user string, t *transport, rand io.
// methods that may continue if this auth is not successful.
var methods []string
for i, key := range validKeys {
- pubkey := serializePublicKey(key)
- algoname := algoName(key)
+ pubkey := MarshalPublicKey(key)
+ algoname := key.PublicKeyAlgo()
sign, err := p.Sign(i, rand, buildDataSignedForAuth(session, userAuthRequestMsg{
User: user,
Service: serviceSSH,
@@ -225,7 +224,7 @@ func (p *publickeyAuth) auth(session []byte, user string, t *transport, rand io.
return false, nil, err
}
// manually wrap the serialized signature in a string
- s := serializeSignature(algoname, sign)
+ s := serializeSignature(key.PublicKeyAlgo(), sign)
sig := make([]byte, stringLength(len(s)))
marshalString(sig, s)
msg := publickeyAuthMsg{
@@ -253,9 +252,9 @@ func (p *publickeyAuth) auth(session []byte, user string, t *transport, rand io.
}
// validateKey validates the key provided it is acceptable to the server.
-func (p *publickeyAuth) validateKey(key interface{}, user string, t *transport) (bool, error) {
- pubkey := serializePublicKey(key)
- algoname := algoName(key)
+func (p *publickeyAuth) validateKey(key PublicKey, user string, t *transport) (bool, error) {
+ pubkey := MarshalPublicKey(key)
+ algoname := key.PublicKeyAlgo()
msg := publickeyAuthMsg{
User: user,
Service: serviceSSH,
@@ -271,9 +270,9 @@ func (p *publickeyAuth) validateKey(key interface{}, user string, t *transport)
return p.confirmKeyAck(key, t)
}
-func (p *publickeyAuth) confirmKeyAck(key interface{}, t *transport) (bool, error) {
- pubkey := serializePublicKey(key)
- algoname := algoName(key)
+func (p *publickeyAuth) confirmKeyAck(key PublicKey, t *transport) (bool, error) {
+ pubkey := MarshalPublicKey(key)
+ algoname := key.PublicKeyAlgo()
for {
packet, err := t.readPacket()
@@ -352,7 +351,7 @@ type agentKeyring struct {
keys []*AgentKey
}
-func (kr *agentKeyring) Key(i int) (key interface{}, err error) {
+func (kr *agentKeyring) Key(i int) (key PublicKey, err error) {
if kr.keys == nil {
if kr.keys, err = kr.agent.RequestIdentities(); err != nil {
return
@@ -365,7 +364,7 @@ func (kr *agentKeyring) Key(i int) (key interface{}, err error) {
}
func (kr *agentKeyring) Sign(i int, rand io.Reader, data []byte) (sig []byte, err error) {
- var key interface{}
+ var key PublicKey
if key, err = kr.Key(i); err != nil {
return
}