@@ -12,6 +12,7 @@ import (
1212 "code.gitea.io/gitea/modules/timeutil"
1313 "code.gitea.io/gitea/modules/util"
1414
15+ "github.com/go-webauthn/webauthn/protocol"
1516 "github.com/go-webauthn/webauthn/webauthn"
1617)
1718
@@ -89,14 +90,33 @@ func (cred *WebAuthnCredential) AfterLoad() {
8990// WebAuthnCredentialList is a list of *WebAuthnCredential
9091type WebAuthnCredentialList []* WebAuthnCredential
9192
93+ // newCredentialFlagsFromAuthenticatorFlags is copied from https://github.com/go-webauthn/webauthn/pull/337
94+ // to convert protocol.AuthenticatorFlags to webauthn.CredentialFlags
95+ func newCredentialFlagsFromAuthenticatorFlags (flags protocol.AuthenticatorFlags ) webauthn.CredentialFlags {
96+ return webauthn.CredentialFlags {
97+ UserPresent : flags .HasUserPresent (),
98+ UserVerified : flags .HasUserVerified (),
99+ BackupEligible : flags .HasBackupEligible (),
100+ BackupState : flags .HasBackupState (),
101+ }
102+ }
103+
92104// ToCredentials will convert all WebAuthnCredentials to webauthn.Credentials
93- func (list WebAuthnCredentialList ) ToCredentials () []webauthn.Credential {
105+ func (list WebAuthnCredentialList ) ToCredentials (defaultAuthFlags ... protocol.AuthenticatorFlags ) []webauthn.Credential {
106+ // TODO: at the moment, Gitea doesn't store or check the flags
107+ // so we need to use the default flags from the authenticator to make the login validation pass
108+ // In the future, we should:
109+ // 1. store the flags when registering the credential
110+ // 2. provide the stored flags when converting the credentials (for login)
111+ // 3. for old users, still use this fallback to the default flags
112+ defAuthFlags := util .OptionalArg (defaultAuthFlags )
94113 creds := make ([]webauthn.Credential , 0 , len (list ))
95114 for _ , cred := range list {
96115 creds = append (creds , webauthn.Credential {
97116 ID : cred .CredentialID ,
98117 PublicKey : cred .PublicKey ,
99118 AttestationType : cred .AttestationType ,
119+ Flags : newCredentialFlagsFromAuthenticatorFlags (defAuthFlags ),
100120 Authenticator : webauthn.Authenticator {
101121 AAGUID : cred .AAGUID ,
102122 SignCount : cred .SignCount ,
0 commit comments