mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-23 15:38:50 -05:00
Switch to dnsjava
This commit is contained in:
parent
6c42fe58bd
commit
2b18dc741a
@ -19,7 +19,7 @@ dependencies {
|
||||
compile project(':extern:spongycastle:prov')
|
||||
compile project(':extern:AppMsg:library')
|
||||
compile project(':extern:SuperToasts:supertoasts')
|
||||
compile project(':extern:dnsjava')
|
||||
compile project(':extern:minidns')
|
||||
compile project(':extern:KeybaseLib:Lib')
|
||||
|
||||
|
||||
|
@ -57,11 +57,13 @@ public class EmailKeyHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// Most users don't have the SRV record, so ask a default server as well
|
||||
String[] servers = Preferences.getPreferences(context).getKeyServers();
|
||||
if (servers != null && servers.length != 0) {
|
||||
HkpKeyserver hkp = new HkpKeyserver(servers[0]);
|
||||
keys.addAll(getEmailKeys(mail, hkp));
|
||||
if (keys.isEmpty()) {
|
||||
// Most users don't have the SRV record, so ask a default server as well
|
||||
String[] servers = Preferences.getPreferences(context).getKeyServers();
|
||||
if (servers != null && servers.length != 0) {
|
||||
HkpKeyserver hkp = new HkpKeyserver(servers[0]);
|
||||
keys.addAll(getEmailKeys(mail, hkp));
|
||||
}
|
||||
}
|
||||
return new ArrayList<ImportKeysListEntry>(keys);
|
||||
}
|
||||
|
@ -18,6 +18,10 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.keyimport;
|
||||
|
||||
import de.measite.minidns.Client;
|
||||
import de.measite.minidns.Question;
|
||||
import de.measite.minidns.Record;
|
||||
import de.measite.minidns.record.SRV;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
@ -33,10 +37,6 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.xbill.DNS.Lookup;
|
||||
import org.xbill.DNS.Record;
|
||||
import org.xbill.DNS.SRVRecord;
|
||||
import org.xbill.DNS.Type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -396,19 +396,20 @@ public class HkpKeyserver extends Keyserver {
|
||||
*/
|
||||
public static HkpKeyserver resolve(String domain) {
|
||||
try {
|
||||
Record[] records = new Lookup("_hkp._tcp." + domain, Type.SRV).run();
|
||||
Record[] records = new Client().query(new Question("_hkp._tcp." + domain, Record.TYPE.SRV)).getAnswers();
|
||||
if (records.length > 0) {
|
||||
Arrays.sort(records, new Comparator<Record>() {
|
||||
@Override
|
||||
public int compare(Record lhs, Record rhs) {
|
||||
if (!(lhs instanceof SRVRecord)) return 1;
|
||||
if (!(rhs instanceof SRVRecord)) return -1;
|
||||
return ((SRVRecord) lhs).getPriority() - ((SRVRecord) rhs).getPriority();
|
||||
if (lhs.getPayload().getType() != Record.TYPE.SRV) return 1;
|
||||
if (rhs.getPayload().getType() != Record.TYPE.SRV) return -1;
|
||||
return ((SRV) lhs.getPayload()).getPriority() - ((SRV) rhs.getPayload()).getPriority();
|
||||
}
|
||||
});
|
||||
Record record = records[0]; // This is our best choice
|
||||
if (record instanceof SRVRecord) {
|
||||
return new HkpKeyserver(((SRVRecord) record).getTarget().toString(), (short) ((SRVRecord) record).getPort());
|
||||
if (record.getPayload().getType() == Record.TYPE.SRV) {
|
||||
return new HkpKeyserver(((SRV) record.getPayload()).getName(),
|
||||
(short) ((SRV) record.getPayload()).getPort());
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
@ -12,5 +12,5 @@ include ':extern:spongycastle:pkix'
|
||||
include ':extern:spongycastle:prov'
|
||||
include ':extern:AppMsg:library'
|
||||
include ':extern:SuperToasts:supertoasts'
|
||||
include ':extern:dnsjava'
|
||||
include ':extern:minidns'
|
||||
include ':extern:KeybaseLib:Lib'
|
||||
|
Loading…
Reference in New Issue
Block a user