ssh-keys: allow generation of legacy keys for older systems and windows.
This commit is contained in:
parent
82dddbb8b2
commit
3b5d294eac
4 changed files with 19 additions and 5 deletions
|
|
@ -872,7 +872,10 @@ class UsersView(UserAppView):
|
|||
|
||||
c.active = 'ssh_keys_generate'
|
||||
comment = 'RhodeCode-SSH {}'.format(c.user.email or '')
|
||||
c.private, c.public = SshKeyModel().generate_keypair(comment=comment)
|
||||
private_format = self.request.GET.get('private_format') \
|
||||
or SshKeyModel.DEFAULT_PRIVATE_KEY_FORMAT
|
||||
c.private, c.public = SshKeyModel().generate_keypair(
|
||||
comment=comment, private_format=private_format)
|
||||
|
||||
return self._get_template_context(c)
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,11 @@ class MyAccountSshKeysView(BaseAppView, DataGridAppView):
|
|||
|
||||
c.active = 'ssh_keys_generate'
|
||||
if c.ssh_key_generator_enabled:
|
||||
private_format = self.request.GET.get('private_format') \
|
||||
or SshKeyModel.DEFAULT_PRIVATE_KEY_FORMAT
|
||||
comment = 'RhodeCode-SSH {}'.format(c.user.email or '')
|
||||
c.private, c.public = SshKeyModel().generate_keypair(comment=comment)
|
||||
c.private, c.public = SshKeyModel().generate_keypair(
|
||||
comment=comment, private_format=private_format)
|
||||
c.target_form_url = h.route_path(
|
||||
'my_account_ssh_keys', _query=dict(default_key=c.public))
|
||||
return self._get_template_context(c)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ log = logging.getLogger(__name__)
|
|||
|
||||
class SshKeyModel(BaseModel):
|
||||
cls = UserSshKeys
|
||||
DEFAULT_PRIVATE_KEY_FORMAT = 'pkcs8'
|
||||
|
||||
def parse_key(self, key_data):
|
||||
"""
|
||||
|
|
@ -66,16 +67,23 @@ class SshKeyModel(BaseModel):
|
|||
log.error("Key Parse error: %s", err)
|
||||
raise
|
||||
|
||||
def generate_keypair(self, comment=None):
|
||||
def generate_keypair(self, comment=None, private_format=DEFAULT_PRIVATE_KEY_FORMAT):
|
||||
|
||||
key = rsa.generate_private_key(
|
||||
backend=crypto_default_backend(),
|
||||
public_exponent=65537,
|
||||
key_size=2048
|
||||
)
|
||||
if private_format == self.DEFAULT_PRIVATE_KEY_FORMAT:
|
||||
private_format = crypto_serialization.PrivateFormat.PKCS8
|
||||
else:
|
||||
# legacy format that can be used by older systems, use if pkcs8 have
|
||||
# problems
|
||||
private_format = crypto_serialization.PrivateFormat.TraditionalOpenSSL
|
||||
|
||||
private_key = key.private_bytes(
|
||||
crypto_serialization.Encoding.PEM,
|
||||
crypto_serialization.PrivateFormat.PKCS8,
|
||||
private_format,
|
||||
crypto_serialization.NoEncryption())
|
||||
public_key = key.public_key().public_bytes(
|
||||
crypto_serialization.Encoding.OpenSSH,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<div class="panel-body">
|
||||
%if c.ssh_enabled and c.ssh_key_generator_enabled:
|
||||
<p>
|
||||
${_('Below is a 2048 bit generated SSH RSA key.')}<br/>
|
||||
${_('Below is a 2048 bit generated SSH RSA key.')}<br/>${_('If you use older systems please try to generate a')} <a href="${h.current_route_path(request, private_format='legacy')}">${_('legacy format')}</a> ssh key.<br/>
|
||||
${_('If You wish to use it to access RhodeCode via the SSH please save the private key and click `Use this generated key` at the bottom.')}
|
||||
</p>
|
||||
<h4>${_('Private key')}</h4>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue