Fix url building to support certificate check on hkps servers

Note: the CA used by sks-keyservers.net is not valid for android, thus using hkps fails for them. pgp.mit.edu uses a perfectly valid cert.
This commit is contained in:
mar-v-in 2014-05-28 20:44:01 +02:00
parent cb92c9ccc8
commit c676e53479

View File

@ -201,15 +201,26 @@ public class HkpKeyserver extends Keyserver {
} }
private String query(String request) throws QueryFailedException, HttpError { private String query(String request) throws QueryFailedException, HttpError {
InetAddress ips[]; List<String> urls = new ArrayList<String>();
try { if (mSecure) {
ips = InetAddress.getAllByName(mHost); urls.add(getUrlPrefix() + mHost + ":" + mPort + request);
} catch (UnknownHostException e) { } else {
throw new QueryFailedException(e.toString()); InetAddress ips[];
} try {
for (int i = 0; i < ips.length; ++i) { ips = InetAddress.getAllByName(mHost);
} catch (UnknownHostException e) {
throw new QueryFailedException(e.toString());
}
for (InetAddress ip : ips) {
// Note: This is actually not HTTP 1.1 compliant, as we hide the real "Host" value,
// but Android's HTTPUrlConnection does not support any other way to set
// Socket's remote IP address...
urls.add(getUrlPrefix() + ip.getHostAddress() + ":" + mPort + request);
}
}
for (String url : urls) {
try { try {
String url = getUrlPrefix() + ips[i].getHostAddress() + ":" + mPort + request;
Log.d(Constants.TAG, "hkp keyserver query: " + url); Log.d(Constants.TAG, "hkp keyserver query: " + url);
URL realUrl = new URL(url); URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
@ -272,7 +283,7 @@ public class HkpKeyserver extends Keyserver {
while (matcher.find()) { while (matcher.find()) {
final ImportKeysListEntry entry = new ImportKeysListEntry(); final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(query); entry.setQuery(query);
entry.setOrigin("hkp:" + mHost + ":" + mPort); entry.setOrigin(getUrlPrefix() + mHost + ":" + mPort);
entry.setBitStrength(Integer.parseInt(matcher.group(3))); entry.setBitStrength(Integer.parseInt(matcher.group(3)));