Revision 479c3051 snf-cyclades-app/synnefo/ui/userdata/views.py
b/snf-cyclades-app/synnefo/ui/userdata/views.py | ||
---|---|---|
33 | 33 |
# or implied, of GRNET S.A. |
34 | 34 |
|
35 | 35 |
from django import http |
36 |
from django.template import RequestContext, loader |
|
37 | 36 |
from django.utils import simplejson as json |
38 | 37 |
from django.conf import settings |
39 | 38 |
|
... | ... | |
51 | 50 |
|
52 | 51 |
import base64 |
53 | 52 |
|
53 |
|
|
54 | 54 |
class PublicKeyPairResourceView(rest.UserResourceView): |
55 | 55 |
model = PublicKeyPair |
56 | 56 |
exclude_fields = ["user"] |
57 | 57 |
|
58 |
|
|
58 | 59 |
class PublicKeyPairCollectionView(rest.UserCollectionView): |
59 | 60 |
model = PublicKeyPair |
60 | 61 |
exclude_fields = ["user"] |
61 | 62 |
|
63 |
|
|
62 | 64 |
SSH_KEY_LENGTH = getattr(settings, 'USERDATA_SSH_KEY_LENGTH', 2048) |
65 |
|
|
66 |
|
|
63 | 67 |
def generate_key_pair(request): |
64 | 68 |
""" |
65 | 69 |
Response to generate private/public RSA key pair |
... | ... | |
74 | 78 |
raise Exception("Application does not support ssh keys generation") |
75 | 79 |
|
76 | 80 |
if PublicKeyPair.user_limit_exceeded(request.user): |
77 |
raise http.HttpResponseServerError("SSH keys limit exceeded"); |
|
78 |
|
|
81 |
raise http.HttpResponseServerError("SSH keys limit exceeded") |
|
79 | 82 |
|
80 | 83 |
# generate RSA key |
81 | 84 |
from Crypto import Random |
82 | 85 |
Random.atfork() |
83 | 86 |
|
84 |
key = rsakey.RSA.generate(SSH_KEY_LENGTH);
|
|
87 |
key = rsakey.RSA.generate(SSH_KEY_LENGTH) |
|
85 | 88 |
|
86 | 89 |
# get PEM string |
87 | 90 |
pem = exportKey(key, 'PEM') |
... | ... | |
97 | 100 |
data = {'private': pem, 'public': public} |
98 | 101 |
return http.HttpResponse(json.dumps(data), mimetype="application/json") |
99 | 102 |
|
103 |
|
|
100 | 104 |
def download_private_key(request): |
101 | 105 |
""" |
102 | 106 |
Return key contents |
... | ... | |
108 | 112 |
response['Content-Disposition'] = 'attachment; filename=%s' % name |
109 | 113 |
response.write(data) |
110 | 114 |
return response |
111 |
|
Also available in: Unified diff