use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class RawKeyAccessor method sign.
@Override
public byte[] sign(@NonNull final byte[] text) throws ClientException {
final String errCode;
final Exception exception;
try {
final SecretKeySpec key = new SecretKeySpec(this.key, suite.cipher().name());
Mac mac = Mac.getInstance(suite.macName());
mac.init(key);
return mac.doFinal(text);
} catch (final NoSuchAlgorithmException e) {
errCode = NO_SUCH_ALGORITHM;
exception = e;
} catch (final InvalidKeyException e) {
errCode = INVALID_KEY;
exception = e;
}
throw new ClientException(errCode, exception.getMessage());
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class RawKeyAccessor method decrypt.
@Override
public byte[] decrypt(@NonNull final byte[] ciphertext) throws ClientException {
final String errCode;
final Exception exception;
try {
final SecretKeySpec key = new SecretKeySpec(this.key, suite.cipher().name());
final Cipher c = Cipher.getInstance(key.getAlgorithm());
final IvParameterSpec ivSpec = new IvParameterSpec(ciphertext, 0, 12);
c.init(Cipher.DECRYPT_MODE, key, ivSpec);
byte[] out = Arrays.copyOfRange(ciphertext, 12, ciphertext.length);
return c.doFinal(out);
} catch (final NoSuchAlgorithmException e) {
errCode = NO_SUCH_ALGORITHM;
exception = e;
} catch (final NoSuchPaddingException e) {
errCode = NO_SUCH_PADDING;
exception = e;
} catch (final IllegalBlockSizeException e) {
errCode = INVALID_BLOCK_SIZE;
exception = e;
} catch (final BadPaddingException e) {
errCode = BAD_PADDING;
exception = e;
} catch (final InvalidKeyException e) {
errCode = INVALID_KEY;
exception = e;
} catch (final InvalidAlgorithmParameterException e) {
errCode = INVALID_ALG_PARAMETER;
exception = e;
}
throw new ClientException(errCode, exception.getMessage(), exception);
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class RawKeyAccessor method getThumprint.
@Override
public byte[] getThumprint() throws ClientException {
final SecretKey keySpec = new SecretKeySpec(key, suite.cipher().name());
final Cipher cipher;
final String errCode;
final Exception exception;
try {
cipher = Cipher.getInstance(keySpec.getAlgorithm());
final MessageDigest digest = MessageDigest.getInstance("SHA256");
return digest.digest(cipher.doFinal((keySpec.getAlgorithm() + cipher.getBlockSize() + cipher.getParameters()).getBytes(UTF8)));
} catch (final NoSuchAlgorithmException e) {
errCode = NO_SUCH_ALGORITHM;
exception = e;
} catch (final NoSuchPaddingException e) {
errCode = NO_SUCH_PADDING;
exception = e;
} catch (final BadPaddingException e) {
errCode = BAD_PADDING;
exception = e;
} catch (final IllegalBlockSizeException e) {
errCode = INVALID_BLOCK_SIZE;
exception = e;
}
throw new ClientException(errCode, exception.getMessage(), exception);
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrowserAuthorizationFragment method onResume.
@Override
public void onResume() {
super.onResume();
// This check is needed when using customTabs or browser flow.
if (!mBrowserFlowStarted) {
mBrowserFlowStarted = true;
if (mAuthIntent != null) {
// We cannot start browser activity inside OnCreate().
// Because the life cycle of the current activity will continue and onResume will be called before finishing the login in browser.
// This is by design of Android OS.
startActivity(mAuthIntent);
} else {
final Intent resultIntent = new Intent();
resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_AUTHENTICATION_EXCEPTION, new ClientException(ErrorStrings.AUTHORIZATION_INTENT_IS_NULL));
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_AUTHENTICATION_EXCEPTION, resultIntent);
finish();
}
} else {
if (!StringUtil.isEmpty(sCustomTabResponseUri)) {
completeAuthorizationInBrowserFlow(sCustomTabResponseUri);
} else {
cancelAuthorization(true);
}
sCustomTabResponseUri = null;
}
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class CurrentTaskBrowserAuthorizationFragment method onResume.
@Override
public void onResume() {
super.onResume();
if (mResponseReceived) {
// The custom tab was closed without getting a result.
finish();
}
// This check is needed when using customTabs or browser flow.
if (!mBrowserFlowStarted) {
mBrowserFlowStarted = true;
if (mAuthIntent != null) {
// We cannot start browser activity inside OnCreate().
// Because the life cycle of the current activity will continue and onResume will be called before finishing the login in browser.
// This is by design of Android OS.
startActivity(mAuthIntent);
} else {
final Intent resultIntent = new Intent();
resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_AUTHENTICATION_EXCEPTION, new ClientException(ErrorStrings.AUTHORIZATION_INTENT_IS_NULL));
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_AUTHENTICATION_EXCEPTION, resultIntent);
finish();
}
} else {
cancelAuthorization(true);
}
}
Aggregations