mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 15:43:52 +03:00
Use ErrKeyUnableToVerify if fail to calc fingerprint in ssh-keygen (#10863)
* Use ErrKeyUnableToVerify if fail to calc fingerprint in ssh-keygen Fix #3985 Signed-off-by: Andrew Thornton <art27@cantab.net> * Pass up the unable to verify
This commit is contained in:
parent
f9f2c163b1
commit
ea67e563dd
2 changed files with 10 additions and 0 deletions
|
@ -425,6 +425,9 @@ func calcFingerprintSSHKeygen(publicKeyContent string) (string, error) {
|
||||||
defer os.Remove(tmpPath)
|
defer os.Remove(tmpPath)
|
||||||
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)
|
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)
|
||||||
if err != nil {
|
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)
|
return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)
|
||||||
} else if len(stdout) < 2 {
|
} else if len(stdout) < 2 {
|
||||||
return "", errors.New("not enough output for calculating fingerprint: " + stdout)
|
return "", errors.New("not enough output for calculating fingerprint: " + stdout)
|
||||||
|
@ -455,6 +458,10 @@ func calcFingerprint(publicKeyContent string) (string, error) {
|
||||||
fp, err = calcFingerprintSSHKeygen(publicKeyContent)
|
fp, err = calcFingerprintSSHKeygen(publicKeyContent)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if IsErrKeyUnableVerify(err) {
|
||||||
|
log.Info("%s", publicKeyContent)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
return "", fmt.Errorf("%s: %v", fnName, err)
|
return "", fmt.Errorf("%s: %v", fnName, err)
|
||||||
}
|
}
|
||||||
return fp, nil
|
return fp, nil
|
||||||
|
|
|
@ -92,6 +92,9 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) {
|
||||||
|
|
||||||
ctx.Data["Err_Title"] = true
|
ctx.Data["Err_Title"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form)
|
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:
|
default:
|
||||||
ctx.ServerError("AddPublicKey", err)
|
ctx.ServerError("AddPublicKey", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue