Package: django-dreiattest
django-dreiattestdreiattest leveragespyttestand integrates it into django. It handles routing, different config options and persistence of tokens and public keys. To use dreiAttest you need to use the corresponing libraries foriOSandAndroid / Kotlin Multiplatform.InstallationdreiAttest is available on PyPI and can be installed via$ python -m pip install dreiattest-django.After the installation make sure to adddreiattestto yourINSTALLED_APPSand trigger all migrations
withpython manage.py migrate dreiattest. Also, you need to register the default endpoints in your urls.pyurlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('dreiattest.urls')),
    ...
]ConfigThere are multiple settings you can and or have to set in your settings.py. The following are mandatory:Apple:DREIATTEST_APPLE_APPIDGoogle (Legacy: Safety Net):DREIATTEST_GOOGLE_APK_NAME,DREIATTEST_GOOGLE_APK_CERTIFICATE_DIGESTGoogle Play Integrity API:DREIATTEST_GOOGLE_APK_NAME,DREIATTEST_GOOGLE_DECRYPTION_KEY,DREIATTEST_GOOGLE_VERIFICATION_KEYThese are all the possible config values and what they do.DREIATTEST_BASE_URL: Our different endpoints like /key and /nonce will be bellow this slugDREIATTEST_UID_HEADER: Header containing the DeviceSession uidDREIATTEST_ASSERTION_HEADER: Header containing the assertionDREIATTEST_USER_HEADERS_HEADER: Header containing the list of comma separated headers that are included in the assertionDREIATTEST_NONCE_HEADER: Header containing the server nonce that was used inside the attestationDREIATTEST_BYPASS_HEADER: Header containing the shared secret to bypass the verification process. Helpfull for debuggingDREIATTEST_APPLE_APPID: Header containing the apple app idDREIATTEST_GOOGLE_APK_NAME: Header containing the google apk nameDREIATTEST_GOOGLE_DECRYPTION_KEY: A Base64 encoded AES key secret as describedhereDREIATTEST_GOOGLE_VERIFICATION_KEY: A Base64 encoded public key as describedhereDREIATTEST_PRODUCTION: Indicating if we're in a production environment or not. Some extra verifications are made if this is true. Those are described in thepyttestreadme.DREIATTEST_GOOGLE_APK_CERTIFICATE_DIGEST: SHA256 hex of the Google APK CertificateDREIATTEST_PLUGINS: List of classes implementingBasePlugin- gives you the option to handle extra verificationDREIATTEST_BYPASS_SECRET:DANGERZONEIf this is set and DREIATTEST_BYPASS_HEADER is sent by the client, the veirification is skipped.You can find the default value (if any) for each of them in thesettings.pyUsageAll that's left is to add thesignature_requiredview decorator.fromdreiattest.decoratorsimportsignature_required@signature_required()defdemo(request:WSGIRequest):returnJsonResponse({'foo':'bar'})Error HandlingThe main two exceptions that should be handled by you arePyAttestExceptionandDreiAttestException. dreiattest ships with theHandleDreiattestExceptionsMiddlewareyou could use if you don't want to handle those errors by yourself. The middleware only catches those two exception classes and returns aJsonResponsewith status code 400.MIDDLEWARE = [
    ...
    'dreiattest.middlewares.HandleDreiattestExceptionsMiddleware',
]Typical FlowCLIENT (could be android or google) makes a request to dreiattest/nonce with a device session identifier to obtain a server nonce. The session id as well as the nonce are persisted on the server.CLIENT sends an attestation to dreiattest/key. This request again holds the device session identifier as well as the nonce from step 1. The nonce will be marked as "used" and used to verify the attestation. The public key from the client is then assigned to the device session and also persisted in the database.CLIENT sends a request to any view decorated with@signature_required. The request holds an assertion which will be verified before the actual django view is executed.Publishing / ContributingCreate a branch frommasterfor possible pull requestsTo publish a new version to pypi:Update the version in__version__.pyTrigger$ pipenv run upload- This will automatically create and push the correct tag in git and upload that version to pypi