- commit
- a2cf1d6
- parent
- 001a4b4
- author
- cheddar
- date
- 2025-02-21 05:00:04 +0100 CET
Add some registration validation
2 files changed,
+23,
-0
+6,
-0
1@@ -90,6 +90,12 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
2 return
3 }
4
5+ if !isValidKeyType(key) {
6+ fmt.Println("Attempted to register invalid key type")
7+ http.Error(w, "Invalid key type", 400)
8+ return
9+ }
10+
11 fmt.Printf("Registering key for %s\n", request.UserId)
12
13 keyId, err := keyDir.RegisterKey(key, request.UserId)
+17,
-0
1@@ -0,0 +1,17 @@
2+package server
3+
4+import (
5+ "crypto"
6+ "crypto/ecdsa"
7+ "crypto/ed25519"
8+ "crypto/rsa"
9+)
10+
11+func isValidKeyType(key crypto.PublicKey) bool {
12+ switch key.(type) {
13+ case ed25519.PublicKey, *rsa.PublicKey, *ecdsa.PublicKey:
14+ return true
15+ default:
16+ return false
17+ }
18+}