Add some registration validation
This commit is contained in:
parent
001a4b4ac5
commit
a2cf1d6b7b
2 changed files with 23 additions and 0 deletions
|
@ -90,6 +90,12 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
|
||||||
return
|
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)
|
fmt.Printf("Registering key for %s\n", request.UserId)
|
||||||
|
|
||||||
keyId, err := keyDir.RegisterKey(key, request.UserId)
|
keyId, err := keyDir.RegisterKey(key, request.UserId)
|
||||||
|
|
17
server/validation.go
Normal file
17
server/validation.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue