Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c14af483
authored
Jun 30, 2014
by
Scott Duckworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
methods to export keys in openssh or rfc4716 format
parent
1c2d5cd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
django_sshkey/models.py
+34
-0
No files found.
django_sshkey/models.py
View file @
c14af483
...
@@ -31,6 +31,27 @@ from django.contrib.auth.models import User
...
@@ -31,6 +31,27 @@ from django.contrib.auth.models import User
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django_sshkey.util
import
SSHKeyFormatError
,
key_parse
from
django_sshkey.util
import
SSHKeyFormatError
,
key_parse
def
wrap
(
text
,
width
,
end
=
None
):
n
=
0
t
=
''
if
end
is
None
:
while
n
<
len
(
text
):
m
=
n
+
width
t
+=
text
[
n
:
m
]
if
len
(
text
)
<=
m
:
return
t
t
+=
'
\n
'
n
=
m
else
:
while
n
<
len
(
text
):
m
=
n
+
width
if
len
(
text
)
<=
m
:
return
t
+
text
[
n
:
m
]
m
-=
len
(
end
)
t
+=
text
[
n
:
m
]
+
end
+
'
\n
'
n
=
m
return
t
class
UserKey
(
models
.
Model
):
class
UserKey
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
blank
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
blank
=
True
)
...
@@ -85,3 +106,16 @@ class UserKey(models.Model):
...
@@ -85,3 +106,16 @@ class UserKey(models.Model):
raise
ValidationError
({
'key'
:
[
message
]})
raise
ValidationError
({
'key'
:
[
message
]})
except
type
(
self
)
.
DoesNotExist
:
except
type
(
self
)
.
DoesNotExist
:
pass
pass
def
export_openssh
(
self
):
return
self
.
key
.
encode
(
'utf-8'
)
def
export_rfc4716
(
self
):
info
=
key_parse
(
self
.
key
)
out
=
b
'---- BEGIN SSH2 PUBLIC KEY ----
\n
'
if
info
.
comment
:
comment
=
'Comment: "
%
s"'
%
info
.
comment
out
+=
wrap
(
comment
,
72
,
'
\\
'
)
.
encode
(
'ascii'
)
+
b
'
\n
'
out
+=
wrap
(
info
.
b64key
,
72
)
.
encode
(
'ascii'
)
+
b
'
\n
'
out
+=
b
'---- END SSH2 PUBLIC KEY ----'
return
out
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment