This repository has been archived on 2021-04-21. You can view files and clone it, but cannot push or open issues or pull requests.
djangoldp-webpushnotification/djangoldp_webpushnotification/management/commands/gen_vapid_key.py

22 lines
522 B
Python

import ecdsa
from ecdsa import SigningKey
from base64 import urlsafe_b64encode
from django.core.management.base import BaseCommand
from djangoldp_webpushnotification.models import VAPIDKeyset
class Command(BaseCommand):
help = "Generate VAPID key pair"
def handle(self, *args, **options):
priv_key = SigningKey.generate(curve=ecdsa.NIST256p)
VAPIDKeyset.objects.create(
private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=")
)
self.stdout.write("VAPID Keyset succesfully generated")
exit(0)