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
cb5048dd
Commit
cb5048dd
authored
Oct 23, 2014
by
Tom Evans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OF-807: Use IDN rules for S2S server names
Allow international domain names (per RFC 3490).
parent
2df7460b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
40 deletions
+54
-40
StringUtils.java
src/java/org/jivesoftware/util/StringUtils.java
+17
-15
StringUtilsTest.java
src/test/java/org/jivesoftware/util/StringUtilsTest.java
+29
-21
server2server-settings.jsp
src/web/server2server-settings.jsp
+8
-4
No files found.
src/java/org/jivesoftware/util/StringUtils.java
View file @
cb5048dd
...
@@ -20,9 +20,11 @@
...
@@ -20,9 +20,11 @@
package
org
.
jivesoftware
.
util
;
package
org
.
jivesoftware
.
util
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.IDN
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.BreakIterator
;
import
java.text.BreakIterator
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
...
@@ -33,7 +35,6 @@ import java.util.Map;
...
@@ -33,7 +35,6 @@ import java.util.Map;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.StringTokenizer
;
import
java.util.StringTokenizer
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.regex.Pattern
;
import
javax.mail.internet.AddressException
;
import
javax.mail.internet.AddressException
;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.InternetAddress
;
...
@@ -54,8 +55,6 @@ public class StringUtils {
...
@@ -54,8 +55,6 @@ public class StringUtils {
private
static
final
char
[]
LT_ENCODE
=
"<"
.
toCharArray
();
private
static
final
char
[]
LT_ENCODE
=
"<"
.
toCharArray
();
private
static
final
char
[]
GT_ENCODE
=
">"
.
toCharArray
();
private
static
final
char
[]
GT_ENCODE
=
">"
.
toCharArray
();
private
static
final
Pattern
DOMAIN_NAME
=
Pattern
.
compile
(
"^(?:[A-Za-z0-9][A-Za-z0-9\\-]{0,61}[A-Za-z0-9]|[A-Za-z0-9])$"
);
private
StringUtils
()
{
private
StringUtils
()
{
// Not instantiable.
// Not instantiable.
}
}
...
@@ -1122,22 +1121,25 @@ public class StringUtils {
...
@@ -1122,22 +1121,25 @@ public class StringUtils {
}
}
/**
/**
* Returns true if the string passed in is a valid domain name
* Returns a valid domain name, possibly as an ACE-encoded IDN
* (per <a href="http://www.ietf.org/rfc/rfc3490.txt">RFC 3490</a>).
*
*
* @param domain Proposed domain name
* @param domain Proposed domain name
* @return true if the string passed in is a valid domain name
* @return The validated domain name, possibly ACE-encoded
* @throws IllegalArgumentException The given domain name is not valid
*/
*/
public
static
boolean
isValidDomainName
(
String
domain
)
{
public
static
String
validateDomainName
(
String
domain
)
{
if
(
domain
==
null
)
{
if
(
domain
==
null
||
domain
.
trim
().
length
()
==
0
)
{
return
false
;
throw
new
IllegalArgumentException
(
"Domain name cannot be null or empty"
);
}
StringTokenizer
parser
=
new
StringTokenizer
(
domain
,
"."
);
while
(
parser
.
hasMoreTokens
())
{
if
(!
DOMAIN_NAME
.
matcher
(
parser
.
nextToken
()).
matches
())
{
return
false
;
}
}
}
return
true
;
String
result
=
IDN
.
toASCII
(
domain
);
if
(
result
.
equals
(
domain
))
{
// no conversion; validate again via USE_STD3_ASCII_RULES
IDN
.
toASCII
(
domain
,
IDN
.
USE_STD3_ASCII_RULES
);
}
else
{
Log
.
info
(
MessageFormat
.
format
(
"Converted domain name: from '{0}' to '{1}'"
,
domain
,
result
));
}
return
result
;
}
}
/**
/**
...
...
src/test/java/org/jivesoftware/util/StringUtilsTest.java
View file @
cb5048dd
package
org
.
jivesoftware
.
util
;
package
org
.
jivesoftware
.
util
;
import
static
org
.
junit
.
Assert
.
assert
False
;
import
static
org
.
junit
.
Assert
.
assert
Equals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -10,30 +10,38 @@ public class StringUtilsTest {
...
@@ -10,30 +10,38 @@ public class StringUtilsTest {
@Test
@Test
public
void
testValidDomainNames
()
{
public
void
testValidDomainNames
()
{
String
domain
=
"www.mycompany.com"
;
assertValidDomainName
(
"www.mycompany.com"
);
assertTrue
(
"Domain should be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
assertValidDomainName
(
"www.my-company.com"
);
assertValidDomainName
(
"abc.de"
);
domain
=
"www.my-company.com"
;
assertValidDomainName
(
"tronon.be"
,
"xn--tronon-zua.be"
);
assertTrue
(
"Domain should be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
assertValidDomainName
(
"bb.at"
,
"xn--bb-eka.at"
);
domain
=
"abc.de"
;
assertTrue
(
"Domain should be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
}
}
@Test
@Test
public
void
testInvalidDomainNames
()
{
public
void
testInvalidDomainNames
()
{
String
domain
=
"www.my_company.com"
;
assertInvalidDomainName
(
"www.my_company.com"
,
"Contains non-LDH characters"
);
assertFalse
(
"Domain should not be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
assertInvalidDomainName
(
"www.-dash.com"
,
"Has leading or trailing hyphen"
);
assertInvalidDomainName
(
"www.dash-.com"
,
"Has leading or trailing hyphen"
);
domain
=
"www.-dash.com"
;
assertInvalidDomainName
(
"abc.<test>.de"
,
"Contains non-LDH characters"
);
assertFalse
(
"Domain should not be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
}
domain
=
"www.dash-.com"
;
assertFalse
(
"Domain should not be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
private
void
assertValidDomainName
(
String
domain
)
{
assertValidDomainName
(
domain
,
domain
);
domain
=
"abc.<test>.de"
;
}
assertFalse
(
"Domain should not be valid"
,
StringUtils
.
isValidDomainName
(
domain
));
private
void
assertValidDomainName
(
String
domain
,
String
expected
)
{
assertEquals
(
"Domain should be valid: "
+
domain
,
expected
,
StringUtils
.
validateDomainName
(
domain
));
}
}
private
void
assertInvalidDomainName
(
String
domain
,
String
expectedCause
)
{
try
{
StringUtils
.
validateDomainName
(
domain
);
fail
(
"Domain should not be valid: "
+
domain
);
}
catch
(
IllegalArgumentException
iae
)
{
assertEquals
(
"Unexpected cause: "
+
iae
.
getMessage
(),
expectedCause
,
iae
.
getMessage
());
}
}
}
}
src/web/server2server-settings.jsp
View file @
cb5048dd
...
@@ -136,8 +136,10 @@
...
@@ -136,8 +136,10 @@
if
(
serverAllowed
)
{
if
(
serverAllowed
)
{
int
intRemotePort
=
0
;
int
intRemotePort
=
0
;
// Validate params
// Validate params
if
(
domain
==
null
||
domain
.
trim
().
length
()
==
0
||
!
StringUtils
.
isValidDomainName
(
domain
))
{
try
{
errors
.
put
(
"domain"
,
""
);
StringUtils
.
validateDomainName
(
domain
);
}
catch
(
IllegalArgumentException
iae
)
{
errors
.
put
(
"domain"
,
""
);
}
}
if
(
remotePort
==
null
||
remotePort
.
trim
().
length
()
==
0
||
"0"
.
equals
(
remotePort
))
{
if
(
remotePort
==
null
||
remotePort
.
trim
().
length
()
==
0
||
"0"
.
equals
(
remotePort
))
{
errors
.
put
(
"remotePort"
,
""
);
errors
.
put
(
"remotePort"
,
""
);
...
@@ -164,8 +166,10 @@
...
@@ -164,8 +166,10 @@
if
(
serverBlocked
)
{
if
(
serverBlocked
)
{
// Validate params
// Validate params
if
(
domain
==
null
||
domain
.
trim
().
length
()
==
0
||
!
StringUtils
.
isValidDomainName
(
domain
))
{
try
{
errors
.
put
(
"domain"
,
""
);
StringUtils
.
validateDomainName
(
domain
);
}
catch
(
IllegalArgumentException
iae
)
{
errors
.
put
(
"domain"
,
""
);
}
}
// If no errors, continue:
// If no errors, continue:
if
(
errors
.
isEmpty
())
{
if
(
errors
.
isEmpty
())
{
...
...
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