Skip to content
Snippets Groups Projects
Commit 8ed9dea0 authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'XX-3105/RemoveOfuscation' into 'release'

Remove identity obfuscation

Closes XX-3105

See merge request !649
parents 727d112e 45da778e
Branches
Tags
2 merge requests!23Release,!4Xx 3105/remove ofuscation
...@@ -104,16 +104,16 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source, ...@@ -104,16 +104,16 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source,
}, },
LastUpdate: uint64(m.Instance.GetLastUpdateID()), LastUpdate: uint64(m.Instance.GetLastUpdateID()),
ReceptionID: identity.EphId[:], ReceptionID: identity.EphId[:],
StartTimestamp: identity.StartRequest.UnixNano(), StartTimestamp: identity.StartValid.UnixNano(),
EndTimestamp: identity.EndRequest.UnixNano(), EndTimestamp: identity.EndValid.UnixNano(),
ClientVersion: []byte(version.String()), ClientVersion: []byte(version.String()),
FastPolling: m.param.FastPolling, FastPolling: m.param.FastPolling,
} }
result, err := m.GetSender().SendToAny(func(host *connect.Host) (interface{}, error) { result, err := m.GetSender().SendToAny(func(host *connect.Host) (interface{}, error) {
jww.DEBUG.Printf("Executing poll for %v(%s) range: %s-%s(%s) from %s", jww.DEBUG.Printf("Executing poll for %v(%s) range: %s-%s(%s) from %s",
identity.EphId.Int64(), identity.Source, identity.StartRequest, identity.EphId.Int64(), identity.Source, identity.StartValid,
identity.EndRequest, identity.EndRequest.Sub(identity.StartRequest), host.GetId()) identity.EndValid, identity.StartValid.Sub(identity.EndValid), host.GetId())
return comms.SendPoll(host, &pollReq) return comms.SendPoll(host, &pollReq)
}, stop) }, stop)
......
...@@ -95,7 +95,6 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, ...@@ -95,7 +95,6 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte,
ExtraChecks: 10, ExtraChecks: 10,
StartValid: timeStart.Add(-2 * timeout), StartValid: timeStart.Add(-2 * timeout),
EndValid: timeStart.Add(2 * timeout), EndValid: timeStart.Add(2 * timeout),
RequestMask: 48*time.Hour - timeout,
Ephemeral: true, Ephemeral: true,
}) })
if err != nil { if err != nil {
......
...@@ -2,24 +2,14 @@ package reception ...@@ -2,24 +2,14 @@ package reception
import ( import (
"fmt" "fmt"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/storage/rounds" "gitlab.com/elixxir/client/storage/rounds"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/xx_network/crypto/randomness"
"io"
"math/big"
"strconv" "strconv"
"strings" "strings"
"time"
) )
type IdentityUse struct { type IdentityUse struct {
Identity Identity
// Randomly generated time to poll between
StartRequest time.Time // Timestamp to request the start of bloom filters
EndRequest time.Time // Timestamp to request the End of bloom filters
// Denotes if the identity is fake, in which case we do not process messages // Denotes if the identity is fake, in which case we do not process messages
Fake bool Fake bool
...@@ -28,36 +18,12 @@ type IdentityUse struct { ...@@ -28,36 +18,12 @@ type IdentityUse struct {
CR *rounds.CheckedRounds CR *rounds.CheckedRounds
} }
// setSamplingPeriod add the Request mask as a random buffer around the sampling
// time to obfuscate it.
func (iu IdentityUse) setSamplingPeriod(rng io.Reader) (IdentityUse, error) {
// Generate the seed
seed := make([]byte, 32)
if _, err := rng.Read(seed); err != nil {
return IdentityUse{}, errors.WithMessage(err, "Failed to choose ID "+
"due to rng failure")
}
h, err := hash.NewCMixHash()
if err != nil {
return IdentityUse{}, err
}
// Calculate the period offset
periodOffset := randomness.RandInInterval(
big.NewInt(iu.RequestMask.Nanoseconds()), seed, h).Int64()
iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset))
iu.EndRequest = iu.EndValid.Add(iu.RequestMask - time.Duration(periodOffset))
return iu, nil
}
func (iu IdentityUse) GoString() string { func (iu IdentityUse) GoString() string {
str := make([]string, 0, 7) str := make([]string, 0, 7)
str = append(str, "Identity:"+iu.Identity.GoString()) str = append(str, "Identity:"+iu.Identity.GoString())
str = append(str, "StartRequest:"+iu.StartRequest.String()) str = append(str, "StartValid:"+iu.StartValid.String())
str = append(str, "EndRequest:"+iu.EndRequest.String()) str = append(str, "EndValid:"+iu.EndValid.String())
str = append(str, "Fake:"+strconv.FormatBool(iu.Fake)) str = append(str, "Fake:"+strconv.FormatBool(iu.Fake))
str = append(str, "UR:"+fmt.Sprintf("%+v", iu.UR)) str = append(str, "UR:"+fmt.Sprintf("%+v", iu.UR))
str = append(str, "ER:"+fmt.Sprintf("%+v", iu.ER)) str = append(str, "ER:"+fmt.Sprintf("%+v", iu.ER))
......
...@@ -40,7 +40,6 @@ func generateFakeIdentity(rng io.Reader, addressSize uint8, ...@@ -40,7 +40,6 @@ func generateFakeIdentity(rng io.Reader, addressSize uint8,
ExtraChecks: 0, ExtraChecks: 0,
StartValid: start, StartValid: start,
EndValid: end, EndValid: end,
RequestMask: 24 * time.Hour,
Ephemeral: true, Ephemeral: true,
}, },
Fake: true, Fake: true,
......
...@@ -25,9 +25,8 @@ func Test_generateFakeIdentity(t *testing.T) { ...@@ -25,9 +25,8 @@ func Test_generateFakeIdentity(t *testing.T) {
"\"End\":" + string(end) + ",\"ExtraChecks\":0," + "\"End\":" + string(end) + ",\"ExtraChecks\":0," +
"\"StartValid\":" + string(startValid) + "," + "\"StartValid\":" + string(startValid) + "," +
"\"EndValid\":" + string(endValid) + "," + "\"EndValid\":" + string(endValid) + "," +
"\"RequestMask\":86400000000000,\"Ephemeral\":true," + "\"Ephemeral\":true," +
"\"StartRequest\":\"0001-01-01T00:00:00Z\"," + "\"Fake\":true,\"UR\":null,\"ER\":null,\"CR\":null}"
"\"EndRequest\":\"0001-01-01T00:00:00Z\",\"Fake\":true,\"UR\":null,\"ER\":null,\"CR\":null}"
timestamp := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) timestamp := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
......
...@@ -29,8 +29,6 @@ type Identity struct { ...@@ -29,8 +29,6 @@ type Identity struct {
// Polling parameters // Polling parameters
StartValid time.Time // Timestamp when the ephID begins being valid StartValid time.Time // Timestamp when the ephID begins being valid
EndValid time.Time // Timestamp when the ephID stops being valid EndValid time.Time // Timestamp when the ephID stops being valid
RequestMask time.Duration // Amount of extra time requested for the poll in
// order to mask the exact valid time for the ID
// Makes the identity not store on disk // Makes the identity not store on disk
Ephemeral bool Ephemeral bool
...@@ -92,7 +90,6 @@ func (i Identity) GoString() string { ...@@ -92,7 +90,6 @@ func (i Identity) GoString() string {
str = append(str, "ExtraChecks:"+strconv.FormatUint(uint64(i.ExtraChecks), 10)) str = append(str, "ExtraChecks:"+strconv.FormatUint(uint64(i.ExtraChecks), 10))
str = append(str, "StartValid:"+i.StartValid.String()) str = append(str, "StartValid:"+i.StartValid.String())
str = append(str, "EndValid:"+i.EndValid.String()) str = append(str, "EndValid:"+i.EndValid.String())
str = append(str, "RequestMask:"+i.RequestMask.String())
str = append(str, "Ephemeral:"+strconv.FormatBool(i.Ephemeral)) str = append(str, "Ephemeral:"+strconv.FormatBool(i.Ephemeral))
return "{" + strings.Join(str, ", ") + "}" return "{" + strings.Join(str, ", ") + "}"
...@@ -106,6 +103,5 @@ func (i Identity) Equal(b Identity) bool { ...@@ -106,6 +103,5 @@ func (i Identity) Equal(b Identity) bool {
i.ExtraChecks == b.ExtraChecks && i.ExtraChecks == b.ExtraChecks &&
i.StartValid.Equal(b.StartValid) && i.StartValid.Equal(b.StartValid) &&
i.EndValid.Equal(b.EndValid) && i.EndValid.Equal(b.EndValid) &&
i.RequestMask == b.RequestMask &&
i.Ephemeral == b.Ephemeral i.Ephemeral == b.Ephemeral
} }
package reception
import (
"math/rand"
"testing"
"time"
)
func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
rng := rand.New(rand.NewSource(42))
const numTests = 1000
for i := 0; i < numTests; i++ {
// Generate an identity use
start := randate()
end := start.Add(time.Duration(rand.Uint64() % uint64(92*time.Hour)))
mask := time.Duration(rand.Uint64() % uint64(92*time.Hour))
iu := IdentityUse{
Identity: Identity{
StartValid: start,
EndValid: end,
RequestMask: mask,
},
}
// Generate the sampling period
var err error
iu, err = iu.setSamplingPeriod(rng)
if err != nil {
t.Errorf("Errored in generatign sampling "+
"period on interation %v: %+v", i, err)
}
// Test that the range between the periods is correct
resultRange := iu.EndRequest.Sub(iu.StartRequest)
expectedRange := iu.EndValid.Sub(iu.StartValid) + iu.RequestMask
if resultRange != expectedRange {
t.Errorf("The generated sampling period is of the wrong "+
"size: Expecterd: %s, Received: %s", expectedRange, resultRange)
}
// Test the sampling range does not exceed a reasonable lower bound
lowerBound := iu.StartValid.Add(-iu.RequestMask)
if !iu.StartRequest.After(lowerBound) {
t.Errorf("Start request exceeds the reasonable lower "+
"bound: \n\t Bound: %s\n\t Start: %s", lowerBound, iu.StartValid)
}
// Test the sampling range does not exceed a reasonable upper bound
upperBound := iu.EndValid.Add(iu.RequestMask - time.Millisecond)
if iu.EndRequest.After(upperBound) {
t.Errorf("End request exceeds the reasonable upper bound")
}
}
}
func randate() time.Time {
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min
sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}
...@@ -21,7 +21,6 @@ func TestIdentity_EncodeDecode(t *testing.T) { ...@@ -21,7 +21,6 @@ func TestIdentity_EncodeDecode(t *testing.T) {
ExtraChecks: 12, ExtraChecks: 12,
StartValid: netTime.Now().Round(0), StartValid: netTime.Now().Round(0),
EndValid: netTime.Now().Round(0), EndValid: netTime.Now().Round(0),
RequestMask: 2 * time.Hour,
Ephemeral: false, Ephemeral: false,
} }
...@@ -51,7 +50,6 @@ func TestIdentity_Delete(t *testing.T) { ...@@ -51,7 +50,6 @@ func TestIdentity_Delete(t *testing.T) {
ExtraChecks: 12, ExtraChecks: 12,
StartValid: netTime.Now().Round(0), StartValid: netTime.Now().Round(0),
EndValid: netTime.Now().Round(0), EndValid: netTime.Now().Round(0),
RequestMask: 2 * time.Hour,
Ephemeral: false, Ephemeral: false,
} }
......
...@@ -165,12 +165,6 @@ func (s *Store) GetIdentity(rng io.Reader, addressSize uint8) (IdentityUse, erro ...@@ -165,12 +165,6 @@ func (s *Store) GetIdentity(rng io.Reader, addressSize uint8) (IdentityUse, erro
} }
} }
// Calculate the sampling period
identity, err = identity.setSamplingPeriod(rng)
if err != nil {
jww.FATAL.Panicf("Failed to calculate the sampling period: %+v", err)
}
return identity, nil return identity, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment