diff --git a/docs/operator-notes.md b/docs/operator-notes.md index aac8de8a..920c6192 100644 --- a/docs/operator-notes.md +++ b/docs/operator-notes.md @@ -67,6 +67,19 @@ - 自动化测试覆盖身份请求编码、认证门控、发送失败和配置覆盖;不替代 Spark、VOXI 或其他运营商的真卡验收。 +## 2degrees NZ(530/24) + +- REGISTER 的 200 里列出的 Contact 去掉了用户部分,只剩内层 IP 和端口。按 RFC 3261 §10.2.4、§19.1.4 比对不上,会被判注册失败。 +- 预设 `accept_register_contact_without_user`:带用户部分比对不上时,去掉我们这边的用户部分再按同样的 URI 比较规则比一次,对上就按注册成功处理,日志记 `IMS REGISTER binding matched a Contact without the user part`。这是 2degrees 兼容策略,其他运营商比对不上仍判失败。 +- 可通过 `config/carrier_overrides.yaml` 关闭,修改后需重启服务: + + ```yaml + carrier_overrides: + "53024": + ims_register_template: + accept_register_contact_without_user: false + ``` + ## 德国 O2(262/03、262/07) - 预设已有:`O2_de_26203`、`O2_de_26207_alias`。ePDG 用 3GPP 名 `epdg.epc.mnc003.mcc262.pub.3gppnetwork.org` / `mnc007`。 diff --git a/third_party/vowifi-go/internal/runtimehostcarrier/convert.go b/third_party/vowifi-go/internal/runtimehostcarrier/convert.go index f0054b83..dc6a3005 100644 --- a/third_party/vowifi-go/internal/runtimehostcarrier/convert.go +++ b/third_party/vowifi-go/internal/runtimehostcarrier/convert.go @@ -42,6 +42,7 @@ func TemplateToInternal(t carrier.IMSRegisterTemplate) policy.IMSRegisterTemplat SecurityClientIncludesServerParams: t.SecurityClientIncludesServerParams, SecurityClientMechanisms: mechanismsToInternal(t.SecurityClientMechanisms), StrictSecurityServerOffer: t.StrictSecurityServerOffer, + AcceptRegisterContactWithoutUser: t.AcceptRegisterContactWithoutUser, EnableInitialRejectFallback: t.EnableInitialRejectFallback, FallbackIncludesServerParamsInSecCl: t.FallbackIncludesServerParamsInSecCl, RegisterPolicy: registerPolicyToInternal(t.RegisterPolicy), @@ -66,6 +67,7 @@ func TemplateFromInternal(t policy.IMSRegisterTemplate) carrier.IMSRegisterTempl SecurityClientIncludesServerParams: t.SecurityClientIncludesServerParams, SecurityClientMechanisms: mechanismsFromInternal(t.SecurityClientMechanisms), StrictSecurityServerOffer: t.StrictSecurityServerOffer, + AcceptRegisterContactWithoutUser: t.AcceptRegisterContactWithoutUser, EnableInitialRejectFallback: t.EnableInitialRejectFallback, FallbackIncludesServerParamsInSecCl: t.FallbackIncludesServerParamsInSecCl, RegisterPolicy: registerPolicyFromInternal(t.RegisterPolicy), diff --git a/third_party/vowifi-go/internal/runtimehostcarrier/convert_test.go b/third_party/vowifi-go/internal/runtimehostcarrier/convert_test.go index 8e3d07c3..916847d8 100644 --- a/third_party/vowifi-go/internal/runtimehostcarrier/convert_test.go +++ b/third_party/vowifi-go/internal/runtimehostcarrier/convert_test.go @@ -24,6 +24,18 @@ func TestEffectiveCarrierConfigRoundTrip(t *testing.T) { } } +// The round trip only proves fields the fixture sets, so a new template +// field must be populated here before the round trip can catch a drop. +func TestPopulatedTemplateSetsEveryField(t *testing.T) { + value := reflect.ValueOf(populatedTemplate("all")) + for i := 0; i < value.NumField(); i++ { + field := value.Type().Field(i) + if field.IsExported() && value.Field(i).IsZero() { + t.Errorf("populatedTemplate leaves %s unset", field.Name) + } + } +} + func TestConversionsOwnNestedSlices(t *testing.T) { source := populatedCarrierConfig() internal := ToInternal(source) @@ -113,8 +125,8 @@ func populatedTemplate(id string) carrier.IMSRegisterTemplate { SecurityClientMechanisms: []carrier.IPSec3GPPSecurityMechanism{ {Alg: "hmac-md5-96", EAlg: "aes-cbc", Prot: "esp", Mode: "trans"}, }, - StrictSecurityServerOffer: true, EnableInitialRejectFallback: true, - FallbackIncludesServerParamsInSecCl: true, + StrictSecurityServerOffer: true, AcceptRegisterContactWithoutUser: true, + EnableInitialRejectFallback: true, FallbackIncludesServerParamsInSecCl: true, RegisterPolicy: carrier.IMSRegisterPolicy{ ID: "register", TemporaryStatusCodes: []int{408, 500}, ForbiddenStatusCodes: []int{403}, InitialRejectFallbackStatusCodes: []int{404, 488}, TemporaryRetrySeconds: 15, diff --git a/third_party/vowifi-go/internal/vowifi/imscore/register.go b/third_party/vowifi-go/internal/vowifi/imscore/register.go index 4707e058..da70ecd6 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/register.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/register.go @@ -396,15 +396,22 @@ func updateRegisterAttemptAuth(result *registerAttemptResult, session *registerS } func (s *Service) commitRegisterSuccess(resp *sipResponse, session *registerSession) (time.Duration, error) { - expires, err := registrationExpires(resp, session.requestContact, s.cfg.Expires) + acceptWithoutUser := s.cfg.IMSRegisterTemplate.AcceptRegisterContactWithoutUser + expires, err := registrationExpires(resp, session.requestContact, s.cfg.Expires, acceptWithoutUser) if err != nil { if errors.Is(err, errRegisterContactMissing) { logging.Info("IMS REGISTER response Contact mismatch", "device", s.DeviceID(), "requested", redactContactUser(session.requestContact), - "response", redactedResponseContacts(resp), "response_headers", sipHeaderNames(resp)) + "response", redactedResponseContacts(resp), "response_headers", sipHeaderNames(resp), + "accept_without_user", acceptWithoutUser) } return 0, err } + if acceptWithoutUser && matchingRegisterContact(resp, session.requestContact, false) == "" { + logging.Info("IMS REGISTER binding matched a Contact without the user part", + "device", s.DeviceID(), "requested", redactContactUser(session.requestContact), + "response", redactedResponseContacts(resp)) + } s.finalizeRegistrationTransportSwitch() s.lastRegisterContactCount.Store(int32(registerContactBindingCount(resp))) session.expires = expires diff --git a/third_party/vowifi-go/internal/vowifi/imscore/register_expiry.go b/third_party/vowifi-go/internal/vowifi/imscore/register_expiry.go index 55a62255..2e0c2ba6 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/register_expiry.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/register_expiry.go @@ -13,8 +13,10 @@ import ( var errRegisterContactMissing = errors.New("imscore: REGISTER response does not contain the requested Contact binding") -func registrationExpires(response *sipResponse, requestContact string, configured time.Duration) (time.Duration, error) { - contact := matchingRegisterContact(response, requestContact) +func registrationExpires( + response *sipResponse, requestContact string, configured time.Duration, acceptWithoutUser bool, +) (time.Duration, error) { + contact := matchingRegisterContact(response, requestContact, acceptWithoutUser) if contact == "" { return 0, errRegisterContactMissing } @@ -43,11 +45,23 @@ func parseRegistrationLifetime(value string) (time.Duration, error) { return time.Duration(seconds) * time.Second, nil } -func matchingRegisterContact(response *sipResponse, requestContact string) string { +func matchingRegisterContact(response *sipResponse, requestContact string, acceptWithoutUser bool) string { var own sip.Uri if _, err := sip.ParseAddressValue(requestContact, &own, nil); err != nil || own.Host == "" { return "" } + if contact := findRegisterContact(response, own); contact != "" || !acceptWithoutUser || own.User == "" { + return contact + } + // RFC 3261 19.1.4 says a URI without a user part does not match ours. + // 2degrees NZ still answers our REGISTER with only the userless form of + // our address. The inner IP and protected port are unique to this flow, + // so the preset opts in to taking that form as our binding. + own.User, own.Password = "", "" + return findRegisterContact(response, own) +} + +func findRegisterContact(response *sipResponse, own sip.Uri) string { for _, header := range response.HeaderValues("Contact") { for _, contact := range splitQuotedSIPHeaderValues(header) { var candidate sip.Uri diff --git a/third_party/vowifi-go/internal/vowifi/imscore/register_expiry_test.go b/third_party/vowifi-go/internal/vowifi/imscore/register_expiry_test.go index 0c308f9e..7df5a5ad 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/register_expiry_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/register_expiry_test.go @@ -51,7 +51,7 @@ func TestRegistrationExpiresMatchesCurrentBinding(t *testing.T) { if err != nil { t.Fatal(err) } - got, err := registrationExpires(response, own, 10*time.Minute) + got, err := registrationExpires(response, own, 10*time.Minute, false) if (err != nil) != test.wantError || got != test.want { t.Fatalf("registrationExpires = %s, %v; want %s, error=%t", got, err, test.want, test.wantError) } @@ -87,7 +87,7 @@ func TestRegisterContactURIMatching(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { response := &sipResponse{Headers: map[string]string{"Contact": test.response + ";expires=120"}} - got := matchingRegisterContact(response, test.request) != "" + got := matchingRegisterContact(response, test.request, false) != "" if got != test.match { t.Fatalf("matched = %t, want %t", got, test.match) } @@ -95,6 +95,31 @@ func TestRegisterContactURIMatching(t *testing.T) { } } +func TestRegisterContactWithoutUserNeedsPresetOptIn(t *testing.T) { + const own = "" + tests := []struct { + name, response string + strict, optIn bool + }{ + {"userless echo", "", false, true}, + {"userless other port", "", false, false}, + {"userless other transport", "", false, false}, + {"other user", "", false, false}, + {"own user", own, true, true}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + response := &sipResponse{Headers: map[string]string{"Contact": test.response + ";expires=600"}} + if got := matchingRegisterContact(response, own, false) != ""; got != test.strict { + t.Fatalf("strict matched = %t, want %t", got, test.strict) + } + if got := matchingRegisterContact(response, own, true) != ""; got != test.optIn { + t.Fatalf("opt-in matched = %t, want %t", got, test.optIn) + } + }) + } +} + func TestRegisterSchedulesRefreshFromSentContact(t *testing.T) { registrar, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)}) if err != nil { diff --git a/third_party/vowifi-go/internal/vowifi/imscore/register_restore_test.go b/third_party/vowifi-go/internal/vowifi/imscore/register_restore_test.go index dcccf8b3..519105eb 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/register_restore_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/register_restore_test.go @@ -134,7 +134,7 @@ func TestParseRecoveredRegisterResponseFields(t *testing.T) { "Expires": "3600", "Contact": ";expires=120", "Retry-After": "9", "Min-Expires": "600", }} - if got, err := registrationExpires(response, "", 10*time.Second); err != nil || got != 120*time.Second { + if got, err := registrationExpires(response, "", 10*time.Second, false); err != nil || got != 120*time.Second { t.Fatalf("registrationExpires = %s, %v", got, err) } retryAfter, retryAfterSet, minExpires := parseRegisterRetryHintsFromResponse(response) diff --git a/third_party/vowifi-go/internal/vowifi/imscore/register_transport_test.go b/third_party/vowifi-go/internal/vowifi/imscore/register_transport_test.go index 68b3645b..95b1b863 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/register_transport_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/register_transport_test.go @@ -555,7 +555,7 @@ func TestRegistrationExpiresPrefersOwnContact(t *testing.T) { response := &sipResponse{Headers: map[string]string{ "Contact": ";expires=120", "Expires": "3600", }} - if got, err := registrationExpires(response, "", time.Hour); err != nil || got != 120*time.Second { + if got, err := registrationExpires(response, "", time.Hour, false); err != nil || got != 120*time.Second { t.Fatalf("registrationExpires = %s, %v, want 120s", got, err) } } diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sip_parser_test.go b/third_party/vowifi-go/internal/vowifi/imscore/sip_parser_test.go index e0065410..36a0430a 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sip_parser_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sip_parser_test.go @@ -165,7 +165,7 @@ func TestParseSIPResponsePreservesStructuredHeaders(t *testing.T) { !strings.Contains(contacts, "second@ims.example") { t.Fatalf("projected Contact header = %q", contacts) } - if expires, err := registrationExpires(response, "", 600*time.Second); err != nil || expires != 42*time.Second { + if expires, err := registrationExpires(response, "", 600*time.Second, false); err != nil || expires != 42*time.Second { t.Fatalf("registration expires = %s, %v", expires, err) } if string(response.Body) != "body" { diff --git a/third_party/vowifi-go/internal/vowifi/policy/override_merge.go b/third_party/vowifi-go/internal/vowifi/policy/override_merge.go index 91f4df05..90cb0dd1 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/override_merge.go +++ b/third_party/vowifi-go/internal/vowifi/policy/override_merge.go @@ -190,6 +190,7 @@ func applyIMSRegisterTemplateOverride(target IMSRegisterTemplate, override IMSRe target.SecurityClientMechanisms = cloneMechanisms(override.SecurityClientMechanisms) } applyBoolPtr(&target.StrictSecurityServerOffer, override.StrictSecurityServerOffer) + applyBoolPtr(&target.AcceptRegisterContactWithoutUser, override.AcceptRegisterContactWithoutUser) applyBoolPtr(&target.EnableInitialRejectFallback, override.EnableInitialRejectFallback) applyBoolPtr(&target.FallbackIncludesServerParamsInSecCl, override.FallbackIncludesServerParamsInSecCl) target.RegisterPolicy = applyIMSRegisterPolicyOverride(target.RegisterPolicy, override.RegisterPolicy) diff --git a/third_party/vowifi-go/internal/vowifi/policy/override_store.go b/third_party/vowifi-go/internal/vowifi/policy/override_store.go index 9910cf1c..40f9297f 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/override_store.go +++ b/third_party/vowifi-go/internal/vowifi/policy/override_store.go @@ -103,6 +103,7 @@ func cloneCarrierOverridePointers(value *CarrierOverride) { template.IncludeConnectionKeepaliveInAuth = cloneBoolPointer(template.IncludeConnectionKeepaliveInAuth) template.SecurityClientIncludesServerParams = cloneBoolPointer(template.SecurityClientIncludesServerParams) template.StrictSecurityServerOffer = cloneBoolPointer(template.StrictSecurityServerOffer) + template.AcceptRegisterContactWithoutUser = cloneBoolPointer(template.AcceptRegisterContactWithoutUser) template.EnableInitialRejectFallback = cloneBoolPointer(template.EnableInitialRejectFallback) template.FallbackIncludesServerParamsInSecCl = cloneBoolPointer(template.FallbackIncludesServerParamsInSecCl) template.RegisterPolicy.TemporaryRetrySeconds = cloneIntPointer(template.RegisterPolicy.TemporaryRetrySeconds) diff --git a/third_party/vowifi-go/internal/vowifi/policy/policy_test.go b/third_party/vowifi-go/internal/vowifi/policy/policy_test.go index 606661b0..b1ce7a7f 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/policy_test.go +++ b/third_party/vowifi-go/internal/vowifi/policy/policy_test.go @@ -151,6 +151,14 @@ func TestResolveEmbeddedCarrierPresets(t *testing.T) { !one.WithholdDeviceIdentity || !CarrierPlanFromEffectiveConfig(one).Device.Withhold { t.Fatalf("one nz = %+v", one) } + if twoDegrees := ResolveEffectiveCarrierConfig("530", "24"); twoDegrees.PresetID != "2degrees_nz_53024" || + !twoDegrees.IMSRegisterTemplate.AcceptRegisterContactWithoutUser || + !CarrierPlanFromEffectiveConfig(twoDegrees).IMS.RegisterTemplate.AcceptRegisterContactWithoutUser { + t.Fatalf("2degrees nz = %+v", twoDegrees.IMSRegisterTemplate) + } + if spark := ResolveEffectiveCarrierConfig("530", "05"); spark.IMSRegisterTemplate.AcceptRegisterContactWithoutUser { + t.Fatal("spark nz accepts a Contact without the user part") + } if globe := ResolveEffectiveCarrierConfig("515", "02"); globe.PresetID != "globe_ph_51502" || globe.EPDGAddr != "weconnect.globe.com.ph" || globe.EPDGAddrSource != "preset" || globe.IMSTransport != "tcp" || CarrierPlanFromEffectiveConfig(globe).IMS.Transport != "tcp" { diff --git a/third_party/vowifi-go/internal/vowifi/policy/preset_original_test.go b/third_party/vowifi-go/internal/vowifi/policy/preset_original_test.go index 336c67cc..b5b87e20 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/preset_original_test.go +++ b/third_party/vowifi-go/internal/vowifi/policy/preset_original_test.go @@ -10,7 +10,7 @@ import ( func TestOriginalCarrierPresetAssetsRemainExact(t *testing.T) { wantHashes := map[string]string{ - "2degrees_nz_53024.yaml": "40ba4fc4b21aed123cb5d2c3634a3a4a0d7d7a33046dd2e356e8950e6250c471", + "2degrees_nz_53024.yaml": "361779ed5f41ae506d96d7595b66c9524717bc7a12e1d8dda2ba1875ca778808", "ais_th_52001.yaml": "f02b536317933c00c1960bfcceaf1b3f2ec8e22e1106917854231953832ccaa0", "ais_th_52003.yaml": "7b7c444a9c641d19c9ea184997c27c24eacc52d6b31db729b448fe9e1f50d0fd", "att_310280.yaml": "7337399037af7fbe67874b83f8f0c95ff0a1c588ec49ee41a404cf33e04fd054", diff --git a/third_party/vowifi-go/internal/vowifi/policy/presets/2degrees_nz_53024.yaml b/third_party/vowifi-go/internal/vowifi/policy/presets/2degrees_nz_53024.yaml index 875982db..459fa662 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/presets/2degrees_nz_53024.yaml +++ b/third_party/vowifi-go/internal/vowifi/policy/presets/2degrees_nz_53024.yaml @@ -10,3 +10,5 @@ esp_proposals: - aes256-sha512 ims_register_template: id: 2degrees_nz_53024_ios + # The 200 to REGISTER lists our Contact without the user part. + accept_register_contact_without_user: true diff --git a/third_party/vowifi-go/internal/vowifi/policy/types.go b/third_party/vowifi-go/internal/vowifi/policy/types.go index 06975953..0b06d70c 100644 --- a/third_party/vowifi-go/internal/vowifi/policy/types.go +++ b/third_party/vowifi-go/internal/vowifi/policy/types.go @@ -70,6 +70,7 @@ type IMSRegisterTemplate struct { SecurityClientIncludesServerParams bool SecurityClientMechanisms []IPSec3GPPSecurityMechanism StrictSecurityServerOffer bool + AcceptRegisterContactWithoutUser bool EnableInitialRejectFallback bool FallbackIncludesServerParamsInSecCl bool RegisterPolicy IMSRegisterPolicy @@ -106,6 +107,7 @@ type IMSRegisterTemplateOverride struct { SecurityClientIncludesServerParams *bool `yaml:"security_client_includes_server_params"` SecurityClientMechanisms []IPSec3GPPSecurityMechanism `yaml:"security_client_mechanisms"` StrictSecurityServerOffer *bool `yaml:"strict_security_server_offer"` + AcceptRegisterContactWithoutUser *bool `yaml:"accept_register_contact_without_user"` EnableInitialRejectFallback *bool `yaml:"enable_initial_reject_fallback"` FallbackIncludesServerParamsInSecCl *bool `yaml:"fallback_includes_server_params_in_sec_client"` RegisterPolicy IMSRegisterPolicyOverride `yaml:"register_policy"` diff --git a/third_party/vowifi-go/runtimehost/carrier/conversion.go b/third_party/vowifi-go/runtimehost/carrier/conversion.go index 104a7374..c5862c74 100644 --- a/third_party/vowifi-go/runtimehost/carrier/conversion.go +++ b/third_party/vowifi-go/runtimehost/carrier/conversion.go @@ -22,6 +22,7 @@ func RegisterTemplateFromInternal(value policy.IMSRegisterTemplate) IMSRegisterT SecurityClientIncludesServerParams: value.SecurityClientIncludesServerParams, SecurityClientMechanisms: mechanismsFromInternal(value.SecurityClientMechanisms), StrictSecurityServerOffer: value.StrictSecurityServerOffer, + AcceptRegisterContactWithoutUser: value.AcceptRegisterContactWithoutUser, EnableInitialRejectFallback: value.EnableInitialRejectFallback, FallbackIncludesServerParamsInSecCl: value.FallbackIncludesServerParamsInSecCl, RegisterPolicy: registerPolicyFromInternal(value.RegisterPolicy), diff --git a/third_party/vowifi-go/runtimehost/carrier/override_json.go b/third_party/vowifi-go/runtimehost/carrier/override_json.go index 5ee0cb47..58986480 100644 --- a/third_party/vowifi-go/runtimehost/carrier/override_json.go +++ b/third_party/vowifi-go/runtimehost/carrier/override_json.go @@ -222,6 +222,7 @@ func copyTemplateScalarOverrides(result *policy.IMSRegisterTemplateOverride, val result.IncludeConnectionKeepaliveInAuth = trueBoolPointer(value.IncludeConnectionKeepaliveInAuth) result.SecurityClientIncludesServerParams = trueBoolPointer(value.SecurityClientIncludesServerParams) result.StrictSecurityServerOffer = trueBoolPointer(value.StrictSecurityServerOffer) + result.AcceptRegisterContactWithoutUser = trueBoolPointer(value.AcceptRegisterContactWithoutUser) result.EnableInitialRejectFallback = trueBoolPointer(value.EnableInitialRejectFallback) result.FallbackIncludesServerParamsInSecCl = trueBoolPointer(value.FallbackIncludesServerParamsInSecCl) } diff --git a/third_party/vowifi-go/runtimehost/carrier/types.go b/third_party/vowifi-go/runtimehost/carrier/types.go index b96d1dc8..81da931d 100644 --- a/third_party/vowifi-go/runtimehost/carrier/types.go +++ b/third_party/vowifi-go/runtimehost/carrier/types.go @@ -70,6 +70,7 @@ type IMSRegisterTemplate struct { SecurityClientIncludesServerParams bool SecurityClientMechanisms []IPSec3GPPSecurityMechanism StrictSecurityServerOffer bool + AcceptRegisterContactWithoutUser bool EnableInitialRejectFallback bool FallbackIncludesServerParamsInSecCl bool RegisterPolicy IMSRegisterPolicy