Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh auth using signed certificate #204

Closed
rickyninja opened this issue Aug 23, 2023 · 3 comments
Closed

ssh auth using signed certificate #204

rickyninja opened this issue Aug 23, 2023 · 3 comments

Comments

@rickyninja
Copy link

I've been trying to use signed certificates to do ssh auth via PublicKeyCallback & CreatePrivateKeyAuth. So far I've been unable to convert the signed cert into the byte slice param provided to CreatePrivateKeyAuth. Maybe this is not the correct auth provider for certificates. I also see CreateRemoteSignerAuth, but I can't envision what input would be in the meta string param. Which SshPiperPluginConfig callback & auth provider should be used with signed certificates? I haven't been able to find an example using certs for auth.

@tg123
Copy link
Owner

tg123 commented Aug 23, 2023

@rickyninja
Copy link
Author

rickyninja commented Aug 23, 2023

Thank you for your response. I don't think it is quite what I'm looking for. I don't see an ssh.Certificate being used in the provided links. I want the benefit of being able to use a signed certificate so that access expires.

I have working code using sshpiper with an RSA public & private keypair. I also have working code using crypto/ssh package to make the connection using a signed certificate without sshpiper.

This question from stackoverflow shows how to use a signed certificate for auth. I'd like to do this in combination with sshpiper.

The relevant code from stackoverflow answer follows. The ssh.PublicKeys(certSigner), part shows using the certificate for auth, but I can't plug that directly into sshpiper because it's not using the same interfaces.

package main

import (
    "bytes"
    "io/ioutil"
    "log"

    "golang.org/x/crypto/ssh"
)

func main() {
    key, err := ioutil.ReadFile("/tmp/mycert")
    if err != nil {
        log.Fatalf("unable to read private key: %v", err)
    }

    // Create the Signer for this private key.
    signer, err := ssh.ParsePrivateKey(key)
    if err != nil {
        log.Fatalf("unable to parse private key: %v", err)
    }

    // Load the certificate
    cert, err := ioutil.ReadFile("/tmp/mycert-cert.pub")
    if err != nil {
        log.Fatalf("unable to read certificate file: %v", err)
    }

    pk, _, _, _, err := ssh.ParseAuthorizedKey(cert)
    if err != nil {
        log.Fatalf("unable to parse public key: %v", err)
    }

    certSigner, err := ssh.NewCertSigner(pk.(*ssh.Certificate), signer)
    if err != nil {
        log.Fatalf("failed to create cert signer: %v", err)
    }

    config := &ssh.ClientConfig{
        User: "user",
        Auth: []ssh.AuthMethod{
            // Use the PublicKeys method for remote authentication.
            ssh.PublicKeys(certSigner),
        },
        HostKeyCallback: ssh.InsecureIgnoreHostKey(),
    }

    // Connect to the remote server and perform the SSH handshake.
    client, err := ssh.Dial("tcp", "host.com:22", config)
    if err != nil {
        log.Fatalf("unable to connect: %v", err)
    }
    defer client.Close()
}

@tg123
Copy link
Owner

tg123 commented Aug 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants