Skip to content

Commit db14517

Browse files
committed
cmd/ssh-chat: Accept multiple --identity keys
Fixes #401
1 parent 88fa53f commit db14517

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

cmd/ssh-chat/cmd.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ var Version string = "dev"
2828

2929
// Options contains the flag options
3030
type Options struct {
31-
Admin string `long:"admin" description:"File of public keys who are admins."`
32-
Bind string `long:"bind" description:"Host and port to listen on." default:"0.0.0.0:2022"`
33-
Identity string `short:"i" long:"identity" description:"Private key to identify server with." default:"~/.ssh/id_rsa"`
34-
Log string `long:"log" description:"Write chat log to this file."`
35-
Motd string `long:"motd" description:"Optional Message of the Day file."`
36-
Pprof int `long:"pprof" description:"Enable pprof http server for profiling."`
37-
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
38-
Version bool `long:"version" description:"Print version and exit."`
39-
Whitelist string `long:"whitelist" description:"Optional file of public keys who are allowed to connect."`
40-
Passphrase string `long:"unsafe-passphrase" description:"Require an interactive passphrase to connect. Whitelist feature is more secure."`
31+
Admin string `long:"admin" description:"File of public keys who are admins."`
32+
Bind string `long:"bind" description:"Host and port to listen on." default:"0.0.0.0:2022"`
33+
Identity []string `short:"i" long:"identity" description:"Private key to identify server with." default:"~/.ssh/id_rsa"`
34+
Log string `long:"log" description:"Write chat log to this file."`
35+
Motd string `long:"motd" description:"Optional Message of the Day file."`
36+
Pprof int `long:"pprof" description:"Enable pprof http server for profiling."`
37+
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
38+
Version bool `long:"version" description:"Print version and exit."`
39+
Whitelist string `long:"whitelist" description:"Optional file of public keys who are allowed to connect."`
40+
Passphrase string `long:"unsafe-passphrase" description:"Require an interactive passphrase to connect. Whitelist feature is more secure."`
4141
}
4242

4343
const extraHelp = `There are hidden options and easter eggs in ssh-chat. The source code is a good
@@ -102,25 +102,28 @@ func main() {
102102
message.SetLogger(os.Stderr)
103103
}
104104

105-
privateKeyPath := options.Identity
106-
if strings.HasPrefix(privateKeyPath, "~/") {
107-
user, err := user.Current()
108-
if err == nil {
109-
privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1)
110-
}
111-
}
112-
113-
signer, err := ReadPrivateKey(privateKeyPath)
114-
if err != nil {
115-
fail(3, "Failed to read identity private key: %v\n", err)
116-
}
117-
118105
auth := sshchat.NewAuth()
119106
config := sshd.MakeAuth(auth)
120-
config.AddHostKey(signer)
121107
config.ServerVersion = "SSH-2.0-Go ssh-chat"
122108
// FIXME: Should we be using config.NoClientAuth = true by default?
123109

110+
for _, privateKeyPath := range options.Identity {
111+
if strings.HasPrefix(privateKeyPath, "~/") {
112+
user, err := user.Current()
113+
if err == nil {
114+
privateKeyPath = strings.Replace(privateKeyPath, "~", user.HomeDir, 1)
115+
}
116+
}
117+
118+
signer, err := ReadPrivateKey(privateKeyPath)
119+
if err != nil {
120+
fail(3, "Failed to read identity private key: %v\n", err)
121+
}
122+
123+
config.AddHostKey(signer)
124+
fmt.Printf("Added server identity: %s\n", sshd.Fingerprint(signer.PublicKey()))
125+
}
126+
124127
s, err := sshd.ListenSSH(options.Bind, config)
125128
if err != nil {
126129
fail(4, "Failed to listen on socket: %v\n", err)

0 commit comments

Comments
 (0)