Zertifikatsprüfung eingebaut

Code formatiert.
This commit is contained in:
Lyndon
2018-06-06 17:32:20 +02:00
parent 58825a6c43
commit a1e8a13fd6
12 changed files with 77 additions and 34 deletions

View File

@@ -140,4 +140,4 @@ task adp2upload(type: Exec, dependsOn: "build") {
commandLine 'upload_build.sh', "-c", "$channel", "-v", "$versionCode", "-p", "android", "-a", "$slug", "-f", "$file", "-i", "$identifier", "-n", "$notes"
}
//apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'

View File

@@ -33,7 +33,7 @@ public class BewoplanerApplication extends Application {
Realm.init(this);
if (!BuildConfig.DEBUG) {
if(!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
}

View File

@@ -1,5 +1,7 @@
package de.beyondsoft.ownchat.data.api;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -12,13 +14,19 @@ import de.beyondsoft.ownchat.di.scopes.ApplicationScope;
import de.beyondsoft.ownchat.utils.Constants;
import java.io.File;
import java.math.BigInteger;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.net.ssl.SSLHandshakeException;
import dagger.Module;
import dagger.Provides;
import okhttp3.Cache;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@@ -30,9 +38,9 @@ import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.schedulers.Schedulers;
/**
* Created by laszloffiferenc on 2/21/17.
*/
import static de.beyondsoft.ownchat.utils.Constants.INTERMEDIATE_PUB_KEY;
import static de.beyondsoft.ownchat.utils.Constants.LOG_TAG_NETWORK_INTERCEPTOR;
@Module
public class ApiModule {
@@ -90,6 +98,40 @@ public class ApiModule {
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(loggingInterceptor)
.addInterceptor(interceptor)
.addNetworkInterceptor(chain -> {
Request request = chain.request();
HttpUrl url = request.url();
Log.d(LOG_TAG_NETWORK_INTERCEPTOR, "Pinning certificate for URL: " + url);
List<Certificate> certificates = chain.connection().handshake().peerCertificates();
boolean isVerified = false;
if(url.toString().contains(".ownchat.de")) {
for(Certificate cert : certificates) {
X509Certificate x509Certificate = (X509Certificate) cert;
BigInteger serialNumber = x509Certificate.getSerialNumber();
String name = x509Certificate.getIssuerX500Principal().getName();
Log.d(LOG_TAG_NETWORK_INTERCEPTOR, "Certificate name: " + name + "; serial number: " + serialNumber);
if(serialNumber.equals(INTERMEDIATE_PUB_KEY) && name.contains("O=Let's Encrypt")) {
isVerified = true;
break;
}
}
}
if(!isVerified) {
Log.e(LOG_TAG_NETWORK_INTERCEPTOR, "SSL certificates are invalid!");
throw new SSLHandshakeException("Invalid SSL certificates");
}
return chain.proceed(request);
})
.build();
}

View File

@@ -16,9 +16,6 @@ import javax.inject.Inject;
import rx.Subscriber;
import rx.schedulers.Schedulers;
/**
* Created by laszloffiferenc on 3/1/17.
*/
public class MessagingInstanceIdService extends FirebaseInstanceIdService {
private static String TAG = "messaging";

View File

@@ -112,7 +112,6 @@ public class GroupChatActivity extends BaseChatActivity {
}
}
Log.d("GROUP_CHAT_ACTIVITY", "Resuming group chat activity. Canceling notification. Group is null: " + (mGroup == null));
cancelNotification();
IntentFilter filter = new IntentFilter(Constants.NOTIFICATION_BROADCAST);
registerReceiver(mReceiver, filter);
@@ -171,8 +170,6 @@ public class GroupChatActivity extends BaseChatActivity {
mGroup = group;
setToolbar();
Log.d("GROUP_CHAT_ACTIVITY", "Group(" + mGroup.id + ") has been set. Canceling notification");
cancelNotification();
}
}

View File

@@ -4,9 +4,6 @@ import android.support.v4.app.Fragment;
import butterknife.Unbinder;
/**
* Created by imarneanu on 2/22/17.
*/
public class BaseFragment extends Fragment {
protected Unbinder mUnbinder;
@@ -15,7 +12,7 @@ public class BaseFragment extends Fragment {
public void onDestroyView() {
super.onDestroyView();
if (mUnbinder == null) {
if(mUnbinder == null) {
return;
}

View File

@@ -3,6 +3,8 @@ package de.beyondsoft.ownchat.page.login;
import com.google.gson.JsonObject;
import com.bumptech.glide.Glide;
import de.beyondsoft.ownchat.BewoplanerApplication;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.data.api.common.ErrorHandlingResponseConverter;

View File

@@ -1,6 +1,7 @@
package de.beyondsoft.ownchat.page.main;
import com.bumptech.glide.Glide;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.data.events.InvalidTokenEvent;
@@ -111,8 +112,7 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
CircleImageView avatar = headerLayout.findViewById(R.id.menu_profile_imageView);
Glide.with(this).load(mAvatarPreference.get()).into(avatar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
@@ -133,17 +133,18 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
@SuppressLint("MissingSuperCall")
@Override
protected void onSaveInstanceState(Bundle outState) {}
protected void onSaveInstanceState(Bundle outState) {
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.hasExtra(REDIRECT_TO_CHAT) && !mChatOpenedPref.get()) {
if(intent.hasExtra(REDIRECT_TO_CHAT) && !mChatOpenedPref.get()) {
Bundle message = intent.getBundleExtra(BUNDLE);
Intent startIntent;
if (intent.getIntExtra(Constants.GROUP_NR_USERS, 2) > 2) {
if(intent.getIntExtra(Constants.GROUP_NR_USERS, 2) > 2) {
startIntent = GroupChatActivity.createIntent(this, message);
} else {
startIntent = SingleChatActivity.createIntent(this, message);
@@ -170,11 +171,11 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
private void switchFragment(@NonNull Fragment fragment, boolean clearBackStack) {
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_main);
if (fragment.getClass().isInstance(currentFragment)) {
if(fragment.getClass().isInstance(currentFragment)) {
return;
}
if (clearBackStack) {
if(clearBackStack) {
Utils.clearFullBackStack(this);
}
@@ -191,11 +192,11 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
@Override
public void onBackPressed() {
if (mDrawer.isDrawerOpen(GravityCompat.START)) {
if(mDrawer.isDrawerOpen(GravityCompat.START)) {
mDrawer.closeDrawer(GravityCompat.START);
}
if (getSupportFragmentManager().getBackStackEntryCount() <= 1) {
if(getSupportFragmentManager().getBackStackEntryCount() <= 1) {
finish();
}
@@ -228,7 +229,7 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
},
(dialog, which) -> dialog.dismiss());
if (!isFinishing()) {
if(!isFinishing()) {
alertDialog.show();
}
}
@@ -247,7 +248,7 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
@Override
public void goToLoginActivity() {
if (isFinishing()) {
if(isFinishing()) {
return;
}

View File

@@ -1,5 +1,7 @@
package de.beyondsoft.ownchat.utils;
import java.math.BigInteger;
/**
* Created by laszloffiferenc on 2/21/17.
*/
@@ -38,4 +40,8 @@ public interface Constants {
String AUDIO_RECORDINGS_DIR = "audio_recordings";
int RECORDING_BIT_RATE_IN_MS = 32000;
String LOG_TAG_NETWORK_INTERCEPTOR = "NETWORK_INTERCEPTOR";
BigInteger INTERMEDIATE_PUB_KEY = new BigInteger("281431956120940106936008670181301568443719");
}

View File

@@ -26,19 +26,19 @@ public abstract class EndlessScrollListener extends RecyclerView.OnScrollListene
int totalItemCount = mLayoutManager.getItemCount();
mVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (mLoading) {
if (totalItemCount > mPreviousTotal) {
if(mLoading) {
if(totalItemCount > mPreviousTotal) {
mLoading = false;
mPreviousTotal = totalItemCount;
}
}
if (recyclerView == null) {
if(recyclerView == null) {
return;
}
recyclerView.post(() -> {
if (!mLoading && (totalItemCount - visibleItemCount) <= (mVisibleItem + mVisibleThreshold)) {
if(!mLoading && (totalItemCount - visibleItemCount) <= (mVisibleItem + mVisibleThreshold)) {
mLoading = onLoad();
}
});

View File

@@ -18,7 +18,7 @@ public final class Preconditions {
* @param args Optional args
*/
public static void checkState(boolean condition, String message, Object... args) {
if (!condition) {
if(!condition) {
throw new IllegalStateException(formatMessage(message, args));
}
}
@@ -31,7 +31,7 @@ public final class Preconditions {
* @param args Optional args
*/
public static void checkArgument(boolean condition, String message, Object... args) {
if (!condition) {
if(!condition) {
throw new IllegalArgumentException(formatMessage(message, args));
}
}
@@ -45,7 +45,7 @@ public final class Preconditions {
*/
@NonNull
public static <T> T checkNotNull(T thing, String message, Object... args) {
if (thing == null) {
if(thing == null) {
throw new NullPointerException(formatMessage(message, args));
}
@@ -60,7 +60,7 @@ public final class Preconditions {
* @param args Optional args
*/
public static void checkNull(Object thing, String message, Object... args) {
if (thing != null) {
if(thing != null) {
throw new IllegalStateException(formatMessage(message, args));
}
}

View File

@@ -11,6 +11,7 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.1'
}
}