Skip to content

Commit 0183a8b

Browse files
authored
Merge pull request #51 from lwch/dev
v0.11.0
2 parents c1b7cd3 + ba10f07 commit 0183a8b

File tree

85 files changed

+178
-9651
lines changed

Some content is hidden

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

85 files changed

+178
-9651
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
- macos-11
2323
- macos-12
2424
go:
25-
- '1.16'
2625
- '1.17'
2726
- '1.18'
2827
- '1.19'

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,15 @@
156156
# v0.10.5
157157

158158
1. 修改注册系统服务时的配置项
159-
2. 升级第三方库
159+
2. 升级第三方库
160+
161+
# v0.11.0
162+
163+
1. 修改握手时的签名算法
164+
2. go版本升级到1.19.1
165+
3. AdminLTE库升级到3.2.0
166+
4. bootstrap库升级到4.6.2
167+
5. jquery库升级到3.6.1
168+
6. xterm.js库升级到5.0.0
169+
7. fontawesome库升级到6.2.0
170+
8. 去除go1.16的支持

build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
VERSION=0.10.5
3+
VERSION=0.11.0
44

55
DOCKER_BUILDKIT=1 docker build -t natpass -f contrib/build/Dockerfile .
66
docker run --rm \

build_all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
VERSION=0.10.5
3+
VERSION=0.11.0
44

55
DOCKER_BUILDKIT=1 docker build -t natpass -f contrib/build/Dockerfile .
66
docker run --rm \

code/client/conn/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func writeHandshake(conn *network.Conn, cfg *global.Configure) error {
103103
msg.To = "server"
104104
msg.Payload = &network.Msg_Hsp{
105105
Hsp: &network.HandshakePayload{
106-
Enc: cfg.Enc[:],
106+
Enc: cfg.Hasher.Hash(),
107107
},
108108
}
109109
return conn.WriteMessage(&msg, 5*time.Second)

code/client/global/conf.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package global
22

33
import (
4-
"crypto/md5"
54
"fmt"
65
"os"
76
"path/filepath"
87
"time"
98

9+
"github.com/lwch/natpass/code/hash"
1010
"github.com/lwch/natpass/code/utils"
1111
"github.com/lwch/runtime"
1212
"github.com/lwch/yaml"
@@ -32,7 +32,7 @@ type Configure struct {
3232
Server string
3333
UseSSL bool
3434
SSLInsecure bool
35-
Enc [md5.Size]byte
35+
Hasher *hash.Hasher
3636
Links int
3737
LogDir string
3838
LogSize utils.Bytes
@@ -103,7 +103,7 @@ func LoadConf(dir string) *Configure {
103103
Server: cfg.Server,
104104
UseSSL: cfg.SSL.Enabled,
105105
SSLInsecure: cfg.SSL.Insecure,
106-
Enc: md5.Sum([]byte(cfg.Secret)),
106+
Hasher: hash.New(cfg.Secret, 60),
107107
ReadTimeout: cfg.Link.ReadTimeout,
108108
WriteTimeout: cfg.Link.WriteTimeout,
109109
LogDir: cfg.Log.Dir,

code/hash/hash.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package hash
2+
3+
import (
4+
"crypto/hmac"
5+
"crypto/sha512"
6+
"encoding/binary"
7+
"hash"
8+
"math"
9+
"sync"
10+
"time"
11+
)
12+
13+
// Hasher hasher for handshake
14+
type Hasher struct {
15+
sync.Mutex
16+
period uint
17+
h hash.Hash
18+
}
19+
20+
// New create hasher
21+
func New(secret string, period uint) *Hasher {
22+
if period == 0 {
23+
period = 30
24+
}
25+
return &Hasher{
26+
period: period,
27+
h: hmac.New(sha512.New, []byte(secret)),
28+
}
29+
}
30+
31+
// Hash hash func
32+
func (h *Hasher) Hash() []byte {
33+
now := time.Now()
34+
i := math.Floor(float64(now.Unix()) / float64(h.period))
35+
var buf [8]byte
36+
binary.BigEndian.PutUint64(buf[:], uint64(i))
37+
h.Lock()
38+
defer h.Unlock()
39+
h.h.Reset()
40+
h.h.Write(buf[:])
41+
ret := h.h.Sum(nil)
42+
return ret
43+
}

code/server/global/conf.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package global
22

33
import (
4-
"crypto/md5"
54
"os"
65
"path/filepath"
76
"time"
87

8+
"github.com/lwch/natpass/code/hash"
99
"github.com/lwch/natpass/code/utils"
1010
"github.com/lwch/runtime"
1111
"github.com/lwch/yaml"
@@ -14,7 +14,7 @@ import (
1414
// Configure server configure
1515
type Configure struct {
1616
Listen uint16
17-
Enc [md5.Size]byte
17+
Hasher *hash.Hasher
1818
TLSKey string
1919
TLSCrt string
2020
ReadTimeout time.Duration
@@ -51,7 +51,7 @@ func LoadConf(dir string) *Configure {
5151
}
5252
return &Configure{
5353
Listen: cfg.Listen,
54-
Enc: md5.Sum([]byte(cfg.Secret)),
54+
Hasher: hash.New(cfg.Secret, 60),
5555
TLSKey: cfg.TLS.Key,
5656
TLSCrt: cfg.TLS.Crt,
5757
ReadTimeout: cfg.Link.ReadTimeout,

code/server/handler/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (h *Handler) readHandshake(c *network.Conn) (string, error) {
9191
if msg.GetXType() != network.Msg_handshake {
9292
return "", errNotHandshake
9393
}
94-
n := bytes.Compare(msg.GetHsp().GetEnc(), h.cfg.Enc[:])
94+
n := bytes.Compare(msg.GetHsp().GetEnc(), h.cfg.Hasher.Hash())
9595
if n != 0 {
9696
return "", errInvalidHandshake
9797
}

contrib/build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG APT_MIRROR=mirrors.ustc.edu.cn
2-
ARG GO_VERSION=1.19
2+
ARG GO_VERSION=1.19.1
33
ARG GO_PROXY=https://goproxy.cn,direct
44

55
FROM lwch/darwin-crosscompiler:11.3

0 commit comments

Comments
 (0)