Skip to content

Commit

Permalink
fix(webauthn): expose cred params functions (#286)
Browse files Browse the repository at this point in the history
This exposes useful functions for generating credential properties.
  • Loading branch information
james-d-elliott authored Aug 29, 2024
1 parent 33464f5 commit e736323
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions webauthn/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (webauthn *WebAuthn) BeginRegistration(user User, opts ...RegistrationOptio
},
}

credentialParams := defaultRegistrationCredentialParameters()
credentialParams := CredentialParametersDefault()

creation = &protocol.CredentialCreation{
Response: protocol.PublicKeyCredentialCreationOptions{
Expand Down Expand Up @@ -234,7 +234,8 @@ func (webauthn *WebAuthn) CreateCredential(user User, session SessionData, parse
return NewCredential(clientDataHash, parsedResponse)
}

func defaultRegistrationCredentialParameters() []protocol.CredentialParameter {
// CredentialParametersDefault is the default protocol.CredentialParameter list.
func CredentialParametersDefault() []protocol.CredentialParameter {
return []protocol.CredentialParameter{
{
Type: protocol.PublicKeyCredentialType,
Expand Down Expand Up @@ -278,3 +279,68 @@ func defaultRegistrationCredentialParameters() []protocol.CredentialParameter {
},
}
}

// CredentialParametersRecommendedL3 is explicitly the Level 3 recommended protocol.CredentialParameter list.
func CredentialParametersRecommendedL3() []protocol.CredentialParameter {
return []protocol.CredentialParameter{
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgEdDSA,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgES256,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgRS256,
},
}
}

// CredentialParametersExtendedL3 is the Level 3 recommended protocol.CredentialParameter list with all of the other
// parameters supported by the library.
func CredentialParametersExtendedL3() []protocol.CredentialParameter {
return []protocol.CredentialParameter{
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgEdDSA,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgES256,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgES384,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgES512,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgRS256,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgRS384,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgRS512,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgPS256,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgPS384,
},
{
Type: protocol.PublicKeyCredentialType,
Algorithm: webauthncose.AlgPS512,
},
}
}

0 comments on commit e736323

Please sign in to comment.