Add some registration validation

This commit is contained in:
cheddar 2025-02-20 23:00:04 -05:00
parent 001a4b4ac5
commit a2cf1d6b7b
No known key found for this signature in database
2 changed files with 23 additions and 0 deletions

View file

@ -90,6 +90,12 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
return
}
if !isValidKeyType(key) {
fmt.Println("Attempted to register invalid key type")
http.Error(w, "Invalid key type", 400)
return
}
fmt.Printf("Registering key for %s\n", request.UserId)
keyId, err := keyDir.RegisterKey(key, request.UserId)

17
server/validation.go Normal file
View file

@ -0,0 +1,17 @@
package server
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
)
func isValidKeyType(key crypto.PublicKey) bool {
switch key.(type) {
case ed25519.PublicKey, *rsa.PublicKey, *ecdsa.PublicKey:
return true
default:
return false
}
}