Skip to content

Commit

Permalink
Remove mimcry package add only hook
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorsm committed Apr 22, 2024
1 parent 66a9388 commit ccaad47
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 253 deletions.
7 changes: 3 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/dtls/v2/pkg/mimicry"
"github.com/pion/dtls/v2/pkg/protocol/handshake"
"github.com/pion/logging"
)

Expand Down Expand Up @@ -198,9 +198,8 @@ type Config struct {
// https://datatracker.ietf.org/doc/html/rfc9146#section-4
PaddingLengthGenerator func(uint) uint

MimicryEnabled bool

ClientHelloFingerprint mimicry.ClientHelloFingerprint
// Random, SessionID, Cookie
ClientHelloMessageHook func(handshake.Random, []byte, []byte) handshake.Message
}

func defaultConnectContextMaker() (context.Context, func()) {
Expand Down
3 changes: 1 addition & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ func createConn(ctx context.Context, nextConn net.PacketConn, rAddr net.Addr, co
localGetClientCertificate: config.GetClientCertificate,
insecureSkipHelloVerify: config.InsecureSkipVerifyHello,
connectionIDGenerator: config.ConnectionIDGenerator,
mimicryEnabled: config.MimicryEnabled,
clientHelloFingerprint: config.ClientHelloFingerprint,
clientHelloMessageHook: config.ClientHelloMessageHook,
}

// rfc5246#section-7.4.3
Expand Down
44 changes: 1 addition & 43 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/pion/dtls/v2"
"github.com/pion/dtls/v2/pkg/crypto/selfsign"
"github.com/pion/dtls/v2/pkg/mimicry"

Check failure on line 27 in e2e/e2e_test.go

View workflow job for this annotation

GitHub Actions / test (1.21) / Go 1.21

no required module provides package github.com/pion/dtls/v2/pkg/mimicry; to add it:

Check failure on line 27 in e2e/e2e_test.go

View workflow job for this annotation

GitHub Actions / test (1.22) / Go 1.22

no required module provides package github.com/pion/dtls/v2/pkg/mimicry; to add it:
"github.com/pion/transport/v3/test"
)

Expand Down Expand Up @@ -569,45 +570,6 @@ func testPionE2ESimpleRSAClientCert(t *testing.T, server, client func(*comm), op
comm.assert(t)
}

func testPionE2ESimpleMimicry(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

report := test.CheckRoutines(t)
defer report()

t.Run("Mimicry ClientHello", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

cert, err := selfsign.GenerateSelfSignedWithDNS("localhost")
if err != nil {
t.Fatal(err)
}

client_cfg := &dtls.Config{
Certificates: []tls.Certificate{cert},
MimicryEnabled: true,
InsecureSkipVerify: true,
}

server_cfg := &dtls.Config{
Certificates: []tls.Certificate{cert},
SRTPProtectionProfiles: []dtls.SRTPProtectionProfile{dtls.SRTP_AES128_CM_HMAC_SHA1_80, dtls.SRTP_AES128_CM_HMAC_SHA1_32, dtls.SRTP_AEAD_AES_128_GCM, dtls.SRTP_AEAD_AES_256_GCM},
InsecureSkipVerify: true,
}

for _, o := range opts {
o(client_cfg)
o(server_cfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, client_cfg, server_cfg, serverPort, server, client)
defer comm.cleanup(t)
comm.assert(t)
})
}

func TestPionE2ESimple(t *testing.T) {
testPionE2ESimple(t, serverPion, clientPion)
}
Expand Down Expand Up @@ -663,7 +625,3 @@ func TestPionE2ESimpleECDSAClientCertCID(t *testing.T) {
func TestPionE2ESimpleRSAClientCertCID(t *testing.T) {
testPionE2ESimpleRSAClientCert(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimpleMimicry(t *testing.T) {
testPionE2ESimpleMimicry(t, serverPion, clientPion)
}
15 changes: 2 additions & 13 deletions flight1handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"

"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/dtls/v2/pkg/mimicry"
"github.com/pion/dtls/v2/pkg/protocol"
"github.com/pion/dtls/v2/pkg/protocol/alert"
"github.com/pion/dtls/v2/pkg/protocol/extension"
Expand Down Expand Up @@ -134,25 +133,15 @@ func flight1Generate(c flightConn, state *State, _ *handshakeCache, cfg *handsha
extensions = append(extensions, &extension.ConnectionID{CID: state.localConnectionID})
}

if cfg.mimicryEnabled {
msg := &mimicry.MimickedClientHello{
Random: state.localRandom,
SessionID: state.SessionID,
Cookie: state.cookie,
}

msg.LoadFingerprint(cfg.clientHelloFingerprint)

cfg.localSRTPProtectionProfiles = msg.SRTPProtectionProfiles

if cfg.clientHelloMessageHook != nil {
return []*packet{

Check warning on line 137 in flight1handler.go

View check run for this annotation

Codecov / codecov/patch

flight1handler.go#L137

Added line #L137 was not covered by tests
{
record: &recordlayer.RecordLayer{
Header: recordlayer.Header{
Version: protocol.Version1_2,
},
Content: &handshake.Handshake{
Message: msg,
Message: cfg.clientHelloMessageHook(state.localRandom, state.SessionID, state.cookie),
},
},
},
Expand Down
15 changes: 2 additions & 13 deletions flight3handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pion/dtls/v2/internal/ciphersuite/types"
"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/dtls/v2/pkg/crypto/prf"
"github.com/pion/dtls/v2/pkg/mimicry"
"github.com/pion/dtls/v2/pkg/protocol"
"github.com/pion/dtls/v2/pkg/protocol/alert"
"github.com/pion/dtls/v2/pkg/protocol/extension"
Expand Down Expand Up @@ -288,25 +287,15 @@ func flight3Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handsha
extensions = append(extensions, &extension.ConnectionID{CID: state.localConnectionID})
}

if cfg.mimicryEnabled {
msg := &mimicry.MimickedClientHello{
Random: state.localRandom,
SessionID: state.SessionID,
Cookie: state.cookie,
}

msg.LoadFingerprint(cfg.clientHelloFingerprint)

cfg.localSRTPProtectionProfiles = msg.SRTPProtectionProfiles

if cfg.clientHelloMessageHook != nil {
return []*packet{

Check warning on line 291 in flight3handler.go

View check run for this annotation

Codecov / codecov/patch

flight3handler.go#L291

Added line #L291 was not covered by tests
{
record: &recordlayer.RecordLayer{
Header: recordlayer.Header{
Version: protocol.Version1_2,
},
Content: &handshake.Handshake{
Message: msg,
Message: cfg.clientHelloMessageHook(state.localRandom, state.SessionID, state.cookie),
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions handshaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/dtls/v2/pkg/crypto/signaturehash"
"github.com/pion/dtls/v2/pkg/mimicry"
"github.com/pion/dtls/v2/pkg/protocol/alert"
"github.com/pion/dtls/v2/pkg/protocol/handshake"
"github.com/pion/logging"
Expand Down Expand Up @@ -127,8 +126,7 @@ type handshakeConfig struct {

mu sync.Mutex

mimicryEnabled bool
clientHelloFingerprint mimicry.ClientHelloFingerprint
clientHelloMessageHook func(handshake.Random, []byte, []byte) handshake.Message // Random, SessionID, Cookie
}

type flightConn interface {
Expand Down
28 changes: 0 additions & 28 deletions pkg/mimicry/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/mimicry/fingerprints.go

This file was deleted.

126 changes: 0 additions & 126 deletions pkg/mimicry/mimic_client_hello.go

This file was deleted.

0 comments on commit ccaad47

Please sign in to comment.