@@ -219,10 +219,17 @@ func RotateAuthorizedKey(t *testing.T, dut *ondatra.DUTDevice, dir, username, ve
219219 t .Fatalf ("Failed reading private key contents, error: %s" , err )
220220 }
221221 dataTypes := bytes .Fields (data )
222+ keyType := keyTypeFromAlgo (string (dataTypes [0 ]))
223+ if keyType == cpb .KeyType_KEY_TYPE_UNSPECIFIED {
224+ keyType = cpb .KeyType_KEY_TYPE_ED25519
225+ }
226+ authKey := dataTypes [1 ]
227+ if dut .Vendor () == ondatra .JUNIPER {
228+ authKey = bytes .Join (dataTypes [:2 ], []byte (" " ))
229+ }
222230 keyContents = append (keyContents , & cpb.AccountCredentials_AuthorizedKey {
223- // AuthorizedKey: data,
224- AuthorizedKey : dataTypes [1 ],
225- KeyType : cpb .KeyType_KEY_TYPE_ED25519 ,
231+ AuthorizedKey : authKey ,
232+ KeyType : keyType ,
226233 })
227234 }
228235 request := & cpb.RotateAccountCredentialsRequest {
@@ -253,9 +260,17 @@ func RotateTrustedUserCA(t *testing.T, dut *ondatra.DUTDevice, dir string) {
253260 t .Fatalf ("Failed reading ca public key contents, error: %s" , err )
254261 }
255262 dataTypes := bytes .Fields (data )
263+ keyType := keyTypeFromAlgo (string (dataTypes [0 ]))
264+ if keyType == cpb .KeyType_KEY_TYPE_UNSPECIFIED {
265+ t .Fatalf ("Unrecognized key type: %s" , dataTypes [0 ])
266+ }
267+ pubKey := dataTypes [1 ]
268+ if dut .Vendor () == ondatra .JUNIPER {
269+ pubKey = bytes .Join (dataTypes [:2 ], []byte (" " ))
270+ }
256271 keyContents = append (keyContents , & cpb.PublicKey {
257- PublicKey : dataTypes [ 1 ] ,
258- KeyType : cpb . KeyType_KEY_TYPE_ED25519 ,
272+ PublicKey : pubKey ,
273+ KeyType : keyType ,
259274 })
260275 }
261276 request := & cpb.RotateHostParametersRequest {
@@ -424,23 +439,29 @@ func GetDutPublicKey(t *testing.T, dut *ondatra.DUTDevice, targetAlgo string) []
424439 return []byte (keyLine )
425440}
426441
427- // CreateSSHKeyPair creates ssh keypair with a filename of keyName in the specified directory.
428- // Keypairs can be created for ca/dut/testuser as per individual credentialz test requirements.
429- func CreateSSHKeyPair ( t * testing. T , dir , keyName string ) {
430- sshCmd := exec . Command (
431- "ssh-keygen" ,
432- "-t" , "ed25519" ,
433- "-f " , keyName ,
434- "-C" , keyName ,
435- "- q" , "-N" , "" ,
436- )
442+ // CreateSSHKeyPairAlgo creates ssh keypair with a filename of keyName in the specified directory with the specified algo .
443+ func CreateSSHKeyPairAlgo ( t * testing. T , dir , keyName , algo string ) {
444+ args := [] string {
445+ "-t" , algo ,
446+ }
447+ if algo == "rsa" {
448+ args = append ( args , "-b " , "4096" )
449+ }
450+ args = append ( args , "-f" , keyName , "-C" , keyName , "- q" , "-N" , "" )
451+ sshCmd := exec . Command ( "ssh-keygen" , args ... )
437452 sshCmd .Dir = dir
438453 err := sshCmd .Run ()
439454 if err != nil {
440455 t .Fatalf ("Failed generating %s key pair, error: %s" , keyName , err )
441456 }
442457}
443458
459+ // CreateSSHKeyPair creates ssh keypair with a filename of keyName in the specified directory.
460+ // Keypairs can be created for ca/dut/testuser as per individual credentialz test requirements.
461+ func CreateSSHKeyPair (t * testing.T , dir , keyName string ) {
462+ CreateSSHKeyPairAlgo (t , dir , keyName , "ed25519" )
463+ }
464+
444465// CreateUserCertificate creates ssh user certificate in the specified directory.
445466func CreateUserCertificate (t * testing.T , dir , userPrincipal string ) {
446467 userCertCmd := exec .Command (
@@ -727,6 +748,23 @@ func GetConfiguredHostKey(t *testing.T, dut *ondatra.DUTDevice, algo string, fqd
727748 return algo + " " + matchingKey
728749}
729750
751+ func keyTypeFromAlgo (algo string ) cpb.KeyType {
752+ switch algo {
753+ case "ssh-rsa" :
754+ return cpb .KeyType_KEY_TYPE_RSA_4096
755+ case "ecdsa-sha2-nistp256" :
756+ return cpb .KeyType_KEY_TYPE_ECDSA_P_256
757+ case "ecdsa-sha2-nistp384" :
758+ return cpb .KeyType_KEY_TYPE_ECDSA_P_384
759+ case "ecdsa-sha2-nistp521" :
760+ return cpb .KeyType_KEY_TYPE_ECDSA_P_521
761+ case "ssh-ed25519" :
762+ return cpb .KeyType_KEY_TYPE_ED25519
763+ default :
764+ return cpb .KeyType_KEY_TYPE_UNSPECIFIED
765+ }
766+ }
767+
730768func sshAlgo (t * testing.T , pk * cpb.PublicKey ) string {
731769 keyType := pk .KeyType
732770 switch keyType {
0 commit comments