Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #94 from privacyidea/prep_2.0.4
Browse files Browse the repository at this point in the history
2.0.4
  • Loading branch information
nilsbehlen authored Feb 27, 2020
2 parents 2d20fd6 + 61789a2 commit 587c74e
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 167 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {

def versionMajor = 2
def versionMinor = 0
def versionPatch = 3
def versionAdditive = 1
def versionPatch = 4
def versionAdditive = 0

versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionAdditive
versionName "${versionMajor}.${versionMinor}.${versionPatch}b${versionAdditive}"
Expand Down Expand Up @@ -51,6 +51,7 @@ android {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildToolsVersion = '29.0.2'
}

dependencies {
Expand All @@ -60,7 +61,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core:1.2.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0-alpha02'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'commons-codec:commons-codec:1.10'
implementation 'androidx.preference:preference:1.1.0'
implementation 'junit:junit:4.12'
Expand All @@ -69,8 +70,8 @@ dependencies {
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'

implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.0.1'
implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.google.firebase:firebase-messaging:20.1.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity
android:name=".viewcontroller.MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void makeAlertDialog(int titleID, String message, int positiveBtnTextID, boolean
void makeAlertDialog(int titleID, int messageID, int positiveBtnTextID, boolean cancelable,
@Nullable DialogInterface.OnClickListener positiveBtnListener);

void makeDeviceNotSupportedDialog();
void makeDeviceNotSupportedDialog(Exception e);

void makeToast(String message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.util.Pair;

import org.apache.commons.codec.binary.Base32;
import org.json.JSONException;

import java.io.IOException;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -106,9 +107,29 @@ public Presenter(TokenListViewInterface tokenListViewInterface, MainActivityInte
public void init() {
// Logic of onCreate
if (model == null) {
model = new Model(util.loadTokens());
try {
model = new Model(util.loadTokens());
} catch (IOException e) { // TODO handle exceptions
e.printStackTrace();
mainActivityInterface.makeDeviceNotSupportedDialog(e);
} catch (GeneralSecurityException e) {
e.printStackTrace();
mainActivityInterface.makeDeviceNotSupportedDialog(e);
}
}
if (model == null) {
model = new Model();
}
FirebaseInitConfig firebaseInitConfig = null;
try {
firebaseInitConfig = util.loadFirebaseConfig();
} catch (IOException e) {
e.printStackTrace();
} catch (GeneralSecurityException e) { // TODO handle e
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
FirebaseInitConfig firebaseInitConfig = util.loadFirebaseConfig();
if (firebaseInitConfig != null) {
mainActivityInterface.firebaseInit(firebaseInitConfig);
}
Expand Down Expand Up @@ -152,6 +173,10 @@ public void scanQRfinished(ScanResult result) {
mainActivityInterface.makeAlertDialog(R.string.firebase_config_broken_title,
R.string.firebase_config_broken);
return;
} catch (GeneralSecurityException e) { // TODO handle e
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
token.sslVerify = result.sslverify;
Expand Down Expand Up @@ -248,14 +273,20 @@ public void onStop() {

@Override
public void saveTokenlist() {
util.saveTokens(model.getTokens());
try {
util.saveTokens(model.getTokens());
} catch (GeneralSecurityException e) {
e.printStackTrace(); // TODO handle e
} catch (IOException e) {
e.printStackTrace();
}
}

public void checkKeyStoreIsWorking() {
try {
util.saveToFile("test", new byte[]{});
} catch (InvalidKeyException e) {
mainActivityInterface.makeDeviceNotSupportedDialog();
} catch (GeneralSecurityException | IOException e) {
mainActivityInterface.makeDeviceNotSupportedDialog(e);
}
}

Expand Down Expand Up @@ -425,6 +456,8 @@ public void startPushAuthentication(Token token) {
e.printStackTrace();
} catch (UnrecoverableEntryException e) {
e.printStackTrace();
} catch (GeneralSecurityException e) { // TODO handle e
e.printStackTrace();
}
}

Expand Down Expand Up @@ -543,12 +576,14 @@ private void checkForExpiredAuths() {
}

private void refreshOTPs() {
for (int i = 0; i < model.getTokens().size(); i++) {
if (!model.getTokens().get(i).getType().equals(PUSH)) {
model.getTokens().get(i).setCurrentOTP(generateOTP(model.getTokens().get(i)));
if (model != null) {
for (int i = 0; i < model.getTokens().size(); i++) {
if (!model.getTokens().get(i).getType().equals(PUSH)) {
model.getTokens().get(i).setCurrentOTP(generateOTP(model.getTokens().get(i)));
}
}
tokenListInterface.notifyChange();
}
tokenListInterface.notifyChange();
}

private void doTwoStepRollout(Token token, int phonepartlength, int iterations, int output_size) {
Expand Down Expand Up @@ -589,7 +624,11 @@ public PublicKey generatePublicKeyFor(String serial) {
@Override
public void receivePublicKey(String key, Token token) {
try {
util.storePIPubkey(key, token.getSerial());
try {
util.storePIPubkey(key, token.getSerial());
} catch (IOException e) {
e.printStackTrace(); // TODO handle e
}
} catch (GeneralSecurityException e) {
// this means the "key" field was empty or the DECODED data is not a key
updateTaskStatus(PRO_STATUS_RESPONSE_NO_KEY, token);
Expand Down Expand Up @@ -721,6 +760,7 @@ public void authenticationFinished(boolean success, Token token) {
/**
* Cancel the running Authentication Task and remove the pair from the runningAuthentications List
* Sets the tokens 'lastAuthHadError' so the authentication can be dismissed
*
* @param token token of the pair
*/
private void deleteRunningAuthenticationFor(Token token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ public void authenticationFinished(boolean success, Token token) {
//if (isRunningInBackground()) {
token.getPendingAuths().remove(req);
if (util != null) {
util.saveTokens(tokenlist);
try {
util.saveTokens(tokenlist);
} catch (GeneralSecurityException e) {
e.printStackTrace(); // TODO handle e
} catch (IOException e) {
e.printStackTrace();
}
}
// Close the notification that the authentication is running
NotificationManagerCompat.from(this).cancel(req.getNotificationID());
Expand Down Expand Up @@ -280,7 +286,13 @@ public void handleAuthError(int statusCode, Token token) {
private void saveIfAppNotRunning() {
//if (isRunningInBackground()) {
if (util != null) {
util.saveTokens(tokenlist);
try {
util.saveTokens(tokenlist);
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) { // TODO handle e
e.printStackTrace();
}
}
//}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,6 @@ public SecretKeyWrapper(Context context)
mPair = new KeyPair(publicKey, privateKey);*/
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static void generateKeyPair(Context context)
throws GeneralSecurityException {
final Calendar start = new GregorianCalendar();
final Calendar end = new GregorianCalendar();
end.add(Calendar.YEAR, 100);
final KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
final KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
.setAlias("settings")
.setSubject(new X500Principal("CN=" + "settings"))
.setSerialNumber(BigInteger.ONE)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
gen.initialize(spec);
gen.generateKeyPair();
}

/**
* Wrap a {@link SecretKey} using the public key assigned to this wrapper.
* Use {@link #unwrap(byte[])} to later recover the original
Expand Down
Loading

0 comments on commit 587c74e

Please sign in to comment.