@@ -11,6 +11,7 @@ import (
1111 "code.gitea.io/gitea/models/db"
1212 "code.gitea.io/gitea/modules/timeutil"
1313 "code.gitea.io/gitea/modules/util"
14+ "github.com/go-webauthn/webauthn/protocol"
1415
1516 "github.com/go-webauthn/webauthn/webauthn"
1617)
@@ -50,6 +51,7 @@ type WebAuthnCredential struct {
5051 PublicKey []byte
5152 AttestationType string
5253 AAGUID []byte
54+ Flags protocol.AuthenticatorFlags
5355 SignCount uint32 `xorm:"BIGINT"`
5456 CloneWarning bool
5557 CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
@@ -103,7 +105,10 @@ func (list WebAuthnCredentialList) ToCredentials() []webauthn.Credential {
103105 CloneWarning : cred .CloneWarning ,
104106 },
105107 Flags : webauthn.CredentialFlags {
106- BackupEligible : true ,
108+ UserPresent : cred .Flags .HasUserPresent (),
109+ UserVerified : cred .Flags .HasUserVerified (),
110+ BackupEligible : cred .Flags .HasBackupEligible (),
111+ BackupState : cred .Flags .HasBackupState (),
107112 },
108113 })
109114 }
@@ -161,13 +166,27 @@ func GetWebAuthnCredentialByCredID(ctx context.Context, userID int64, credID []b
161166
162167// CreateCredential will create a new WebAuthnCredential from the given Credential
163168func CreateCredential (ctx context.Context , userID int64 , name string , cred * webauthn.Credential ) (* WebAuthnCredential , error ) {
169+ var flags protocol.AuthenticatorFlags
170+ if cred .Flags .UserPresent {
171+ flags |= protocol .FlagUserPresent
172+ }
173+ if cred .Flags .UserVerified {
174+ flags |= protocol .FlagUserVerified
175+ }
176+ if cred .Flags .BackupEligible {
177+ flags |= protocol .FlagBackupEligible
178+ }
179+ if cred .Flags .BackupState {
180+ flags |= protocol .FlagBackupState
181+ }
164182 c := & WebAuthnCredential {
165183 UserID : userID ,
166184 Name : name ,
167185 CredentialID : cred .ID ,
168186 PublicKey : cred .PublicKey ,
169187 AttestationType : cred .AttestationType ,
170188 AAGUID : cred .Authenticator .AAGUID ,
189+ Flags : flags ,
171190 SignCount : cred .Authenticator .SignCount ,
172191 CloneWarning : false ,
173192 }
0 commit comments