summaryrefslogtreecommitdiff
path: root/internal/webauthn/credential.go
blob: 46637722c8a4a8ddf4613a96af27f2efc99c104a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package webauthn

import (
	"github.com/go-webauthn/webauthn/webauthn"

	"github.com/authelia/authelia/v4/internal/configuration/schema"
	"github.com/authelia/authelia/v4/internal/model"
)

func VerifyCredential(config *schema.WebAuthn, credential *model.WebAuthnCredential, mds MetaDataProvider) (result VerifyCredentialResult) {
	var (
		c   *webauthn.Credential
		err error
	)

	if c, err = credential.ToCredential(); err != nil {
		result.Malformed = true
	}

	if len(credential.Attestation) == 0 {
		result.MissingStatement = true
	} else if c != nil && mds != nil {
		if err = c.Verify(mds); err != nil {
			result.MetaDataValidationError = true
		}
	}

	if config.Filtering.ProhibitBackupEligibility && credential.BackupEligible {
		result.IsProhibitedBackupEligibility = true
	}

	if len(config.Filtering.PermittedAAGUIDs) != 0 {
		found := false

		for _, aaguid := range config.Filtering.PermittedAAGUIDs {
			if credential.AAGUID.UUID == aaguid {
				found = true

				break
			}
		}

		if !found {
			result.IsProhibitedAAGUID = true
		}
	}

	if !result.IsProhibitedAAGUID {
		for _, aaguid := range config.Filtering.ProhibitedAAGUIDs {
			if credential.AAGUID.UUID == aaguid {
				result.IsProhibitedAAGUID = true

				break
			}
		}
	}

	return result
}

type VerifyCredentialResult struct {
	Malformed                     bool
	MissingStatement              bool
	IsProhibitedBackupEligibility bool
	IsProhibitedAAGUID            bool
	MetaDataValidationError       bool
}