mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-21 19:34:41 +02:00
global-functions: drop $GetRandomSha256, introduce $GetRandom20CharHex
Do do generate certificate, but use scep-server otp.
This commit is contained in:
parent
1bac1b4d3d
commit
3b28440b05
1 changed files with 12 additions and 16 deletions
|
@ -25,8 +25,8 @@
|
||||||
:global DNSIsResolving;
|
:global DNSIsResolving;
|
||||||
:global DownloadPackage;
|
:global DownloadPackage;
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
|
:global GetRandom20CharHex;
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
:global GetRandomSha256;
|
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global IPCalc;
|
:global IPCalc;
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
|
@ -299,6 +299,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# generate random 20 chars hex (0-9 and a-f)
|
||||||
|
:set GetRandom20CharHex do={
|
||||||
|
:local Random ([ / certificate scep-server otp generate minutes-valid=0 as-value ]->"password");
|
||||||
|
/ certificate scep-server otp remove [ find where password=$Random ];
|
||||||
|
:return $Random;
|
||||||
|
}
|
||||||
|
|
||||||
# generate random number
|
# generate random number
|
||||||
:set GetRandomNumber do={
|
:set GetRandomNumber do={
|
||||||
:local Max 4294967295;
|
:local Max 4294967295;
|
||||||
|
@ -306,13 +313,13 @@
|
||||||
:set Max ([ :tonum $1 ] + 1);
|
:set Max ([ :tonum $1 ] + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
:global GetRandomSha256;
|
:global GetRandom20CharHex;
|
||||||
|
|
||||||
:local Num;
|
:local Num;
|
||||||
:local Sha256 [ $GetRandomSha256 ];
|
:local 40CharHex ([ $GetRandom20CharHex ] . [ $GetRandom20CharHex ]);
|
||||||
|
|
||||||
:for I from=0 to=63 do={
|
:for I from=0 to=39 do={
|
||||||
:local Char [ :pick $Sha256 $I ];
|
:local Char [ :pick $40CharHex $I ];
|
||||||
:if ($Char~"[0-9]") do={
|
:if ($Char~"[0-9]") do={
|
||||||
:set Num ($Num . $Char);
|
:set Num ($Num . $Char);
|
||||||
}
|
}
|
||||||
|
@ -321,17 +328,6 @@
|
||||||
:return ([ :tonum [ :pick $Num 0 18 ] ] % $Max);
|
:return ([ :tonum [ :pick $Num 0 18 ] ] % $Max);
|
||||||
}
|
}
|
||||||
|
|
||||||
# generate random sha256 string
|
|
||||||
# returns 64 bytes of 0-9 and a-f
|
|
||||||
:set GetRandomSha256 do={
|
|
||||||
:local FingerPrint;
|
|
||||||
/ certificate add name=GetRandomSha256-template common-name=GetRandomSha256 key-size=prime256v1;
|
|
||||||
/ certificate sign GetRandomSha256-template name=GetRandomSha256 without-paging as-value;
|
|
||||||
:set FingerPrint [ / certificate get GetRandomSha256 fingerprint ];
|
|
||||||
/ certificate remove GetRandomSha256;
|
|
||||||
:return $FingerPrint;
|
|
||||||
}
|
|
||||||
|
|
||||||
# mimic conditional/ternary operator (condition ? consequent : alternative)
|
# mimic conditional/ternary operator (condition ? consequent : alternative)
|
||||||
:set IfThenElse do={
|
:set IfThenElse do={
|
||||||
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={
|
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue