TOTP for PSU

3 votes

avatar

I believe all modern services should natively provide TOTP and I would love to see it in PSU.

Here is all the algorithm stuff you need to do it in pwsh: https://github.com/ecspresso/TOTPPowerShellModule
Whats missing on that page: When checking user input against the results from the function, it is important not to just use "-eq" (according to AI).
This is how to do it safely:

function Compare-ConstantTime {
    #prevents timing based attacks
    param([string]$a, [string]$b)
    if ($a.Length -ne $b.Length) { return $false }
    $result = 0
    for ($i = 0; $i -lt $a.Length; $i++) {
        $result = $result -bor ($a[$i].GetHashCode() -bxor $b[$i].GetHashCode())
    }
    return $result -eq 0
}


I have already implement something similar in the past but it was quite cumbersome to set everything up (authentication.ps1, login.ps1, storing and retrieving secrets) so a native implementation would be awesome.

Thank you for considering ~~

All Comments (1)

avatar

@Dynamic66 Thanks! I've opened a feature request to investigate on our end.

Adam Driscoll
PowerShell Expert and Developer at Devolutions