mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-23 14:41:54 -05:00
work on cookie scanning during creation
This commit is contained in:
parent
f9ef1160ca
commit
e573cd774a
@ -771,6 +771,12 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_LV_FP_OK (LogLevel.DEBUG, R.string.msg_lv_fp_ok),
|
MSG_LV_FP_OK (LogLevel.DEBUG, R.string.msg_lv_fp_ok),
|
||||||
MSG_LV_FP_ERROR (LogLevel.ERROR, R.string.msg_lv_fp_error),
|
MSG_LV_FP_ERROR (LogLevel.ERROR, R.string.msg_lv_fp_error),
|
||||||
|
|
||||||
|
MSG_LV_ERROR_TWITTER_AUTH (LogLevel.ERROR, R.string.msg_lv_error_twitter_auth),
|
||||||
|
MSG_LV_ERROR_TWITTER_HANDLE (LogLevel.ERROR, R.string.msg_lv_error_twitter_handle),
|
||||||
|
MSG_LV_ERROR_TWITTER_RESPONSE (LogLevel.ERROR, R.string.msg_lv_error_twitter_response),
|
||||||
|
MSG_LV_ERROR_GITHUB_HANDLE (LogLevel.ERROR, R.string.msg_lv_error_github_handle),
|
||||||
|
MSG_LV_ERROR_GITHUB_NOT_FOUND (LogLevel.ERROR, R.string.msg_lv_error_github_not_found),
|
||||||
|
|
||||||
MSG_LV_FETCH (LogLevel.DEBUG, R.string.msg_lv_fetch),
|
MSG_LV_FETCH (LogLevel.DEBUG, R.string.msg_lv_fetch),
|
||||||
MSG_LV_FETCH_REDIR (LogLevel.DEBUG, R.string.msg_lv_fetch_redir),
|
MSG_LV_FETCH_REDIR (LogLevel.DEBUG, R.string.msg_lv_fetch_redir),
|
||||||
MSG_LV_FETCH_OK (LogLevel.DEBUG, R.string.msg_lv_fetch_ok),
|
MSG_LV_FETCH_OK (LogLevel.DEBUG, R.string.msg_lv_fetch_ok),
|
||||||
@ -778,14 +784,14 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_LV_FETCH_ERROR_URL (LogLevel.ERROR, R.string.msg_lv_fetch_error_url),
|
MSG_LV_FETCH_ERROR_URL (LogLevel.ERROR, R.string.msg_lv_fetch_error_url),
|
||||||
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
|
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
|
||||||
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
|
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
|
||||||
|
MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing),
|
||||||
|
|
||||||
//export log
|
//export log
|
||||||
MSG_EXPORT_LOG(LogLevel.START,R.string.msg_export_log_start),
|
MSG_EXPORT_LOG(LogLevel.START,R.string.msg_export_log_start),
|
||||||
MSG_EXPORT_LOG_EXPORT_ERROR_NO_FILE(LogLevel.ERROR,R.string.msg_export_log_error_no_file),
|
MSG_EXPORT_LOG_EXPORT_ERROR_NO_FILE(LogLevel.ERROR,R.string.msg_export_log_error_no_file),
|
||||||
MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN(LogLevel.ERROR,R.string.msg_export_log_error_fopen),
|
MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN(LogLevel.ERROR,R.string.msg_export_log_error_fopen),
|
||||||
MSG_EXPORT_LOG_EXPORT_ERROR_WRITING(LogLevel.ERROR,R.string.msg_export_log_error_writing),
|
MSG_EXPORT_LOG_EXPORT_ERROR_WRITING(LogLevel.ERROR,R.string.msg_export_log_error_writing),
|
||||||
MSG_EXPORT_LOG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_log_success),
|
MSG_EXPORT_LOG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_log_success);
|
||||||
;
|
|
||||||
|
|
||||||
public final int mMsgId;
|
public final int mMsgId;
|
||||||
public final LogLevel mLevel;
|
public final LogLevel mLevel;
|
||||||
|
@ -4,10 +4,10 @@ import android.content.Context;
|
|||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
|
||||||
import org.apache.http.client.methods.HttpRequestBase;
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
@ -19,6 +19,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -86,7 +87,23 @@ public abstract class LinkedCookieResource extends LinkedResource {
|
|||||||
log.add(LogType.MSG_LV, 0);
|
log.add(LogType.MSG_LV, 0);
|
||||||
|
|
||||||
// Try to fetch resource. Logs for itself
|
// Try to fetch resource. Logs for itself
|
||||||
String res = fetchResource(log, 1);
|
String res = null;
|
||||||
|
try {
|
||||||
|
res = fetchResource(log, 1);
|
||||||
|
} catch (HttpStatusException e) {
|
||||||
|
// log verbose output to logcat
|
||||||
|
Log.e(Constants.TAG, "http error (" + e.getStatus() + "): " + e.getReason());
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR, 2, Integer.toString(e.getStatus()));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_URL, 2);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "io error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_IO, 2);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(Constants.TAG, "json error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
// if this is null, an error was recorded in fetchResource above
|
// if this is null, an error was recorded in fetchResource above
|
||||||
return new LinkedVerifyResult(LinkedVerifyResult.RESULT_ERROR, log);
|
return new LinkedVerifyResult(LinkedVerifyResult.RESULT_ERROR, log);
|
||||||
@ -98,7 +115,8 @@ public abstract class LinkedCookieResource extends LinkedResource {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String fetchResource (OperationLog log, int indent);
|
protected abstract String fetchResource (OperationLog log, int indent) throws HttpStatusException, IOException,
|
||||||
|
JSONException;
|
||||||
|
|
||||||
protected Matcher matchResource (OperationLog log, int indent, String res) {
|
protected Matcher matchResource (OperationLog log, int indent, String res) {
|
||||||
return magicPattern.matcher(res);
|
return magicPattern.matcher(res);
|
||||||
@ -130,6 +148,8 @@ public abstract class LinkedCookieResource extends LinkedResource {
|
|||||||
public static String getResponseBody(HttpRequestBase request) throws IOException, HttpStatusException {
|
public static String getResponseBody(HttpRequestBase request) throws IOException, HttpStatusException {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
request.setHeader("User-Agent", "Open Keychain");
|
||||||
|
|
||||||
DefaultHttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
|
DefaultHttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
|
||||||
HttpResponse response = httpClient.execute(request);
|
HttpResponse response = httpClient.execute(request);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
@ -8,6 +8,7 @@ import android.support.annotation.StringRes;
|
|||||||
|
|
||||||
import com.textuality.keybase.lib.Search;
|
import com.textuality.keybase.lib.Search;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
@ -40,53 +41,15 @@ public class GenericHttpsResource extends LinkedCookieResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String fetchResource (OperationLog log, int indent) {
|
protected String fetchResource (OperationLog log, int indent) throws HttpStatusException, IOException {
|
||||||
|
|
||||||
log.add(LogType.MSG_LV_FETCH, indent, mSubUri.toString());
|
log.add(LogType.MSG_LV_FETCH, indent, mSubUri.toString());
|
||||||
indent += 1;
|
indent += 1;
|
||||||
|
|
||||||
try {
|
HttpGet httpGet = new HttpGet(mSubUri);
|
||||||
|
return getResponseBody(httpGet);
|
||||||
|
|
||||||
HttpsURLConnection conn = null;
|
// log.add(LogType.MSG_LV_FETCH_REDIR, indent, url.toString());
|
||||||
URL url = mSubUri.toURL();
|
|
||||||
int status = 0;
|
|
||||||
int redirects = 0;
|
|
||||||
|
|
||||||
while (redirects < 5) {
|
|
||||||
conn = (HttpsURLConnection) url.openConnection();
|
|
||||||
conn.addRequestProperty("User-Agent", "OpenKeychain");
|
|
||||||
conn.setConnectTimeout(5000);
|
|
||||||
conn.setReadTimeout(25000);
|
|
||||||
conn.connect();
|
|
||||||
status = conn.getResponseCode();
|
|
||||||
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 {
|
|
||||||
// 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) {
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_URL, indent);
|
|
||||||
return null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(Constants.TAG, "io error", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_IO, indent);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,58 +48,43 @@ public class GithubResource extends LinkedCookieResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String fetchResource (OperationLog log, int indent) {
|
protected String fetchResource (OperationLog log, int indent)
|
||||||
|
throws HttpStatusException, IOException, JSONException {
|
||||||
|
|
||||||
log.add(LogType.MSG_LV_FETCH, indent, mSubUri.toString());
|
log.add(LogType.MSG_LV_FETCH, indent, mSubUri.toString());
|
||||||
indent += 1;
|
indent += 1;
|
||||||
|
|
||||||
try {
|
HttpGet httpGet = new HttpGet("https://api.github.com/gists/" + mGistId);
|
||||||
|
String response = getResponseBody(httpGet);
|
||||||
|
|
||||||
HttpGet httpGet = new HttpGet("https://api.github.com/gists/" + mGistId);
|
JSONObject obj = new JSONObject(response);
|
||||||
httpGet.setHeader("User-Agent", "OpenKeychain");
|
|
||||||
|
|
||||||
String response = getResponseBody(httpGet);
|
JSONObject owner = obj.getJSONObject("owner");
|
||||||
|
if (!mHandle.equals(owner.getString("login"))) {
|
||||||
JSONObject obj = new JSONObject(response);
|
log.add(LogType.MSG_LV_ERROR_GITHUB_HANDLE, indent);
|
||||||
|
return null;
|
||||||
JSONObject owner = obj.getJSONObject("owner");
|
|
||||||
if (!mHandle.equals(owner.getString("login"))) {
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, indent);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject files = obj.getJSONObject("files");
|
|
||||||
Iterator<String> it = files.keys();
|
|
||||||
if (it.hasNext()) {
|
|
||||||
// TODO can there be multiple candidates?
|
|
||||||
JSONObject file = files.getJSONObject(it.next());
|
|
||||||
return file.getString("content");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (HttpStatusException e) {
|
|
||||||
// log verbose output to logcat
|
|
||||||
Log.e(Constants.TAG, "http error (" + e.getStatus() + "): " + e.getReason());
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR, indent, Integer.toString(e.getStatus()));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_URL, indent);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(Constants.TAG, "io error", e);
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_IO, indent);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(Constants.TAG, "json error", e);
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, indent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSONObject files = obj.getJSONObject("files");
|
||||||
|
Iterator<String> it = files.keys();
|
||||||
|
if (it.hasNext()) {
|
||||||
|
// TODO can there be multiple candidates?
|
||||||
|
JSONObject file = files.getJSONObject(it.next());
|
||||||
|
return file.getString("content");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.add(LogType.MSG_LV_ERROR_GITHUB_NOT_FOUND, indent);
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GithubResource searchInGithubStream(String screenName, String needle) {
|
public static GithubResource searchInGithubStream(String screenName, String needle,
|
||||||
|
OperationLog log) {
|
||||||
|
|
||||||
// narrow the needle down to important part
|
// narrow the needle down to important part
|
||||||
Matcher matcher = magicPattern.matcher(needle);
|
Matcher matcher = magicPattern.matcher(needle);
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
Log.e(Constants.TAG, "needle didn't contain cookie!");
|
throw new AssertionError("Needle must contain cookie pattern! This is a programming error, please report.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
needle = matcher.group();
|
needle = matcher.group();
|
||||||
|
|
||||||
@ -150,9 +135,21 @@ public class GithubResource extends LinkedCookieResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the results with the body of the response
|
// update the results with the body of the response
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_NOTHING, 2);
|
||||||
return null;
|
return null;
|
||||||
} catch (JSONException | HttpStatusException | IOException e) {
|
|
||||||
Log.e(Constants.TAG, "exception parsing stream", e);
|
} catch (HttpStatusException e) {
|
||||||
|
// log verbose output to logcat
|
||||||
|
Log.e(Constants.TAG, "http error (" + e.getStatus() + "): " + e.getReason());
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR, 2, Integer.toString(e.getStatus()));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_URL, 2);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "io error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_IO, 2);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(Constants.TAG, "json error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,6 +22,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat
|
|||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -66,11 +67,14 @@ public class TwitterResource extends LinkedCookieResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String fetchResource(OperationLog log, int indent) {
|
protected String fetchResource(OperationLog log, int indent) throws IOException, HttpStatusException,
|
||||||
|
JSONException {
|
||||||
|
|
||||||
String authToken = getAuthToken();
|
String authToken;
|
||||||
|
try {
|
||||||
if (authToken == null) {
|
authToken = getAuthToken();
|
||||||
|
} catch (IOException | HttpStatusException | JSONException e) {
|
||||||
|
log.add(LogType.MSG_LV_ERROR_TWITTER_AUTH, indent);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,32 +91,19 @@ public class TwitterResource extends LinkedCookieResource {
|
|||||||
try {
|
try {
|
||||||
String response = getResponseBody(httpGet);
|
String response = getResponseBody(httpGet);
|
||||||
JSONObject obj = new JSONObject(response);
|
JSONObject obj = new JSONObject(response);
|
||||||
|
|
||||||
if (!obj.has("text")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject user = obj.getJSONObject("user");
|
JSONObject user = obj.getJSONObject("user");
|
||||||
if (!mHandle.equalsIgnoreCase(user.getString("screen_name"))) {
|
if (!mHandle.equalsIgnoreCase(user.getString("screen_name"))) {
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, indent);
|
log.add(LogType.MSG_LV_ERROR_TWITTER_HANDLE, indent);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the results with the body of the response
|
// update the results with the body of the response
|
||||||
return obj.getString("text");
|
return obj.getString("text");
|
||||||
} catch (HttpStatusException e) {
|
|
||||||
// log verbose output to logcat
|
|
||||||
Log.e(Constants.TAG, "http error (" + e.getStatus() + "): " + e.getReason());
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR, indent, Integer.toString(e.getStatus()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(Constants.TAG, "io error", e);
|
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_IO, indent);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(Constants.TAG, "json error", e);
|
log.add(LogType.MSG_LV_ERROR_TWITTER_RESPONSE, indent);
|
||||||
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, indent);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,11 +139,14 @@ public class TwitterResource extends LinkedCookieResource {
|
|||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TwitterResource searchInTwitterStream(String screenName, String needle) {
|
public static TwitterResource searchInTwitterStream(
|
||||||
|
String screenName, String needle, OperationLog log) {
|
||||||
|
|
||||||
String authToken = getAuthToken();
|
String authToken;
|
||||||
|
try {
|
||||||
if (authToken == null) {
|
authToken = getAuthToken();
|
||||||
|
} catch (IOException | HttpStatusException | JSONException e) {
|
||||||
|
log.add(LogType.MSG_LV_ERROR_TWITTER_AUTH, 1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,46 +178,51 @@ public class TwitterResource extends LinkedCookieResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the results with the body of the response
|
// update the results with the body of the response
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_NOTHING, 1);
|
||||||
return null;
|
return null;
|
||||||
} catch (JSONException | HttpStatusException | IOException e) {
|
|
||||||
Log.e(Constants.TAG, "exception parsing stream", e);
|
} catch (HttpStatusException e) {
|
||||||
|
// log verbose output to logcat
|
||||||
|
Log.e(Constants.TAG, "http error (" + e.getStatus() + "): " + e.getReason());
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR, 1, Integer.toString(e.getStatus()));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_URL, 1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "io error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_IO, 1);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(Constants.TAG, "json error", e);
|
||||||
|
log.add(LogType.MSG_LV_FETCH_ERROR_FORMAT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String authToken;
|
private static String cachedAuthToken;
|
||||||
|
|
||||||
private static String getAuthToken() {
|
private static String getAuthToken() throws IOException, HttpStatusException, JSONException {
|
||||||
if (authToken != null) {
|
if (cachedAuthToken != null) {
|
||||||
return authToken;
|
return cachedAuthToken;
|
||||||
}
|
}
|
||||||
try {
|
String base64Encoded = rot13("D293FQqanH0jH29KIaWJER5DomqSGRE2Ewc1LJACn3cbD1c"
|
||||||
|
+ "Fq1bmqSAQAz5MI2cIHKOuo3cPoRAQI1OyqmIVFJS6LHMXq2g6MRLkIj") + "==";
|
||||||
|
|
||||||
String base64Encoded = rot13("D293FQqanH0jH29KIaWJER5DomqSGRE2Ewc1LJACn3cbD1c"
|
// Step 2: Obtain a bearer token
|
||||||
+ "Fq1bmqSAQAz5MI2cIHKOuo3cPoRAQI1OyqmIVFJS6LHMXq2g6MRLkIj") + "==";
|
HttpPost httpPost = new HttpPost("https://api.twitter.com/oauth2/token");
|
||||||
|
httpPost.setHeader("Authorization", "Basic " + base64Encoded);
|
||||||
|
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
||||||
|
httpPost.setEntity(new StringEntity("grant_type=client_credentials"));
|
||||||
|
JSONObject rawAuthorization = new JSONObject(getResponseBody(httpPost));
|
||||||
|
|
||||||
// Step 2: Obtain a bearer token
|
// Applications should verify that the value associated with the
|
||||||
HttpPost httpPost = new HttpPost("https://api.twitter.com/oauth2/token");
|
// token_type key of the returned object is bearer
|
||||||
httpPost.setHeader("Authorization", "Basic " + base64Encoded);
|
if (!"bearer".equals(JWalk.getString(rawAuthorization, "token_type"))) {
|
||||||
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
throw new JSONException("Expected bearer token in response!");
|
||||||
httpPost.setEntity(new StringEntity("grant_type=client_credentials"));
|
|
||||||
JSONObject rawAuthorization = new JSONObject(getResponseBody(httpPost));
|
|
||||||
|
|
||||||
// Applications should verify that the value associated with the
|
|
||||||
// token_type key of the returned object is bearer
|
|
||||||
if (!"bearer".equals(JWalk.getString(rawAuthorization, "token_type"))) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
authToken = JWalk.getString(rawAuthorization, "access_token");
|
|
||||||
return authToken;
|
|
||||||
|
|
||||||
} catch (JSONException | IllegalStateException | HttpStatusException | IOException ex) {
|
|
||||||
Log.e(Constants.TAG, "exception fetching auth token", ex);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cachedAuthToken = rawAuthorization.getString("access_token");
|
||||||
|
return cachedAuthToken;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String rot13(String input) {
|
public static String rot13(String input) {
|
||||||
|
@ -31,6 +31,7 @@ import android.widget.TextView;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.resources.DnsResource;
|
import org.sufficientlysecure.keychain.pgp.linked.resources.DnsResource;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
@ -104,7 +105,7 @@ public class LinkedIdCreateDnsStep2Fragment extends LinkedIdCreateFinalFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
LinkedCookieResource getResource() {
|
LinkedCookieResource getResource(OperationLog log) {
|
||||||
return DnsResource.createNew(mResourceDomain);
|
return DnsResource.createNew(mResourceDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import android.widget.ViewAnimator;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity;
|
||||||
@ -28,6 +29,8 @@ import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
|||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
|
|
||||||
public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
||||||
|
|
||||||
@ -95,7 +98,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract LinkedCookieResource getResource();
|
abstract LinkedCookieResource getResource(OperationLog log);
|
||||||
|
|
||||||
private void setVerifyProgress(boolean on, Boolean success) {
|
private void setVerifyProgress(boolean on, Boolean success) {
|
||||||
if (success == null) {
|
if (success == null) {
|
||||||
@ -133,7 +136,12 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
|||||||
protected LinkedVerifyResult doInBackground(Void... params) {
|
protected LinkedVerifyResult doInBackground(Void... params) {
|
||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
|
|
||||||
LinkedCookieResource resource = getResource();
|
OperationLog log = new OperationLog();
|
||||||
|
LinkedCookieResource resource = getResource(log);
|
||||||
|
if (resource == null) {
|
||||||
|
return new LinkedVerifyResult(LinkedVerifyResult.RESULT_ERROR, log);
|
||||||
|
}
|
||||||
|
|
||||||
LinkedVerifyResult result = resource.verify(mLinkedIdWizard.mFingerprint);
|
LinkedVerifyResult result = resource.verify(mLinkedIdWizard.mFingerprint);
|
||||||
|
|
||||||
// ux flow: this operation should take at last a second
|
// ux flow: this operation should take at last a second
|
||||||
@ -178,7 +186,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void certifyLinkedIdentity (String passphrase) {
|
private void certifyLinkedIdentity (Passphrase passphrase) {
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
getString(R.string.progress_saving),
|
getString(R.string.progress_saving),
|
||||||
@ -227,7 +235,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
|||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putString(KeychainIntentService.EDIT_KEYRING_PASSPHRASE, passphrase);
|
data.putParcelable(KeychainIntentService.EDIT_KEYRING_PASSPHRASE, passphrase);
|
||||||
data.putParcelable(KeychainIntentService.EDIT_KEYRING_PARCEL, skp);
|
data.putParcelable(KeychainIntentService.EDIT_KEYRING_PARCEL, skp);
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
@ -249,8 +257,8 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
|
|||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_PASSPHRASE:
|
case REQUEST_CODE_PASSPHRASE:
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
String passphrase =
|
Passphrase passphrase =
|
||||||
data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
|
data.getParcelableExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE);
|
||||||
certifyLinkedIdentity(passphrase);
|
certifyLinkedIdentity(passphrase);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -26,6 +26,7 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.resources.GithubResource;
|
import org.sufficientlysecure.keychain.pgp.linked.resources.GithubResource;
|
||||||
|
|
||||||
@ -82,8 +83,8 @@ public class LinkedIdCreateGithubStep2Fragment extends LinkedIdCreateFinalFragme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
LinkedCookieResource getResource() {
|
LinkedCookieResource getResource(OperationLog log) {
|
||||||
return GithubResource.searchInGithubStream(mResourceHandle, mResourceString);
|
return GithubResource.searchInGithubStream(mResourceHandle, mResourceString, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +30,7 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.resources.GenericHttpsResource;
|
import org.sufficientlysecure.keychain.pgp.linked.resources.GenericHttpsResource;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
@ -66,7 +67,7 @@ public class LinkedIdCreateHttpsStep2Fragment extends LinkedIdCreateFinalFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
GenericHttpsResource getResource() {
|
GenericHttpsResource getResource(OperationLog log) {
|
||||||
return GenericHttpsResource.createNew(mResourceUri);
|
return GenericHttpsResource.createNew(mResourceUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
|
||||||
import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource;
|
import org.sufficientlysecure.keychain.pgp.linked.resources.TwitterResource;
|
||||||
|
|
||||||
@ -82,8 +83,8 @@ public class LinkedIdCreateTwitterStep2Fragment extends LinkedIdCreateFinalFragm
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
LinkedCookieResource getResource() {
|
LinkedCookieResource getResource(OperationLog log) {
|
||||||
return TwitterResource.searchInTwitterStream(mResourceHandle, mResourceString);
|
return TwitterResource.searchInTwitterStream(mResourceHandle, mResourceString, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -133,7 +133,7 @@ public class LinkedIdViewFragment extends Fragment implements
|
|||||||
case LOADER_ID_LINKED_ID:
|
case LOADER_ID_LINKED_ID:
|
||||||
|
|
||||||
if (!cursor.moveToFirst()) {
|
if (!cursor.moveToFirst()) {
|
||||||
Notify.createNotify(getActivity(), "Error loading identity!",
|
Notify.create(getActivity(), "Error loading identity!",
|
||||||
Notify.LENGTH_LONG, Style.ERROR).show();
|
Notify.LENGTH_LONG, Style.ERROR).show();
|
||||||
finishFragment();
|
finishFragment();
|
||||||
break;
|
break;
|
||||||
|
@ -1175,6 +1175,12 @@
|
|||||||
<string name="msg_lv_fp_ok">"Fingerprint ok."</string>
|
<string name="msg_lv_fp_ok">"Fingerprint ok."</string>
|
||||||
<string name="msg_lv_fp_error">"Fingerprint mismatch!"</string>
|
<string name="msg_lv_fp_error">"Fingerprint mismatch!"</string>
|
||||||
|
|
||||||
|
<string name="msg_lv_error_twitter_auth">"Error obtaining Twitter auth token!"</string>
|
||||||
|
<string name="msg_lv_error_twitter_handle">"Twitter account handle mismatch in response!"</string>
|
||||||
|
<string name="msg_lv_error_twitter_response">"Unexpected response from Twitter API!"</string>
|
||||||
|
<string name="msg_lv_error_github_handle">"Github account handle mismatch in response!"</string>
|
||||||
|
<string name="msg_lv_error_github_not_found">"Gist contains no matching files!"</string>
|
||||||
|
|
||||||
<string name="msg_lv_fetch">"Fetching URI '%s'"</string>
|
<string name="msg_lv_fetch">"Fetching URI '%s'"</string>
|
||||||
<string name="msg_lv_fetch_redir">"Following redirect to '%s'"</string>
|
<string name="msg_lv_fetch_redir">"Following redirect to '%s'"</string>
|
||||||
<string name="msg_lv_fetch_ok">"Successfully fetched (HTTP %s)"</string>
|
<string name="msg_lv_fetch_ok">"Successfully fetched (HTTP %s)"</string>
|
||||||
@ -1182,6 +1188,7 @@
|
|||||||
<string name="msg_lv_fetch_error_url">"URL is malformed!"</string>
|
<string name="msg_lv_fetch_error_url">"URL is malformed!"</string>
|
||||||
<string name="msg_lv_fetch_error_io">"IO Error!"</string>
|
<string name="msg_lv_fetch_error_io">"IO Error!"</string>
|
||||||
<string name="msg_lv_fetch_error_format">"Format error!"</string>
|
<string name="msg_lv_fetch_error_format">"Format error!"</string>
|
||||||
|
<string name="msg_lv_fetch_error_nothing">"Resource not found!"</string>
|
||||||
|
|
||||||
<string name="msg_acc_saved">"Account saved"</string>
|
<string name="msg_acc_saved">"Account saved"</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user