Skip to content

Commit 6d96b54

Browse files
committed
Merge branch 'master' into utls-transport
2 parents be931b4 + f53c00b commit 6d96b54

Some content is hidden

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

66 files changed

+4652
-584
lines changed

Makefile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,28 @@ conjure-sim: detect.c loadkey.c rust_util.c rust libtapdance
3636
registration-server:
3737
cd ./cmd/registration-server/ && make
3838

39-
# Note this copies in the whole current directory as context and results in
40-
# overly large context. should not be used to build release/production images.
41-
custom-build:
42-
docker build --build-arg CUSTOM_BUILD=1 -f docker/Dockerfile .
39+
PARAMS := det app reg zbalance sim
40+
target := unk
41+
# makefile arguments take preference, if one is not provided we check the environment variable.
42+
# If that is also missing then we use "latest" and install pfring from pkg in the docker build.
43+
ifndef pfring_ver
44+
ifdef PFRING_VER
45+
pfring_ver := ${PFRING_VER}
46+
else
47+
pfring_ver := latest
48+
endif
49+
endif
50+
51+
container:
52+
ifeq (unk,$(target))
53+
DOCKER_BUILDKIT=1 docker build -t conjure -t pf-$(pfring_ver) -f docker/Dockerfile --build-arg pfring_ver=$(pfring_ver) .
54+
# @printf "DOCKER_BUILDKIT=1 docker build -t conjure -f docker/Dockerfile --build-arg pfring_ver=$(pfring_ver) .\n"
55+
else ifneq (,$(findstring $(target), $(PARAMS)))
56+
DOCKER_BUILDKIT=1 docker build --target conjure_$(target) -t conjure_$(target) -t pf-$(pfring_ver) -f docker/Dockerfile --build-arg pfring_ver=$(pfring_ver) .
57+
# @printf "DOCKER_BUILDKIT=1 docker build --target conjure_$(target) -t conjure_$(target) -f docker/Dockerfile --build-arg pfring_ver=$(pfring_ver) .\n"
58+
else
59+
@printf "unrecognized container target $(target) - please use one of [ $(PARAMS) ]\n"
60+
endif
4361

4462

4563
backup-config:

application/config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ socket_name = "zmq-proxy"
1010

1111
# Absolute path to private key to use when authenticating with servers.
1212
# Can be either privkey or privkey || pubkey; only first 32 bytes will
13-
# be used.
14-
privkey_path = "/opt/conjure/sysconfig/privkey"
13+
# be used. If this is blank then the environment variable CJ_PRIVKEY
14+
# which is defined in conjure.conf will be used (if that fails to parse
15+
# the station will shutdown).
16+
privkey_path = ""
1517

1618
# Time in milliseconds to wait between sending heartbeats.
1719
# Heartbeats are only sent when other traffic doesn't come through;
@@ -75,7 +77,7 @@ covert_blocklist_subnets = [
7577

7678
# Automatically add all addresses and subnets associated with local devices to
7779
# the blocklist.
78-
covert_blocklist_public_addrs = false
80+
covert_blocklist_public_addrs = true
7981

8082
# Override the blocklist providing a more restrictive allowlist. Any addresses
8183
# not explicitly included in an allowlisted subnet will be considered

application/lib/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ type Config struct {
2020
// variable.
2121
func ParseConfig() (*Config, error) {
2222
var c Config
23-
_, err := toml.DecodeFile(os.Getenv("CJ_STATION_CONFIG"), &c)
23+
var envPath = os.Getenv("CJ_STATION_CONFIG")
24+
_, err := toml.DecodeFile(envPath, &c)
2425
if err != nil {
25-
return nil, fmt.Errorf("failed to load config: %v", err)
26+
return nil, fmt.Errorf("failed to load config (%s): %v", envPath, err)
2627
}
2728

2829
c.ParseBlocklists()

application/lib/zmq_proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ func (zi *ZMQIngester) PrintAndReset(logger *log.Logger) {
145145
// location of the config file with the CJ_PROXY_CONFIG environment variable.
146146
func (zi *ZMQIngester) proxyZMQ() {
147147

148-
privkey, err := os.ReadFile(zi.PrivateKeyPath)
148+
privkeyPath := zi.PrivateKeyPath
149+
if privkeyPath == "" {
150+
privkeyPath = os.Getenv("CJ_PRIVKEY")
151+
}
152+
153+
privkey, err := os.ReadFile(privkeyPath)
149154
if err != nil {
150155
zi.logger.Fatalln("failed to load private key:", err)
151156
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package transports
2+
3+
import (
4+
"fmt"
5+
6+
"google.golang.org/protobuf/proto"
7+
"google.golang.org/protobuf/reflect/protoreflect"
8+
"google.golang.org/protobuf/types/known/anypb"
9+
)
10+
11+
// UnmarshalAnypbTo unmarshals the src anypb to dst without reading the src type url.
12+
// Used to unmarshal TransportParams in the registration message for saving space from
13+
// the type url so that the registration payload is small enough for the DNS registrar.
14+
func UnmarshalAnypbTo(src *anypb.Any, dst protoreflect.ProtoMessage) error {
15+
expected, err := anypb.New(dst)
16+
if err != nil {
17+
return fmt.Errorf("error reading src type: %v", err)
18+
}
19+
20+
if src.TypeUrl != "" && src.TypeUrl != expected.TypeUrl {
21+
return fmt.Errorf("incorrect non-empty TypeUrl: %v != %v", src.TypeUrl, expected.TypeUrl)
22+
}
23+
24+
src.TypeUrl = expected.TypeUrl
25+
return anypb.UnmarshalTo(src, dst, proto.UnmarshalOptions{})
26+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package transports_test
2+
3+
import (
4+
"math/rand"
5+
"testing"
6+
7+
"github.com/refraction-networking/conjure/application/transports"
8+
pb "github.com/refraction-networking/gotapdance/protobuf"
9+
"github.com/stretchr/testify/require"
10+
"google.golang.org/protobuf/proto"
11+
"google.golang.org/protobuf/types/known/anypb"
12+
)
13+
14+
func TestUnmarshall(t *testing.T) {
15+
src, err := anypb.New(&pb.GenericTransportParams{RandomizeDstPort: proto.Bool(true)})
16+
require.Nil(t, err)
17+
src.TypeUrl = ""
18+
19+
dst := &pb.GenericTransportParams{}
20+
err = transports.UnmarshalAnypbTo(src, dst)
21+
require.Nil(t, err)
22+
23+
require.True(t, dst.GetRandomizeDstPort())
24+
}
25+
26+
func TestMissingTypeURL(t *testing.T) {
27+
src, err := anypb.New(&pb.GenericTransportParams{RandomizeDstPort: proto.Bool(true)})
28+
require.Nil(t, err)
29+
src.TypeUrl = ""
30+
31+
dst := &pb.GenericTransportParams{}
32+
err = anypb.UnmarshalTo(src, dst, proto.UnmarshalOptions{})
33+
require.NotNil(t, err)
34+
}
35+
36+
func TestWrongType(t *testing.T) {
37+
src, err := anypb.New(&pb.ClientToStation{Padding: []byte{0, 1}})
38+
require.Nil(t, err)
39+
40+
dst := &pb.GenericTransportParams{}
41+
err = transports.UnmarshalAnypbTo(src, dst)
42+
require.NotNil(t, err)
43+
}
44+
45+
func TestGarbage(t *testing.T) {
46+
src, err := anypb.New(&pb.GenericTransportParams{RandomizeDstPort: proto.Bool(true)})
47+
require.Nil(t, err)
48+
garbagebytes, err := proto.Marshal(src)
49+
require.Nil(t, err)
50+
_, err = rand.Read(garbagebytes)
51+
require.Nil(t, err)
52+
53+
dstAnypb := &anypb.Any{}
54+
55+
err = proto.Unmarshal(garbagebytes, dstAnypb)
56+
require.NotNil(t, err)
57+
}

0 commit comments

Comments
 (0)