@@ -66,18 +66,18 @@ func hashPassword(password string) string {
66
66
return hex .EncodeToString (hash [:8 ]) // Use first 8 bytes for shorter hash
67
67
}
68
68
69
- func (s * Server ) getInvite (from string ) * inProgressInvite {
69
+ func (s * Server ) getInvite (sipCallID string ) * inProgressInvite {
70
70
s .imu .Lock ()
71
71
defer s .imu .Unlock ()
72
72
for i := range s .inProgressInvites {
73
- if s .inProgressInvites [i ].from == from {
73
+ if s .inProgressInvites [i ].sipCallID == sipCallID {
74
74
return s .inProgressInvites [i ]
75
75
}
76
76
}
77
77
if len (s .inProgressInvites ) >= digestLimit {
78
78
s .inProgressInvites = s .inProgressInvites [1 :]
79
79
}
80
- is := & inProgressInvite {from : from }
80
+ is := & inProgressInvite {sipCallID : sipCallID }
81
81
s .inProgressInvites = append (s .inProgressInvites , is )
82
82
return is
83
83
}
@@ -103,8 +103,13 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
103
103
_ = tx .Respond (sip .NewResponseFromRequest (req , 100 , "Processing" , nil ))
104
104
}
105
105
106
- inviteState := s .getInvite (from )
107
- log = log .WithValues ("inviteStateFrom" , from )
106
+ // Extract SIP Call ID for tracking in-progress invites
107
+ sipCallID := ""
108
+ if h := req .CallID (); h != nil {
109
+ sipCallID = h .Value ()
110
+ }
111
+ inviteState := s .getInvite (sipCallID )
112
+ log = log .WithValues ("inviteStateSipCallID" , sipCallID )
108
113
109
114
h := req .GetHeader ("Proxy-Authorization" )
110
115
if h == nil {
@@ -144,8 +149,8 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
144
149
145
150
// Check if we have a valid challenge state
146
151
if inviteState .challenge .Realm == "" {
147
- log .Warnw ("No challenge state found for authentication attempt" , nil ,
148
- "from " , from ,
152
+ log .Warnw ("No challenge state found for authentication attempt" , errors . New ( "missing challenge state" ) ,
153
+ "sipCallID " , sipCallID ,
149
154
"expectedRealm" , UserAgent ,
150
155
)
151
156
_ = tx .Respond (sip .NewResponseFromRequest (req , 401 , "Bad credentials" , nil ))
@@ -178,7 +183,7 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
178
183
)
179
184
180
185
if cred .Response != digCred .Response {
181
- log .Warnw ("Authentication failed - response mismatch" , nil ,
186
+ log .Warnw ("Authentication failed - response mismatch" , errors . New ( "response mismatch" ) ,
182
187
"expectedResponse" , digCred .Response ,
183
188
"receivedResponse" , cred .Response ,
184
189
)
@@ -266,12 +271,19 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
266
271
cc .Processing ()
267
272
}
268
273
274
+ // Extract SIP Call ID directly from the request
275
+ sipCallID := ""
276
+ if h := req .CallID (); h != nil {
277
+ sipCallID = h .Value ()
278
+ }
279
+
269
280
callInfo := & rpc.SIPCall {
270
- LkCallId : callID ,
271
- SourceIp : src .Addr ().String (),
272
- Address : ToSIPUri ("" , cc .Address ()),
273
- From : ToSIPUri ("" , from ),
274
- To : ToSIPUri ("" , to ),
281
+ LkCallId : callID ,
282
+ SipCallId : sipCallID ,
283
+ SourceIp : src .Addr ().String (),
284
+ Address : ToSIPUri ("" , cc .Address ()),
285
+ From : ToSIPUri ("" , from ),
286
+ To : ToSIPUri ("" , to ),
275
287
}
276
288
for _ , h := range cc .RemoteHeaders () {
277
289
switch h := h .(type ) {
@@ -1150,14 +1162,17 @@ type sipInbound struct {
1150
1162
}
1151
1163
1152
1164
func (c * sipInbound ) ValidateInvite () error {
1165
+ if c .callID == "" {
1166
+ return errors .New ("no Call-ID header in INVITE" )
1167
+ }
1153
1168
if c .from == nil {
1154
- return errors .New ("no From header" )
1169
+ return errors .New ("no From header in INVITE " )
1155
1170
}
1156
1171
if c .to == nil {
1157
- return errors .New ("no To header" )
1172
+ return errors .New ("no To header in INVITE " )
1158
1173
}
1159
1174
if c .tag == "" {
1160
- return errors .New ("no tag in From" )
1175
+ return errors .New ("no tag in From in INVITE " )
1161
1176
}
1162
1177
return nil
1163
1178
}
0 commit comments