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