Skip to content

Commit 0aab6bf

Browse files
committed
init
1 parent 1240f5d commit 0aab6bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+14222
-0
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
23+
internal
24+
encrypted_fs.go
25+
*.enc
26+
dssh

.vscode/tasks.json

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "go",
6+
"label": "go: build _",
7+
"command": "build",
8+
"args": [
9+
"-C",
10+
"${fileDirname}",
11+
"-ldflags",
12+
"-s",
13+
"-trimpath",
14+
],
15+
"problemMatcher": [
16+
"$go"
17+
],
18+
"group": {
19+
"kind": "build",
20+
}
21+
},
22+
{
23+
"type": "go",
24+
"label": "go: build file",
25+
"command": "build",
26+
"args": [
27+
"-C",
28+
"${fileDirname}",
29+
"-ldflags",
30+
"-s",
31+
"-trimpath",
32+
"${file}"
33+
],
34+
"problemMatcher": [
35+
"$go"
36+
],
37+
"group": {
38+
"kind": "build",
39+
}
40+
},
41+
{
42+
"type": "go",
43+
"label": "go: build _ 386",
44+
"command": "build",
45+
"options": {
46+
"env": {
47+
"GOARCH": "386"
48+
}
49+
},
50+
"args": [
51+
"-C",
52+
"${fileDirname}",
53+
"-ldflags",
54+
"-s",
55+
"-trimpath",
56+
],
57+
"problemMatcher": [
58+
"$go"
59+
],
60+
"group": {
61+
"kind": "build",
62+
}
63+
},
64+
{
65+
"type": "shell",
66+
"label": "go: install",
67+
"command": "go",
68+
"args": [
69+
"install",
70+
"-C",
71+
"${fileDirname}",
72+
"-ldflags",
73+
"-s",
74+
"-trimpath",
75+
],
76+
"problemMatcher": [
77+
"$go"
78+
],
79+
"group": {
80+
"kind": "build",
81+
}
82+
},
83+
{
84+
"type": "go",
85+
"label": "go: build file 386",
86+
"command": "build",
87+
"options": {
88+
"env": {
89+
"GOARCH": "386"
90+
}
91+
},
92+
"args": [
93+
"-C",
94+
"${fileDirname}",
95+
"-ldflags",
96+
"-s",
97+
"-trimpath",
98+
"${file}"
99+
],
100+
"problemMatcher": [
101+
"$go"
102+
],
103+
"group": {
104+
"kind": "build",
105+
}
106+
},
107+
{
108+
"type": "go",
109+
"label": "go: build _ amd64",
110+
"command": "build",
111+
"options": {
112+
"env": {
113+
"GOARCH": "amd64"
114+
}
115+
},
116+
"args": [
117+
"-C",
118+
"${fileDirname}",
119+
"-ldflags",
120+
"-s",
121+
"-trimpath",
122+
],
123+
"problemMatcher": [
124+
"$go"
125+
],
126+
"group": {
127+
"kind": "build",
128+
},
129+
},
130+
{
131+
"type": "go",
132+
"label": "go: build file amd64",
133+
"command": "build",
134+
"options": {
135+
"env": {
136+
"GOARCH": "amd64"
137+
}
138+
},
139+
"args": [
140+
"-C",
141+
"${fileDirname}",
142+
"-ldflags",
143+
"-s",
144+
"-trimpath",
145+
"${file}"
146+
],
147+
"problemMatcher": [
148+
"$go"
149+
],
150+
"group": {
151+
"kind": "build",
152+
},
153+
},
154+
{
155+
"type": "shell",
156+
"label": "winres make",
157+
"command": "go-winres make --product-version=git-tag --file-version=git-tag",
158+
"group": "build"
159+
},
160+
{
161+
"type": "shell",
162+
"label": "ver.cmd",
163+
"command": "./ver.cmd",
164+
"group": "build"
165+
}
166+
]
167+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 abakum
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# dssh
2+
3+
dssh:=(tssh from trzsz)+(CA key with embed-encrypt)+(sshd from gliderlabs)

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

cmd/main.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"crypto/ecdsa"
5+
"crypto/elliptic"
6+
"crypto/rand"
7+
"crypto/x509"
8+
"flag"
9+
"internal/tool"
10+
"os"
11+
"path/filepath"
12+
)
13+
14+
func main() {
15+
const (
16+
ROOT = "internal"
17+
FILEMODE = 0600
18+
CA = "ca"
19+
)
20+
flag.Parse()
21+
tool.Priv(flag.Arg(0), flag.Arg(1))
22+
wd, err := os.Getwd()
23+
Panic(err)
24+
25+
name := filepath.Join(wd, ROOT, CA)
26+
_, err = os.Stat(name)
27+
if err == nil {
28+
os.Exit(0)
29+
}
30+
31+
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
32+
Panic(err)
33+
34+
data, err := x509.MarshalPKCS8PrivateKey(key)
35+
Panic(err)
36+
37+
err = os.WriteFile(name, data, FILEMODE)
38+
Panic(err)
39+
}
40+
41+
func Panic(err error) {
42+
if err != nil {
43+
panic(err)
44+
}
45+
}

dssh_etc.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package main
5+
6+
import (
7+
"bufio"
8+
"os"
9+
"path"
10+
"strings"
11+
12+
"github.com/abakum/winssh"
13+
)
14+
15+
var (
16+
PuTTY = winssh.UserHomeDirs(".putty")
17+
Sessions = path.Join(PuTTY, "sessions")
18+
SshHostCAs = path.Join(PuTTY, "sshhostcas")
19+
SshHostKeys = path.Join(PuTTY, "sshhostkeys")
20+
)
21+
22+
func confToMap(name, separator string) (kv map[string]string) {
23+
kv = make(map[string]string)
24+
file, err := os.Open(name)
25+
if err != nil {
26+
Println(err)
27+
return
28+
}
29+
defer file.Close()
30+
31+
scanner := bufio.NewScanner(file)
32+
for scanner.Scan() {
33+
s := scanner.Text()
34+
if s == "" {
35+
continue
36+
}
37+
ss := strings.Split(s, separator)
38+
v := ""
39+
if len(ss) > 1 {
40+
v = ss[1]
41+
}
42+
kv[ss[0]] = v
43+
}
44+
return
45+
}
46+
47+
func mapToConf(name, separator string, p map[string]string) (err error) {
48+
os.MkdirAll(path.Dir(name), 0700)
49+
f, err := os.Create(name)
50+
if err != nil {
51+
return
52+
}
53+
defer f.Close()
54+
defer f.Chmod(FILEMODE)
55+
for k, v := range p {
56+
_, err = f.WriteString(k + separator + v + "\n")
57+
if err != nil {
58+
return
59+
}
60+
}
61+
return
62+
}
63+
64+
// Конфиг для putty на linux
65+
func Conf(name, separator string, kv map[string]string) {
66+
p := confToMap(name, separator)
67+
for k, v := range kv {
68+
if k == "" {
69+
continue
70+
}
71+
p[k] = v
72+
}
73+
mapToConf(name, separator, p)
74+
}
75+
76+
func GlobalSshPath() string {
77+
return path.Join("/etc", "ssh")
78+
}

dssh_windows.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package main
5+
6+
import (
7+
"os"
8+
"path/filepath"
9+
"strconv"
10+
11+
"golang.org/x/sys/windows/registry"
12+
)
13+
14+
var (
15+
PuTTY = `SOFTWARE\SimonTatham\PuTTY` //root
16+
Sessions = filepath.Join(PuTTY, "Sessions") //dir
17+
SshHostCAs = filepath.Join(PuTTY, "SshHostCAs") //dir
18+
SshHostKeys = filepath.Join(PuTTY, "SshHostKeys") //file
19+
)
20+
21+
// Конфиг для putty на Windows
22+
func Conf(name, _ string, kv map[string]string) {
23+
rk, _, err := registry.CreateKey(registry.CURRENT_USER,
24+
name,
25+
registry.CREATE_SUB_KEY|registry.SET_VALUE)
26+
if err != nil {
27+
Println(err)
28+
return
29+
}
30+
defer rk.Close()
31+
32+
for k, v := range kv {
33+
if i, err := strconv.Atoi(v); err == nil {
34+
rk.SetDWordValue(k, uint32(i))
35+
} else {
36+
rk.SetStringValue(k, v)
37+
}
38+
}
39+
}
40+
41+
func GlobalSshPath() string {
42+
return filepath.Join(os.Getenv("ProgramData"), "ssh")
43+
}

0 commit comments

Comments
 (0)