Skip to content

Commit 2bcfb7c

Browse files
committed
add version command
1 parent 2abac25 commit 2bcfb7c

File tree

9 files changed

+125
-102
lines changed

9 files changed

+125
-102
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/firefart/stunner
22

3-
go 1.22
3+
go 1.23
44

55
require (
66
github.com/firefart/gosocks v0.4.2

internal/helpers_stun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestPadding(t *testing.T) {
99
t.Parallel()
1010

11-
var tests = []struct {
11+
tests := []struct {
1212
testName string
1313
inputLen int
1414
expectedLen int

internal/helpers_turn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func ParseMappedAdress(input []byte) (*netip.Addr, uint16, error) {
7878
return nil, 0, fmt.Errorf("invalid buffer length %d, need to be > 4", len(input))
7979
}
8080
family := input[0:2] // 0x0001 = ipv4, 0x0002 = ipv6
81-
if !bytes.Equal(family, []byte{00, 01}) && !bytes.Equal(family, []byte{00, 02}) {
81+
if !bytes.Equal(family, []byte{0o0, 0o1}) && !bytes.Equal(family, []byte{0o0, 0o2}) {
8282
return nil, 0, fmt.Errorf("invalid family %02x", family)
8383
}
8484
portRaw := input[2:4]
@@ -96,7 +96,7 @@ func ConvertXORAddr(input []byte, transactionID string) (string, uint16, error)
9696
return "", 0, fmt.Errorf("invalid buffer length %d, need to be > 4", len(input))
9797
}
9898
family := input[0:2] // 0x0001 = ipv4, 0x0002 = ipv6
99-
if !bytes.Equal(family, []byte{00, 01}) && !bytes.Equal(family, []byte{00, 02}) {
99+
if !bytes.Equal(family, []byte{0o0, 0o1}) && !bytes.Equal(family, []byte{0o0, 0o2}) {
100100
return "", 0, fmt.Errorf("invalid family %02x", family)
101101
}
102102
portRaw := input[2:4]

internal/helpers_turn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestXorAddr(t *testing.T) {
2323
func TestConvertXORAddr(t *testing.T) {
2424
t.Parallel()
2525

26-
var tests = []struct {
26+
tests := []struct {
2727
input string
2828
transactionID string
2929
expectedHost string

internal/parsers_stun_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestFromBytes(t *testing.T) {
1010
t.Parallel()
1111

12-
var tests = []struct {
12+
tests := []struct {
1313
testName string
1414
input string
1515
}{
@@ -43,7 +43,7 @@ func TestFromBytes(t *testing.T) {
4343
func TestFromBytesFail(t *testing.T) {
4444
t.Parallel()
4545

46-
var tests = []struct {
46+
tests := []struct {
4747
testName string
4848
input string
4949
}{

internal/requests_turn.go

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@ func AllocateRequestAuth(username, password, nonce, realm string, targetProtocol
4848
Method: MsgTypeMethodAllocate,
4949
}
5050

51-
s.Attributes = []Attribute{{
52-
Type: AttrRequestedTransport,
53-
Value: transport,
54-
}, {
55-
Type: AttrUsername,
56-
Value: []byte(username),
57-
}, {
58-
Type: AttrRealm,
59-
Value: []byte(realm),
60-
}, {
61-
Type: AttrNonce,
62-
Value: []byte(nonce),
63-
},
51+
s.Attributes = []Attribute{
52+
{
53+
Type: AttrRequestedTransport,
54+
Value: transport,
55+
}, {
56+
Type: AttrUsername,
57+
Value: []byte(username),
58+
}, {
59+
Type: AttrRealm,
60+
Value: []byte(realm),
61+
}, {
62+
Type: AttrNonce,
63+
Value: []byte(nonce),
64+
},
6465
}
6566

6667
if allocateProtcol != AllocateProtocolIgnore {
@@ -88,13 +89,14 @@ func SendRequest(target netip.Addr, port uint16) (*Stun, error) {
8889
Method: MsgTypeMethodSend,
8990
}
9091

91-
s.Attributes = []Attribute{{
92-
Type: AttrXorPeerAddress,
93-
Value: targetXOR,
94-
}, {
95-
Type: AttrData,
96-
Value: []byte("pwned by firefart\n"),
97-
},
92+
s.Attributes = []Attribute{
93+
{
94+
Type: AttrXorPeerAddress,
95+
Value: targetXOR,
96+
}, {
97+
Type: AttrData,
98+
Value: []byte("pwned by firefart\n"),
99+
},
98100
}
99101

100102
return s, nil
@@ -115,19 +117,20 @@ func CreatePermissionRequest(username, password, nonce, realm string, target net
115117
Method: MsgTypeMethodCreatePermission,
116118
}
117119

118-
s.Attributes = []Attribute{{
119-
Type: AttrXorPeerAddress,
120-
Value: targetXOR,
121-
}, {
122-
Type: AttrUsername,
123-
Value: []byte(username),
124-
}, {
125-
Type: AttrRealm,
126-
Value: []byte(realm),
127-
}, {
128-
Type: AttrNonce,
129-
Value: []byte(nonce),
130-
},
120+
s.Attributes = []Attribute{
121+
{
122+
Type: AttrXorPeerAddress,
123+
Value: targetXOR,
124+
}, {
125+
Type: AttrUsername,
126+
Value: []byte(username),
127+
}, {
128+
Type: AttrRealm,
129+
Value: []byte(realm),
130+
}, {
131+
Type: AttrNonce,
132+
Value: []byte(nonce),
133+
},
131134
}
132135

133136
return s, nil
@@ -152,22 +155,23 @@ func ChannelBindRequest(username, password, nonce, realm string, target netip.Ad
152155
Method: MsgTypeMethodChannelbind,
153156
}
154157

155-
s.Attributes = []Attribute{{
156-
Type: AttrChannelNumber,
157-
Value: append(channelNumber, []byte{0x00, 0x00}...),
158-
}, {
159-
Type: AttrXorPeerAddress,
160-
Value: targetXOR,
161-
}, {
162-
Type: AttrUsername,
163-
Value: []byte(username),
164-
}, {
165-
Type: AttrRealm,
166-
Value: []byte(realm),
167-
}, {
168-
Type: AttrNonce,
169-
Value: []byte(nonce),
170-
},
158+
s.Attributes = []Attribute{
159+
{
160+
Type: AttrChannelNumber,
161+
Value: append(channelNumber, []byte{0x00, 0x00}...),
162+
}, {
163+
Type: AttrXorPeerAddress,
164+
Value: targetXOR,
165+
}, {
166+
Type: AttrUsername,
167+
Value: []byte(username),
168+
}, {
169+
Type: AttrRealm,
170+
Value: []byte(realm),
171+
}, {
172+
Type: AttrNonce,
173+
Value: []byte(nonce),
174+
},
171175
}
172176

173177
return s, nil
@@ -183,16 +187,17 @@ func RefreshRequest(username, password, nonce, realm string) *Stun {
183187
Method: MsgTypeMethodRefresh,
184188
}
185189

186-
s.Attributes = []Attribute{{
187-
Type: AttrUsername,
188-
Value: []byte(username),
189-
}, {
190-
Type: AttrRealm,
191-
Value: []byte(realm),
192-
}, {
193-
Type: AttrNonce,
194-
Value: []byte(nonce),
195-
},
190+
s.Attributes = []Attribute{
191+
{
192+
Type: AttrUsername,
193+
Value: []byte(username),
194+
}, {
195+
Type: AttrRealm,
196+
Value: []byte(realm),
197+
}, {
198+
Type: AttrNonce,
199+
Value: []byte(nonce),
200+
},
196201
}
197202

198203
return s

internal/requests_turntcp.go

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ func ConnectRequest(target netip.Addr, port uint16) (*Stun, error) {
1717
Method: MsgTypeMethodConnect,
1818
}
1919

20-
s.Attributes = []Attribute{{
21-
Type: AttrXorPeerAddress,
22-
Value: targetXOR,
23-
},
20+
s.Attributes = []Attribute{
21+
{
22+
Type: AttrXorPeerAddress,
23+
Value: targetXOR,
24+
},
2425
}
2526

2627
return s, nil
@@ -40,19 +41,20 @@ func ConnectRequestAuth(username, password, nonce, realm string, target netip.Ad
4041
Method: MsgTypeMethodConnect,
4142
}
4243

43-
s.Attributes = []Attribute{{
44-
Type: AttrXorPeerAddress,
45-
Value: targetXOR,
46-
}, {
47-
Type: AttrUsername,
48-
Value: []byte(username),
49-
}, {
50-
Type: AttrRealm,
51-
Value: []byte(realm),
52-
}, {
53-
Type: AttrNonce,
54-
Value: []byte(nonce),
55-
},
44+
s.Attributes = []Attribute{
45+
{
46+
Type: AttrXorPeerAddress,
47+
Value: targetXOR,
48+
}, {
49+
Type: AttrUsername,
50+
Value: []byte(username),
51+
}, {
52+
Type: AttrRealm,
53+
Value: []byte(realm),
54+
}, {
55+
Type: AttrNonce,
56+
Value: []byte(nonce),
57+
},
5658
}
5759

5860
return s, nil
@@ -68,19 +70,20 @@ func ConnectionBindRequest(connectionID []byte, username, password, nonce, realm
6870
Method: MsgTypeMethodConnectionBind,
6971
}
7072

71-
s.Attributes = []Attribute{{
72-
Type: AttrConnectionID,
73-
Value: connectionID,
74-
}, {
75-
Type: AttrUsername,
76-
Value: []byte(username),
77-
}, {
78-
Type: AttrRealm,
79-
Value: []byte(realm),
80-
}, {
81-
Type: AttrNonce,
82-
Value: []byte(nonce),
83-
},
73+
s.Attributes = []Attribute{
74+
{
75+
Type: AttrConnectionID,
76+
Value: connectionID,
77+
}, {
78+
Type: AttrUsername,
79+
Value: []byte(username),
80+
}, {
81+
Type: AttrRealm,
82+
Value: []byte(realm),
83+
}, {
84+
Type: AttrNonce,
85+
Value: []byte(nonce),
86+
},
8487
}
8588

8689
return s

internal/types_stun.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"github.com/firefart/stunner/internal/helper"
99
)
1010

11-
const headerSize = 20
12-
const messageIntegritySize = 20
11+
const (
12+
headerSize = 20
13+
messageIntegritySize = 20
14+
)
1315

1416
// nolint:deadcode,varcheck,unused
1517
const fingerPrintSize = 4
1618

17-
var (
18-
// MagicCookie is the fixed value according to the rfc
19-
MagicCookie = []byte{'\x21', '\x12', '\xa4', '\x42'}
20-
)
19+
// MagicCookie is the fixed value according to the rfc
20+
var MagicCookie = []byte{'\x21', '\x12', '\xa4', '\x42'}
2121

2222
// Stun is the main object
2323
type Stun struct {

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"net"
1818
"net/netip"
1919
"os"
20+
"runtime/debug"
2021
"strconv"
2122
"strings"
2223
"time"
@@ -397,6 +398,20 @@ func main() {
397398
})
398399
},
399400
},
401+
{
402+
Name: "version",
403+
Usage: "prints the current version and build infos",
404+
Description: "prints the current version and build infos",
405+
Action: func(ctx *cli.Context) error {
406+
info, ok := debug.ReadBuildInfo()
407+
if !ok {
408+
return fmt.Errorf("could not get buildinfo")
409+
}
410+
fmt.Printf("Build info:\n")
411+
fmt.Printf("%s", info)
412+
return nil
413+
},
414+
},
400415
},
401416
}
402417

0 commit comments

Comments
 (0)