Skip to content

Commit

Permalink
add test for data packet buffer length before use of data encryption …
Browse files Browse the repository at this point in the history
…and data integrity services
  • Loading branch information
sijms committed Sep 13, 2024
1 parent 8e629f6 commit 77afbbe
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions v2/network/data_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,23 @@ func newDataPacketFromData(packetData []byte, sessionCtx *SessionContext, tracer
} else {
pck.length = uint32(binary.BigEndian.Uint16(packetData))
}
var err error
if sessionCtx.AdvancedService.CryptAlgo != nil || sessionCtx.AdvancedService.HashAlgo != nil {
pck.buffer = pck.buffer[:len(pck.buffer)-1]
}
if sessionCtx.AdvancedService.CryptAlgo != nil {
pck.buffer, err = sessionCtx.AdvancedService.CryptAlgo.Decrypt(pck.buffer)
if err != nil {
return nil, err
if len(pck.buffer) > 1 {
var err error
if sessionCtx.AdvancedService.CryptAlgo != nil || sessionCtx.AdvancedService.HashAlgo != nil {
pck.buffer = pck.buffer[:len(pck.buffer)-1]
}
tracer.LogPacket("Read packet (Decrypted): ", pck.buffer)
}
if sessionCtx.AdvancedService.HashAlgo != nil {
pck.buffer, err = sessionCtx.AdvancedService.HashAlgo.Validate(pck.buffer)
if err != nil {
return nil, err
if sessionCtx.AdvancedService.CryptAlgo != nil {
pck.buffer, err = sessionCtx.AdvancedService.CryptAlgo.Decrypt(pck.buffer)
if err != nil {
return nil, err
}
tracer.LogPacket("Read packet (Decrypted): ", pck.buffer)
}
if sessionCtx.AdvancedService.HashAlgo != nil {
pck.buffer, err = sessionCtx.AdvancedService.HashAlgo.Validate(pck.buffer)
if err != nil {
return nil, err
}
}
}
return pck, nil
Expand Down

0 comments on commit 77afbbe

Please sign in to comment.