aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-07-25 13:39:15 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-07-25 16:17:01 +0200
commit3b28440b05449f567834e740029a5ac9d0e8ce46 (patch)
treedfd080f812c04798ac334d0dee4685c175962df8 /global-functions
parent1bac1b4d3d91c366842437cc477274b7c7d40d3f (diff)
global-functions: drop $GetRandomSha256, introduce $GetRandom20CharHex
Do do generate certificate, but use scep-server otp.
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions28
1 files changed, 12 insertions, 16 deletions
diff --git a/global-functions b/global-functions
index 8149d4b..3895550 100644
--- a/global-functions
+++ b/global-functions
@@ -25,8 +25,8 @@
:global DNSIsResolving;
:global DownloadPackage;
:global GetMacVendor;
+:global GetRandom20CharHex;
:global GetRandomNumber;
-:global GetRandomSha256;
:global IfThenElse;
:global IPCalc;
: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
:set GetRandomNumber do={
:local Max 4294967295;
@@ -306,13 +313,13 @@
:set Max ([ :tonum $1 ] + 1);
}
- :global GetRandomSha256;
+ :global GetRandom20CharHex;
:local Num;
- :local Sha256 [ $GetRandomSha256 ];
+ :local 40CharHex ([ $GetRandom20CharHex ] . [ $GetRandom20CharHex ]);
- :for I from=0 to=63 do={
- :local Char [ :pick $Sha256 $I ];
+ :for I from=0 to=39 do={
+ :local Char [ :pick $40CharHex $I ];
:if ($Char~"[0-9]") do={
:set Num ($Num . $Char);
}
@@ -321,17 +328,6 @@
: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)
:set IfThenElse do={
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={