Generate a random key ID on registration

This commit is contained in:
cheddar 2025-02-17 21:03:31 -05:00
parent 949d1fc2ad
commit 09417b5147
No known key found for this signature in database
5 changed files with 47 additions and 10 deletions

View file

@ -56,10 +56,10 @@ func getDefaultHandler(isCaddyAuth bool) http.Handler {
if isCaddyAuth {
w.Header().Add("Remote-User", attr)
} else {
msg := fmt.Sprintf("hello, %s!", attr)
w.Write([]byte(msg))
}
msg := fmt.Sprintf("hello, %s!", attr)
w.Write([]byte(msg))
}
return http.HandlerFunc(handler)
@ -90,7 +90,14 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
fmt.Printf("Registering %s key for %s\n", alg, request.UserId)
keyDir.RegisterKey(key, alg, request.UserId)
keyId, err := keyDir.RegisterKey(key, alg, request.UserId)
if err != nil {
http.Error(w, fmt.Sprintf("Server error - %s", err), 500)
return
}
w.Write([]byte(keyId))
}
return http.HandlerFunc(handler)