Show More
@@ -872,7 +872,10 b' class UsersView(UserAppView):' | |||
|
872 | 872 | |
|
873 | 873 | c.active = 'ssh_keys_generate' |
|
874 | 874 | comment = 'RhodeCode-SSH {}'.format(c.user.email or '') |
|
875 | c.private, c.public = SshKeyModel().generate_keypair(comment=comment) | |
|
875 | private_format = self.request.GET.get('private_format') \ | |
|
876 | or SshKeyModel.DEFAULT_PRIVATE_KEY_FORMAT | |
|
877 | c.private, c.public = SshKeyModel().generate_keypair( | |
|
878 | comment=comment, private_format=private_format) | |
|
876 | 879 | |
|
877 | 880 | return self._get_template_context(c) |
|
878 | 881 |
@@ -72,8 +72,11 b' class MyAccountSshKeysView(BaseAppView, ' | |||
|
72 | 72 | |
|
73 | 73 | c.active = 'ssh_keys_generate' |
|
74 | 74 | if c.ssh_key_generator_enabled: |
|
75 | private_format = self.request.GET.get('private_format') \ | |
|
76 | or SshKeyModel.DEFAULT_PRIVATE_KEY_FORMAT | |
|
75 | 77 | comment = 'RhodeCode-SSH {}'.format(c.user.email or '') |
|
76 |
c.private, c.public = SshKeyModel().generate_keypair( |
|
|
78 | c.private, c.public = SshKeyModel().generate_keypair( | |
|
79 | comment=comment, private_format=private_format) | |
|
77 | 80 | c.target_form_url = h.route_path( |
|
78 | 81 | 'my_account_ssh_keys', _query=dict(default_key=c.public)) |
|
79 | 82 | return self._get_template_context(c) |
@@ -38,6 +38,7 b' log = logging.getLogger(__name__)' | |||
|
38 | 38 | |
|
39 | 39 | class SshKeyModel(BaseModel): |
|
40 | 40 | cls = UserSshKeys |
|
41 | DEFAULT_PRIVATE_KEY_FORMAT = 'pkcs8' | |
|
41 | 42 | |
|
42 | 43 | def parse_key(self, key_data): |
|
43 | 44 | """ |
@@ -66,16 +67,23 b' class SshKeyModel(BaseModel):' | |||
|
66 | 67 | log.error("Key Parse error: %s", err) |
|
67 | 68 | raise |
|
68 | 69 | |
|
69 | def generate_keypair(self, comment=None): | |
|
70 | def generate_keypair(self, comment=None, private_format=DEFAULT_PRIVATE_KEY_FORMAT): | |
|
70 | 71 | |
|
71 | 72 | key = rsa.generate_private_key( |
|
72 | 73 | backend=crypto_default_backend(), |
|
73 | 74 | public_exponent=65537, |
|
74 | 75 | key_size=2048 |
|
75 | 76 | ) |
|
77 | if private_format == self.DEFAULT_PRIVATE_KEY_FORMAT: | |
|
78 | private_format = crypto_serialization.PrivateFormat.PKCS8 | |
|
79 | else: | |
|
80 | # legacy format that can be used by older systems, use if pkcs8 have | |
|
81 | # problems | |
|
82 | private_format = crypto_serialization.PrivateFormat.TraditionalOpenSSL | |
|
83 | ||
|
76 | 84 | private_key = key.private_bytes( |
|
77 | 85 | crypto_serialization.Encoding.PEM, |
|
78 |
|
|
|
86 | private_format, | |
|
79 | 87 | crypto_serialization.NoEncryption()) |
|
80 | 88 | public_key = key.public_key().public_bytes( |
|
81 | 89 | crypto_serialization.Encoding.OpenSSH, |
@@ -10,7 +10,7 b'' | |||
|
10 | 10 | <div class="panel-body"> |
|
11 | 11 | %if c.ssh_enabled and c.ssh_key_generator_enabled: |
|
12 | 12 | <p> |
|
13 | ${_('Below is a 2048 bit generated SSH RSA key.')}<br/> | |
|
13 | ${_('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/> | |
|
14 | 14 | ${_('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.')} |
|
15 | 15 | </p> |
|
16 | 16 | <h4>${_('Private key')}</h4> |
General Comments 0
You need to be logged in to leave comments.
Login now