Update jain-sip (setting ports and address of some resend messages), issue#894.

Make sure we filter requests that are not coming from our proxy.
cusax-fix
Damian Minkov 15 years ago
parent 770d369d99
commit a4161466f7

@ -904,6 +904,15 @@ public void processRequest(RequestEvent requestEvent)
{
Request request = requestEvent.getRequest();
if(getRegistrarConnection() != null
&& !getRegistrarConnection().isRegistrarless()
&& !getRegistrarConnection().isRequestFromSameConnection(request))
{
logger.warn("Received request not from our proxy, ignoring it! "
+ "Request:" + request);
return;
}
// test if an Event header is present and known
EventHeader eventHeader = (EventHeader)
request.getHeader(EventHeader.NAME);

@ -15,6 +15,7 @@
import javax.sip.header.*;
import javax.sip.message.*;
import gov.nist.javax.sip.message.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -136,6 +137,20 @@ public class SipRegistrarConnection
*/
private String registrationTransport = null;
/**
* We remember the last received address that REGISTER OK is coming from.
* For security reasons if we are registered this is the address
* that all messages must come from.
*/
private InetAddress lastRegisterAddressReceived = null;
/**
* We remember the last received port that REGISTER OK is coming from.
* For security reasons if we are registered this is the port
* that all messages must come from.
*/
private int lastRegisterPortReceived = -1;
/**
* Creates a new instance of this class.
*
@ -458,6 +473,11 @@ public void processOK(ClientTransaction clientTransatcion,
}
}
// remember the address and port from which we received this
// message
lastRegisterAddressReceived =
((SIPMessage)response).getRemoteAddress();
lastRegisterPortReceived = ((SIPMessage)response).getRemotePort();
//schedule a reregistration.
scheduleReRegistration(scheduleTime);
@ -482,6 +502,28 @@ && getRegistrationState().equals(RegistrationState.REGISTERING))
}
}
/**
* Checks a particular request is it coming from the same proxy we are
* currently using. A check for security reasons, preventing injection
* of other messages in the PP.
* @param request the request to check.
* @return <tt>false</tt> if the request doesn't belong to our register
* or if we cannot decide we keep the old behaviour.
*/
public boolean isRequestFromSameConnection(Request request)
{
SIPMessage msg = (SIPMessage)request;
if(msg.getRemoteAddress() != null
&& lastRegisterAddressReceived != null)
{
if(!msg.getRemoteAddress().equals(lastRegisterAddressReceived)
|| msg.getRemotePort() != lastRegisterPortReceived)
return false;
}
return true;
}
/**
* Sends a unregistered request to the registrar thus ending our
* registration.

@ -880,6 +880,25 @@ private ProtocolProviderServiceSipImpl findTargetFor(Request request)
}
}
// Let narrow candidates by checking addresses and ports
Iterator<ProtocolProviderServiceSipImpl> iterPP =
candidates.iterator();
while(iterPP.hasNext())
{
ProtocolProviderServiceSipImpl candidate = iterPP.next();
if(!candidate.getRegistrarConnection().isRegistrarless()
&& !candidate.getRegistrarConnection()
.isRequestFromSameConnection(request))
iterPP.remove();
}
if(candidates.size() == 0)
{
logger.error("no listeners, or message not fo us");
return null;
}
// Past this point, our guess is not reliable. We try to find
// the "least worst" match based on parameters like the To field

Loading…
Cancel
Save