diff --git a/ssh/agent.go b/ssh/agent.go index 34d084c..5d2175d 100644 --- a/ssh/agent.go +++ b/ssh/agent.go @@ -206,7 +206,7 @@ func (ac *AgentClient) RequestIdentities() ([]*AgentKey, error) { // as defined in [PROTOCOL.agent] section 2.6.2. func (ac *AgentClient) SignRequest(key interface{}, data []byte) ([]byte, error) { req := marshal(agentSignRequest, signRequestAgentMsg{ - KeyBlob: serializePublickey(key), + KeyBlob: serializePublicKey(key), Data: data, }) diff --git a/ssh/certs.go b/ssh/certs.go index 82c120e..0094b3d 100644 --- a/ssh/certs.go +++ b/ssh/certs.go @@ -160,7 +160,7 @@ func marshalOpenSSHCertV01(cert *OpenSSHCertV01) []byte { panic("ssh: unknown public key type in cert") } - sigKey := serializePublickey(cert.SignatureKey) + sigKey := serializePublicKey(cert.SignatureKey) length := stringLength(len(cert.Nonce)) length += len(pubKey) diff --git a/ssh/client_auth.go b/ssh/client_auth.go index 5301d49..abdb24a 100644 --- a/ssh/client_auth.go +++ b/ssh/client_auth.go @@ -214,7 +214,7 @@ 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) + pubkey := serializePublicKey(key) algoname := algoName(key) sign, err := p.Sign(i, rand, buildDataSignedForAuth(session, userAuthRequestMsg{ User: user, @@ -254,7 +254,7 @@ 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) + pubkey := serializePublicKey(key) algoname := algoName(key) msg := publickeyAuthMsg{ User: user, @@ -272,7 +272,7 @@ func (p *publickeyAuth) validateKey(key interface{}, user string, t *transport) } func (p *publickeyAuth) confirmKeyAck(key interface{}, t *transport) (bool, error) { - pubkey := serializePublickey(key) + pubkey := serializePublicKey(key) algoname := algoName(key) for { diff --git a/ssh/client_auth_test.go b/ssh/client_auth_test.go index ff64ad7..ba11949 100644 --- a/ssh/client_auth_test.go +++ b/ssh/client_auth_test.go @@ -135,7 +135,7 @@ var ( }, PublicKeyCallback: func(conn *ServerConn, user, algo string, pubkey []byte) bool { key := &clientKeychain.keys[0].(*rsa.PrivateKey).PublicKey - expected := []byte(serializePublickey(key)) + expected := []byte(serializePublicKey(key)) algoname := algoName(key) return user == "testuser" && algo == algoname && bytes.Equal(pubkey, expected) }, @@ -198,7 +198,7 @@ func newMockAuthServer(t *testing.T) string { return l.Addr().String() } -func TestClientAuthPublickey(t *testing.T) { +func TestClientAuthPublicKey(t *testing.T) { config := &ClientConfig{ User: "testuser", Auth: []ClientAuth{ @@ -283,7 +283,7 @@ func TestClientAuthWrongKeyboardInteractive(t *testing.T) { } // the mock server will only authenticate ssh-rsa keys -func TestClientAuthInvalidPublickey(t *testing.T) { +func TestClientAuthInvalidPublicKey(t *testing.T) { kc := new(keychain) kc.keys = append(kc.keys, dsakey) config := &ClientConfig{ diff --git a/ssh/common.go b/ssh/common.go index bbbb00e..3df556d 100644 --- a/ssh/common.go +++ b/ssh/common.go @@ -248,7 +248,7 @@ func serializeSignature(algoname string, sig []byte) []byte { } // serialize a *rsa.PublicKey or *dsa.PublicKey according to RFC 4253 6.6. -func serializePublickey(key interface{}) []byte { +func serializePublicKey(key interface{}) []byte { var pubKeyBytes []byte algoname := algoName(key) switch key := key.(type) { @@ -304,7 +304,7 @@ func algoName(key interface{}) string { } } } - panic("unexpected key type") + panic(fmt.Sprintf("unexpected key type %T", key)) } // buildDataSignedForAuth returns the data that is signed in order to prove diff --git a/ssh/keys.go b/ssh/keys.go index d1b1c79..1dd6856 100644 --- a/ssh/keys.go +++ b/ssh/keys.go @@ -125,21 +125,6 @@ func parseECDSA(in []byte) (out *ecdsa.PublicKey, rest []byte, ok bool) { return key, in, ok } -// marshalPrivRSA serializes an RSA private key according to RFC 4253, section 6.6. -func marshalPrivRSA(priv *rsa.PrivateKey) []byte { - e := new(big.Int).SetInt64(int64(priv.E)) - length := stringLength(len(KeyAlgoRSA)) - length += intLength(e) - length += intLength(priv.N) - - ret := make([]byte, length) - r := marshalString(ret, []byte(KeyAlgoRSA)) - r = marshalInt(r, e) - r = marshalInt(r, priv.N) - - return ret -} - // marshalPubRSA serializes an RSA public key according to RFC 4253, section 6.6. func marshalPubRSA(key *rsa.PublicKey) []byte { e := new(big.Int).SetInt64(int64(key.E)) @@ -334,7 +319,7 @@ func MarshalAuthorizedKey(key interface{}) []byte { b.WriteString(algoName(key)) b.WriteByte(' ') e := base64.NewEncoder(base64.StdEncoding, b) - e.Write(serializePublickey(key)) + e.Write(serializePublicKey(key)) e.Close() b.WriteByte('\n') return b.Bytes() @@ -345,5 +330,5 @@ func MarshalAuthorizedKey(key interface{}) []byte { // of ServerConfig's PublicKeyCallback as well as for generating an // authorized_keys or host_keys file. func MarshalPublicKey(key interface{}) []byte { - return serializePublickey(key) + return serializePublicKey(key) } diff --git a/ssh/server.go b/ssh/server.go index 434932c..c172a09 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -82,7 +82,7 @@ func (s *ServerConfig) SetRSAPrivateKey(pemBytes []byte) error { return err } - s.rsaSerialized = marshalPrivRSA(s.rsa) + s.rsaSerialized = serializePublicKey(&s.rsa.PublicKey) return nil }