From 6251626de45a2310b3532176c0fc12c52dbd6e32 Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Fri, 2 Jan 2015 15:38:11 +0200 Subject: Implement #798 Flexible ssh-key input It is now possible to input ssh keys in a number of formats: openssh, SSH2 or just the base64 encoded key. --- routers/user/setting.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'routers/user/setting.go') diff --git a/routers/user/setting.go b/routers/user/setting.go index 419e84b3..953e6113 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -325,10 +325,15 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { return } - // Remove newline characters from form.KeyContent - cleanContent := strings.Replace(form.Content, "\n", "", -1) + // Parse openssh style string from form content + content, err := models.ParseKeyString(form.Content) + if err != nil { + ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") + return + } - if ok, err := models.CheckPublicKeyString(cleanContent); !ok { + if ok, err := models.CheckPublicKeyString(content); !ok { if err == models.ErrKeyUnableVerify { ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key")) } else { @@ -341,7 +346,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { k := &models.PublicKey{ OwnerId: ctx.User.Id, Name: form.SSHTitle, - Content: cleanContent, + Content: content, } if err := models.AddPublicKey(k); err != nil { if err == models.ErrKeyAlreadyExist { -- cgit v1.2.3