Fixes the bug with scope (ie: read access only) with no redirect url *urn:ietf:wg:oauth:2.0:oob*+ back to the classic login page & removes the useless google lib

This commit is contained in:
tom79 2017-05-25 13:33:33 +02:00
parent d69c083dc0
commit 5e1e2ed41f
13 changed files with 281 additions and 287 deletions

View File

@ -20,7 +20,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-safetynet:10.2.4'
compile 'com.google.android.gms:play-services-safetynet:10.2.6'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

View File

@ -70,11 +70,6 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="fr.gouv.etalab.mastodon.activities.WebviewActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
/>
<activity
android:name="fr.gouv.etalab.mastodon.activities.SplashActivity"
android:theme="@style/SplashTheme">

View File

@ -15,27 +15,36 @@
package fr.gouv.etalab.mastodon.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import cz.msebera.android.httpclient.Header;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.MastalabSSLSocketFactory;
import fr.gouv.etalab.mastodon.client.OauthClient;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT;
/**
* Created by Thomas on 23/04/2017.
@ -65,13 +74,12 @@ public class LoginActivity extends AppCompatActivity {
private void retrievesClientId(){
final Button connectionButton = (Button) findViewById(R.id.login_button);
final Intent webviewIntent = new Intent(this, WebviewActivity.class);
String action = "/api/v1/apps";
RequestParams parameters = new RequestParams();
parameters.put(Helper.CLIENT_NAME, Helper.OAUTH_REDIRECT_HOST);
parameters.put(Helper.REDIRECT_URIS,"https://" + Helper.INSTANCE + Helper.REDIRECT_CONTENT);
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES);
parameters.put(Helper.WEBSITE,"https://" + Helper.INSTANCE);
parameters.add(Helper.CLIENT_NAME, Helper.OAUTH_REDIRECT_HOST);
parameters.add(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
parameters.add(Helper.SCOPES, Helper.OAUTH_SCOPES);
parameters.add(Helper.WEBSITE,"https://" + Helper.INSTANCE);
new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
@ -106,12 +114,53 @@ public class LoginActivity extends AppCompatActivity {
connectionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(webviewIntent);
finish();
connectionButton.setEnabled(false);
AsyncHttpClient client = new AsyncHttpClient();
RequestParams requestParams = new RequestParams();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
requestParams.add(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
requestParams.add(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
requestParams.add("grant_type", "password");
EditText login_uid = (EditText) findViewById(R.id.login_uid);
EditText login_passwd = (EditText) findViewById(R.id.login_passwd);
requestParams.add("username",login_uid.getText().toString().trim());
requestParams.add("password",login_passwd.getText().toString().trim());
requestParams.add("scope"," read write follow");
client.setUserAgent(USER_AGENT);
try {
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.post("https://" + Helper.INSTANCE + "/oauth/token", requestParams, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String response = new String(responseBody);
JSONObject resobj;
try {
resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(LoginActivity.this, token).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
connectionButton.setEnabled(true);
Toast.makeText(getApplicationContext(),R.string.toast_error_login,Toast.LENGTH_LONG).show();
}
});
} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException e) {
e.printStackTrace();
}
}
});
}
}

View File

@ -53,6 +53,7 @@ import java.util.HashMap;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -124,6 +125,7 @@ public class MainActivity extends AppCompatActivity
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()

View File

@ -1,212 +0,0 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastodon Etalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestHandle;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.SyncHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import cz.msebera.android.httpclient.Header;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.OauthClient;
import fr.gouv.etalab.mastodon.helper.Helper;
/**
* Created by Thomas on 24/04/2017.
* Webview to connect accounts
*/
public class WebviewActivity extends AppCompatActivity {
private WebView webView;
private AlertDialog alert;
private String clientId, clientSecret;
private WebResourceResponse webResourceResponse;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
clientId = sharedpreferences.getString(Helper.CLIENT_ID, null);
clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null);
webView = (WebView) findViewById(R.id.webviewConnect);
clearCookies(getApplicationContext());
final ProgressBar pbar = (ProgressBar) findViewById(R.id.progress_bar);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) {
pbar.setVisibility(ProgressBar.VISIBLE);
}
pbar.setProgress(progress);
if (progress == 100) {
pbar.setVisibility(ProgressBar.GONE);
}
}
});
webView.setWebViewClient(new WebViewClient() {
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
super.shouldOverrideUrlLoading(view,url);
if( url.contains(Helper.REDIRECT_CONTENT)){
String val[] = url.split("code=");
String code = val[1];
String action = "/oauth/token";
RequestParams parameters = new RequestParams();
parameters.add(Helper.CLIENT_ID, clientId);
parameters.add(Helper.CLIENT_SECRET, clientSecret);
parameters.add(Helper.REDIRECT_URI,"https://" + Helper.INSTANCE + Helper.REDIRECT_CONTENT);
parameters.add("grant_type", "authorization_code");
parameters.add("code",code);
new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String response = new String(responseBody);
JSONObject resobj;
try {
resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(WebviewActivity.this, true, token).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
error.printStackTrace();
}
});
return true;
}
return false;
}
});
webView.loadUrl(redirectUserToAuthorizeAndLogin());
}
@Override
public void onBackPressed() {
if (webView != null && webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
private String redirectUserToAuthorizeAndLogin() {
String queryString = Helper.CLIENT_ID + "="+ clientId;
queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode("https://" + Helper.INSTANCE + "/redirect_mastodon_api");
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
queryString += "&" + Helper.SCOPE +"=" + Helper.OAUTH_SCOPES;
/*try {
queryString = URLEncoder.encode(queryString, "utf-8");
} catch (UnsupportedEncodingException ignored) {}*/
return "https://" + Helper.INSTANCE + Helper.EP_AUTHORIZE + "?" + queryString;
}
@Override
public void onDestroy() {
super.onDestroy();
if (alert != null) {
alert.dismiss();
alert = null;
}
}
@SuppressWarnings("deprecation")
public static void clearCookies(Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
} else
{
CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
cookieSyncMngr.startSync();
CookieManager cookieManager=CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
}
}

View File

@ -20,13 +20,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
@ -39,22 +37,11 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private String token;
private boolean fromWebview;
private boolean error;
private OnUpdateAccountInfoInterface listener;
public UpdateAccountInfoAsyncTask(Context context, String token, OnUpdateAccountInfoInterface onUpdateAccountInfoInterface){
public UpdateAccountInfoAsyncTask(Context context, String token){
this.context = context;
this.token = token;
this.fromWebview = false;
this.error = false;
this.listener = onUpdateAccountInfoInterface;
}
public UpdateAccountInfoAsyncTask(Context context, boolean fromWebview, String token){
this.context = context;
this.token = token;
this.fromWebview = fromWebview;
}
@ -78,8 +65,6 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
else {
if( account.getUsername() != null && account.getCreated_at() != null)
new AccountDAO(context, db).insertAccount(account);
else //Here the user credential in db doesn't match the remote one (it will be disconnected)
error = true;
}
return null;
}
@ -87,14 +72,10 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
if( fromWebview){
Intent mainActivity = new Intent(context, MainActivity.class);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainActivity);
((Activity) context).finish();
}else{
listener.onUpdateAccountInfo(error);
}
Intent mainActivity = new Intent(context, MainActivity.class);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainActivity);
((Activity) context).finish();
}

View File

@ -1156,28 +1156,46 @@ public class API {
private void get(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) {
client.setTimeout(10000);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setUserAgent(USER_AGENT);
client.get(getAbsoluteUrl(action), params, responseHandler);
try {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.get(getAbsoluteUrl(action), params, responseHandler);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
e.printStackTrace();
}
}
private void post(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setUserAgent(USER_AGENT);
client.post(getAbsoluteUrl(action), params, responseHandler);
try {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.post(getAbsoluteUrl(action), params, responseHandler);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
e.printStackTrace();
}
}
private void delete(String action, RequestParams params, AsyncHttpResponseHandler responseHandler){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setUserAgent(USER_AGENT);
client.delete(getAbsoluteUrl(action), params, responseHandler);
try {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.delete(getAbsoluteUrl(action), params, responseHandler);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
e.printStackTrace();
}
}
private String getAbsoluteUrl(String action) {

View File

@ -15,12 +15,16 @@
package fr.gouv.etalab.mastodon.client;
import android.util.Log;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -38,16 +42,26 @@ public class OauthClient {
private static AsyncHttpClient client = new AsyncHttpClient();
public void get(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) {
client.setTimeout(5000);
client.setUserAgent(USER_AGENT);
client.post(getAbsoluteUrl(action), params, responseHandler);
client.get(getAbsoluteUrl(action), params, responseHandler);
try {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.get(getAbsoluteUrl(action), params, responseHandler);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
e.printStackTrace();
}
}
public void post(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
client.post(getAbsoluteUrl(action), params, responseHandler);
try {
client.setConnectTimeout(30000); //30s timeout
client.setUserAgent(USER_AGENT);
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
client.post(getAbsoluteUrl(action), params, responseHandler);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
e.printStackTrace();
}
}
private String getAbsoluteUrl(String action) {

View File

@ -0,0 +1,127 @@
package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.Socket;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/**
* Created by Thomas on 21/05/2017.
* Patch for universal image loader to support TLS 1.1+
*/
public class PatchBaseImageDownloader extends BaseImageDownloader {
private SSLSocketFactory sf;
public PatchBaseImageDownloader(Context context) {
super(context);
initSSLSocketFactory();
}
private void initSSLSocketFactory() {
sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
sf = new MySSLSocketFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setSSLSocketFactory(sf);
}
return new ContentLengthInputStream(new BufferedInputStream(conn.getInputStream(), BUFFER_SIZE), conn.getContentLength());
}
private static class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
MySSLSocketFactory() throws Exception {
super();
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sslContext.init(null, new TrustManager[]{tm}, null);
}
@Override
public String[] getDefaultCipherSuites() {
return new String[0];
}
@Override
public String[] getSupportedCipherSuites() {
return new String[0];
}
@Override
public Socket createSocket(String host, int port) throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket(host, port));
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket(host, port, localHost, localPort));
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket(host, port));
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket(address, port, localAddress, localPort));
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket(socket, host, port, autoClose));
}
@Override
public Socket createSocket() throws IOException {
return enableTLSOnSocket(sslContext.getSocketFactory().createSocket());
}
private Socket enableTLSOnSocket(Socket socket) {
if(socket != null && (socket instanceof SSLSocket)) {
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
}
return socket;
}
}
}

View File

@ -72,7 +72,7 @@ public class Helper {
public static final String OAUTH_SCOPES = "read write follow";
public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token";
public static final String PREF_KEY_ID = "userID";
public static final String REDIRECT_CONTENT = "/redirect_mastodon_api";
public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob";
public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84;
//Some definitions

View File

@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveHomeTimelineServiceAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHomeTimelineServiceInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
@ -132,6 +133,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
.imageDownloader(new PatchBaseImageDownloader(getContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()

View File

@ -36,6 +36,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveNotificationsAsyncTask;
@ -190,6 +191,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
.imageDownloader(new PatchBaseImageDownloader(getContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()

View File

@ -24,25 +24,41 @@
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="100dp"
android:layout_gravity="center_horizontal"
android:padding="20dp"
android:layout_weight="2"
android:src="@drawable/mastodonlogo"
android:layout_height="0dp"
android:layout_height="100dp"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_margin="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/login_uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/email"
/>
<EditText
android:id = "@+id/login_passwd"
android:inputType="textPassword"
android:hint="@string/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/login_button"
android:textAllCaps="false"
android:drawableLeft="@drawable/mastodon_icon"
android:drawableStart="@drawable/mastodon_icon"
android:gravity="center"
android:layout_marginTop="20dp"
android:drawablePadding="10dp"
android:paddingLeft="15dp"
android:paddingStart="15dp"