Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
fbe36af6
Commit
fbe36af6
authored
Sep 23, 2017
by
Guus der Kinderen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OF-159: Log all data, terminate only on exact response to IQ ping.
parent
6735b769
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
35 deletions
+39
-35
S2STestService.java
src/java/org/jivesoftware/util/S2STestService.java
+39
-35
No files found.
src/java/org/jivesoftware/util/S2STestService.java
View file @
fbe36af6
package
org
.
jivesoftware
.
util
;
import
java.security.cert.Certificate
;
import
java.security.cert.X509Certificate
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Semaphore
;
import
java.util.concurrent.TimeUnit
;
import
javax.xml.bind.DatatypeConverter
;
import
org.apache.log4j.Appender
;
import
org.apache.log4j.Level
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.PatternLayout
;
import
org.apache.log4j.WriterAppender
;
import
org.apache.log4j.*
;
import
org.apache.log4j.spi.LoggingEvent
;
import
org.jivesoftware.openfire.SessionManager
;
import
org.jivesoftware.openfire.XMPPServer
;
...
...
@@ -29,9 +14,18 @@ import org.jivesoftware.util.cert.SANCertificateIdentityMapping;
import
org.slf4j.LoggerFactory
;
import
org.xmpp.packet.IQ
;
import
org.xmpp.packet.IQ.Type
;
import
org.xmpp.packet.JID
;
import
org.xmpp.packet.Packet
;
import
javax.xml.bind.DatatypeConverter
;
import
java.security.cert.Certificate
;
import
java.security.cert.X509Certificate
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Semaphore
;
import
java.util.concurrent.TimeUnit
;
/**
* Runs server to server test.
*
...
...
@@ -75,19 +69,24 @@ public class S2STestService {
outgoingServerSession
.
close
();
}
final
IQ
pingRequest
=
new
IQ
(
Type
.
get
);
pingRequest
.
setChildElement
(
"ping"
,
IQPingHandler
.
NAMESPACE
);
pingRequest
.
setFrom
(
XMPPServer
.
getInstance
().
getServerInfo
().
getXMPPDomain
()
);
pingRequest
.
setTo
(
domain
);
// Intercept logging.
final
StringBuilder
logs
=
new
StringBuilder
();
Appender
appender
=
interceptLogging
(
logs
);
// Intercept packets.
PacketInterceptor
interceptor
=
new
S2SInterceptor
(
);
final
PacketInterceptor
interceptor
=
new
S2SInterceptor
(
pingRequest
);
InterceptorManager
.
getInstance
().
addInterceptor
(
interceptor
);
// Send ping.
try
{
Log
.
info
(
"Sending server to server ping request to "
+
domain
);
sendPing
(
);
XMPPServer
.
getInstance
().
getIQRouter
().
route
(
pingRequest
);
// Wait for success or exceed socket 5s timeout.
waitUntil
.
tryAcquire
(
6
,
TimeUnit
.
SECONDS
);
...
...
@@ -164,17 +163,6 @@ public class S2STestService {
}
}
/**
* Sends a server to server ping request.
*/
private
void
sendPing
()
{
final
IQ
pingRequest
=
new
IQ
(
Type
.
get
);
pingRequest
.
setChildElement
(
"ping"
,
IQPingHandler
.
NAMESPACE
);
pingRequest
.
setFrom
(
XMPPServer
.
getInstance
().
getServerInfo
().
getXMPPDomain
());
pingRequest
.
setTo
(
domain
);
XMPPServer
.
getInstance
().
getIQRouter
().
route
(
pingRequest
);
}
/**
* @return A String representation of the certificate chain for the connection to the domain under test.
*/
...
...
@@ -217,6 +205,16 @@ public class S2STestService {
private
class
S2SInterceptor
implements
PacketInterceptor
{
private
StringBuilder
xml
=
new
StringBuilder
();
private
final
IQ
ping
;
/**
* @param ping The IQ ping request that was used to initiate the test.
*/
public
S2SInterceptor
(
IQ
ping
)
{
this
.
ping
=
ping
;
}
/**
* Keeps a log of the XMPP traffic, releasing the wait lock on response received.
*/
...
...
@@ -224,17 +222,23 @@ public class S2STestService {
public
void
interceptPacket
(
Packet
packet
,
Session
session
,
boolean
incoming
,
boolean
processed
)
throws
PacketRejectedException
{
if
(!
processed
&&
(
domain
.
equals
(
packet
.
getFrom
().
getDomain
())
||
domain
.
equals
(
packet
.
getTo
().
getDomain
())))
{
&&
(
ping
.
getTo
().
getDomain
().
equals
(
packet
.
getFrom
().
getDomain
())
||
ping
.
getTo
().
getDomain
().
equals
(
packet
.
getTo
().
getDomain
())))
{
// Log all traffic to and from the domain.
xml
.
append
(
packet
.
toXML
());
xml
.
append
(
'\n'
);
// If we've received our IQ response, stop waiting.
if
(
domain
.
equals
(
packet
.
getFrom
().
getDomain
())
&&
"result"
.
equals
(
packet
.
getElement
().
attributeValue
(
"type"
)))
{
// If we've received our IQ response, stop the test.
if
(
packet
instanceof
IQ
)
{
final
IQ
iq
=
(
IQ
)
packet
;
if
(
iq
.
isResponse
()
&&
ping
.
getID
().
equals
(
iq
.
getID
()
)
&&
ping
.
getTo
().
equals
(
iq
.
getFrom
()
)
)
{
Log
.
info
(
"Successful server to server response received."
);
waitUntil
.
release
();
}
}
}
}
/**
* Returns the received stanzas as a String.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment