Skip to content
Snippets Groups Projects
Commit 1a6ce098 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Clean up public file writing.

Public key and cert writing now moved into client.
parent 9a2fa6cd
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -16,6 +16,14 @@ import ( ...@@ -16,6 +16,14 @@ import (
"golang.org/x/crypto/ssh/agent" "golang.org/x/crypto/ssh/agent"
) )
// InstallPublicFiles installs the public part of the cert and key.
func InstallPublicFiles(c Config, cert *ssh.Certificate, pub PublicKey) error {
ioutil.WriteFile(client.ExpandTilde(c.PublicKey),
ssh.MarshalAuthorizedKey(pub), 0644)
ioutil.WriteFile(client.ExpandTilde(c.PublicCert),
[]byte(cert.Type()+" "+base64.StdEncoding.EncodeToString(cert.Marshal())), 0644)
}
// InstallCert adds the private key and signed certificate to the ssh agent. // InstallCert adds the private key and signed certificate to the ssh agent.
func InstallCert(a agent.Agent, cert *ssh.Certificate, key Key) error { func InstallCert(a agent.Agent, cert *ssh.Certificate, key Key) error {
t := time.Unix(int64(cert.ValidBefore), 0) t := time.Unix(int64(cert.ValidBefore), 0)
......
...@@ -63,9 +63,8 @@ func main() { ...@@ -63,9 +63,8 @@ func main() {
if err := client.InstallCert(a, cert, priv); err != nil { if err := client.InstallCert(a, cert, priv); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
ioutil.WriteFile(client.ExpandTilde(c.PublicKey), if err := client.InstallPublicFilis(c, cert, pub); err != nil {
ssh.MarshalAuthorizedKey(pub), 0644) log.Fatalln(err)
ioutil.WriteFile(client.ExpandTilde(c.PublicCert), }
[]byte(cert.Type()+" "+base64.StdEncoding.EncodeToString(cert.Marshal())), 0644)
fmt.Println("Credentials added.") fmt.Println("Credentials added.")
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment