Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ private OkHostnameVerifier() {

@Override
public boolean verify(String host, SSLSession session) {
if (!isAscii(host)) {
return false;
}
try {
Certificate[] certificates = session.getPeerCertificates();
return verify(host, (X509Certificate) certificates[0]);
Expand Down Expand Up @@ -254,4 +257,13 @@ private boolean verifyHostName(String hostName, String pattern) {
// hostName matches pattern
return true;
}

private static boolean isAscii(String input) {
try {
// All only ascii characters are 1 byte in utf8
return input.getBytes("UTF-8").length == input.length();
} catch (java.io.UnsupportedEncodingException e) {
return false;
}
}
}