Decreases the log level of messages for unexpected packets, checks
expected STUN packets more thoroughly.
This commit is contained in:
parent
5f0bf2090b
commit
c5866ca317
@ -338,7 +338,7 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to parse the bytes in <tt>buf</tt> at offset <tt>off</tt> (and
|
* Tries to parse the bytes in <tt>buf</tt> at offset <tt>off</tt> (and
|
||||||
* length <tt>len</tt>) and a STUN Binding Request message. If successful,
|
* length <tt>len</tt>) as a STUN Binding Request message. If successful,
|
||||||
* looks for a USERNAME attribute and returns the local username fragment
|
* looks for a USERNAME attribute and returns the local username fragment
|
||||||
* part (see RFC5245 Section 7.1.2.3).
|
* part (see RFC5245 Section 7.1.2.3).
|
||||||
* In case of any failure returns <tt>null</tt>.
|
* In case of any failure returns <tt>null</tt>.
|
||||||
@ -351,6 +351,29 @@ public class SinglePortUdpHarvester
|
|||||||
*/
|
*/
|
||||||
private String getUfrag(byte[] buf, int off, int len)
|
private String getUfrag(byte[] buf, int off, int len)
|
||||||
{
|
{
|
||||||
|
// RFC5389, Section 6:
|
||||||
|
// All STUN messages MUST start with a 20-byte header followed by zero
|
||||||
|
// or more Attributes.
|
||||||
|
if (buf == null || buf.length < off + len || len < 20)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC5389, Section 6:
|
||||||
|
// The magic cookie field MUST contain the fixed value 0x2112A442 in
|
||||||
|
// network byte order.
|
||||||
|
if ( !( (buf[off + 4] & 0xFF) == 0x21 &&
|
||||||
|
(buf[off + 5] & 0xFF) == 0x12 &&
|
||||||
|
(buf[off + 6] & 0xFF) == 0xA4 &&
|
||||||
|
(buf[off + 7] & 0xFF) == 0x42))
|
||||||
|
{
|
||||||
|
if (logger.isLoggable(Level.FINE))
|
||||||
|
{
|
||||||
|
logger.fine("Not a STUN packet, magic cookie not found.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Message stunMessage
|
Message stunMessage
|
||||||
@ -378,7 +401,10 @@ public class SinglePortUdpHarvester
|
|||||||
{
|
{
|
||||||
// Catch everything. We are going to log, and then drop the packet
|
// Catch everything. We are going to log, and then drop the packet
|
||||||
// anyway.
|
// anyway.
|
||||||
logger.info("Failed to extract local ufrag: " + e);
|
if (logger.isLoggable(Level.FINE))
|
||||||
|
{
|
||||||
|
logger.fine("Failed to extract local ufrag: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user