Ejemplo n.º 1
0
def application(environ, start_response):
    status = '200 OK'
    with statsd.timer('services.verify'):

        data = environ['wsgi.input'].read()
        try:
            addon_id = id_re.search(environ['PATH_INFO']).group('addon_id')
        except AttributeError:
            output = ''
            log_info({'receipt': '%s...' % data[:10], 'addon': 'empty'},
                     'Wrong url %s' % environ['PATH_INFO'][:20])
            start_response('500 Internal Server Error', [])
            return [output]

        try:
            verify = Verify(addon_id, data, environ)
            output = verify()
            start_response(status, verify.get_headers(len(output)))
            receipt_cef.log(environ, addon_id, 'verify',
                            'Receipt verification')
        except:
            output = ''
            log_exception({'receipt': '%s...' % data[:10], 'addon': addon_id})
            receipt_cef.log(environ, addon_id, 'verify',
                            'Receipt verification error')
            start_response('500 Internal Server Error', [])

    return [output]
Ejemplo n.º 2
0
def issue(request, addon):
    user = request.user
    review = acl.action_allowed_user(user, 'Apps', 'Review') if user else None
    developer = addon.has_author(user)
    if not (review or developer):
        raise PermissionDenied

    install, flavour = ((apps.INSTALL_TYPE_REVIEWER, 'reviewer') if review else
                        (apps.INSTALL_TYPE_DEVELOPER, 'developer'))
    installed, c = Installed.objects.safer_get_or_create(addon=addon,
                                                         user=request.user,
                                                         install_type=install)

    error = ''
    receipt_cef.log(request, addon, 'sign', 'Receipt signing for %s' % flavour)
    receipt = None
    try:
        receipt = create_receipt(addon,
                                 user,
                                 get_uuid(addon, user),
                                 flavour=flavour)
    except SigningError:
        error = _('There was a problem installing the app.')

    return {'addon': addon.pk, 'receipt': receipt, 'error': error}
Ejemplo n.º 3
0
def application(environ, start_response):
    status = '200 OK'
    with statsd.timer('services.verify'):

        data = environ['wsgi.input'].read()
        try:
            addon_id = id_re.search(environ['PATH_INFO']).group('addon_id')
        except AttributeError:
            output = ''
            log_info({
                'receipt': '%s...' % data[:10],
                'addon': 'empty'
            }, 'Wrong url %s' % environ['PATH_INFO'][:20])
            start_response('500 Internal Server Error', [])
            return [output]

        try:
            verify = Verify(addon_id, data, environ)
            output = verify()
            start_response(status, verify.get_headers(len(output)))
            receipt_cef.log(environ, addon_id, 'verify',
                            'Receipt verification')
        except:
            output = ''
            log_exception({'receipt': '%s...' % data[:10], 'addon': addon_id})
            receipt_cef.log(environ, addon_id, 'verify',
                            'Receipt verification error')
            start_response('500 Internal Server Error', [])

    return [output]
Ejemplo n.º 4
0
def application(environ, start_response):
    status = "200 OK"
    with statsd.timer("services.verify"):

        data = environ["wsgi.input"].read()
        try:
            addon_id = id_re.search(environ["PATH_INFO"]).group("addon_id")
        except AttributeError:
            output = ""
            log_info({"receipt": "%s..." % data[:10], "addon": "empty"}, "Wrong url %s" % environ["PATH_INFO"][:20])
            start_response("500 Internal Server Error", [])
            return [output]

        try:
            verify = Verify(addon_id, data, environ)
            output = verify()
            start_response(status, verify.get_headers(len(output)))
            receipt_cef.log(environ, addon_id, "verify", "Receipt verification")
        except:
            output = ""
            log_exception({"receipt": "%s..." % data[:10], "addon": addon_id})
            receipt_cef.log(environ, addon_id, "verify", "Receipt verification error")
            start_response("500 Internal Server Error", [])

    return [output]
Ejemplo n.º 5
0
 def obj_create(self, bundle, request=None, **kwargs):
     receipt_cef.log(request, None, 'sign', 'Test receipt signing')
     bundle.data = {
         'receipt':
         create_test_receipt(bundle.data['root'],
                             bundle.data['receipt_type'])
     }
     return bundle
Ejemplo n.º 6
0
def test_receipt(request):
    form = forms.TestInstall(request.DATA)
    if not form.is_valid():
        return Response({"error_message": form.errors}, status=400)

    receipt_cef.log(request._request, None, "sign", "Test receipt signing")
    data = {"receipt": create_test_receipt(form.cleaned_data["root"], form.cleaned_data["receipt_type"])}
    return Response(data, status=201)
Ejemplo n.º 7
0
 def refund(self):
     receipt_cef.log(
         self.environ,
         self.get_app_id(raise_exception=False),
         'verify',
         'Refunded receipt'
     )
     return {'status': 'refunded'}
Ejemplo n.º 8
0
 def expired(self, receipt):
     if settings.WEBAPPS_RECEIPT_EXPIRED_SEND:
         receipt['exp'] = (calendar.timegm(gmtime()) +
                           settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS)
         receipt_cef.log(self.environ, self.addon_id, 'sign',
                         'Expired signing request')
         return json.dumps({'status': 'expired', 'receipt': sign(receipt)})
     return json.dumps({'status': 'expired'})
Ejemplo n.º 9
0
 def refund(self):
     receipt_cef.log(
         self.environ,
         self.get_app_id(raise_exception=False),
         'verify',
         'Refunded receipt'
     )
     return {'status': 'refunded'}
Ejemplo n.º 10
0
 def expired(self, receipt):
     if settings.WEBAPPS_RECEIPT_EXPIRED_SEND:
         receipt['exp'] = (calendar.timegm(gmtime()) +
                           settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS)
         receipt_cef.log(self.environ, self.addon_id, 'sign',
                         'Expired signing request')
         return json.dumps({'status': 'expired', 'receipt': sign(receipt)})
     return json.dumps({'status': 'expired'})
Ejemplo n.º 11
0
 def invalid(self, reason=''):
     receipt_cef.log(
         self.environ,
         self.get_app_id(raise_exception=False),
         'verify',
         'Invalid receipt'
     )
     return {'status': 'invalid', 'reason': reason}
Ejemplo n.º 12
0
 def invalid(self, reason=''):
     receipt_cef.log(
         self.environ,
         self.get_app_id(raise_exception=False),
         'verify',
         'Invalid receipt'
     )
     return {'status': 'invalid', 'reason': reason}
Ejemplo n.º 13
0
def _record(request, addon):
    logged = request.user.is_authenticated()
    premium = addon.is_premium()

    # Require login for premium.
    if not logged and premium:
        return http.HttpResponseRedirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged:
        is_dev = request.check_ownership(addon,
                                         require_owner=False,
                                         ignore_disabled=True,
                                         admin=False)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_public() and not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and not addon.has_purchased(request.user)
                and not is_reviewer and not is_dev):
            raise PermissionDenied

        # If you are reviewer, you get a user receipt. Use the reviewer tools
        # to get a reviewer receipt. App developers still get their special
        # receipt.
        install = (apps.INSTALL_TYPE_DEVELOPER
                   if is_dev else apps.INSTALL_TYPE_USER)
        # Log the install.
        installed, c = Installed.objects.get_or_create(addon=addon,
                                                       user=request.user,
                                                       install_type=install)

        # Get a suitable uuid for this receipt.
        uuid = get_uuid(addon, request.user)

        error = ''
        receipt_cef.log(request, addon, 'sign', 'Receipt requested')
        try:
            receipt = create_receipt(addon, request.user, uuid)
        except SigningError:
            error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    record_action(
        'install', request, {
            'app-domain': addon.domain_from_url(addon.origin, allow_none=True),
            'app-id': addon.pk,
            'anonymous': request.user.is_anonymous(),
        })

    return ctx
Ejemplo n.º 14
0
def _record(request, addon):
    logged = request.user.is_authenticated()
    premium = addon.is_premium()

    # Require login for premium.
    if not logged and premium:
        return http.HttpResponseRedirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged:
        is_dev = request.check_ownership(addon, require_owner=False,
                                         ignore_disabled=True, admin=False)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp() or not addon.is_public() and
            not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and
            not addon.has_purchased(request.amo_user) and
            not is_reviewer and not is_dev):
            raise PermissionDenied

        # If you are reviewer, you get a user receipt. Use the reviewer tools
        # to get a reviewer receipt. App developers still get their special
        # receipt.
        install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev
                        else apps.INSTALL_TYPE_USER)
        # Log the install.
        installed, c = Installed.objects.get_or_create(addon=addon,
            user=request.amo_user, install_type=install_type)

        # Get a suitable uuid for this receipt.
        uuid = get_uuid(addon, request.amo_user)

        error = ''
        receipt_cef.log(request, addon, 'sign', 'Receipt requested')
        try:
            receipt = create_receipt(addon, request.amo_user, uuid)
        except SigningError:
            error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    record_action('install', request, {
        'app-domain': addon.domain_from_url(addon.origin, allow_none=True),
        'app-id': addon.pk,
        'anonymous': request.user.is_anonymous(),
    })

    return ctx
Ejemplo n.º 15
0
def install_record(obj, request, install_type):
    # Generate or re-use an existing install record.
    installed, created = Installed.objects.get_or_create(addon=obj, user=request.user, install_type=install_type)

    log.info("Installed record %s: %s" % ("created" if created else "re-used", obj.pk))

    log.info("Creating receipt: %s" % obj.pk)
    receipt_cef.log(request._request, obj, "sign", "Receipt signing")
    uuid = get_uuid(installed.addon, installed.user)
    return create_receipt(installed.addon, installed.user, uuid)
Ejemplo n.º 16
0
 def expired(self):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Expired receipt')
     if settings.WEBAPPS_RECEIPT_EXPIRED_SEND:
         self.decoded['exp'] = (calendar.timegm(gmtime()) +
                                settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS)
         # Log that we are signing a new receipt as well.
         receipt_cef.log(self.environ, self.addon_id, 'sign',
                         'Expired signing request')
         return {'status': 'expired', 'receipt': sign(self.decoded)}
     return {'status': 'expired'}
Ejemplo n.º 17
0
def install_record(obj, request, install_type):
    # Generate or re-use an existing install record.
    installed, created = Installed.objects.get_or_create(
        addon=obj, user=request.user.get_profile(), install_type=install_type)

    log.info('Installed record %s: %s' %
             ('created' if created else 're-used', obj.pk))

    log.info('Creating receipt: %s' % obj.pk)
    receipt_cef.log(request._request, obj, 'sign', 'Receipt signing')
    return create_receipt(installed)
Ejemplo n.º 18
0
    def record(self, bundle, request, install_type):
        # Generate or re-use an existing install record.
        installed, created = Installed.objects.get_or_create(
            addon=bundle.obj, user=request.user.get_profile(), install_type=install_type
        )

        log.info("Installed record %s: %s" % ("created" if created else "re-used", bundle.obj.pk))

        log.info("Creating receipt: %s" % bundle.obj.pk)
        receipt_cef.log(request, bundle.obj, "sign", "Receipt signing")
        return create_receipt(installed)
Ejemplo n.º 19
0
def test_receipt(request):
    form = forms.TestInstall(request.DATA)
    if not form.is_valid():
        return Response({'error_message': form.errors}, status=400)

    receipt_cef.log(request._request, None, 'sign', 'Test receipt signing')
    data = {
        'receipt': create_test_receipt(form.cleaned_data['root'],
                                       form.cleaned_data['receipt_type'])
    }
    return Response(data, status=201)
Ejemplo n.º 20
0
def test_receipt(request):
    form = TestInstall(request.DATA)
    if not form.is_valid():
        return Response({'error_message': form.errors}, status=400)

    receipt_cef.log(request._request, None, 'sign', 'Test receipt signing')
    data = {
        'receipt': create_test_receipt(form.cleaned_data['root'],
                                       form.cleaned_data['receipt_type'])
    }
    return Response(data, status=201)
Ejemplo n.º 21
0
 def expired(self):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Expired receipt')
     if settings.WEBAPPS_RECEIPT_EXPIRED_SEND:
         self.decoded['exp'] = (calendar.timegm(gmtime()) +
                                settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS)
         # Log that we are signing a new receipt as well.
         receipt_cef.log(self.environ, self.addon_id, 'sign',
                         'Expired signing request')
         return {'status': 'expired',
                 'receipt': sign(self.decoded)}
     return {'status': 'expired'}
Ejemplo n.º 22
0
def _record(request, addon):
    # TODO(andym): simplify this.
    logged = request.user.is_authenticated()
    premium = addon.is_premium()
    allow_anon_install = waffle.switch_is_active('anonymous-free-installs')

    # Require login for premium.
    if not logged and (premium or not allow_anon_install):
        return redirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged or not allow_anon_install:
        is_dev = request.check_ownership(addon,
                                         require_owner=False,
                                         ignore_disabled=True)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp()
                or not addon.is_public() and not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and not addon.has_purchased(request.amo_user)
                and not is_reviewer and not is_dev):
            return http.HttpResponseForbidden()

        installed, c = Installed.objects.safer_get_or_create(
            addon=addon, user=request.amo_user)
        # Look up to see if its in the receipt cache and log if we have
        # to recreate it.
        receipt = memoize_get('create-receipt', installed.pk)
        error = ''
        receipt_cef.log(request, addon, 'request', 'Receipt requested')
        if not receipt:
            receipt_cef.log(request, addon, 'sign', 'Receipt signing')
            try:
                receipt = create_receipt(installed.pk)
            except SigningError:
                error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    send_request('install', request, {
        'app-domain': addon.domain_from_url(addon.origin),
        'app-id': addon.pk
    })

    return ctx
Ejemplo n.º 23
0
def _record(request, addon):
    # TODO(andym): simplify this.
    logged = request.user.is_authenticated()
    premium = addon.is_premium()
    allow_anon_install = waffle.switch_is_active('anonymous-free-installs')

    # Require login for premium.
    if not logged and (premium or not allow_anon_install):
        return redirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged or not allow_anon_install:
        is_dev = request.check_ownership(addon, require_owner=False,
                                     ignore_disabled=True)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp() or not addon.is_public() and
            not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and
            not addon.has_purchased(request.amo_user) and
            not is_reviewer and not is_dev):
            return http.HttpResponseForbidden()

        installed, c = Installed.objects.safer_get_or_create(addon=addon,
            user=request.amo_user)
        # Look up to see if its in the receipt cache and log if we have
        # to recreate it.
        receipt = memoize_get('create-receipt', installed.pk)
        error = ''
        receipt_cef.log(request, addon, 'request', 'Receipt requested')
        if not receipt:
            receipt_cef.log(request, addon, 'sign', 'Receipt signing')
            try:
                receipt = create_receipt(installed.pk)
            except SigningError:
                error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    send_request('install', request, {
        'app-domain': addon.domain_from_url(addon.origin),
        'app-id': addon.pk
    })

    return ctx
Ejemplo n.º 24
0
def test_receipt(request):
    form = forms.TestInstall(request.POST)
    if form.is_valid():
        receipt_type = form.cleaned_data['receipt_type']

        if receipt_type == 'none':
            return {'receipt': '', 'error': ''}

        receipt_cef.log(request, None, 'sign', 'Test receipt signing')
        receipt = create_test_receipt(form.root, receipt_type)
        return {'receipt': receipt, 'error': ''}

    return {'receipt': '', 'error': form.errors}
Ejemplo n.º 25
0
def devhub_receipt(request):
    form = forms.TestInstall(request.POST)
    if form.is_valid():
        data = form.cleaned_data

        if data["receipt_type"] == "none":
            return {"receipt": "", "error": ""}

        receipt_cef.log(request, None, "sign", "Test receipt signing")
        receipt = create_test_receipt(data["root"], data["receipt_type"])
        return {"receipt": receipt, "error": ""}

    return {"receipt": "", "error": form.errors}
Ejemplo n.º 26
0
    def record(self, bundle, request, install_type):
        # Generate or re-use an existing install record.
        installed, created = Installed.objects.get_or_create(
            addon=bundle.obj, user=request.user.get_profile(),
            install_type=install_type)

        log.info('Installed record %s: %s' % (
            'created' if created else 're-used',
            bundle.obj.pk))

        log.info('Creating receipt: %s' % bundle.obj.pk)
        receipt_cef.log(request, bundle.obj, 'sign', 'Receipt signing')
        return create_receipt(installed)
Ejemplo n.º 27
0
def test_receipt(request):
    form = forms.TestInstall(request.POST)
    if form.is_valid():
        receipt_type = form.cleaned_data['receipt_type']

        if receipt_type == 'none':
            return {'receipt': '', 'error': ''}

        receipt_cef.log(request, None, 'sign', 'Test receipt signing')
        receipt = create_test_receipt(form.root, receipt_type)
        return {'receipt': receipt, 'error': ''}

    return {'receipt': '', 'error': form.errors}
Ejemplo n.º 28
0
def devhub_receipt(request):
    form = forms.TestInstall(request.POST)
    if form.is_valid():
        data = form.cleaned_data

        if data['receipt_type'] == 'none':
            return {'receipt': '', 'error': ''}

        receipt_cef.log(request, None, 'sign', 'Test receipt signing')
        receipt = create_test_receipt(data['root'], data['receipt_type'])
        return {'receipt': receipt, 'error': ''}

    return {'receipt': '', 'error': form.errors}
Ejemplo n.º 29
0
Archivo: api.py Proyecto: flyun/zamboni
    def record(self, bundle, request, install_type):
        # Generate or re-use an existing install record.
        installed, created = Installed.objects.safer_get_or_create(
            addon=bundle.obj, user=request.user.get_profile(),
            install_type=install_type)

        # Generate or re-use a recent receipt.
        receipt_cef.log(request, bundle.obj, 'request', 'Receipt requested')
        receipt = memoize_get('create-receipt', installed.pk)
        if receipt:
            return receipt

        receipt_cef.log(request, bundle.obj, 'sign', 'Receipt signing')
        return create_receipt(installed.pk)
Ejemplo n.º 30
0
def install_record(obj, request, install_type):
    # Generate or re-use an existing install record.
    installed, created = Installed.objects.get_or_create(
        addon=obj, user=request.user,
        install_type=install_type)

    log.info('Installed record %s: %s' % (
        'created' if created else 're-used',
        obj.pk))

    log.info('Creating receipt: %s' % obj.pk)
    receipt_cef.log(request._request, obj, 'sign', 'Receipt signing')
    uuid = get_uuid(installed.addon, installed.user)
    return create_receipt(installed.addon, installed.user, uuid)
Ejemplo n.º 31
0
    def record(self, bundle, request, install_type):
        # Generate or re-use an existing install record.
        installed, created = Installed.objects.safer_get_or_create(
            addon=bundle.obj,
            user=request.user.get_profile(),
            install_type=install_type)

        # Generate or re-use a recent receipt.
        receipt_cef.log(request, bundle.obj, 'request', 'Receipt requested')
        receipt = memoize_get('create-receipt', installed.pk)
        if receipt:
            return receipt

        receipt_cef.log(request, bundle.obj, 'sign', 'Receipt signing')
        return create_receipt(installed.pk)
Ejemplo n.º 32
0
def issue(request, addon):
    user = request.amo_user
    review = acl.action_allowed_user(user, "Apps", "Review") if user else None
    developer = addon.has_author(user)
    if not (review or developer):
        raise PermissionDenied

    installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.amo_user)
    error = ""
    flavour = "reviewer" if review else "developer"
    receipt_cef.log(request, addon, "sign", "Receipt signing for %s" % flavour)
    try:
        receipt = create_receipt(installed.pk, flavour=flavour)
    except SigningError:
        error = _("There was a problem installing the app.")

    return {"addon": addon.pk, "receipt": receipt, "error": error}
Ejemplo n.º 33
0
def reissue(request):
    """
    Reissues an existing receipt, provided from the client. Will only do
    so if the receipt is a full receipt and expired.
    """
    raw = request.read()
    verify = Verify(raw, request.META)
    output = verify.check_full()

    # We will only re-sign expired receipts.
    if output["status"] != "expired":
        log.info("Receipt not expired returned: {0}".format(output))
        receipt_cef.log(request._request, None, "sign", "Receipt reissue failed")
        output["receipt"] = ""
        return Response(output, status=400)

    receipt_cef.log(request._request, None, "sign", "Receipt reissue signing")
    return Response({"reason": "", "receipt": reissue_receipt(raw), "status": "expired"})
Ejemplo n.º 34
0
def issue(request, addon):
    user = request.amo_user
    review = acl.action_allowed_user(user, 'Apps', 'Review') if user else None
    developer = addon.has_author(user)
    if not (review or developer):
        return http.HttpResponseForbidden()

    installed, c = Installed.objects.safer_get_or_create(addon=addon,
                                                         user=request.amo_user)
    error = ''
    flavour = 'reviewer' if review else 'developer'
    receipt_cef.log(request, addon, 'sign', 'Receipt signing for %s' % flavour)
    try:
        receipt = create_receipt(installed.pk, flavour=flavour)
    except SigningError:
        error = _('There was a problem installing the app.')

    return {'addon': addon.pk, 'receipt': receipt, 'error': error}
Ejemplo n.º 35
0
def issue(request, addon):
    user = request.amo_user
    review = acl.action_allowed_user(user, 'Apps', 'Review') if user else None
    author = addon.has_author(user)
    if not user or not (review or author):
        return http.HttpResponseForbidden()

    installed, c = Installed.objects.safer_get_or_create(addon=addon,
                                                         user=request.amo_user)
    error = ''
    flavour = 'reviewer' if review else 'developer'
    receipt_cef.log(request, addon, 'sign', 'Receipt signing for %s' % flavour)
    try:
        receipt = create_receipt(installed.pk, flavour=flavour)
    except SigningError:
        error = _('There was a problem installing the app.')

    return {'addon': addon.pk, 'receipt': receipt, 'error': error}
Ejemplo n.º 36
0
def reissue(request):
    """
    Reissues an existing receipt, provided from the client. Will only do
    so if the receipt is a full receipt and expired.
    """
    raw = request.read()
    verify = Verify(raw, request.META)
    output = verify.check_full()

    # We will only re-sign expired receipts.
    if output['status'] != 'expired':
        log.info('Receipt not expired returned: {0}'.format(output))
        receipt_cef.log(request._request, None, 'sign',
                        'Receipt reissue failed')
        output['receipt'] = ''
        return Response(output, status=400)

    receipt_cef.log(request._request, None, 'sign', 'Receipt reissue signing')
    return Response({'reason': '', 'receipt': reissue_receipt(raw),
                     'status': 'expired'})
Ejemplo n.º 37
0
def reissue(request):
    """
    Reissues an existing receipt, provided from the client. Will only do
    so if the receipt is a full receipt and expired.
    """
    raw = request.read()
    verify = Verify(raw, request.META)
    output = verify.check_full()

    # We will only re-sign expired receipts.
    if output['status'] != 'expired':
        log.info('Receipt not expired returned: {0}'.format(output))
        receipt_cef.log(request._request, None, 'sign',
                        'Receipt reissue failed')
        output['receipt'] = ''
        return Response(output, status=400)

    receipt_cef.log(request._request, None, 'sign', 'Receipt reissue signing')
    return Response({'reason': '', 'receipt': reissue_receipt(raw),
                     'status': 'expired'})
Ejemplo n.º 38
0
def issue(request, addon):
    user = request.amo_user
    review = acl.action_allowed_user(user, 'Apps', 'Review') if user else None
    developer = addon.has_author(user)
    if not (review or developer):
        raise PermissionDenied

    install, flavour = ((apps.INSTALL_TYPE_REVIEWER, 'reviewer') if review
                        else (apps.INSTALL_TYPE_DEVELOPER, 'developer'))
    installed, c = Installed.objects.safer_get_or_create(addon=addon,
        user=request.amo_user, install_type=install)

    error = ''
    receipt_cef.log(request, addon, 'sign', 'Receipt signing for %s' % flavour)
    receipt = None
    try:
        receipt = create_receipt(installed.pk, flavour=flavour)
    except SigningError:
        error = _('There was a problem installing the app.')

    return {'addon': addon.pk, 'receipt': receipt, 'error': error}
Ejemplo n.º 39
0
def issue(request, addon):
    user = request.user
    review = acl.action_allowed_user(user, "Apps", "Review") if user else None
    developer = addon.has_author(user)
    if not (review or developer):
        raise PermissionDenied

    install, flavour = (
        (apps.INSTALL_TYPE_REVIEWER, "reviewer") if review else (apps.INSTALL_TYPE_DEVELOPER, "developer")
    )
    installed, c = Installed.objects.safer_get_or_create(addon=addon, user=request.user, install_type=install)

    error = ""
    receipt_cef.log(request, addon, "sign", "Receipt signing for %s" % flavour)
    receipt = None
    try:
        receipt = create_receipt(addon, user, get_uuid(addon, user), flavour=flavour)
    except SigningError:
        error = _("There was a problem installing the app.")

    return {"addon": addon.pk, "receipt": receipt, "error": error}
Ejemplo n.º 40
0
 def refund(self):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Refunded receipt')
     return {'status': 'refunded'}
Ejemplo n.º 41
0
 def invalid(self, reason=''):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Invalid receipt')
     return {'status': 'invalid', 'reason': reason}
Ejemplo n.º 42
0
 def obj_create(self, bundle, request=None, **kwargs):
     receipt_cef.log(request, None, "sign", "Test receipt signing")
     bundle.data = {"receipt": create_test_receipt(bundle.data["root"], bundle.data["receipt_type"])}
     return bundle
Ejemplo n.º 43
0
 def refund(self):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Refunded receipt')
     return {'status': 'refunded'}
Ejemplo n.º 44
0
 def obj_create(self, bundle, request=None, **kwargs):
     receipt_cef.log(request, None, 'sign', 'Test receipt signing')
     bundle.data = {'receipt': create_test_receipt(
         bundle.data['root'], bundle.data['receipt_type'])}
     return bundle
Ejemplo n.º 45
0
def _record(request, addon):
    # TODO(andym): we have an API now, replace this with that.
    logged = request.user.is_authenticated()
    premium = addon.is_premium()

    # Require login for premium.
    if not logged and premium:
        return http.HttpResponseRedirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged:
        is_dev = request.check_ownership(addon,
                                         require_owner=False,
                                         ignore_disabled=True,
                                         admin=False)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp()
                or not addon.is_public() and not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and not addon.has_purchased(request.amo_user)
                and not is_reviewer and not is_dev):
            raise PermissionDenied

        # If you are reviewer, you get a user receipt. Use the reviewer tools
        # to get a reviewer receipt. App developers still get their special
        # receipt.
        install_type = (apps.INSTALL_TYPE_DEVELOPER
                        if is_dev else apps.INSTALL_TYPE_USER)
        # Log the install.
        installed, c = Installed.objects.safer_get_or_create(
            addon=addon, user=request.amo_user, install_type=install_type)

        # Get download source from GET if it exists, if so get the download
        # source object if it exists. Then grab a client data object to hook up
        # with the Installed object.
        download_source = DownloadSource.objects.filter(
            name=request.REQUEST.get('src', None))
        download_source = download_source[0] if download_source else None
        try:
            region = request.REGION.id
        except AttributeError:
            region = mkt.regions.WORLDWIDE.id
        client_data, c = ClientData.objects.get_or_create(
            download_source=download_source,
            device_type=request.POST.get('device_type', ''),
            user_agent=request.META.get('HTTP_USER_AGENT', ''),
            is_chromeless=request.POST.get('chromeless', False),
            language=request.LANG,
            region=region)
        installed.update(client_data=client_data)

        # Look up to see if its in the receipt cache and log if we have
        # to recreate it.
        receipt = memoize_get('create-receipt', installed.pk)
        error = ''
        receipt_cef.log(request, addon, 'request', 'Receipt requested')
        if not receipt:
            receipt_cef.log(request, addon, 'sign', 'Receipt signing')
            try:
                receipt = create_receipt(installed.pk)
            except SigningError:
                error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    record_action(
        'install', request, {
            'app-domain': addon.domain_from_url(addon.origin),
            'app-id': addon.pk,
            'anonymous': request.user.is_anonymous(),
        })

    return ctx
Ejemplo n.º 46
0
 def invalid(self, reason=''):
     receipt_cef.log(self.environ, self.addon_id, 'verify',
                     'Invalid receipt')
     return {'status': 'invalid', 'reason': reason}
Ejemplo n.º 47
0
def _record(request, addon):
    # TODO(andym): simplify this.
    logged = request.user.is_authenticated()
    premium = addon.is_premium()
    allow_anon_install = waffle.switch_is_active('anonymous-free-installs')

    # Require login for premium.
    if not logged and (premium or not allow_anon_install):
        return redirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged or not allow_anon_install:
        is_dev = request.check_ownership(addon, require_owner=False,
                                     ignore_disabled=True)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp() or not addon.is_public() and
            not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and
            not addon.has_purchased(request.amo_user) and
            not is_reviewer and not is_dev):
            return http.HttpResponseForbidden()

        # Log the install.
        installed, c = Installed.objects.safer_get_or_create(addon=addon,
            user=request.amo_user)

        # Get download source from GET if it exists, if so get the download
        # source object if it exists. Then grab a client data object to hook up
        # with the Installed object.
        download_source = DownloadSource.objects.filter(
            name=request.REQUEST.get('src', None))
        download_source = download_source[0] if download_source else None
        try:
            region = request.REGION.id
        except AttributeError:
            region = mkt.regions.WORLDWIDE.id
        client_data, c = ClientData.objects.get_or_create(
            download_source=download_source,
            device_type=request.POST.get('device_type', ''),
            user_agent=request.META.get('HTTP_USER_AGENT', ''),
            is_chromeless=request.POST.get('chromeless', False),
            language=request.LANG,
            region=region)
        installed.update(client_data=client_data)

        # Look up to see if its in the receipt cache and log if we have
        # to recreate it.
        receipt = memoize_get('create-receipt', installed.pk)
        error = ''
        receipt_cef.log(request, addon, 'request', 'Receipt requested')
        if not receipt:
            receipt_cef.log(request, addon, 'sign', 'Receipt signing')
            try:
                receipt = create_receipt(installed.pk)
            except SigningError:
                error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    send_request('install', request, {
        'app-domain': addon.domain_from_url(addon.origin),
        'app-id': addon.pk
    })

    return ctx
Ejemplo n.º 48
0
def _record(request, addon):
    # TODO(andym): we have an API now, replace this with that.
    logged = request.user.is_authenticated()
    premium = addon.is_premium()

    # Require login for premium.
    if not logged and premium:
        return http.HttpResponseRedirect(reverse('users.login'))

    ctx = {'addon': addon.pk}

    # Don't generate receipts if we're allowing logged-out install.
    if logged:
        is_dev = request.check_ownership(addon, require_owner=False,
                                         ignore_disabled=True, admin=False)
        is_reviewer = acl.check_reviewer(request)
        if (not addon.is_webapp() or not addon.is_public() and
            not (is_reviewer or is_dev)):
            raise http.Http404

        if (premium and
            not addon.has_purchased(request.amo_user) and
            not is_reviewer and not is_dev):
            raise PermissionDenied

        # If you are reviewer, you get a user receipt. Use the reviewer tools
        # to get a reviewer receipt. App developers still get their special
        # receipt.
        install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev
                        else apps.INSTALL_TYPE_USER)
        # Log the install.
        installed, c = Installed.objects.get_or_create(addon=addon,
            user=request.amo_user, install_type=install_type)

        # Get download source from GET if it exists, if so get the download
        # source object if it exists. Then grab a client data object to hook up
        # with the Installed object.
        download_source = DownloadSource.objects.filter(
            name=request.REQUEST.get('src', None))
        download_source = download_source[0] if download_source else None
        try:
            region = request.REGION.id
        except AttributeError:
            region = mkt.regions.WORLDWIDE.id
        client_data, c = ClientData.objects.get_or_create(
            download_source=download_source,
            device_type=request.POST.get('device_type', ''),
            user_agent=request.META.get('HTTP_USER_AGENT', ''),
            is_chromeless=request.POST.get('chromeless', False),
            language=request.LANG,
            region=region)
        installed.update(client_data=client_data)

        error = ''
        receipt_cef.log(request, addon, 'sign', 'Receipt requested')
        try:
            receipt = create_receipt(installed)
        except SigningError:
            error = _('There was a problem installing the app.')

        ctx.update(receipt=receipt, error=error)
    else:
        if not addon.is_public() or not addon.is_webapp():
            raise http.Http404

    amo.log(amo.LOG.INSTALL_ADDON, addon)
    record_action('install', request, {
        'app-domain': addon.domain_from_url(addon.origin, allow_none=True),
        'app-id': addon.pk,
        'anonymous': request.user.is_anonymous(),
    })

    return ctx