2018-05-17 12:05:00 +08:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-05-17 12:05:00 +08:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
2024-03-02 09:21:01 +08:00
|
|
|
"fmt"
|
2021-04-05 23:30:52 +08:00
|
|
|
"net/http"
|
|
|
|
|
2021-12-10 16:14:24 +08:00
|
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
2021-09-24 19:32:56 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2024-03-29 23:05:41 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2018-05-17 12:05:00 +08:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-01-26 23:36:53 +08:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-12-10 16:14:24 +08:00
|
|
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2021-04-07 03:44:05 +08:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2018-05-17 12:05:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tplSettingsKeys base.TplName = "user/settings/keys"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Keys render user's SSH/GPG public keys page
|
|
|
|
func Keys(ctx *context.Context) {
|
2024-07-10 01:36:31 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys, setting.UserFeatureManageGPGKeys) {
|
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("keys setting is not allowed to be changed"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-02 06:56:10 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("settings.ssh_gpg_keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["PageIsSettingsKeys"] = true
|
|
|
|
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
2020-10-11 08:38:09 +08:00
|
|
|
ctx.Data["BuiltinSSH"] = setting.SSH.StartBuiltinServer
|
|
|
|
ctx.Data["AllowPrincipals"] = setting.SSH.AuthorizedPrincipalsEnabled
|
2024-07-10 01:36:31 +08:00
|
|
|
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
|
2018-05-17 12:05:00 +08:00
|
|
|
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
2018-05-17 12:05:00 +08:00
|
|
|
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsKeys)
|
2018-05-17 12:05:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// KeysPost response for change user's SSH/GPG keys
|
2021-01-26 23:36:53 +08:00
|
|
|
func KeysPost(ctx *context.Context) {
|
2021-04-07 03:44:05 +08:00
|
|
|
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["Title"] = ctx.Tr("settings")
|
|
|
|
ctx.Data["PageIsSettingsKeys"] = true
|
2020-10-11 08:38:09 +08:00
|
|
|
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
|
|
|
ctx.Data["BuiltinSSH"] = setting.SSH.StartBuiltinServer
|
|
|
|
ctx.Data["AllowPrincipals"] = setting.SSH.AuthorizedPrincipalsEnabled
|
2024-07-10 01:36:31 +08:00
|
|
|
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
|
2018-05-17 12:05:00 +08:00
|
|
|
|
|
|
|
if ctx.HasError() {
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
2021-04-05 23:30:52 +08:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsKeys)
|
2018-05-17 12:05:00 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch form.Type {
|
2020-10-11 08:38:09 +08:00
|
|
|
case "principal":
|
2023-09-15 01:09:32 +08:00
|
|
|
content, err := asymkey_model.CheckPrincipalKeyString(ctx, ctx.Doer, form.Content)
|
2020-10-11 08:38:09 +08:00
|
|
|
if err != nil {
|
2021-12-10 16:14:24 +08:00
|
|
|
if db.IsErrSSHDisabled(err) {
|
2020-10-11 08:38:09 +08:00
|
|
|
ctx.Flash.Info(ctx.Tr("settings.ssh_disabled"))
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Error(ctx.Tr("form.invalid_ssh_principal", err.Error()))
|
|
|
|
}
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
|
|
|
return
|
|
|
|
}
|
2024-03-04 16:57:39 +08:00
|
|
|
if _, err = asymkey_service.AddPrincipalKey(ctx, ctx.Doer.ID, content, 0); err != nil {
|
2020-10-11 08:38:09 +08:00
|
|
|
ctx.Data["HasPrincipalError"] = true
|
|
|
|
switch {
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrKeyAlreadyExist(err), asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
2020-10-11 08:38:09 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
|
|
|
ctx.Data["Err_Content"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_principal_been_used"), tplSettingsKeys, &form)
|
|
|
|
default:
|
|
|
|
ctx.ServerError("AddPrincipalKey", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.add_principal_success", form.Content))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
case "gpg":
|
2024-03-29 23:05:41 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
2024-03-02 09:21:01 +08:00
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:03:22 +08:00
|
|
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
|
|
|
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
2021-07-13 21:28:07 +08:00
|
|
|
|
2023-09-25 21:17:37 +08:00
|
|
|
keys, err := asymkey_model.AddGPGKey(ctx, ctx.Doer.ID, form.Content, token, form.Signature)
|
2021-12-10 16:14:24 +08:00
|
|
|
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
2023-09-25 21:17:37 +08:00
|
|
|
keys, err = asymkey_model.AddGPGKey(ctx, ctx.Doer.ID, form.Content, lastToken, form.Signature)
|
2021-07-13 21:28:07 +08:00
|
|
|
}
|
2018-05-17 12:05:00 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.Data["HasGPGError"] = true
|
|
|
|
switch {
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrGPGKeyParsing(err):
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Flash.Error(ctx.Tr("form.invalid_gpg_key", err.Error()))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err):
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["Err_Content"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_key_id_used"), tplSettingsKeys, &form)
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
2021-07-13 21:28:07 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
ctx.Data["Err_Content"] = true
|
|
|
|
ctx.Data["Err_Signature"] = true
|
2022-12-30 12:53:05 +08:00
|
|
|
keyID := err.(asymkey_model.ErrGPGInvalidTokenSignature).ID
|
|
|
|
ctx.Data["KeyID"] = keyID
|
|
|
|
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
2021-07-13 21:28:07 +08:00
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_invalid_token_signature"), tplSettingsKeys, &form)
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrGPGNoEmailFound(err):
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["Err_Content"] = true
|
2021-07-13 21:28:07 +08:00
|
|
|
ctx.Data["Err_Signature"] = true
|
2022-12-30 12:53:05 +08:00
|
|
|
keyID := err.(asymkey_model.ErrGPGNoEmailFound).ID
|
|
|
|
ctx.Data["KeyID"] = keyID
|
|
|
|
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form)
|
|
|
|
default:
|
|
|
|
ctx.ServerError("AddPublicKey", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-08-21 18:45:50 +08:00
|
|
|
keyIDs := ""
|
|
|
|
for _, key := range keys {
|
|
|
|
keyIDs += key.KeyID
|
|
|
|
keyIDs += ", "
|
|
|
|
}
|
|
|
|
if len(keyIDs) > 0 {
|
|
|
|
keyIDs = keyIDs[:len(keyIDs)-2]
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.add_gpg_key_success", keyIDs))
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2021-07-13 21:28:07 +08:00
|
|
|
case "verify_gpg":
|
2022-03-22 15:03:22 +08:00
|
|
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
|
|
|
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
2021-07-13 21:28:07 +08:00
|
|
|
|
2023-10-14 16:37:24 +08:00
|
|
|
keyID, err := asymkey_model.VerifyGPGKey(ctx, ctx.Doer.ID, form.KeyID, token, form.Signature)
|
2021-12-10 16:14:24 +08:00
|
|
|
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
2023-10-14 16:37:24 +08:00
|
|
|
keyID, err = asymkey_model.VerifyGPGKey(ctx, ctx.Doer.ID, form.KeyID, lastToken, form.Signature)
|
2021-07-13 21:28:07 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
ctx.Data["HasGPGVerifyError"] = true
|
|
|
|
switch {
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
2021-07-13 21:28:07 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
ctx.Data["VerifyingID"] = form.KeyID
|
|
|
|
ctx.Data["Err_Signature"] = true
|
2022-12-30 12:53:05 +08:00
|
|
|
keyID := err.(asymkey_model.ErrGPGInvalidTokenSignature).ID
|
|
|
|
ctx.Data["KeyID"] = keyID
|
|
|
|
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
2021-07-13 21:28:07 +08:00
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_invalid_token_signature"), tplSettingsKeys, &form)
|
|
|
|
default:
|
|
|
|
ctx.ServerError("VerifyGPG", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.verify_gpg_key_success", keyID))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
case "ssh":
|
2024-03-29 23:05:41 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
2024-03-04 15:50:21 +08:00
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:14:24 +08:00
|
|
|
content, err := asymkey_model.CheckPublicKeyString(form.Content)
|
2018-05-17 12:05:00 +08:00
|
|
|
if err != nil {
|
2021-12-10 16:14:24 +08:00
|
|
|
if db.IsErrSSHDisabled(err) {
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Flash.Info(ctx.Tr("settings.ssh_disabled"))
|
2021-12-10 16:14:24 +08:00
|
|
|
} else if asymkey_model.IsErrKeyUnableVerify(err) {
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
|
2023-02-03 02:25:54 +08:00
|
|
|
} else if err == asymkey_model.ErrKeyIsPrivate {
|
|
|
|
ctx.Flash.Error(ctx.Tr("form.must_use_public_key"))
|
2018-05-17 12:05:00 +08:00
|
|
|
} else {
|
|
|
|
ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))
|
|
|
|
}
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-11 12:24:07 +08:00
|
|
|
if _, err = asymkey_model.AddPublicKey(ctx, ctx.Doer.ID, form.Title, content, 0); err != nil {
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["HasSSHError"] = true
|
|
|
|
switch {
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrKeyAlreadyExist(err):
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["Err_Content"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), tplSettingsKeys, &form)
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
2018-06-19 02:24:45 +08:00
|
|
|
loadKeysData(ctx)
|
|
|
|
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Data["Err_Title"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form)
|
2021-12-10 16:14:24 +08:00
|
|
|
case asymkey_model.IsErrKeyUnableVerify(err):
|
2020-03-29 01:24:55 +08:00
|
|
|
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
default:
|
|
|
|
ctx.ServerError("AddPublicKey", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.add_key_success", form.Title))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2021-12-19 13:37:18 +08:00
|
|
|
case "verify_ssh":
|
2024-03-29 23:05:41 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
2024-03-04 15:50:21 +08:00
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:03:22 +08:00
|
|
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
|
|
|
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
2021-12-19 13:37:18 +08:00
|
|
|
|
2023-10-14 16:37:24 +08:00
|
|
|
fingerprint, err := asymkey_model.VerifySSHKey(ctx, ctx.Doer.ID, form.Fingerprint, token, form.Signature)
|
2021-12-19 13:37:18 +08:00
|
|
|
if err != nil && asymkey_model.IsErrSSHInvalidTokenSignature(err) {
|
2023-10-14 16:37:24 +08:00
|
|
|
fingerprint, err = asymkey_model.VerifySSHKey(ctx, ctx.Doer.ID, form.Fingerprint, lastToken, form.Signature)
|
2021-12-19 13:37:18 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
ctx.Data["HasSSHVerifyError"] = true
|
|
|
|
switch {
|
|
|
|
case asymkey_model.IsErrSSHInvalidTokenSignature(err):
|
|
|
|
loadKeysData(ctx)
|
|
|
|
ctx.Data["Err_Signature"] = true
|
|
|
|
ctx.Data["Fingerprint"] = err.(asymkey_model.ErrSSHInvalidTokenSignature).Fingerprint
|
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_invalid_token_signature"), tplSettingsKeys, &form)
|
|
|
|
default:
|
|
|
|
ctx.ServerError("VerifySSH", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.verify_ssh_key_success", fingerprint))
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
ctx.Flash.Warning("Function not implemented")
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteKey response for delete user's SSH/GPG key
|
|
|
|
func DeleteKey(ctx *context.Context) {
|
2021-08-11 08:31:13 +08:00
|
|
|
switch ctx.FormString("type") {
|
2018-05-17 12:05:00 +08:00
|
|
|
case "gpg":
|
2024-03-29 23:05:41 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
2024-03-02 09:21:01 +08:00
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
|
|
|
return
|
|
|
|
}
|
2023-09-25 21:17:37 +08:00
|
|
|
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.FormInt64("id")); err != nil {
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Flash.Error("DeleteGPGKey: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.gpg_key_deletion_success"))
|
|
|
|
}
|
|
|
|
case "ssh":
|
2024-03-29 23:05:41 +08:00
|
|
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
2024-03-04 15:50:21 +08:00
|
|
|
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-29 09:42:15 +08:00
|
|
|
keyID := ctx.FormInt64("id")
|
2023-10-11 12:24:07 +08:00
|
|
|
external, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, keyID)
|
2020-12-26 12:24:47 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("sshKeysExternalManaged", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if external {
|
2021-09-25 22:27:01 +08:00
|
|
|
ctx.Flash.Error(ctx.Tr("settings.ssh_externally_managed"))
|
2020-12-26 12:24:47 +08:00
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
|
|
|
return
|
|
|
|
}
|
2023-09-25 21:17:37 +08:00
|
|
|
if err := asymkey_service.DeletePublicKey(ctx, ctx.Doer, keyID); err != nil {
|
2018-05-17 12:05:00 +08:00
|
|
|
ctx.Flash.Error("DeletePublicKey: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.ssh_key_deletion_success"))
|
|
|
|
}
|
2020-10-11 08:38:09 +08:00
|
|
|
case "principal":
|
2023-09-25 21:17:37 +08:00
|
|
|
if err := asymkey_service.DeletePublicKey(ctx, ctx.Doer, ctx.FormInt64("id")); err != nil {
|
2020-10-11 08:38:09 +08:00
|
|
|
ctx.Flash.Error("DeletePublicKey: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.ssh_principal_deletion_success"))
|
|
|
|
}
|
2018-05-17 12:05:00 +08:00
|
|
|
default:
|
|
|
|
ctx.Flash.Warning("Function not implemented")
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
|
|
|
}
|
2023-07-26 14:04:01 +08:00
|
|
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/keys")
|
2018-05-17 12:05:00 +08:00
|
|
|
}
|
2018-06-19 02:24:45 +08:00
|
|
|
|
|
|
|
func loadKeysData(ctx *context.Context) {
|
2023-11-24 11:49:41 +08:00
|
|
|
keys, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
|
|
|
|
OwnerID: ctx.Doer.ID,
|
|
|
|
NotKeytype: asymkey_model.KeyTypePrincipal,
|
|
|
|
})
|
2018-06-19 02:24:45 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListPublicKeys", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Keys"] = keys
|
|
|
|
|
2023-10-11 12:24:07 +08:00
|
|
|
externalKeys, err := asymkey_model.PublicKeysAreExternallyManaged(ctx, keys)
|
2020-12-26 12:24:47 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListPublicKeys", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["ExternalKeys"] = externalKeys
|
|
|
|
|
2024-01-15 10:19:25 +08:00
|
|
|
gpgkeys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
|
|
|
ListOptions: db.ListOptionsAll,
|
|
|
|
OwnerID: ctx.Doer.ID,
|
|
|
|
})
|
2018-06-19 02:24:45 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListGPGKeys", err)
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 10:19:25 +08:00
|
|
|
if err := asymkey_model.GPGKeyList(gpgkeys).LoadSubKeys(ctx); err != nil {
|
|
|
|
ctx.ServerError("LoadSubKeys", err)
|
|
|
|
return
|
|
|
|
}
|
2018-06-19 02:24:45 +08:00
|
|
|
ctx.Data["GPGKeys"] = gpgkeys
|
2022-03-22 15:03:22 +08:00
|
|
|
tokenToSign := asymkey_model.VerificationToken(ctx.Doer, 1)
|
2021-07-13 21:28:07 +08:00
|
|
|
|
|
|
|
// generate a new aes cipher using the csrfToken
|
|
|
|
ctx.Data["TokenToSign"] = tokenToSign
|
2020-10-11 08:38:09 +08:00
|
|
|
|
2024-01-15 10:19:25 +08:00
|
|
|
principals, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
|
|
|
|
ListOptions: db.ListOptionsAll,
|
|
|
|
OwnerID: ctx.Doer.ID,
|
|
|
|
KeyTypes: []asymkey_model.KeyType{asymkey_model.KeyTypePrincipal},
|
|
|
|
})
|
2020-10-11 08:38:09 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListPrincipalKeys", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Principals"] = principals
|
2021-07-13 21:28:07 +08:00
|
|
|
|
2021-08-11 08:31:13 +08:00
|
|
|
ctx.Data["VerifyingID"] = ctx.FormString("verify_gpg")
|
2021-12-19 13:37:18 +08:00
|
|
|
ctx.Data["VerifyingFingerprint"] = ctx.FormString("verify_ssh")
|
2024-03-29 23:05:41 +08:00
|
|
|
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
|
2018-06-19 02:24:45 +08:00
|
|
|
}
|