use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class PushUtils method verifySignature.
public SignatureVerification verifySignature(Context context, byte[] signatureBytes, byte[] subjectBytes) {
Signature signature = null;
PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false);
Account[] accounts = AccountUtils.getAccounts(context);
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
String arbitraryValue;
Gson gson = new Gson();
PushConfigurationState pushArbitraryData;
try {
signature = Signature.getInstance("SHA512withRSA");
if (accounts.length > 0) {
for (Account account : accounts) {
if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
pushArbitraryData = gson.fromJson(arbitraryValue, PushConfigurationState.class);
if (!pushArbitraryData.isShouldBeDeleted()) {
publicKey = (PublicKey) readKeyFromString(true, pushArbitraryData.getUserPublicKey());
signature.initVerify(publicKey);
signature.update(subjectBytes);
if (signature.verify(signatureBytes)) {
signatureVerification.setSignatureValid(true);
signatureVerification.setAccount(account);
return signatureVerification;
}
}
}
}
}
} catch (NoSuchAlgorithmException e) {
Log.d(TAG, "No such algorithm");
} catch (InvalidKeyException e) {
Log.d(TAG, "Invalid key while trying to verify");
} catch (SignatureException e) {
Log.d(TAG, "Signature exception while trying to verify");
}
return signatureVerification;
}
Aggregations