Exception handling with keyserver queries

This commit is contained in:
Dominik Schürmann 2014-07-31 17:56:47 +02:00
parent 33172d598d
commit cc034a0913
2 changed files with 14 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import de.measite.minidns.Client;
import de.measite.minidns.Question;
import de.measite.minidns.Record;
import de.measite.minidns.record.SRV;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.helper.TlsHelper;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
@ -103,7 +104,8 @@ public class HkpKeyserver extends Keyserver {
public static final Pattern PUB_KEY_LINE = Pattern
.compile("pub:([0-9a-fA-F]+):([0-9]+):([0-9]+):([0-9]+):([0-9]*):([rde]*)[ \n\r]*" // pub line
+ "((uid:([^:]*):([0-9]+):([0-9]*):([rde]*)[ \n\r]*)+)", // one or more uid lines
Pattern.CASE_INSENSITIVE);
Pattern.CASE_INSENSITIVE
);
/**
* uid:%escaped uid string%:%creationdate%:%expirationdate%:%flags%
@ -241,8 +243,10 @@ public class HkpKeyserver extends Keyserver {
data = query(request);
} catch (HttpError e) {
if (e.getCode() == 404) {
return results;
} else {
throw new QueryFailedException("keyserver '" + mHost + "' not found. Error 404");
} else if (e.getData() != null) {
Log.d(Constants.TAG, "returned error data: " + e.getData().toLowerCase(Locale.US));
if (e.getData().toLowerCase(Locale.US).contains("no keys found")) {
return results;
} else if (e.getData().toLowerCase(Locale.US).contains("too many")) {
@ -250,7 +254,11 @@ public class HkpKeyserver extends Keyserver {
} else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) {
throw new QueryTooShortException();
}
// NOTE: some keyserver do not provide a more detailed error response
throw new QueryFailedException("Either no keys or too many have been found. Please improve your query!");
}
throw new QueryFailedException("querying server(s) for '" + mHost + "' failed");
}

View File

@ -271,7 +271,7 @@
<string name="error_nfc_needed">NFC is not available on your device!</string>
<string name="error_nothing_import">No keys found!</string>
<string name="error_keyserver_insufficient_query">Key search query too short</string>
<string name="error_searching_keys">Unrecoverable error searching for keys at server</string>
<string name="error_searching_keys">An error occurred when searching for keys</string>
<string name="error_keyserver_too_many_responses">Key search query returned too many candidates; Please refine query</string>
<string name="error_import_no_valid_keys">No valid keys found in File/Clipboard!</string>
<string name="error_generic_report_bug">A generic error occurred, please create a new bug report for OpenKeychain.</string>