2016-10-03 15:54:54 +00:00
|
|
|
from Cryptodome.PublicKey import RSA
|
2016-01-25 20:52:24 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2015-07-13 18:49:08 +00:00
|
|
|
|
2016-01-25 20:52:24 +00:00
|
|
|
from oidc_provider.models import RSAKey
|
2015-07-13 18:49:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Randomly generate a new RSA key for the OpenID server'
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
try:
|
|
|
|
key = RSA.generate(1024)
|
2016-01-25 20:52:24 +00:00
|
|
|
rsakey = RSAKey(key=key.exportKey('PEM').decode('utf8'))
|
|
|
|
rsakey.save()
|
|
|
|
self.stdout.write(u'RSA key successfully created with kid: {0}'.format(rsakey.kid))
|
2015-07-13 18:49:08 +00:00
|
|
|
except Exception as e:
|
2015-10-17 21:06:41 +00:00
|
|
|
self.stdout.write('Something goes wrong: {0}'.format(e))
|