use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class DevicePopManager method getAsymmetricKeyThumbprint.
@Override
public String getAsymmetricKeyThumbprint() throws ClientException {
final Exception exception;
final String errCode;
try {
final KeyStore.PrivateKeyEntry entry = mKeyManager.getEntry();
return getRsaThumbprint(entry);
} catch (final KeyStoreException e) {
exception = e;
errCode = KEYSTORE_NOT_INITIALIZED;
} catch (final NoSuchAlgorithmException e) {
exception = e;
errCode = NO_SUCH_ALGORITHM;
} catch (final UnrecoverableEntryException e) {
exception = e;
errCode = INVALID_PROTECTION_PARAMS;
} catch (final JOSEException e) {
exception = e;
errCode = THUMBPRINT_COMPUTATION_FAILURE;
}
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 DevicePopManager method getRequestConfirmation.
@Override
public void getRequestConfirmation(@NonNull final TaskCompletedCallbackWithError<String, ClientException> callback) {
sThreadExecutor.submit(new Runnable() {
@Override
public void run() {
// Vars for error handling...
final Exception exception;
final String errCode;
try {
final KeyStore.PrivateKeyEntry keyEntry = mKeyManager.getEntry();
final KeyPair rsaKeyPair = getKeyPairForEntry(keyEntry);
final RSAKey rsaKey = getRsaKeyForKeyPair(rsaKeyPair);
final String base64UrlEncodedJwkJsonStr = getReqCnfForRsaKey(rsaKey);
callback.onTaskCompleted(base64UrlEncodedJwkJsonStr);
// We're done.
return;
} catch (final KeyStoreException e) {
exception = e;
errCode = KEYSTORE_NOT_INITIALIZED;
} catch (final NoSuchAlgorithmException e) {
exception = e;
errCode = NO_SUCH_ALGORITHM;
} catch (final UnrecoverableEntryException e) {
exception = e;
errCode = INVALID_PROTECTION_PARAMS;
} catch (final JOSEException e) {
exception = e;
errCode = THUMBPRINT_COMPUTATION_FAILURE;
} catch (final JSONException e) {
exception = e;
errCode = JSON_CONSTRUCTION_FAILED;
}
final ClientException clientException = new ClientException(errCode, exception.getMessage(), exception);
Logger.error(TAG, clientException.getMessage(), clientException);
callback.onError(clientException);
}
});
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class DevicePopManager method getJwkPublicKey.
@NonNull
private String getJwkPublicKey() throws ClientException {
final Exception exception;
final String errCode;
try {
final Map<String, Object> jwkMap = getDevicePopJwkMinifiedJson();
return GSON.toJson(jwkMap.get(SignedHttpRequestJwtClaims.JWK), MAP_STRING_STRING_TYPE);
} catch (final UnrecoverableEntryException e) {
exception = e;
errCode = INVALID_PROTECTION_PARAMS;
} catch (final NoSuchAlgorithmException e) {
exception = e;
errCode = NO_SUCH_ALGORITHM;
} catch (final KeyStoreException e) {
exception = e;
errCode = KEYSTORE_NOT_INITIALIZED;
}
final ClientException clientException = new ClientException(errCode, exception.getMessage(), exception);
Logger.error(TAG, clientException.getMessage(), clientException);
throw clientException;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class DevicePopManager method sign.
@Override
public byte[] sign(@NonNull SigningAlgorithm alg, @NonNull final byte[] inputBytesToSign) throws ClientException {
Exception exception;
String errCode;
final String methodName = ":sign";
try {
final KeyStore.Entry keyEntry = mKeyManager.getEntry();
if (!(keyEntry instanceof KeyStore.PrivateKeyEntry)) {
Logger.warn(TAG + methodName, PRIVATE_KEY_NOT_FOUND);
throw new ClientException(INVALID_KEY_MISSING);
}
final Signature signature = Signature.getInstance(alg.toString());
signature.initSign(((KeyStore.PrivateKeyEntry) keyEntry).getPrivateKey());
signature.update(inputBytesToSign);
return signature.sign();
} catch (final KeyStoreException e) {
exception = e;
errCode = KEYSTORE_NOT_INITIALIZED;
} catch (final NoSuchAlgorithmException e) {
exception = e;
errCode = NO_SUCH_ALGORITHM;
} catch (final UnrecoverableEntryException e) {
exception = e;
errCode = INVALID_PROTECTION_PARAMS;
} catch (final InvalidKeyException e) {
exception = e;
errCode = INVALID_KEY;
} catch (final SignatureException e) {
exception = e;
errCode = SIGNING_FAILURE;
}
final ClientException clientException = new ClientException(errCode, exception.getMessage(), exception);
Logger.error(TAG + methodName, clientException.getMessage(), clientException);
throw clientException;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class DevicePopManager method decrypt.
@Override
public byte[] decrypt(@NonNull Cipher cipher, byte[] ciphertext) throws ClientException {
String errCode;
Exception exception;
final String methodName = ":decrypt";
try {
// Load our key material
final KeyStore.PrivateKeyEntry privateKeyEntry = mKeyManager.getEntry();
// Get a reference to our private key (will not be loaded into app process)
final PrivateKey privateKey = privateKeyEntry.getPrivateKey();
// Init our cipher instance, don't use a named provider as there seems to be a mix of
// BoringSSL & AndroidOpenSSL
// https://issuetracker.google.com/issues/37091211
final javax.crypto.Cipher outputCipher = javax.crypto.Cipher.getInstance(cipher.toString());
if (cipher.getParameters() != null) {
outputCipher.init(javax.crypto.Cipher.DECRYPT_MODE, privateKey, cipher.getParameters());
} else {
outputCipher.init(javax.crypto.Cipher.DECRYPT_MODE, privateKey);
}
return outputCipher.doFinal(ciphertext);
} catch (final NoSuchAlgorithmException e) {
errCode = NO_SUCH_ALGORITHM;
exception = e;
} catch (final InvalidKeyException e) {
errCode = INVALID_KEY;
exception = e;
} catch (final UnrecoverableEntryException e) {
errCode = INVALID_PROTECTION_PARAMS;
exception = e;
} catch (final NoSuchPaddingException e) {
errCode = NO_SUCH_ALGORITHM;
exception = e;
} catch (final KeyStoreException e) {
errCode = KEYSTORE_NOT_INITIALIZED;
exception = e;
} catch (final BadPaddingException e) {
errCode = BAD_PADDING;
exception = e;
} catch (final IllegalBlockSizeException e) {
errCode = INVALID_BLOCK_SIZE;
exception = e;
} catch (final InvalidAlgorithmParameterException e) {
errCode = INVALID_ALG_PARAMETER;
exception = e;
}
final ClientException clientException = new ClientException(errCode, exception.getMessage(), exception);
Logger.error(TAG + methodName, errCode, exception);
throw clientException;
}
Aggregations