Skip to content
Snippets Groups Projects
Commit 9e9a7d50 authored by Niall Sheridan's avatar Niall Sheridan
Browse files

Move GetPublicKey to the shared `lib` package

parent 8066efd4
No related branches found
No related tags found
No related merge requests found
...@@ -79,11 +79,8 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro ...@@ -79,11 +79,8 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro
if err != nil { if err != nil {
return nil, err return nil, err
} }
marshaled := ssh.MarshalAuthorizedKey(pub)
// Remove the trailing newline.
marshaled = marshaled[:len(marshaled)-1]
s, err := json.Marshal(&lib.SignRequest{ s, err := json.Marshal(&lib.SignRequest{
Key: string(marshaled), Key: lib.GetPublicKey(pub),
ValidUntil: time.Now().Add(validity), ValidUntil: time.Now().Add(validity),
}) })
if err != nil { if err != nil {
......
...@@ -34,7 +34,6 @@ import ( ...@@ -34,7 +34,6 @@ import (
"github.com/nsheridan/cashier/server/static" "github.com/nsheridan/cashier/server/static"
"github.com/nsheridan/cashier/server/store" "github.com/nsheridan/cashier/server/store"
"github.com/nsheridan/cashier/server/templates" "github.com/nsheridan/cashier/server/templates"
"github.com/nsheridan/cashier/server/util"
"github.com/nsheridan/cashier/server/wkfs/vaultfs" "github.com/nsheridan/cashier/server/wkfs/vaultfs"
"github.com/nsheridan/wkfs/s3" "github.com/nsheridan/wkfs/s3"
"github.com/sid77/drop" "github.com/sid77/drop"
...@@ -169,7 +168,7 @@ func signHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er ...@@ -169,7 +168,7 @@ func signHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er
} }
json.NewEncoder(w).Encode(&lib.SignResponse{ json.NewEncoder(w).Encode(&lib.SignResponse{
Status: "ok", Status: "ok",
Response: util.GetPublicKey(cert), Response: lib.GetPublicKey(cert),
}) })
return http.StatusOK, nil return http.StatusOK, nil
} }
......
...@@ -9,9 +9,7 @@ type SignRequest struct { ...@@ -9,9 +9,7 @@ type SignRequest struct {
} }
// SignResponse is sent by the server. // SignResponse is sent by the server.
// `Status' is "ok" or "error".
// `Response' contains a signed certificate or an error message.
type SignResponse struct { type SignResponse struct {
Status string `json:"status"` Status string `json:"status"` // Status will be "ok" or "error".
Response string `json:"response"` Response string `json:"response"` // Response will contain either the signed certificate or the error message.
} }
package util package lib
import "golang.org/x/crypto/ssh" import "golang.org/x/crypto/ssh"
// GetPublicKey marshals a ssh certificate to a string. // GetPublicKey marshals a ssh certificate to a string.
func GetPublicKey(cert *ssh.Certificate) string { func GetPublicKey(pub ssh.PublicKey) string {
marshaled := ssh.MarshalAuthorizedKey(cert) marshaled := ssh.MarshalAuthorizedKey(pub)
// Strip trailing newline // Strip trailing newline
return string(marshaled[:len(marshaled)-1]) return string(marshaled[:len(marshaled)-1])
} }
package util package lib
import ( import (
"testing" "testing"
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"github.com/nsheridan/cashier/lib"
"github.com/nsheridan/cashier/server/config" "github.com/nsheridan/cashier/server/config"
"github.com/nsheridan/cashier/server/util"
) )
// New returns a new configured database. // New returns a new configured database.
...@@ -54,6 +54,6 @@ func parseCertificate(cert *ssh.Certificate) *CertRecord { ...@@ -54,6 +54,6 @@ func parseCertificate(cert *ssh.Certificate) *CertRecord {
Principals: cert.ValidPrincipals, Principals: cert.ValidPrincipals,
CreatedAt: parseTime(cert.ValidAfter), CreatedAt: parseTime(cert.ValidAfter),
Expires: parseTime(cert.ValidBefore), Expires: parseTime(cert.ValidBefore),
Raw: util.GetPublicKey(cert), Raw: lib.GetPublicKey(cert),
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment