diff --git a/internal/device/vowifi_delivery_store.go b/internal/device/vowifi_delivery_store.go index aaa86366..41ae569d 100644 --- a/internal/device/vowifi_delivery_store.go +++ b/internal/device/vowifi_delivery_store.go @@ -73,7 +73,12 @@ func (vowifiDeliveryStore) LoadInboundFragments( } result := make([]messaging.StoredInboundFragment, 0, len(rows)) for _, row := range rows { - result = append(result, inboundFragmentFromDB(row)) + // The rows already match the owner's canonical ICCID and IMSI. Hand + // the owner back as given so imscore's exact owner check accepts + // fragments saved on another device or under a padded ICCID. + fragment := inboundFragmentFromDB(row) + fragment.Scope.Owner = owner + result = append(result, fragment) } return result, nil } diff --git a/internal/device/vowifi_fragment_owner_test.go b/internal/device/vowifi_fragment_owner_test.go new file mode 100644 index 00000000..1d2d34bc --- /dev/null +++ b/internal/device/vowifi_fragment_owner_test.go @@ -0,0 +1,58 @@ +package device + +import ( + "path/filepath" + "testing" + "time" + + "github.com/iniwex5/vowifi-go/runtimehost/messaging" + "github.com/yibaiba/hideck/internal/db" +) + +func TestLoadInboundFragmentsReturnsRequestedOwner(t *testing.T) { + previousDB := db.DB + if err := db.Init(filepath.Join(t.TempDir(), "fragments.db")); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { + if sqlDB, err := db.DB.DB(); err == nil { + _ = sqlDB.Close() + } + db.DB = previousDB + }) + + store := vowifiDeliveryStore{} + saved := messaging.InboundFragmentOwner{DeviceID: "dev-a", ICCID: "89640a0000000000001f", IMSI: "530010000000001"} + if _, err := store.SaveInboundFragment( + messaging.InboundFragmentScope{Owner: saved, SessionKey: "session"}, + messaging.InboundFragment{Reference: 7, Total: 2, Sequence: 1, Content: "part", ArrivedAt: time.Now()}, + ); err != nil { + t.Fatalf("save fragment: %v", err) + } + + for _, owner := range []messaging.InboundFragmentOwner{ + saved, + {DeviceID: "dev-b", ICCID: "89640A0000000000001F", IMSI: "530010000000001"}, + } { + records, err := store.LoadInboundFragments(owner) + if err != nil { + t.Fatalf("load fragments for %+v: %v", owner, err) + } + if len(records) != 1 || records[0].Scope.Owner != owner { + t.Fatalf("load fragments for %+v = %+v", owner, records) + } + } + + for _, other := range []messaging.InboundFragmentOwner{ + {DeviceID: "dev-a", ICCID: "8964010000000000002", IMSI: saved.IMSI}, + {DeviceID: "dev-a", ICCID: saved.ICCID, IMSI: "530010000000002"}, + } { + records, err := store.LoadInboundFragments(other) + if err != nil { + t.Fatalf("load fragments for %+v: %v", other, err) + } + if len(records) != 0 { + t.Fatalf("another SIM %+v loaded %+v", other, records) + } + } +} diff --git a/third_party/vowifi-go/runtimehost/identity/adapters.go b/third_party/vowifi-go/runtimehost/identity/adapters.go index 7c4876d1..b5bffb2a 100644 --- a/third_party/vowifi-go/runtimehost/identity/adapters.go +++ b/third_party/vowifi-go/runtimehost/identity/adapters.go @@ -99,7 +99,7 @@ func preparedSessionFromInternal(value internalprofile.PreparedSession) Prepared func profileFromInternal(value internalprofile.Profile) Profile { return Profile{ - IMSI: value.IMSI, MCC: value.MCC, MNC: value.MNC, IMEI: value.IMEI, + ICCID: value.ICCID, IMSI: value.IMSI, MCC: value.MCC, MNC: value.MNC, IMEI: value.IMEI, UserAgent: value.UserAgent, SMSC: value.SMSC, IMSDomain: value.IMSDomain, } } diff --git a/third_party/vowifi-go/runtimehost/identity/prepare_iccid_test.go b/third_party/vowifi-go/runtimehost/identity/prepare_iccid_test.go new file mode 100644 index 00000000..967046a4 --- /dev/null +++ b/third_party/vowifi-go/runtimehost/identity/prepare_iccid_test.go @@ -0,0 +1,22 @@ +package identity + +import "testing" + +func TestPrepareStartKeepsICCID(t *testing.T) { + access := &stubAccess{ident: Identity{ + IMSI: "310280233621715", IMPI: "310280233621715@private.att.net", + IMPU: []string{"sip:310280233621715@one.att.net"}, + Domain: "one.att.net", + }} + prepared, err := PrepareStart(PrepareStartInput{ + DeviceID: "wwan0", + Profile: Profile{ICCID: " 89012802331234567890 ", IMSI: "310280233621715", MCC: "310", MNC: "280"}, + Access: access, + }) + if err != nil { + t.Fatalf("PrepareStart: %v", err) + } + if prepared.Profile.ICCID != "89012802331234567890" { + t.Fatalf("prepared ICCID = %q", prepared.Profile.ICCID) + } +}