Add support for more key types
This commit is contained in:
parent
b1e4a0cf72
commit
001a4b4ac5
14 changed files with 98 additions and 48 deletions
|
@ -77,22 +77,25 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
|
|||
err := json.NewDecoder(r.Body).Decode(&request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
http.Error(w, fmt.Sprintf("Bad request - %s", err), 400)
|
||||
return
|
||||
}
|
||||
|
||||
key, alg, err := parsePublicKey(request.Key)
|
||||
key, err := parsePublicKey(request.Key)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
http.Error(w, fmt.Sprintf("Bad request - %s", err), 400)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Registering %s key for %s\n", alg, request.UserId)
|
||||
fmt.Printf("Registering key for %s\n", request.UserId)
|
||||
|
||||
keyId, err := keyDir.RegisterKey(key, alg, request.UserId)
|
||||
keyId, err := keyDir.RegisterKey(key, request.UserId)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
http.Error(w, fmt.Sprintf("Server error - %s", err), 500)
|
||||
return
|
||||
}
|
||||
|
@ -103,15 +106,12 @@ func getRegistrationHandler(keyDir keydirectory.RegistrationDirectory) http.Hand
|
|||
return http.HandlerFunc(handler)
|
||||
}
|
||||
|
||||
func parsePublicKey(input string) (crypto.PublicKey, string, error) {
|
||||
func parsePublicKey(input string) (crypto.PublicKey, error) {
|
||||
pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(input))
|
||||
|
||||
var alg string
|
||||
|
||||
switch pk.Type() {
|
||||
case "ssh-ed25519":
|
||||
alg = "ed25519"
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pk.(ssh.CryptoPublicKey).CryptoPublicKey(), alg, err
|
||||
return pk.(ssh.CryptoPublicKey).CryptoPublicKey(), err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue