@@ -12,6 +12,7 @@ import (
12
12
"code.gitea.io/gitea/modules/timeutil"
13
13
"code.gitea.io/gitea/modules/util"
14
14
15
+ "github.com/go-webauthn/webauthn/protocol"
15
16
"github.com/go-webauthn/webauthn/webauthn"
16
17
)
17
18
@@ -89,14 +90,33 @@ func (cred *WebAuthnCredential) AfterLoad() {
89
90
// WebAuthnCredentialList is a list of *WebAuthnCredential
90
91
type WebAuthnCredentialList []* WebAuthnCredential
91
92
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
+
92
104
// 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 )
94
113
creds := make ([]webauthn.Credential , 0 , len (list ))
95
114
for _ , cred := range list {
96
115
creds = append (creds , webauthn.Credential {
97
116
ID : cred .CredentialID ,
98
117
PublicKey : cred .PublicKey ,
99
118
AttestationType : cred .AttestationType ,
119
+ Flags : newCredentialFlagsFromAuthenticatorFlags (defAuthFlags ),
100
120
Authenticator : webauthn.Authenticator {
101
121
AAGUID : cred .AAGUID ,
102
122
SignCount : cred .SignCount ,
0 commit comments