Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ErrKeyUnableToVerify if fail to calc fingerprint in ssh-keygen #10863

Merged
merged 4 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use ErrKeyUnableToVerify if fail to calc fingerprint in ssh-keygen
Fix #3985

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Mar 28, 2020
commit 01f64ebf7b70557b30f1c2a72801685085a9f680
3 changes: 3 additions & 0 deletions models/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ func calcFingerprintSSHKeygen(publicKeyContent string) (string, error) {
defer os.Remove(tmpPath)
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)
if err != nil {
if strings.Contains(stderr, "is not a public key file") {
return "", ErrKeyUnableVerify{stderr}
}
return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)
} else if len(stdout) < 2 {
return "", errors.New("not enough output for calculating fingerprint: " + stdout)
Expand Down
3 changes: 3 additions & 0 deletions routers/user/setting/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) {

ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form)
case models.IsErrKeyUnableVerify(err):
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
default:
ctx.ServerError("AddPublicKey", err)
}
Expand Down