diff options
author | Christian Hesse <mail@eworm.de> | 2023-11-02 09:38:47 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-11-07 14:31:59 +0100 |
commit | c3045f372350bd8dd0a8f10efb8a4b938e896145 (patch) | |
tree | adba5b1a0fc5b6d9d93f9aeadfec6d921738294f /mod/ssh-keys-import.rsc | |
parent | 79f3002a38d2d69acc51c59e609b09b1d982b545 (diff) |
mod/ssh-keys-import: parse key into array
Diffstat (limited to 'mod/ssh-keys-import.rsc')
-rw-r--r-- | mod/ssh-keys-import.rsc | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/mod/ssh-keys-import.rsc b/mod/ssh-keys-import.rsc index 31bb3e6..fb6fee1 100644 --- a/mod/ssh-keys-import.rsc +++ b/mod/ssh-keys-import.rsc @@ -14,6 +14,7 @@ :local Key [ :tostr $1 ]; :local User [ :tostr $2 ]; + :global CharacterReplace; :global GetRandom20CharAlNum; :global LogPrintExit2; :global MkDir; @@ -28,9 +29,9 @@ $LogPrintExit2 warning $0 ("User '" . $User . "' does not exist.") true; } - :local Type [ :pick $Key 0 [ :find $Key " " ] ]; - :if (!(([ $RequiredRouterOS $0 "7.12beta1" ] = true && $Type = "ssh-ed25519") || $Type = "ssh-rsa")) do={ - $LogPrintExit2 warning $0 ("SSH key of type '" . $Type . "' is not supported.") true; + :local KeyVal [ :toarray [ $CharacterReplace $Key " " "," ] ]; + :if (!(([ $RequiredRouterOS $0 "7.12beta1" ] = true && $KeyVal->0 = "ssh-ed25519") || $KeyVal->0 = "ssh-rsa")) do={ + $LogPrintExit2 warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.") true; } :if ([ $MkDir "tmpfs/ssh-keys-import" ] = false) do={ @@ -53,6 +54,7 @@ :local FileName [ :tostr $1 ]; :local User [ :tostr $2 ]; + :global CharacterReplace; :global EitherOr; :global LogPrintExit2; :global ParseKeyValueStore; @@ -73,17 +75,17 @@ :local Continue false; :local Line [ :pick $Keys 0 [ :find $Keys "\n" ] ]; :set Keys [ :pick $Keys ([ :find $Keys "\n" ] + 1) [ :len $Keys ] ]; - :local Type [ :pick $Line 0 [ :find $Line " " ] ]; - :if (([ $RequiredRouterOS $0 "7.12beta1" ] = true && $Type = "ssh-ed25519") || $Type = "ssh-rsa") do={ + :local KeyVal [ :toarray [ $CharacterReplace $Key " " "," ] ]; + :if (([ $RequiredRouterOS $0 "7.12beta1" ] = true && $KeyVal->0 = "ssh-ed25519") || $KeyVal->0 = "ssh-rsa") do={ $SSHKeysImport $Line $User; :set Continue true; } - :if ($Continue = false && $Type = "#") do={ + :if ($Continue = false && $KeyVal->0 = "#") do={ :set User [ $EitherOr ([ $ParseKeyValueStore [ :pick $Line 2 [ :len $Line ] ] ]->"user") $User ]; :set Continue true; } - :if ($Continue = false && [ :len $Type ] > 0) do={ - $LogPrintExit2 warning $0 ("SSH key of type '" . $Type . "' is not supported.") false; + :if ($Continue = false && [ :len ($KeyVal->0) ] > 0) do={ + $LogPrintExit2 warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.") false; } } while=([ :len $Keys ] > 0); } |