Skip to content

Commit

Permalink
remove unused encryption support
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-wa committed Dec 2, 2024
1 parent 2422bb3 commit 5eda812
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 237 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,10 @@ The full API documentation is available here on [pkg.go.dev](https://pkg.go.dev/
* Chat & console messages <sup id="achat1">1</sup> - [docs](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events?tab=doc#ChatMessage) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/print-events)
* Matchmaking ranks (official MM demos only) - [docs](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events?tab=doc#RankUpdate)
* Full POV demo support
* Support for encrypted net-messages (if the [decryption key](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4@master/pkg/demoinfocs#ParserConfig) is provided)
* JavaScript (browser / Node.js) support via WebAssembly - [example](https://github.com/markus-wa/demoinfocs-wasm)
* [Easy debugging via build-flags](#debugging)
* Built with performance & concurrency in mind

1. <small id="f1">In MM demos the chat is encrypted, so [`ParserConfig.NetMessageDecryptionKey`](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4@master/pkg/demoinfocs#ParserConfig) needs to be set - see also [`MatchInfoDecryptionKey()`](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4@master/pkg/demoinfocs#MatchInfoDecryptionKey).</small>

## Performance / Benchmarks

Two of the top priorities of this parser are performance and concurrency.
Expand Down
1 change: 0 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Here you can find a overview of examples on how to use demoinfocs-golang.
|[voice-capture](voice-capture)|Capture voice data from players|
|[entities](entities)|Using unhandled data from entities (`Parser.ServerClasses()`)|
|[net-messages](net-messages)|Parsing and handling custom net-messages|
|[encrypted-net-messages](encrypted-net-messages)|Parsing and handling encrypted net-messages (e.g. text chat in MM demos)|
|[print-events](print-events)|Printing kills, scores & chat messages|
|[mocking](mocking)|Using the `fake` package to write unit tests for your code|
|[web-assembly](web-assembly)|Using the library from JavaScript (browser/node) with [WebAssembly](https://webassembly.org/)|
Expand Down
3 changes: 1 addition & 2 deletions examples/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package examples
import (
"flag"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -43,7 +42,7 @@ func RedirectStdout(f func()) {

// Discard the output in a separate goroutine so writing to stdout can't block indefinitely
go func() {
for err := error(nil); err == nil; _, err = io.Copy(ioutil.Discard, r) {
for err := error(nil); err == nil; _, err = io.Copy(io.Discard, r) {
}
}()

Expand Down
14 changes: 0 additions & 14 deletions examples/encrypted-net-messages/README.md

This file was deleted.

60 changes: 0 additions & 60 deletions examples/encrypted-net-messages/enc_net_msg.go

This file was deleted.

28 changes: 0 additions & 28 deletions examples/encrypted-net-messages/enc_net_msg_test.go

This file was deleted.

88 changes: 2 additions & 86 deletions pkg/demoinfocs/demoinfocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
"runtime"
Expand Down Expand Up @@ -247,89 +246,6 @@ func TestS2POV(t *testing.T) {
assertions.NoError(err, "error occurred in ParseToEnd()")
}

func TestEncryptedNetMessages(t *testing.T) {
t.Parallel()

if testing.Short() {
t.Skip("skipping test due to -short flag")
}

infoF, err := os.Open(csDemosPath + "/match730_003528806449641685104_1453182610_271.dem.info")
assert.NoError(t, err)

b, err := ioutil.ReadAll(infoF)
assert.NoError(t, err)

k, err := demoinfocs.MatchInfoDecryptionKey(b)
assert.NoError(t, err)

f, err := os.Open(csDemosPath + "/match730_003528806449641685104_1453182610_271.dem")
assert.NoError(t, err)
defer mustClose(t, f)

cfg := demoinfocs.DefaultParserConfig
cfg.NetMessageDecryptionKey = k

p := demoinfocs.NewParserWithConfig(f, cfg)

p.RegisterEventHandler(func(message events.ChatMessage) {
t.Log(message)
})

err = p.ParseToEnd()
assert.NoError(t, err)
}

func TestMatchInfoDecryptionKey_Error(t *testing.T) {
_, err := demoinfocs.MatchInfoDecryptionKey([]byte{0})
assert.Error(t, err)
}

func TestBadNetMessageDecryptionKey(t *testing.T) {
t.Parallel()

if testing.Short() {
t.Skip("skipping test due to -short flag")
}

const (
demPath = csDemosPath + "/match730_003528806449641685104_1453182610_271.dem"
infoPath = csDemosPath + "/match730_003449478367177343081_1946274414_112.dem.info"
)

infoF, err := os.Open(infoPath)
assert.NoError(t, err)

b, err := ioutil.ReadAll(infoF)
assert.NoError(t, err)

k, err := demoinfocs.MatchInfoDecryptionKey(b)
assert.NoError(t, err)

f, err := os.Open(demPath)
assert.NoError(t, err)

defer f.Close()

cfg := demoinfocs.DefaultParserConfig
cfg.NetMessageDecryptionKey = k

p := demoinfocs.NewParserWithConfig(f, cfg)

var cantReadEncNetMsgWarns []events.ParserWarn

p.RegisterEventHandler(func(warn events.ParserWarn) {
if warn.Type == events.WarnTypeCantReadEncryptedNetMessage {
cantReadEncNetMsgWarns = append(cantReadEncNetMsgWarns, warn)
}
})

err = p.ParseToEnd()
assert.NoError(t, err)

assert.NotEmpty(t, cantReadEncNetMsgWarns)
}

func TestParseToEnd_Cancel(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -605,7 +521,7 @@ func assertGolden(tb testing.TB, assertions *assert.Assertions, testCase string,
gzipReader, err := gzip.NewReader(f)
assertions.NoError(err, "error creating gzip reader for %q", goldenFile)

expected, err := ioutil.ReadAll(gzipReader)
expected, err := io.ReadAll(gzipReader)
assertions.NoError(err, "error reading gzipped data from %q", goldenFile)

mustCloseAssert(assertions, gzipReader, f)
Expand All @@ -627,7 +543,7 @@ func removePointers(s []byte) []byte {
}

func writeFile(assertions *assert.Assertions, file string, data []byte) {
err := ioutil.WriteFile(file, data, 0600)
err := os.WriteFile(file, data, 0600)
assertions.NoError(err, "failed to write to file %q", file)
}

Expand Down
10 changes: 0 additions & 10 deletions pkg/demoinfocs/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,6 @@ const (
WarnTypeTeamSwapPlayerNil // TODO: figure out why this happens
WarnTypeGameEventBeforeDescriptors // may occur in POV demos
WarnUnknownDemoCommandMessageType // occur when we have an unknown EDemoCommands message type, the protobuf messages probably need to be updated

// WarnTypeMissingNetMessageDecryptionKey occurs when encrypted net-messages are encountered and the decryption key is missing.
// See ParserConfig.NetMessageDecryptionKey
WarnTypeMissingNetMessageDecryptionKey

// WarnTypeCantReadEncryptedNetMessage occurs when an encrypted net-messages can't be decrypted even though the decryption key is set.
// May occur because the decryption key used is incorrect.
// See ParserConfig.NetMessageDecryptionKey
WarnTypeCantReadEncryptedNetMessage

WarnTypeUnknownEquipmentIndex
WarnTypeMissingItemDefinitionIndex
WarnTypeStringTableParsingFailure // Should happen only with CS2 POV demos
Expand Down
27 changes: 0 additions & 27 deletions pkg/demoinfocs/matchinfo.go

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/demoinfocs/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type parser struct {
demoInfoProvider demoInfoProvider // Provides demo infos to other packages that the core package depends on
err error // Contains a error that occurred during parsing if any
errLock sync.Mutex // Used to sync up error mutations between parsing & handling go-routines
decryptionKey []byte // Stored in `match730_*.dem.info` see MatchInfoDecryptionKey().
source2FallbackGameEventListBin []byte // sv_hibernate_when_empty bug workaround
ignorePacketEntitiesPanic bool // Used to ignore PacketEntities parsing panics (some POV demos seem to have broken rare broken PacketEntities)
/**
Expand Down Expand Up @@ -347,10 +346,6 @@ type ParserConfig struct {
// See https://github.com/markus-wa/demoinfocs-golang/issues/314
IgnoreErrBombsiteIndexNotFound bool

// NetMessageDecryptionKey tells the parser how to decrypt certain encrypted net-messages.
// See MatchInfoDecryptionKey() on how to retrieve the key from `match730_*.dem.info` files.
NetMessageDecryptionKey []byte

// DisableMimicSource1Events tells the parser to not mimic Source 1 game events for Source 2 demos.
// Unfortunately Source 2 demos *may* not contain Source 1 game events, that's why the parser will try to mimic them.
// It has an impact only with Source 2 demos and is false by default.
Expand Down Expand Up @@ -392,7 +387,6 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
p.gameEventHandler = newGameEventHandler(&p, config.IgnoreErrBombsiteIndexNotFound)
p.bombsiteA.index = -1
p.bombsiteB.index = -1
p.decryptionKey = config.NetMessageDecryptionKey
p.recordingPlayerSlot = -1
p.disableMimicSource1GameEvents = config.DisableMimicSource1Events
p.source2FallbackGameEventListBin = config.Source2FallbackGameEventListBin
Expand Down

0 comments on commit 5eda812

Please sign in to comment.