aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java74
1 files changed, 28 insertions, 46 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java
index 42615d105..c8c3cbb4d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/affirmation/resources/GenericHttpsResource.java
@@ -5,9 +5,14 @@ import android.content.Context;
import com.textuality.keybase.lib.Search;
import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
+import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
+import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
+import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.Progressable;
+import org.sufficientlysecure.keychain.pgp.affirmation.Affirmation;
import org.sufficientlysecure.keychain.pgp.affirmation.AffirmationResource;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@@ -17,7 +22,6 @@ import org.sufficientlysecure.keychain.util.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -33,58 +37,26 @@ public class GenericHttpsResource extends AffirmationResource {
super(flags, params, uri);
}
- @Override
- public boolean verify() {
- return false;
- }
-
- public static String generate (byte[] fingerprint, String uri) {
- long nonce = generateNonce();
-
- StringBuilder b = new StringBuilder();
- b.append("---\r\n");
-
- b.append("fingerprint=");
- b.append(KeyFormattingUtils.convertFingerprintToHex(fingerprint));
- b.append('\r').append('\n');
+ public static String generateText (Context context, byte[] fingerprint, String nonce) {
+ String cookie = AffirmationResource.generate(context, fingerprint, nonce);
- b.append("nonce=");
- b.append(nonce);
- b.append('\r').append('\n');
-
- if (uri != null) {
- b.append("uri=");
- b.append(uri);
- b.append('\r').append('\n');
- }
- b.append("---\r\n");
-
- return b.toString();
+ return String.format(context.getResources().getString(R.string.linked_id_generic_text),
+ cookie, "0x" + KeyFormattingUtils.convertFingerprintToHex(fingerprint).substring(24));
}
- public DecryptVerifyResult verify
- (Context context, ProviderHelper providerHelper, Progressable progress)
- throws IOException {
-
- byte[] data = fetchResource(mUri).getBytes();
- InputData input = new InputData(new ByteArrayInputStream(data), data.length);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PgpDecryptVerify.Builder b =
- new PgpDecryptVerify.Builder(context, providerHelper, progress, input, out);
- PgpDecryptVerify op = b.build();
-
- Log.d(Constants.TAG, new String(out.toByteArray()));
-
- return op.execute();
- }
+ @Override
+ protected String fetchResource (OperationLog log, int indent) {
- protected static String fetchResource (URI uri) throws IOException {
+ log.add(LogType.MSG_LV_FETCH, indent, mUri.toString());
+ indent += 1;
try {
+
HttpsURLConnection conn = null;
- URL url = uri.toURL();
+ URL url = mUri.toURL();
int status = 0;
int redirects = 0;
+
while (redirects < 5) {
conn = (HttpsURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent", "OpenKeychain");
@@ -95,18 +67,28 @@ public class GenericHttpsResource extends AffirmationResource {
if (status == 301) {
redirects++;
url = new URL(conn.getHeaderFields().get("Location").get(0));
+ log.add(LogType.MSG_LV_FETCH_REDIR, indent, url.toString());
} else {
break;
}
}
+
if (status >= 200 && status < 300) {
+ log.add(LogType.MSG_LV_FETCH_OK, indent, Integer.toString(status));
return Search.snarf(conn.getInputStream());
} else {
- throw new IOException("Fetch failed, status " + status + ": " + Search.snarf(conn.getErrorStream()));
+ // log verbose output to logcat
+ Log.e(Constants.TAG, Search.snarf(conn.getErrorStream()));
+ log.add(LogType.MSG_LV_FETCH_ERROR, indent, Integer.toString(status));
+ return null;
}
} catch (MalformedURLException e) {
- throw new IOException(e);
+ log.add(LogType.MSG_LV_FETCH_ERROR_URL, indent);
+ return null;
+ } catch (IOException e) {
+ log.add(LogType.MSG_LV_FETCH_ERROR_IO, indent);
+ return null;
}
}