11package ssh
22
33import (
4- "bytes"
54 "fmt"
6- "strings"
75 "time"
86
97 "github.com/fosrl/cli/internal/api"
108 "github.com/fosrl/cli/internal/sshkeys"
11- "golang.org/x/crypto/ssh"
129)
1310
1411const (
@@ -17,34 +14,6 @@ const (
1714 pollBackoffSteps = 6
1815)
1916
20- func validateSignedCert (pubKey , cert string ) error {
21- cert = strings .TrimSpace (cert )
22- if cert == "" {
23- return fmt .Errorf ("API returned an empty SSH certificate" )
24- }
25-
26- pubParsed , _ , _ , _ , err := ssh .ParseAuthorizedKey ([]byte (pubKey ))
27- if err != nil {
28- return fmt .Errorf ("parse generated public key: %w" , err )
29- }
30-
31- certParsed , _ , _ , _ , err := ssh .ParseAuthorizedKey ([]byte (cert ))
32- if err != nil {
33- return fmt .Errorf ("parse returned certificate: %w" , err )
34- }
35-
36- certKey , ok := certParsed .(* ssh.Certificate )
37- if ! ok {
38- return fmt .Errorf ("API returned %q instead of an SSH certificate" , certParsed .Type ())
39- }
40-
41- if ! bytes .Equal (certKey .Key .Marshal (), pubParsed .Marshal ()) {
42- return fmt .Errorf ("returned certificate does not match generated key" )
43- }
44-
45- return nil
46- }
47-
4817// GenerateAndSignKey generates an Ed25519 key pair and signs the public key via the API.
4918func GenerateAndSignKey (client * api.Client , orgID string , resourceID string , username string ) (privPEM , pubKey , cert string , signData * api.SignSSHKeyData , err error ) {
5019 privPEM , pubKey , err = sshkeys .GenerateKeyPair ()
@@ -68,11 +37,6 @@ func GenerateAndSignKey(client *api.Client, orgID string, resourceID string, use
6837 } else if initResp .MessageID != 0 {
6938 messageIDs = []int64 {initResp .MessageID }
7039 } else {
71- if initResp .AuthDaemonMode != "native" {
72- if err := validateSignedCert (pubKey , initResp .Certificate ); err != nil {
73- return "" , "" , "" , nil , fmt .Errorf ("SSH error: invalid certificate: %w" , err )
74- }
75- }
7640 // return the data as this is okay
7741 return privPEM , pubKey , initResp .Certificate , initResp , nil
7842 }
@@ -90,11 +54,6 @@ func GenerateAndSignKey(client *api.Client, orgID string, resourceID string, use
9054 if msg .Error != nil && * msg .Error != "" {
9155 return "" , "" , "" , nil , fmt .Errorf ("SSH error: %s" , * msg .Error )
9256 }
93- if initResp .AuthDaemonMode != "native" {
94- if err := validateSignedCert (pubKey , initResp .Certificate ); err != nil {
95- return "" , "" , "" , nil , fmt .Errorf ("SSH error: invalid certificate: %w" , err )
96- }
97- }
9857 return privPEM , pubKey , initResp .Certificate , initResp , nil
9958 }
10059 }
0 commit comments