From b585beb94245c72400effa840c7e5a31103c04f8 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 16 Jan 2024 10:25:26 +0100 Subject: [PATCH] test with apple official package --- subscriptions/views.py | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/subscriptions/views.py b/subscriptions/views.py index e5dad7c..fcaca56 100644 --- a/subscriptions/views.py +++ b/subscriptions/views.py @@ -4,6 +4,9 @@ from django.views.decorators.csrf import csrf_exempt from .models import ASSNotification from django.conf import settings +from appstoreserverlibrary.models.Environment import Environment +from appstoreserverlibrary.signed_data_verifier import VerificationException, SignedDataVerifier + import json, jwt import base64 # import os @@ -26,20 +29,43 @@ def app_store_webhook(request): decoded = request.body.decode('utf-8') # Parse the JSON payload - #fulljson = json.loads(data) - # signedPayload = fulljson['signedPayload'] + fulljson = json.loads(data) + signedPayload = fulljson['signedPayload'] + + root_certificates = load_root_certificates() + enable_online_checks = True + bundle_id = "stax.SlashPoker.nosebleed" + environment = Environment.SANDBOX + signed_data_verifier = SignedDataVerifier(root_certificates, enable_online_checks, environment, bundle_id) try: - data = asn2.parse(decoded) - type = data['notificationType'] + signed_notification = "ey.." + payload = signed_data_verifier.verify_and_decode_notification(signedPayload) + print(payload) notification = ASSNotification( - content=type, + content=payload, ) notification.save() - except InvalidTokenError: - pass + + except VerificationException as e: + print(e) + + + + + # try: + # data = asn2.parse(decoded) + # type = data['notificationType'] + # + # notification = ASSNotification( + # content=type, + # ) + # notification.save() + # + # except InvalidTokenError: + # pass # KEY_FILE = settings.ASS_KEY_FILE #