mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 16:02:17 +00:00
fix(ims): accept the userless REGISTER Contact that 2degrees returns
- Add accept_register_contact_without_user to the REGISTER template and carry it through every carrier conversion - Enable it in the 2degrees NZ preset - Log when a binding is matched without the user part - Guard the conversion round trip so every template field must be populated - Note the 2degrees Contact form and the override in the operator notes
This commit is contained in:
1 parent
466e7fe458
commit
f60d7dbb18
18 files changed
+103
-13
No files matched your search
@@ -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`。
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = "<sip:user1@10.137.119.140:23289;transport=tcp>"
|
||||
tests := []struct {
|
||||
name, response string
|
||||
strict, optIn bool
|
||||
}{
|
||||
{"userless echo", "<sip:10.137.119.140:23289;transport=tcp>", false, true},
|
||||
{"userless other port", "<sip:10.137.119.140:23290;transport=tcp>", false, false},
|
||||
{"userless other transport", "<sip:10.137.119.140:23289;transport=udp>", false, false},
|
||||
{"other user", "<sip:user2@10.137.119.140:23289;transport=tcp>", 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 {
|
||||
|
||||
@@ -134,7 +134,7 @@ func TestParseRecoveredRegisterResponseFields(t *testing.T) {
|
||||
"Expires": "3600", "Contact": "<sip:a@example>;expires=120",
|
||||
"Retry-After": "9", "Min-Expires": "600",
|
||||
}}
|
||||
if got, err := registrationExpires(response, "<sip:a@example>", 10*time.Second); err != nil || got != 120*time.Second {
|
||||
if got, err := registrationExpires(response, "<sip:a@example>", 10*time.Second, false); err != nil || got != 120*time.Second {
|
||||
t.Fatalf("registrationExpires = %s, %v", got, err)
|
||||
}
|
||||
retryAfter, retryAfterSet, minExpires := parseRegisterRetryHintsFromResponse(response)
|
||||
|
||||
@@ -555,7 +555,7 @@ func TestRegistrationExpiresPrefersOwnContact(t *testing.T) {
|
||||
response := &sipResponse{Headers: map[string]string{
|
||||
"Contact": "<sip:user@10.0.0.2>;expires=120", "Expires": "3600",
|
||||
}}
|
||||
if got, err := registrationExpires(response, "<sip:user@10.0.0.2>", time.Hour); err != nil || got != 120*time.Second {
|
||||
if got, err := registrationExpires(response, "<sip:user@10.0.0.2>", time.Hour, false); err != nil || got != 120*time.Second {
|
||||
t.Fatalf("registrationExpires = %s, %v, want 120s", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, "<sip:second@ims.example>", 600*time.Second); err != nil || expires != 42*time.Second {
|
||||
if expires, err := registrationExpires(response, "<sip:second@ims.example>", 600*time.Second, false); err != nil || expires != 42*time.Second {
|
||||
t.Fatalf("registration expires = %s, %v", expires, err)
|
||||
}
|
||||
if string(response.Body) != "body" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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" {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
@@ -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"`
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ type IMSRegisterTemplate struct {
|
||||
SecurityClientIncludesServerParams bool
|
||||
SecurityClientMechanisms []IPSec3GPPSecurityMechanism
|
||||
StrictSecurityServerOffer bool
|
||||
AcceptRegisterContactWithoutUser bool
|
||||
EnableInitialRejectFallback bool
|
||||
FallbackIncludesServerParamsInSecCl bool
|
||||
RegisterPolicy IMSRegisterPolicy
|
||||
|
||||
Reference in new issue
Block a user