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