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.
2021-04-07 13:44:56 +00:00
|
|
|
import ecdsa
|
|
|
|
from ecdsa import SigningKey
|
|
|
|
from base64 import urlsafe_b64encode
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
2021-04-07 14:26:13 +00:00
|
|
|
from djangoldp_webpushnotification.models import VAPIDKeyset
|
2021-04-07 13:44:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Generate VAPID key pair"
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
priv_key = SigningKey.generate(curve=ecdsa.NIST256p)
|
|
|
|
|
2021-04-07 14:26:13 +00:00
|
|
|
VAPIDKeyset.objects.create(
|
|
|
|
private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=")
|
|
|
|
)
|
2021-04-07 13:44:56 +00:00
|
|
|
|
2021-04-07 14:26:13 +00:00
|
|
|
self.stdout.write("VAPID Keyset succesfully generated")
|
2021-04-07 13:44:56 +00:00
|
|
|
|
2021-04-07 14:26:13 +00:00
|
|
|
exit(0)
|