forked from x/icebergs
opt some
This commit is contained in:
parent
97e4564f6e
commit
f1efc38f47
@ -6,4 +6,4 @@ const AAA = "aaa"
|
||||
|
||||
var Index = &ice.Context{Name: AAA, Help: "认证模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, ROLE, SESS, TOTP, USER) }
|
||||
func init() { ice.Index.Register(Index, nil, ROLE, SESS, TOTP, USER, RSA) }
|
||||
|
56
base/aaa/rsa.go
Normal file
56
base/aaa/rsa.go
Normal file
@ -0,0 +1,56 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
PUBLIC = "public"
|
||||
PRIVATE = "private"
|
||||
)
|
||||
const RSA = "rsa"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
RSA: {Name: RSA, Help: "角色", Value: kit.Data(mdb.SHORT, mdb.HASH, mdb.FIELD, "time,hash,public,private")},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
RSA: {Name: "rsa hash auto create import", Help: "公钥", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
// m.Cmd(m.PrefixKey(), mdb.IMPORT)
|
||||
}},
|
||||
mdb.IMPORT: {Name: "import key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.PrefixKey(), kit.Keys(mdb.HASH, "id_rsa"), kit.Data(mdb.TIME, m.Time(),
|
||||
PRIVATE, m.Cmdx("nfs.cat", kit.HomePath(m.Option("key"))),
|
||||
PUBLIC, m.Cmdx("nfs.cat", kit.HomePath(m.Option("pub"))),
|
||||
))
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(m.PrefixKey(), m.Option(mdb.HASH)).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmdx("nfs.save", kit.HomePath(m.Option("key")), value[PRIVATE])
|
||||
m.Cmdx("nfs.save", kit.HomePath(m.Option("pub")), value[PUBLIC])
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create bits=2048,4096", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if key, err := rsa.GenerateKey(rand.Reader, kit.Int(m.Option("bits"))); m.Assert(err) {
|
||||
if pub, err := ssh.NewPublicKey(key.Public()); m.Assert(err) {
|
||||
m.Cmdy(mdb.INSERT, m.PrefixKey(), "", mdb.HASH,
|
||||
PRIVATE, string(pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})),
|
||||
PUBLIC, string(ssh.MarshalAuthorizedKey(pub)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...)
|
||||
m.PushAction(mdb.EXPORT, mdb.REMOVE)
|
||||
}},
|
||||
}})
|
||||
}
|
@ -102,7 +102,7 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
CONFIG: {Name: CONFIG, Help: "配置", Value: kit.Data(nfs.PATH, ice.VAR_CONF)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
CONFIG: {Name: "config key auto clear", Help: "配置", Action: map[string]*ice.Action{
|
||||
CONFIG: {Name: "config key auto reset", Help: "配置", Action: map[string]*ice.Action{
|
||||
SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_save(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
@ -122,9 +122,9 @@ func init() {
|
||||
}
|
||||
m.Confv(arg[0], arg[1], kit.List(list...))
|
||||
}},
|
||||
"clear": {Name: "clear conf key", Help: "清空", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.Option("conf"), m.Option("key"), "")
|
||||
m.Cmd(ice.EXIT, 1)
|
||||
"reset": {Name: "reset key sub", Help: "重置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.Option("key"), m.Option("sub"), "")
|
||||
m.Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
|
@ -51,8 +51,8 @@ type {{.Option "name"}} struct {
|
||||
list string {{.Option "text"}}
|
||||
}
|
||||
|
||||
func (h {{.Option "name"}}) List(m *ice.Message, arg ...string) {
|
||||
h.{{.Option "type"}}.List(m, arg...)
|
||||
func (s {{.Option "name"}}) List(m *ice.Message, arg ...string) {
|
||||
s.{{.Option "type"}}.List(m, arg...)
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) }
|
||||
|
2
go.mod
2
go.mod
@ -4,6 +4,6 @@ go 1.11
|
||||
|
||||
require (
|
||||
shylinux.com/x/go-qrcode v0.0.1
|
||||
shylinux.com/x/toolkits v0.5.4
|
||||
shylinux.com/x/toolkits v0.5.5
|
||||
shylinux.com/x/websocket v0.0.1
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -1,4 +1,4 @@
|
||||
shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
|
||||
shylinux.com/x/toolkits v0.5.4 h1:Wy1qw264qEPzLYHfMhy9tmm+6+zycit75hJVxwu83cQ=
|
||||
shylinux.com/x/toolkits v0.5.4/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
||||
shylinux.com/x/toolkits v0.5.5 h1:zbUu6jcfX6xUjzJ479VHC+zLKaSzHHjU4suICeqRCaQ=
|
||||
shylinux.com/x/toolkits v0.5.5/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
||||
shylinux.com/x/websocket v0.0.1/go.mod h1:AaSpMToOxbMULKQytzczeHPuqb708vK1vrAzCxLo/XE=
|
||||
|
Loading…
x
Reference in New Issue
Block a user