diff --git a/client/client.go b/client/client.go index e69f3534bb520b0fd6ea8ddecd14db58ea8e436b..b13c4cbdd9c5ad88246f741077df7d704b298b27 100644 --- a/client/client.go +++ b/client/client.go @@ -79,11 +79,8 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro if err != nil { return nil, err } - marshaled := ssh.MarshalAuthorizedKey(pub) - // Remove the trailing newline. - marshaled = marshaled[:len(marshaled)-1] s, err := json.Marshal(&lib.SignRequest{ - Key: string(marshaled), + Key: lib.GetPublicKey(pub), ValidUntil: time.Now().Add(validity), }) if err != nil { diff --git a/cmd/cashierd/main.go b/cmd/cashierd/main.go index 31ee240b54317d664e3a0e8a34d4191f8476de5d..52b6a8b9548bb6cc15978a64831c4d8c47522b76 100644 --- a/cmd/cashierd/main.go +++ b/cmd/cashierd/main.go @@ -34,7 +34,6 @@ import ( "github.com/nsheridan/cashier/server/static" "github.com/nsheridan/cashier/server/store" "github.com/nsheridan/cashier/server/templates" - "github.com/nsheridan/cashier/server/util" "github.com/nsheridan/cashier/server/wkfs/vaultfs" "github.com/nsheridan/wkfs/s3" "github.com/sid77/drop" @@ -169,7 +168,7 @@ func signHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er } json.NewEncoder(w).Encode(&lib.SignResponse{ Status: "ok", - Response: util.GetPublicKey(cert), + Response: lib.GetPublicKey(cert), }) return http.StatusOK, nil } diff --git a/lib/const.go b/lib/proto.go similarity index 59% rename from lib/const.go rename to lib/proto.go index 1ba274931d7ffa6ea59b67d8683f3c3d8b4e925c..f3d7115605265e9a789d72a911f393c4ab7a3a2f 100644 --- a/lib/const.go +++ b/lib/proto.go @@ -9,9 +9,7 @@ type SignRequest struct { } // SignResponse is sent by the server. -// `Status' is "ok" or "error". -// `Response' contains a signed certificate or an error message. type SignResponse struct { - Status string `json:"status"` - Response string `json:"response"` + Status string `json:"status"` // Status will be "ok" or "error". + Response string `json:"response"` // Response will contain either the signed certificate or the error message. } diff --git a/server/util/util.go b/lib/util.go similarity index 60% rename from server/util/util.go rename to lib/util.go index 10f5eca6e3152e51dcc2b9ef3cd94c9d77c38b9e..b1c7b87016343712bcbbb534cfbecef733a083e6 100644 --- a/server/util/util.go +++ b/lib/util.go @@ -1,10 +1,10 @@ -package util +package lib import "golang.org/x/crypto/ssh" // GetPublicKey marshals a ssh certificate to a string. -func GetPublicKey(cert *ssh.Certificate) string { - marshaled := ssh.MarshalAuthorizedKey(cert) +func GetPublicKey(pub ssh.PublicKey) string { + marshaled := ssh.MarshalAuthorizedKey(pub) // Strip trailing newline return string(marshaled[:len(marshaled)-1]) } diff --git a/server/util/util_test.go b/lib/util_test.go similarity index 95% rename from server/util/util_test.go rename to lib/util_test.go index d294d86d2ec1b20a7bf5410a347a48c974e1960f..9e89297073d63f53c2b2f5110b53efce22b0c485 100644 --- a/server/util/util_test.go +++ b/lib/util_test.go @@ -1,4 +1,4 @@ -package util +package lib import ( "testing" diff --git a/server/store/store.go b/server/store/store.go index a447e726b3821e73d9de3db2f9fe52493768c15c..8af77e330618554fee94580daed704aa87c6c7cb 100644 --- a/server/store/store.go +++ b/server/store/store.go @@ -5,8 +5,8 @@ import ( "golang.org/x/crypto/ssh" + "github.com/nsheridan/cashier/lib" "github.com/nsheridan/cashier/server/config" - "github.com/nsheridan/cashier/server/util" ) // New returns a new configured database. @@ -54,6 +54,6 @@ func parseCertificate(cert *ssh.Certificate) *CertRecord { Principals: cert.ValidPrincipals, CreatedAt: parseTime(cert.ValidAfter), Expires: parseTime(cert.ValidBefore), - Raw: util.GetPublicKey(cert), + Raw: lib.GetPublicKey(cert), } }