Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const (
ServerVersion = "SSH-2.0-ServerMock 1.0"
)
Variables ¶
This section is empty.
Functions ¶
func NewRSAKey ¶
func NewRSAKey(bitSize int) *rsa.PrivateKey
func NewSSHKeyPair ¶
func NewSSHKeyPair(bitSize int) (private *rsa.PrivateKey, public ssh.PublicKey)
NewSSHKeyPair generate new key pair
Example ¶
// prepare keys
privateKey, publicKey := sshtest.NewSSHKeyPair(2048)
// auth in your client with agent
myAgent := agent.NewKeyring()
_ = myAgent.Add(agent.AddedKey{PrivateKey: privateKey})
_ = &ssh.ClientConfig{
Auth: []ssh.AuthMethod{
ssh.PublicKeysCallback(func() (signers []ssh.Signer, err error) {
return myAgent.Signers()
}),
},
}
// auth in your client with signer from key
signer, _ := ssh.NewSignerFromKey(privateKey)
_ = &ssh.ClientConfig{
Auth: []ssh.AuthMethod{
ssh.PublicKeysCallback(func() (signers []ssh.Signer, err error) {
return []ssh.Signer{signer}, nil
}),
},
}
// publicKeyCallback in your server
_ = &ssh.ServerConfig{
PublicKeyCallback: func(c ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
if string(publicKey.Marshal()) == string(pubKey.Marshal()) {
return &ssh.Permissions{
// Record the public key used for authentication.
Extensions: map[string]string{
"pubkey-fp": ssh.FingerprintSHA256(pubKey),
},
}, nil
}
return nil, fmt.Errorf("unknown public key for %q", c.User())
},
}
Types ¶
type Channel ¶
func NewChannel ¶
func NewChannel(channel ssh.NewChannel, mockData *MockData) *Channel
type ChannelStat ¶
type ChannelStat struct {
}
type Connection ¶
type Connection struct {
net.Conn
ClientConn *ssh.ServerConn
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(conn net.Conn, mockData *MockData) *Connection
func (*Connection) ServedChannels ¶
func (s *Connection) ServedChannels() []*Channel
type ConnectionStat ¶
type ConnectionStat struct {
}
type MockData ¶
type MockData struct {
// contains filtered or unexported fields
}
func NewMockData ¶
func NewMockData() *MockData
type Server ¶
type Server struct {
// ssh server config
*ssh.ServerConfig
*MockData
// timeout before force disconnect all clients when server is stopping
StopTimeout time.Duration
// contains filtered or unexported fields
}
func NewMockedServer ¶
func NewMockedServer() (server *Server)
func (*Server) AddAuthorizedKey ¶
func (*Server) ServedConnections ¶
func (s *Server) ServedConnections() []*Connection
Click to show internal directories.
Click to hide internal directories.