mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 01:45:22 +02:00
feat: consider WebAuthn & SSH for instance signing (#7693)
- Currently the options `pubkey` and `twofa` only consider TOTP and GPG keys respectively. Adjust the code to also consider WebAuthn credentials and SSH keys. - While adding the new unified functions I noticed that certain places also benefited from using these unified functions and took the liberty (where it was either a trivial translation or it was covered under testing) to use the new unified functions. - Resolves forgejo/forgejo#7658 - Adds unit and integration tests. Documentation PR: https://codeberg.org/forgejo/docs/pulls/1166 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7693 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
386e7f8208
commit
df5d656827
15 changed files with 222 additions and 65 deletions
29
models/asymkey/asymkey.go
Normal file
29
models/asymkey/asymkey.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
package asymkey
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forgejo.org/models/db"
|
||||
)
|
||||
|
||||
// HasAsymKeyByUID returns true if the user has a GPG key or SSH key associated
|
||||
// with its account.
|
||||
func HasAsymKeyByUID(ctx context.Context, userID int64) (bool, error) {
|
||||
hasGPGKey, err := db.Exist[GPGKey](ctx, FindGPGKeyOptions{
|
||||
OwnerID: userID,
|
||||
IncludeSubKeys: true,
|
||||
}.ToConds())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if hasGPGKey {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return db.Exist[PublicKey](ctx, FindPublicKeyOptions{
|
||||
OwnerID: userID,
|
||||
KeyTypes: []KeyType{KeyTypeUser},
|
||||
}.ToConds())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue