Skip to content

Commit 453bd81

Browse files
author
Ivan
committed
chore: improve Makefile and update various files for improved functionality and security checks
1 parent b4c8b0c commit 453bd81

13 files changed

Lines changed: 103 additions & 39 deletions

File tree

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ GO_LEGACY_WINXP ?= /usr/local/go-legacy-winxp/bin/go
2525
GOFLAGS := -mod=vendor
2626
GOPROXY := off
2727
GOSUMDB := off
28-
export GOFLAGS GOPROXY GOSUMDB
28+
GOTOOLCHAIN ?= local
29+
export GOFLAGS GOPROXY GOSUMDB GOTOOLCHAIN
2930
LIBS_ROOT ?= ../../Reticulum-Go-Projects
3031
GOVULNCHECK_VER ?= v1.1.4
3132
NFPM_VER ?= v2.41.3

‎pkg/cli/git.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,5 @@ func EmitGitJSON(w io.Writer, event string, fields map[string]any) {
254254

255255
// GitBundleVerify wraps git bundle verify for tests.
256256
func GitBundleVerify(path string) error {
257-
return exec.Command("git", "bundle", "verify", "-q", path).Run()
257+
return exec.Command("git", "bundle", "verify", "-q", path).Run() // #nosec G204 -- fixed git binary
258258
}

‎pkg/link/resource_metadata_unpack.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package link
55

66
import (
77
"fmt"
8+
"math"
89
"strconv"
910

1011
"quad4/msgpack/v5/pkg/msgpack"
@@ -51,6 +52,9 @@ func metadataMapKey(k any) string {
5152
case uint32:
5253
return strconv.Itoa(int(x))
5354
case uint64:
55+
if x > math.MaxInt {
56+
return fmt.Sprint(k)
57+
}
5458
return strconv.Itoa(int(x))
5559
default:
5660
return fmt.Sprint(k)

‎pkg/packet/testdata/handshake_vectors.json‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"vectors": [
44
{
55
"name": "announce_h2",
6-
"raw_hex": "4100abababababababababababababababab4f070d727898b6f3e6c51f585387b9c100d293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07ad97ec87043c607d47c8bb9ace71e703ae1a864a0c2df89522e694b344d86542372ea66915f2f5fedf916e0647f3314006a8a2a755ba843d191cdd6a31816a3baa230341d116c2872e969fd2674d00a0117b9fd5cfd544676577623e9d8996dbac3d1a259507b98ad576871664bbd3d240996d7070102",
6+
"raw_hex": "4100abababababababababababababababab749dfe39a82e14abcfe05e592cadb8d300ff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a4f7aeecd079915be05fb5dcbc5c3af1c77bd3478964f334bad94ff4b397cc56972ea66915f2f5fedf916a20acd13f3006a8a48dcf3a85be66bedfcee089433b497e301b700adabd22946832af40358fe3fbc63733932f04c9fc661b2f9bdedc2ecd30c09cb11ed9c5160b716a7b46526cbdac4020102",
77
"packet_type_name": "ANNOUNCE",
88
"context_name": "NONE",
99
"header_type": 1,
1010
"destination_type_name": "SINGLE",
1111
"tree": {
1212
"ok": true,
13-
"raw_hex": "4100abababababababababababababababab4f070d727898b6f3e6c51f585387b9c100d293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07ad97ec87043c607d47c8bb9ace71e703ae1a864a0c2df89522e694b344d86542372ea66915f2f5fedf916e0647f3314006a8a2a755ba843d191cdd6a31816a3baa230341d116c2872e969fd2674d00a0117b9fd5cfd544676577623e9d8996dbac3d1a259507b98ad576871664bbd3d240996d7070102",
13+
"raw_hex": "4100abababababababababababababababab749dfe39a82e14abcfe05e592cadb8d300ff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a4f7aeecd079915be05fb5dcbc5c3af1c77bd3478964f334bad94ff4b397cc56972ea66915f2f5fedf916a20acd13f3006a8a48dcf3a85be66bedfcee089433b497e301b700adabd22946832af40358fe3fbc63733932f04c9fc661b2f9bdedc2ecd30c09cb11ed9c5160b716a7b46526cbdac4020102",
1414
"raw_len": 185,
1515
"flags": 65,
1616
"hops": 0,
@@ -23,22 +23,22 @@
2323
"destination_type_name": "SINGLE",
2424
"context": 0,
2525
"context_name": "NONE",
26-
"destination_hash": "4f070d727898b6f3e6c51f585387b9c1",
26+
"destination_hash": "749dfe39a82e14abcfe05e592cadb8d3",
2727
"transport_id": "abababababababababababababababab",
2828
"data_len": 150,
29-
"data_hex_prefix": "d293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07a"
29+
"data_hex_prefix": "ff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a"
3030
}
3131
},
3232
{
3333
"name": "path_response_announce",
34-
"raw_hex": "5100abababababababababababababababab4f070d727898b6f3e6c51f585387b9c10bd293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07ad97ec87043c607d47c8bb9ace71e703ae1a864a0c2df89522e694b344d86542372ea66915f2f5fedf916e0647f3314006a8a2a755ba843d191cdd6a31816a3baa230341d116c2872e969fd2674d00a0117b9fd5cfd544676577623e9d8996dbac3d1a259507b98ad576871664bbd3d240996d7070102",
34+
"raw_hex": "5100abababababababababababababababab749dfe39a82e14abcfe05e592cadb8d30bff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a4f7aeecd079915be05fb5dcbc5c3af1c77bd3478964f334bad94ff4b397cc56972ea66915f2f5fedf916a20acd13f3006a8a48dcf3a85be66bedfcee089433b497e301b700adabd22946832af40358fe3fbc63733932f04c9fc661b2f9bdedc2ecd30c09cb11ed9c5160b716a7b46526cbdac4020102",
3535
"packet_type_name": "ANNOUNCE",
3636
"context_name": "PATH_RESPONSE",
3737
"header_type": 1,
3838
"destination_type_name": "SINGLE",
3939
"tree": {
4040
"ok": true,
41-
"raw_hex": "5100abababababababababababababababab4f070d727898b6f3e6c51f585387b9c10bd293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07ad97ec87043c607d47c8bb9ace71e703ae1a864a0c2df89522e694b344d86542372ea66915f2f5fedf916e0647f3314006a8a2a755ba843d191cdd6a31816a3baa230341d116c2872e969fd2674d00a0117b9fd5cfd544676577623e9d8996dbac3d1a259507b98ad576871664bbd3d240996d7070102",
41+
"raw_hex": "5100abababababababababababababababab749dfe39a82e14abcfe05e592cadb8d30bff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a4f7aeecd079915be05fb5dcbc5c3af1c77bd3478964f334bad94ff4b397cc56972ea66915f2f5fedf916a20acd13f3006a8a48dcf3a85be66bedfcee089433b497e301b700adabd22946832af40358fe3fbc63733932f04c9fc661b2f9bdedc2ecd30c09cb11ed9c5160b716a7b46526cbdac4020102",
4242
"raw_len": 185,
4343
"flags": 81,
4444
"hops": 0,
@@ -51,22 +51,22 @@
5151
"destination_type_name": "SINGLE",
5252
"context": 11,
5353
"context_name": "PATH_RESPONSE",
54-
"destination_hash": "4f070d727898b6f3e6c51f585387b9c1",
54+
"destination_hash": "749dfe39a82e14abcfe05e592cadb8d3",
5555
"transport_id": "abababababababababababababababab",
5656
"data_len": 150,
57-
"data_hex_prefix": "d293002f17a6dcca4ce5e902619b26beae78ee6c51cba622adcf85657c1eb07a"
57+
"data_hex_prefix": "ff9c7aa64168ddc1b0b5d6a824ee9eca2c570ac06d7a1a6ec61372f668e1f24a"
5858
}
5959
},
6060
{
6161
"name": "link_request",
62-
"raw_hex": "02004f070d727898b6f3e6c51f585387b9c100cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
62+
"raw_hex": "0200749dfe39a82e14abcfe05e592cadb8d300cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
6363
"packet_type_name": "LINKREQUEST",
6464
"context_name": "NONE",
6565
"header_type": 0,
6666
"destination_type_name": "SINGLE",
6767
"tree": {
6868
"ok": true,
69-
"raw_hex": "02004f070d727898b6f3e6c51f585387b9c100cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
69+
"raw_hex": "0200749dfe39a82e14abcfe05e592cadb8d300cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
7070
"raw_len": 83,
7171
"flags": 2,
7272
"hops": 0,
@@ -79,7 +79,7 @@
7979
"destination_type_name": "SINGLE",
8080
"context": 0,
8181
"context_name": "NONE",
82-
"destination_hash": "4f070d727898b6f3e6c51f585387b9c1",
82+
"destination_hash": "749dfe39a82e14abcfe05e592cadb8d3",
8383
"data_len": 64,
8484
"data_hex_prefix": "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
8585
}

‎pkg/rnsgit/config.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func DefaultClientConfigDir() string {
4444
home := os.Getenv("HOME")
4545
if home != "" {
4646
legacy := filepath.Join(home, ".config", "rngit", "config")
47-
if st, err := os.Stat(legacy); err == nil && !st.IsDir() {
47+
if st, err := os.Stat(legacy); err == nil && !st.IsDir() { // #nosec G703 -- legacy config probe
4848
return filepath.Join(home, ".rngit", "reticulum")
4949
}
5050
return filepath.Join(home, ".rngit")
@@ -181,7 +181,7 @@ func EnsureServerConfig(dir string) error {
181181
}
182182

183183
func parseINI(path string) (map[string]map[string]string, error) {
184-
f, err := os.Open(path) // #nosec G304 -- operator config path
184+
f, err := os.Open(path) // #nosec G304 G703 -- operator config path
185185
if err != nil {
186186
return nil, err
187187
}

‎pkg/rnsgit/gitexec.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (g *GitRunner) ListRefs(repoPath string) (string, error) {
4040
return "", fmt.Errorf("git for-each-ref: %w: %s", err, strings.TrimSpace(string(stderr)))
4141
}
4242
headRef := "master"
43-
if b, err := os.ReadFile(filepath.Join(repoPath, "HEAD")); err == nil {
43+
if b, err := os.ReadFile(filepath.Join(repoPath, "HEAD")); err == nil { // #nosec G304 -- bare repo HEAD
4444
s := strings.TrimSpace(string(b))
4545
if after, ok := strings.CutPrefix(s, "ref: "); ok {
4646
headRef = after
@@ -146,7 +146,7 @@ func (g *GitRunner) DeleteRef(repoPath, ref string) error {
146146

147147
// InitBare creates a bare repository.
148148
func (g *GitRunner) InitBare(path string) error {
149-
if err := os.MkdirAll(path, 0o755); err != nil {
149+
if err := os.MkdirAll(path, 0o755); err != nil { // #nosec G301 -- bare git repo root
150150
return err
151151
}
152152
_, stderr, err := g.run(path, "init", "--bare")
@@ -158,7 +158,7 @@ func (g *GitRunner) InitBare(path string) error {
158158

159159
// CloneBare mirrors a remote into path.
160160
func (g *GitRunner) CloneBare(source, path string) error {
161-
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
161+
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { // #nosec G301 -- bare git parent dir
162162
return err
163163
}
164164
_, stderr, err := g.run("", "clone", "--bare", source, path)

‎pkg/rnsgit/mgmt.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ func (n *Node) fetchReleaseArtifact(group, repo, tag, artifact string) ([]byte,
222222

223223
func (n *Node) createRelease(group, repo, tag, notes string) error {
224224
dir := filepath.Join(n.releasesDir(group, repo), tag)
225-
if err := os.MkdirAll(filepath.Join(dir, "artifacts"), 0o755); err != nil {
225+
if err := os.MkdirAll(filepath.Join(dir, "artifacts"), 0o755); err != nil { // #nosec G301 -- release artifacts dir
226226
return err
227227
}
228-
return os.WriteFile(filepath.Join(dir, "RELEASE.md"), []byte(notes), 0o644)
228+
return os.WriteFile(filepath.Join(dir, "RELEASE.md"), []byte(notes), 0o644) // #nosec G306 -- release notes
229229
}
230230

231231
func (n *Node) workDir(group string) string {
@@ -260,13 +260,13 @@ func (n *Node) readWorkDoc(group, docID string) ([]byte, error) {
260260

261261
func (n *Node) createWorkDoc(group, title, content string, remote *identity.Identity) (string, error) {
262262
dir := n.workDir(group)
263-
if err := os.MkdirAll(dir, 0o755); err != nil {
263+
if err := os.MkdirAll(dir, 0o755); err != nil { // #nosec G301 -- work doc directory
264264
return "", err
265265
}
266266
id := fmt.Sprintf("%d", time.Now().Unix())
267267
body := title + "\n" + content + "\nauthor:" + hex.EncodeToString(remote.Hash())
268268
path := filepath.Join(dir, id+".txt")
269-
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
269+
if err := os.WriteFile(path, []byte(body), 0o644); err != nil { // #nosec G306 -- work doc file
270270
return "", err
271271
}
272272
return id, nil

‎pkg/rnsgit/mirror.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ func (n *Node) syncMirrors() {
3535
synced, _ := n.git.ConfigValue(ra.Path, "repository.rngit.upstream.sync")
3636
if synced != "" {
3737
var ts int64
38-
fmt.Sscanf(synced, "%d", &ts)
39-
if time.Since(time.Unix(ts, 0)) < time.Duration(n.cfg.MirrorIntervalHrs)*time.Hour {
40-
continue
38+
if _, err := fmt.Sscanf(synced, "%d", &ts); err == nil {
39+
if time.Since(time.Unix(ts, 0)) < time.Duration(n.cfg.MirrorIntervalHrs)*time.Hour {
40+
continue
41+
}
4142
}
4243
}
4344
source, err := n.git.ConfigValue(ra.Path, "repository.rngit.upstream.source")

‎pkg/rnsgit/msgpack.go‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package rnsgit
55

66
import (
77
"fmt"
8+
"math"
89

910
"quad4/msgpack/v5/pkg/msgpack"
1011
)
@@ -88,12 +89,24 @@ func byteFromAny(v any) (byte, bool) {
8889
case uint8:
8990
return x, true
9091
case int8:
92+
if x < 0 {
93+
return 0, false
94+
}
9195
return byte(x), true
9296
case int:
97+
if x < 0 || x > math.MaxUint8 {
98+
return 0, false
99+
}
93100
return byte(x), true
94101
case int64:
102+
if x < 0 || x > math.MaxUint8 {
103+
return 0, false
104+
}
95105
return byte(x), true
96106
case uint64:
107+
if x > math.MaxUint8 {
108+
return 0, false
109+
}
97110
return byte(x), true
98111
default:
99112
return 0, false
@@ -105,7 +118,9 @@ func MetadataResultCodeRaw(packed []byte) (byte, bool) {
105118
var m map[int]int
106119
if err := msgpack.Unmarshal(packed, &m); err == nil {
107120
if v, ok := m[IdxResultCode]; ok {
108-
return byte(v), true
121+
if b, ok := byteFromAny(v); ok {
122+
return b, true
123+
}
109124
}
110125
}
111126
var anyMap map[any]any
@@ -141,6 +156,9 @@ func toIntKey(k any) (int, bool) {
141156
case uint32:
142157
return int(x), true
143158
case uint64:
159+
if x > math.MaxInt {
160+
return 0, false
161+
}
144162
return int(x), true
145163
default:
146164
return 0, false

‎pkg/rnsgit/permissions.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NewAccessTable(cfg *ServerConfig) (*AccessTable, error) {
8686
}
8787
groupAllowed := filepath.Join(filepath.Dir(abs), group+".allowed")
8888
applyAllowedFile(ga, groupAllowed)
89-
if err := os.MkdirAll(abs, 0o755); err != nil {
89+
if err := os.MkdirAll(abs, 0o755); err != nil { // #nosec G301 -- git group directory
9090
return nil, err
9191
}
9292
entries, _ := os.ReadDir(abs)
@@ -339,7 +339,7 @@ func (ra *RepoAccess) permSet(perm int) PermissionSet {
339339

340340
// WriteAllowedFile saves permission lines to path.
341341
func WriteAllowedFile(path string, content string) error {
342-
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
342+
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { // #nosec G301 -- allowed file parent dir
343343
return err
344344
}
345345
var buf bytes.Buffer
@@ -354,7 +354,7 @@ func WriteAllowedFile(path string, content string) error {
354354
buf.WriteString(line)
355355
buf.WriteByte('\n')
356356
}
357-
return os.WriteFile(path, buf.Bytes(), 0o644)
357+
return os.WriteFile(path, buf.Bytes(), 0o644) // #nosec G306 -- allowed file
358358
}
359359

360360
// ReadAllowedFile returns the contents of an allowed file.

0 commit comments

Comments
 (0)