mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-16 10:13:01 +03:00
feat(passkeys): name new passkeys based on agguids (#332)
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
64
backend/internal/utils/aaguid_util.go
Normal file
64
backend/internal/utils/aaguid_util.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/pocket-id/pocket-id/backend/resources"
|
||||
)
|
||||
|
||||
var (
|
||||
aaguidMap map[string]string
|
||||
aaguidMapOnce sync.Once
|
||||
)
|
||||
|
||||
// FormatAAGUID converts an AAGUID byte slice to UUID string format
|
||||
func FormatAAGUID(aaguid []byte) string {
|
||||
if len(aaguid) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// If exactly 16 bytes, format as UUID
|
||||
if len(aaguid) == 16 {
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x",
|
||||
aaguid[0:4], aaguid[4:6], aaguid[6:8], aaguid[8:10], aaguid[10:16])
|
||||
}
|
||||
|
||||
// Otherwise just return as hex
|
||||
return hex.EncodeToString(aaguid)
|
||||
}
|
||||
|
||||
// GetAuthenticatorName returns the name of the authenticator for the given AAGUID
|
||||
func GetAuthenticatorName(aaguid []byte) string {
|
||||
aaguidStr := FormatAAGUID(aaguid)
|
||||
if aaguidStr == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Then check JSON-sourced map
|
||||
aaguidMapOnce.Do(loadAAGUIDsFromFile)
|
||||
|
||||
if name, ok := aaguidMap[aaguidStr]; ok {
|
||||
return name + " Passkey"
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// loadAAGUIDsFromFile loads AAGUID data from the embedded file system
|
||||
func loadAAGUIDsFromFile() {
|
||||
// Read from embedded file system
|
||||
data, err := resources.FS.ReadFile("aaguids.json")
|
||||
if err != nil {
|
||||
log.Printf("Error reading embedded AAGUID file: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &aaguidMap); err != nil {
|
||||
log.Printf("Error unmarshalling AAGUID data: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user