some tunnel message tests, bug fixes

This commit is contained in:
Hayden Parker
2016-09-08 23:44:09 -07:00
parent 18b5dcf10d
commit 9fd55b7695
2 changed files with 110 additions and 11 deletions

View File

@@ -7,7 +7,41 @@ import (
)
/*
I2P Tunnel Message
I2P Encrypted Tunnel Message
https://geti2p.net/spec/tunnel-message
Accurate for version 0.9.11
+----+----+----+----+----+----+----+----+
| Tunnel ID | IV |
+----+----+----+----+ +
| |
+ +----+----+----+----+
| | |
+----+----+----+----+ +
| |
+ Encrypted Data +
~ ~
| |
+ +-------------------+
| |
+----+----+----+----+
Tunnel ID :: TunnelId
4 bytes
the ID of the next hop
IV ::
16 bytes
the initialization vector
Encrypted Data ::
1008 bytes
the encrypted tunnel message
total size: 1028 Bytes
I2P Decrypted Tunnel Message
https://geti2p.net/spec/tunnel-message
Accurate for version 0.9.11
@@ -112,24 +146,32 @@ func (decrypted_tunnel_message DecryptedTunnelMessage) ID() TunnelID {
}
func (decrypted_tunnel_message DecryptedTunnelMessage) IV() crypto.TunnelIV {
return decrypted_tunnel_message[4:20]
return decrypted_tunnel_message[4 : 4+16]
}
func (decrypted_tunnel_message DecryptedTunnelMessage) Checksum() crypto.TunnelIV {
return decrypted_tunnel_message[24:28]
return decrypted_tunnel_message[4+16 : 4+4+16]
}
//
// Returns the contents of a decrypted tunnel message that contain the data for the
// DeliveryInstructions.
//
func (decrypted_tunnel_message DecryptedTunnelMessage) deliveryInstructionData() []byte {
data_area := decrypted_tunnel_message[28:]
padding_size := 0
for i, _ := range data_area {
if i == 0x00 {
padding_size = i
data_area := decrypted_tunnel_message[4+4+16:]
for i := 0; i < len(data_area); i++ {
if data_area[i] == 0x00 {
return data_area[i+1:]
}
}
return data_area[padding_size:]
return []byte{}
}
//
// Returns a slice of DeliveryInstructionWithFragment structures, which all of the Delivery Instructions
// in the tunnel message and their corresponding MessageFragment structures.
//
//
func (decrypted_tunnel_message DecryptedTunnelMessage) DeliveryInstructionsWithFragments() []DeliveryInstructionsWithFragment {
set := make([]DeliveryInstructionsWithFragment, 0)
data := decrypted_tunnel_message.deliveryInstructionData()

View File

@@ -1,6 +1,63 @@
package tunnel
import (
//"github.com/stretchr/testify/assert"
//"testing"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDeliveryInstructionDataWithNoPadding(t *testing.T) {
assert := assert.New(t)
data := make([]byte, 0)
data = append(data, make([]byte, 4+4+16)...)
data = append(data, 0)
data = append(data, make([]byte, 1028-4-4-16-1)...)
var decrypted_tunnel_message DecryptedTunnelMessage
copy(decrypted_tunnel_message[:], data)
di := decrypted_tunnel_message.deliveryInstructionData()
assert.Equal(1028-4-4-16-1, len(di))
}
func TestDeliveryInstructionDataWithSomePadding(t *testing.T) {
assert := assert.New(t)
data := make([]byte, 0)
data = append(data, make([]byte, 4+4+16)...)
padding_size := 200
for i := 0; i < padding_size; i++ {
data = append(data, 0x01)
}
data = append(data, 0)
data = append(data, make([]byte, 1028-4-4-16-1-padding_size)...)
var decrypted_tunnel_message DecryptedTunnelMessage
copy(decrypted_tunnel_message[:], data)
di := decrypted_tunnel_message.deliveryInstructionData()
assert.Equal(1028-4-4-16-1-padding_size, len(di))
}
func TestDeliveryInstructionDataWithOnlyPadding(t *testing.T) {
assert := assert.New(t)
data := make([]byte, 0)
data = append(data, make([]byte, 4+4+16)...)
padding_size := 1028 - 4 - 4 - 16 - 1
for i := 0; i < padding_size; i++ {
data = append(data, 0x01)
}
data = append(data, 0)
var decrypted_tunnel_message DecryptedTunnelMessage
copy(decrypted_tunnel_message[:], data)
di := decrypted_tunnel_message.deliveryInstructionData()
assert.Equal(0, len(di))
}
func TestDeliveryInstructionsWithFragmentsWithAllPadding(t *testing.T) {
}
// Test invalid delivery instructions and message fragments
func TestDeliveryInstructionsWithFragmentsWithValidData(t *testing.T) {
}