mod/ssh-keys-import: support ed25519 keys...

... with RouterOS 7.12beta1
This commit is contained in:
Christian Hesse 2023-08-18 09:00:54 +02:00
parent 413be6f504
commit ad6825571d
2 changed files with 8 additions and 2 deletions

View file

@ -29,6 +29,11 @@ import that key:
$SSHKeysImport "ssh-rsa AAAAB3Nza...QYZk8= user" admin; $SSHKeysImport "ssh-rsa AAAAB3Nza...QYZk8= user" admin;
Starting with RouterOS *7.12beta1* support for keys of type `ed25519` has
been added:
$SSHKeysImport "ssh-ed25519 AAAAC3Nza...ZVugJT user" admin;
The third part of the key (`user` in this example) is inherited as The third part of the key (`user` in this example) is inherited as
`key-owner` in RouterOS. `key-owner` in RouterOS.
@ -39,7 +44,7 @@ and import all the keys. The user given to the function can be overwritting
from comments in the file. Create a file `keys.pub` with this content: from comments in the file. Create a file `keys.pub` with this content:
``` ```
ssh-rsa AAAAB3Nza...QYZk8= user@client ssh-ed25519 AAAAC3Nza...3OcN8A user@client
ssh-rsa AAAAB3Nza...ozyts= worker@station ssh-rsa AAAAB3Nza...ozyts= worker@station
# user=example # user=example
ssh-rsa AAAAB3Nza...GXQVk= person@host ssh-rsa AAAAB3Nza...GXQVk= person@host

View file

@ -50,6 +50,7 @@
:global EitherOr; :global EitherOr;
:global LogPrintExit2; :global LogPrintExit2;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global RequiredRouterOS;
:global SSHKeysImport; :global SSHKeysImport;
:if ([ :len $FileName ] = 0 || [ :len $User ] = 0) do={ :if ([ :len $FileName ] = 0 || [ :len $User ] = 0) do={
@ -67,7 +68,7 @@
:local Line [ :pick $Keys 0 [ :find $Keys "\n" ] ]; :local Line [ :pick $Keys 0 [ :find $Keys "\n" ] ];
:set Keys [ :pick $Keys ([ :find $Keys "\n" ] + 1) [ :len $Keys ] ]; :set Keys [ :pick $Keys ([ :find $Keys "\n" ] + 1) [ :len $Keys ] ];
:local Type [ :pick $Line 0 [ :find $Line " " ] ]; :local Type [ :pick $Line 0 [ :find $Line " " ] ];
:if ($Type = "ssh-rsa") do={ :if (([ $RequiredRouterOS $0 "7.12beta1" ] = true && $Type = "ssh-ed25519") || $Type = "ssh-rsa") do={
$SSHKeysImport $Line $User; $SSHKeysImport $Line $User;
:set Continue true; :set Continue true;
} }