Skip to content

Commit 0fda5ad

Browse files
authored
Merge pull request #584 from AzureAD/release/0.0.15
Merge Release/0.0.15 to master
2 parents 95deb5e + 2a8f55c commit 0fda5ad

4 files changed

Lines changed: 57 additions & 11 deletions

File tree

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 0.0.15
2+
-------------
3+
- Bug Fix : Adding null safety check to avoid crash on EmbeddedWebViewStrategy
4+
15
Version 0.0.14
26
-------------
37
- Bug fix : Read user id from the request bundle for broker silent request.

common/src/main/java/com/microsoft/identity/common/adal/internal/cache/StorageHelper.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import android.annotation.SuppressLint;
2626
import android.annotation.TargetApi;
2727
import android.content.Context;
28+
import android.content.SharedPreferences;
2829
import android.os.Build;
30+
import android.preference.PreferenceManager;
2931
import android.security.KeyPairGeneratorSpec;
3032
import android.support.annotation.NonNull;
3133
import android.support.annotation.Nullable;
@@ -119,6 +121,8 @@ public class StorageHelper implements IStorageHelper {
119121

120122
private static final String HMAC_ALGORITHM = "HmacSHA256";
121123

124+
private static final String CURRENT_ACTIVE_BROKER = "current_active_broker";
125+
122126
private static final int KEY_SIZE = 256;
123127

124128
/**
@@ -295,13 +299,10 @@ public String decrypt(final String encryptedBlob) throws GeneralSecurityExceptio
295299
}
296300

297301
String result = decryptWithSecretKey(bytes, secretKey);
298-
Logger.verbose(TAG + methodName, "Finished decryption.");
302+
Logger.verbose(TAG + methodName, "Finished decryption with keyType:" + keyType.name());
299303
return result;
300304
} catch (GeneralSecurityException | IOException e) {
301-
logEvent(methodName,
302-
AuthenticationConstants.TelemetryEvents.DECRYPTION_ERROR,
303-
true,
304-
"failed to decrypt with keyType:" + keyType.name() + " exception: " + e.toString());
305+
emitDecryptionFailureTelemetryIfNeeded(keyType, e);
305306
}
306307
}
307308

@@ -312,6 +313,36 @@ public String decrypt(final String encryptedBlob) throws GeneralSecurityExceptio
312313
throw new GeneralSecurityException(ErrorStrings.DECRYPTION_FAILED);
313314
}
314315

316+
// This is to make sure that Decryption error failure is only emitted once - to avoid bombarding ARIA.
317+
private void emitDecryptionFailureTelemetryIfNeeded(@NonNull final KeyType keyType,
318+
@NonNull final Exception exception) {
319+
final String methodName = ":emitDecryptionFailureTelemetryIfNeeded";
320+
final SharedPreferences sharedPreferences = PreferenceManager.
321+
getDefaultSharedPreferences(mContext);
322+
final String previousActiveBroker = sharedPreferences.getString(
323+
CURRENT_ACTIVE_BROKER,
324+
""
325+
);
326+
final String activeBroker = mContext.getPackageName();
327+
328+
if (!previousActiveBroker.equalsIgnoreCase(activeBroker)) {
329+
final String message = "Decryption failed with key: " + keyType.name()
330+
+ " Active broker: " + activeBroker
331+
+ " Exception: " + exception.toString();
332+
333+
Logger.info(TAG + methodName, message);
334+
335+
if (mTelemetryCallback != null) {
336+
mTelemetryCallback.logEvent(mContext,
337+
AuthenticationConstants.TelemetryEvents.DECRYPTION_ERROR,
338+
true,
339+
message);
340+
}
341+
342+
sharedPreferences.edit().putString(CURRENT_ACTIVE_BROKER, activeBroker).apply();
343+
}
344+
}
345+
315346
/**
316347
* Determine type of encryption performed on the given data blob.
317348
* NOTE: If it cannot verify the keyVersion, it will assume that this data is not encrypted.
@@ -524,8 +555,6 @@ protected void setBlobVersion(@NonNull String blobVersion) {
524555
public SecretKey loadSecretKey(@NonNull final KeyType keyType) throws IOException, GeneralSecurityException {
525556
final String methodName = ":loadSecretKey";
526557

527-
Logger.verbose(TAG + methodName, "Loading key with Type:" + keyType.name());
528-
529558
switch (keyType) {
530559
case LEGACY_AUTHENTICATOR_APP_KEY:
531560
return getSecretKey(AuthenticationSettings.INSTANCE.getBrokerSecretKeys().get(AZURE_AUTHENTICATOR_APP_PACKAGE_NAME));

common/src/main/java/com/microsoft/identity/common/internal/ui/webview/EmbeddedWebViewAuthorizationStrategy.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package com.microsoft.identity.common.internal.ui.webview;
2424

2525
import android.app.Activity;
26-
import android.app.PendingIntent;
2726
import android.content.Intent;
2827
import android.net.Uri;
2928
import android.support.annotation.NonNull;
@@ -88,8 +87,22 @@ public Future<AuthorizationResult> requestAuthorization(GenericAuthorizationRequ
8887
@Override
8988
public void completeAuthorization(int requestCode, int resultCode, Intent data) {
9089
if (requestCode == BROWSER_FLOW) {
91-
final AuthorizationResult result = mOAuth2Strategy.getAuthorizationResultFactory().createAuthorizationResult(resultCode, data, mAuthorizationRequest);
92-
mAuthorizationResultFuture.setResult(result);
90+
if (mOAuth2Strategy != null && mAuthorizationResultFuture != null) {
91+
final AuthorizationResult result = mOAuth2Strategy
92+
.getAuthorizationResultFactory()
93+
.createAuthorizationResult(
94+
resultCode,
95+
data,
96+
mAuthorizationRequest
97+
);
98+
mAuthorizationResultFuture.setResult(result);
99+
} else {
100+
Logger.warn(TAG, "SDK Cancel triggering before request is sent out. " +
101+
"Potentially due to an stale activity state, " +
102+
"oAuth2Strategy null ? [" + (mOAuth2Strategy == null) + "]" +
103+
"mAuthorizationResultFuture ? [" + (mAuthorizationResultFuture == null) + "]"
104+
);
105+
}
93106
} else {
94107
Logger.warnPII(TAG, "Unknown request code " + requestCode);
95108
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#Thu Aug 02 12:03:16 PDT 2018
2-
versionName=0.0.14
2+
versionName=0.0.15
33
versionCode=1

0 commit comments

Comments
 (0)