Search in sources :

Example 1 with ReceiptCredentialPresentation

use of org.signal.zkgroup.receipts.ReceiptCredentialPresentation in project Signal-Android by WhisperSystems.

the class SubscriptionReceiptRequestResponseJob method doRun.

private void doRun() throws Exception {
    ActiveSubscription.Subscription subscription = getLatestSubscriptionInformation();
    if (subscription == null) {
        Log.w(TAG, "Subscription is null.", true);
        throw new RetryableException();
    } else if (subscription.isFailedPayment()) {
        Log.w(TAG, "Subscription payment failure in active subscription response (status = " + subscription.getStatus() + ").", true);
        onPaymentFailure(subscription.getStatus());
        throw new Exception("Subscription has a payment failure: " + subscription.getStatus());
    } else if (!subscription.isActive()) {
        Log.w(TAG, "Subscription is not yet active. Status: " + subscription.getStatus(), true);
        throw new RetryableException();
    } else {
        Log.i(TAG, "Recording end of period from active subscription.", true);
        SignalStore.donationsValues().setLastEndOfPeriod(subscription.getEndOfCurrentPeriod());
        MultiDeviceSubscriptionSyncRequestJob.enqueue();
    }
    Log.d(TAG, "Submitting receipt credential request.");
    ServiceResponse<ReceiptCredentialResponse> response = ApplicationDependencies.getDonationsService().submitReceiptCredentialRequest(subscriberId, requestContext.getRequest()).blockingGet();
    if (response.getApplicationError().isPresent()) {
        handleApplicationError(response);
    } else if (response.getResult().isPresent()) {
        ReceiptCredential receiptCredential = getReceiptCredential(response.getResult().get());
        if (!isCredentialValid(subscription, receiptCredential)) {
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(getErrorSource()));
            throw new IOException("Could not validate receipt credential");
        }
        Log.d(TAG, "Validated credential. Handing off to redemption job.", true);
        ReceiptCredentialPresentation receiptCredentialPresentation = getReceiptCredentialPresentation(receiptCredential);
        setOutputData(new Data.Builder().putBlobAsString(DonationReceiptRedemptionJob.INPUT_RECEIPT_CREDENTIAL_PRESENTATION, receiptCredentialPresentation.serialize()).build());
    } else {
        Log.w(TAG, "Encountered a retryable exception: " + response.getStatus(), response.getExecutionError().orNull(), true);
        throw new RetryableException();
    }
}
Also used : ReceiptCredential(org.signal.zkgroup.receipts.ReceiptCredential) ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) IOException(java.io.IOException) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) IOException(java.io.IOException) InvalidInputException(org.signal.zkgroup.InvalidInputException)

Example 2 with ReceiptCredentialPresentation

use of org.signal.zkgroup.receipts.ReceiptCredentialPresentation in project Signal-Android by signalapp.

the class SubscriptionReceiptRequestResponseJob method doRun.

private void doRun() throws Exception {
    ActiveSubscription.Subscription subscription = getLatestSubscriptionInformation();
    if (subscription == null) {
        Log.w(TAG, "Subscription is null.", true);
        throw new RetryableException();
    } else if (subscription.isFailedPayment()) {
        Log.w(TAG, "Subscription payment failure in active subscription response (status = " + subscription.getStatus() + ").", true);
        onPaymentFailure(subscription.getStatus());
        throw new Exception("Subscription has a payment failure: " + subscription.getStatus());
    } else if (!subscription.isActive()) {
        Log.w(TAG, "Subscription is not yet active. Status: " + subscription.getStatus(), true);
        throw new RetryableException();
    } else {
        Log.i(TAG, "Recording end of period from active subscription.", true);
        SignalStore.donationsValues().setLastEndOfPeriod(subscription.getEndOfCurrentPeriod());
        MultiDeviceSubscriptionSyncRequestJob.enqueue();
    }
    Log.d(TAG, "Submitting receipt credential request.");
    ServiceResponse<ReceiptCredentialResponse> response = ApplicationDependencies.getDonationsService().submitReceiptCredentialRequest(subscriberId, requestContext.getRequest()).blockingGet();
    if (response.getApplicationError().isPresent()) {
        handleApplicationError(response);
    } else if (response.getResult().isPresent()) {
        ReceiptCredential receiptCredential = getReceiptCredential(response.getResult().get());
        if (!isCredentialValid(subscription, receiptCredential)) {
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(getErrorSource()));
            throw new IOException("Could not validate receipt credential");
        }
        Log.d(TAG, "Validated credential. Handing off to redemption job.", true);
        ReceiptCredentialPresentation receiptCredentialPresentation = getReceiptCredentialPresentation(receiptCredential);
        setOutputData(new Data.Builder().putBlobAsString(DonationReceiptRedemptionJob.INPUT_RECEIPT_CREDENTIAL_PRESENTATION, receiptCredentialPresentation.serialize()).build());
    } else {
        Log.w(TAG, "Encountered a retryable exception: " + response.getStatus(), response.getExecutionError().orNull(), true);
        throw new RetryableException();
    }
}
Also used : ReceiptCredential(org.signal.zkgroup.receipts.ReceiptCredential) ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) IOException(java.io.IOException) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) IOException(java.io.IOException) InvalidInputException(org.signal.zkgroup.InvalidInputException)

Example 3 with ReceiptCredentialPresentation

use of org.signal.zkgroup.receipts.ReceiptCredentialPresentation in project Signal-Android by WhisperSystems.

the class DonationReceiptRedemptionJob method onRun.

@Override
protected void onRun() throws Exception {
    Data inputData = getInputData();
    if (inputData == null) {
        Log.w(TAG, "No input data. Exiting.", null, true);
        return;
    }
    byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
    if (presentationBytes == null) {
        Log.d(TAG, "No response data. Exiting.", null, true);
        return;
    }
    ReceiptCredentialPresentation presentation = new ReceiptCredentialPresentation(presentationBytes);
    Log.d(TAG, "Attempting to redeem token... isForSubscription: " + isForSubscription(), true);
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().redeemReceipt(presentation, SignalStore.donationsValues().getDisplayBadgesOnProfile(), false).blockingGet();
    if (response.getApplicationError().isPresent()) {
        if (response.getStatus() >= 500) {
            Log.w(TAG, "Encountered a server exception " + response.getStatus(), response.getApplicationError().get(), true);
            throw new RetryableException();
        } else {
            Log.w(TAG, "Encountered a non-recoverable exception " + response.getStatus(), response.getApplicationError().get(), true);
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(errorSource));
            throw new IOException(response.getApplicationError().get());
        }
    } else if (response.getExecutionError().isPresent()) {
        Log.w(TAG, "Encountered a retryable exception", response.getExecutionError().get(), true);
        throw new RetryableException();
    }
    Log.i(TAG, "Successfully redeemed token with response code " + response.getStatus() + "... isForSubscription: " + isForSubscription(), true);
    if (isForSubscription()) {
        Log.d(TAG, "Clearing subscription failure", true);
        SignalStore.donationsValues().clearSubscriptionRedemptionFailed();
    }
}
Also used : ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) Data(org.thoughtcrime.securesms.jobmanager.Data) IOException(java.io.IOException) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Example 4 with ReceiptCredentialPresentation

use of org.signal.zkgroup.receipts.ReceiptCredentialPresentation in project Signal-Android by WhisperSystems.

the class BoostReceiptRequestResponseJob method onRun.

@Override
protected void onRun() throws Exception {
    if (requestContext == null) {
        Log.d(TAG, "Creating request context..");
        SecureRandom secureRandom = new SecureRandom();
        byte[] randomBytes = new byte[ReceiptSerial.SIZE];
        secureRandom.nextBytes(randomBytes);
        ReceiptSerial receiptSerial = new ReceiptSerial(randomBytes);
        ClientZkReceiptOperations operations = ApplicationDependencies.getClientZkReceiptOperations();
        requestContext = operations.createReceiptCredentialRequestContext(secureRandom, receiptSerial);
    } else {
        Log.d(TAG, "Reusing request context from previous run", true);
    }
    Log.d(TAG, "Submitting credential to server", true);
    ServiceResponse<ReceiptCredentialResponse> response = ApplicationDependencies.getDonationsService().submitBoostReceiptCredentialRequest(paymentIntentId, requestContext.getRequest()).blockingGet();
    if (response.getApplicationError().isPresent()) {
        handleApplicationError(context, response);
    } else if (response.getResult().isPresent()) {
        ReceiptCredential receiptCredential = getReceiptCredential(response.getResult().get());
        if (!isCredentialValid(receiptCredential)) {
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(DonationErrorSource.BOOST));
            throw new IOException("Could not validate receipt credential");
        }
        Log.d(TAG, "Validated credential. Handing off to redemption job.", true);
        ReceiptCredentialPresentation receiptCredentialPresentation = getReceiptCredentialPresentation(receiptCredential);
        setOutputData(new Data.Builder().putBlobAsString(DonationReceiptRedemptionJob.INPUT_RECEIPT_CREDENTIAL_PRESENTATION, receiptCredentialPresentation.serialize()).build());
    } else {
        Log.w(TAG, "Encountered a retryable exception: " + response.getStatus(), response.getExecutionError().orNull(), true);
        throw new RetryableException();
    }
}
Also used : ReceiptCredential(org.signal.zkgroup.receipts.ReceiptCredential) ReceiptSerial(org.signal.zkgroup.receipts.ReceiptSerial) ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) ClientZkReceiptOperations(org.signal.zkgroup.receipts.ClientZkReceiptOperations) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException)

Example 5 with ReceiptCredentialPresentation

use of org.signal.zkgroup.receipts.ReceiptCredentialPresentation in project Signal-Android by signalapp.

the class DonationReceiptRedemptionJob method onRun.

@Override
protected void onRun() throws Exception {
    Data inputData = getInputData();
    if (inputData == null) {
        Log.w(TAG, "No input data. Exiting.", null, true);
        return;
    }
    byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
    if (presentationBytes == null) {
        Log.d(TAG, "No response data. Exiting.", null, true);
        return;
    }
    ReceiptCredentialPresentation presentation = new ReceiptCredentialPresentation(presentationBytes);
    Log.d(TAG, "Attempting to redeem token... isForSubscription: " + isForSubscription(), true);
    ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().redeemReceipt(presentation, SignalStore.donationsValues().getDisplayBadgesOnProfile(), false).blockingGet();
    if (response.getApplicationError().isPresent()) {
        if (response.getStatus() >= 500) {
            Log.w(TAG, "Encountered a server exception " + response.getStatus(), response.getApplicationError().get(), true);
            throw new RetryableException();
        } else {
            Log.w(TAG, "Encountered a non-recoverable exception " + response.getStatus(), response.getApplicationError().get(), true);
            DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(errorSource));
            throw new IOException(response.getApplicationError().get());
        }
    } else if (response.getExecutionError().isPresent()) {
        Log.w(TAG, "Encountered a retryable exception", response.getExecutionError().get(), true);
        throw new RetryableException();
    }
    Log.i(TAG, "Successfully redeemed token with response code " + response.getStatus() + "... isForSubscription: " + isForSubscription(), true);
    if (isForSubscription()) {
        Log.d(TAG, "Clearing subscription failure", true);
        SignalStore.donationsValues().clearSubscriptionRedemptionFailed();
    }
}
Also used : ReceiptCredentialPresentation(org.signal.zkgroup.receipts.ReceiptCredentialPresentation) Data(org.thoughtcrime.securesms.jobmanager.Data) IOException(java.io.IOException) EmptyResponse(org.whispersystems.signalservice.internal.EmptyResponse)

Aggregations

IOException (java.io.IOException)6 ReceiptCredentialPresentation (org.signal.zkgroup.receipts.ReceiptCredentialPresentation)6 ReceiptCredential (org.signal.zkgroup.receipts.ReceiptCredential)4 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)4 SecureRandom (java.security.SecureRandom)2 InvalidInputException (org.signal.zkgroup.InvalidInputException)2 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)2 ClientZkReceiptOperations (org.signal.zkgroup.receipts.ClientZkReceiptOperations)2 ReceiptSerial (org.signal.zkgroup.receipts.ReceiptSerial)2 Data (org.thoughtcrime.securesms.jobmanager.Data)2 ActiveSubscription (org.whispersystems.signalservice.api.subscriptions.ActiveSubscription)2 EmptyResponse (org.whispersystems.signalservice.internal.EmptyResponse)2