Skip to content

Commit affa708

Browse files
committed
Add: Certificate verification login function
1 parent 97fd432 commit affa708

File tree

13 files changed

+135
-5
lines changed

13 files changed

+135
-5
lines changed

cmd/create/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ func NewCreateCommand() *cobra.Command {
1919
createCmd.AddCommand(ports.NewPortsCommand())
2020
createCmd.AddCommand(passwords.NewPasswordsCommand())
2121
createCmd.AddCommand(caches.NewCachesCommand())
22+
createCmd.AddCommand(NewKeysCommand())
2223
return createCmd
2324
}

cmd/create/keys.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package create
2+
3+
import (
4+
"github.com/Driver-C/tryssh/config"
5+
"github.com/Driver-C/tryssh/control/create"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const createType = "keys"
10+
11+
func NewKeysCommand() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "keys <keyFilePath>",
14+
Args: cobra.ExactArgs(1),
15+
Short: "Create a alternate key file path",
16+
Long: "Create a alternate key file path",
17+
Aliases: []string{"key"},
18+
Run: func(cmd *cobra.Command, args []string) {
19+
keyPath := args[0]
20+
configuration := config.LoadConfig()
21+
ctl := create.NewCreateController(createType, keyPath, configuration)
22+
ctl.ExecuteCreate()
23+
},
24+
}
25+
return cmd
26+
}

cmd/delete/delete.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ func NewDeleteCommand() *cobra.Command {
1919
deleteCmd.AddCommand(ports.NewPortsCommand())
2020
deleteCmd.AddCommand(passwords.NewPasswordsCommand())
2121
deleteCmd.AddCommand(caches.NewCachesCommand())
22+
deleteCmd.AddCommand(NewKeysCommand())
2223
return deleteCmd
2324
}

cmd/delete/keys.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package delete
2+
3+
import (
4+
"github.com/Driver-C/tryssh/config"
5+
"github.com/Driver-C/tryssh/control/delete"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const deleteType = "keys"
10+
11+
func NewKeysCommand() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "keys <keyFilePath>",
14+
Args: cobra.ExactArgs(1),
15+
Short: "Delete a alternate key file path",
16+
Long: "Delete a alternate key file path",
17+
Aliases: []string{"key"},
18+
Run: func(cmd *cobra.Command, args []string) {
19+
keyPath := args[0]
20+
configuration := config.LoadConfig()
21+
ctl := delete.NewDeleteController(deleteType, keyPath, configuration)
22+
ctl.ExecuteDelete()
23+
},
24+
}
25+
return cmd
26+
}

cmd/get/get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func NewGetCommand() *cobra.Command {
1818
getCmd.AddCommand(ports.NewPortsCommand())
1919
getCmd.AddCommand(passwords.NewPasswordsCommand())
2020
getCmd.AddCommand(caches.NewCachesCommand())
21+
getCmd.AddCommand(NewKeysCommand())
2122
return getCmd
2223
}

cmd/get/keys.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package get
2+
3+
import (
4+
"github.com/Driver-C/tryssh/config"
5+
"github.com/Driver-C/tryssh/control/get"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const getType = "keys"
10+
11+
func NewKeysCommand() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "keys <keyFilePath>",
14+
Short: "Get alternate key file path",
15+
Long: "Get alternate key file path",
16+
Aliases: []string{"key"},
17+
Run: func(cmd *cobra.Command, args []string) {
18+
var keyPath string
19+
if len(args) > 0 {
20+
keyPath = args[0]
21+
}
22+
configuration := config.LoadConfig()
23+
ctl := get.NewGetController(getType, keyPath, configuration)
24+
ctl.ExecuteGet()
25+
},
26+
}
27+
return cmd
28+
}

config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type MainConfig struct {
3838
Ports []string `yaml:"ports,flow"`
3939
Users []string `yaml:"users,flow"`
4040
Passwords []string `yaml:"passwords,flow"`
41+
Keys []string `yaml:"keys,flow"`
4142
} `yaml:"main"`
4243
ServerLists []ServerListConfig `yaml:"serverList"`
4344
}
@@ -48,6 +49,7 @@ type ServerListConfig struct {
4849
Port string `yaml:"port"`
4950
User string `yaml:"user"`
5051
Password string `yaml:"password"`
52+
Key string `yaml:"key"`
5153
Alias string `yaml:"alias"`
5254
}
5355

@@ -122,7 +124,8 @@ func GenerateCombination(ip string, user string, conf *MainConfig) (combinations
122124
users = utils.InterfaceSlice(conf.Main.Users)
123125
}
124126
passwords := utils.InterfaceSlice(conf.Main.Passwords)
127+
keys := utils.InterfaceSlice(conf.Main.Keys)
125128
// Generate combinations with immutable parameter order
126-
combinations = cartesian.Iter(ips, ports, users, passwords)
129+
combinations = cartesian.Iter(ips, ports, users, passwords, keys)
127130
return
128131
}

control/create/create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
typePorts = "ports"
1212
typePasswords = "passwords"
1313
typeCaches = "caches"
14+
typeKeys = "keys"
1415
)
1516

1617
type CacheContent struct {
@@ -41,6 +42,10 @@ func (cc Controller) ExecuteCreate() {
4142
cc.configuration.Main.Passwords = utils.RemoveDuplicate(
4243
append(cc.configuration.Main.Passwords, cc.createContent))
4344
cc.updateConfig()
45+
case typeKeys:
46+
cc.configuration.Main.Keys = utils.RemoveDuplicate(
47+
append(cc.configuration.Main.Keys, cc.createContent))
48+
cc.updateConfig()
4449
case typeCaches:
4550
cc.createCaches()
4651
cc.updateConfig()

control/delete/delete.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
typePorts = "ports"
1111
typePasswords = "passwords"
1212
typeCaches = "caches"
13+
typeKey = "keys"
1314
)
1415

1516
type Controller struct {
@@ -44,6 +45,14 @@ func (dc Controller) ExecuteDelete() {
4445
} else {
4546
utils.Logger.Warnf("No matching password: %s\n", dc.deleteContent)
4647
}
48+
case typeKey:
49+
contents := dc.configuration.Main.Keys
50+
if newContents := dc.searchAndDelete(contents); newContents != nil {
51+
dc.configuration.Main.Keys = newContents
52+
dc.updateConfig()
53+
} else {
54+
utils.Logger.Warnf("No matching key: %s\n", dc.deleteContent)
55+
}
4756
case typeCaches:
4857
// dc.deleteContent is ipAddress
4958
var deleteCount int

control/get/get.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
typePorts = "ports"
1111
typePasswords = "passwords"
1212
typeCaches = "caches"
13+
typeKeys = "keys"
1314
)
1415

1516
type Controller struct {
@@ -29,6 +30,9 @@ func (gc Controller) ExecuteGet() {
2930
case typePasswords:
3031
fmt.Println("INDEX PASSWORD")
3132
gc.searchAndPrint(gc.configuration.Main.Passwords)
33+
case typeKeys:
34+
fmt.Println("INDEX KEY")
35+
gc.searchAndPrint(gc.configuration.Main.Keys)
3236
case typeCaches:
3337
// gc.getContent is ipAddress
3438
fmt.Println("INDEX CACHE")

0 commit comments

Comments
 (0)