Created
August 17, 2017 08:17
-
-
Save tobowers/7df99bac5fb2cb30bb06e4ce4d540364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"crypto/rand" | |
"crypto/rsa" | |
"golang.org/x/crypto/ssh" | |
) | |
func main() { | |
certPrivateKey, err := rsa.GenerateKey(rand.Reader, 512) | |
if err != nil { | |
log.Fatalf("Error generating cert key: %v", err) | |
} | |
certPublicKey, err := ssh.NewPublicKey(&certPrivateKey.PublicKey) | |
if err != nil { | |
log.Fatalf("Error generating ssh public key: %v", err) | |
} | |
cert := &ssh.Certificate{ | |
Key: certPublicKey, | |
CertType: 1, | |
KeyId: "{requester: \"bob\"}", | |
ValidPrincipals: []string{"alice"}, | |
} | |
signer, err := ssh.NewSignerFromKey(certPrivateKey) | |
if err != nil { | |
log.Fatalf("Error creating signer: %v", err) | |
} | |
err = cert.SignCert(rand.Reader, signer) | |
if err != nil { | |
log.Fatalf("Error signing certificate: %v", err) | |
} | |
marshaled := cert.Marshal() | |
pubKey, err := ssh.ParsePublicKey(marshaled) | |
if err != nil { | |
log.Fatalf("error parsing public key") | |
} | |
parsedCert, ok := pubKey.(*ssh.Certificate) | |
if !ok { | |
log.Fatal("agent: bad RSA certificate") | |
} | |
if err != nil { | |
log.Fatalf("error parsing cert: %v", err) | |
} | |
if parsedCert.CertType != cert.CertType { | |
log.Fatalf("Error, parsed certType did not match %s", cert.CertType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment