bfreis / otp

One Time Password generation with Bash
MIT License
22 stars 5 forks source link

TOTP tests fail #2

Closed Mathew1988 closed 3 years ago

Mathew1988 commented 3 years ago

When I run the bash otp --run-tests the totp tests are failing. I'm running the command on a Mac Pro macOS Big Sur 11.1 (20C69) on Intel Chip. I have the recommended software installed (brew install coreutils openssl bash). See the output of the run-tests below:

bash otp --run-tests
[PASS] hotp(3132333435363738393031323334353637383930, 0) = 755224 == 755224
[PASS] hotp(3132333435363738393031323334353637383930, 1) = 287082 == 287082
[PASS] hotp(3132333435363738393031323334353637383930, 2) = 359152 == 359152
[PASS] hotp(3132333435363738393031323334353637383930, 3) = 969429 == 969429
[PASS] hotp(3132333435363738393031323334353637383930, 4) = 338314 == 338314
[PASS] hotp(3132333435363738393031323334353637383930, 5) = 254676 == 254676
[PASS] hotp(3132333435363738393031323334353637383930, 6) = 287922 == 287922
[PASS] hotp(3132333435363738393031323334353637383930, 7) = 162583 == 162583
[PASS] hotp(3132333435363738393031323334353637383930, 8) = 399871 == 399871
[PASS] hotp(3132333435363738393031323334353637383930, 9) = 520489 == 520489
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 94287082
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 46119246
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 90693936
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 07081804
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 68084774
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 25091201
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 14050471
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 67062674
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 99943326
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 89005924
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 91819424
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 93441116
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 69279037
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 90698825
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 38618901
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930, ) = 86283265 == 65353130
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, ) = 38732398 == 77737706
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, ) = 31695031 == 47863826

Failed tests: 18.
Please open an issue at: https://github.com/bfreis/otp

I changed the date command from date +%s --date="@$dt_str" to date -j -f "%Y-%M-%dT%TZ" "@$dt_str" "+%s", but this only resolved the date illegal option error.

https://github.com/bfreis/otp/blob/e0d6117413dfd743bade0592d229df33a03c6f7b/otp#L27 https://github.com/bfreis/otp/blob/e0d6117413dfd743bade0592d229df33a03c6f7b/otp#L34 https://github.com/bfreis/otp/blob/e0d6117413dfd743bade0592d229df33a03c6f7b/otp#L199

The changes lead to the following output:

bash /Users/mw/Seafile/Secrets/cmp-pannet/vpn/otp --run-tests
[PASS] hotp(3132333435363738393031323334353637383930, 0) = 755224 == 755224
[PASS] hotp(3132333435363738393031323334353637383930, 1) = 287082 == 287082
[PASS] hotp(3132333435363738393031323334353637383930, 2) = 359152 == 359152
[PASS] hotp(3132333435363738393031323334353637383930, 3) = 969429 == 969429
[PASS] hotp(3132333435363738393031323334353637383930, 4) = 338314 == 338314
[PASS] hotp(3132333435363738393031323334353637383930, 5) = 254676 == 254676
[PASS] hotp(3132333435363738393031323334353637383930, 6) = 287922 == 287922
[PASS] hotp(3132333435363738393031323334353637383930, 7) = 162583 == 162583
[PASS] hotp(3132333435363738393031323334353637383930, 8) = 399871 == 399871
[PASS] hotp(3132333435363738393031323334353637383930, 9) = 520489 == 520489
[FAIL] totp(3132333435363738393031323334353637383930, 2674859) = 69110493 == 94287082
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 2674859) = 99434264 == 46119246
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 2674859) = 06782705 == 90693936
[FAIL] totp(3132333435363738393031323334353637383930, 1108688309) = 80887688 == 07081804
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 1108688309) = 57807705 == 68084774
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 1108688309) = 91582096 == 25091201
[FAIL] totp(3132333435363738393031323334353637383930, 1108688311) = 97973896 == 14050471
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 1108688311) = 92084829 == 67062674
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 1108688311) = 71192049 == 99943326
[FAIL] totp(3132333435363738393031323334353637383930, 1234564290) = 82576249 == 89005924
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 1234564290) = 42738668 == 91819424
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 1234564290) = 50630307 == 93441116
[FAIL] totp(3132333435363738393031323334353637383930, 1992306800) = 40637266 == 69279037
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 1992306800) = 86877580 == 90698825
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 1992306800) = 39821240 == 38618901
[FAIL] totp(3132333435363738393031323334353637383930, 19979087600) = 44470725 == 65353130
[FAIL] totp(3132333435363738393031323334353637383930313233343536373839303132, 19979087600) = 75274354 == 77737706
[FAIL] totp(31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334, 19979087600) = 04958886 == 47863826

Failed tests: 18.
Please open an issue at: https://github.com/bfreis/otp
bfreis commented 3 years ago

Hey @Mathew1988 , thanks for the report!

Based on the error message shown by date, it seems that it's using the command built-in in MacOS, rather than the one provided by coreutils.

Could you please check the output of which date and date --version?

Also, could you try to add Homebrew's coreutils bin folder in front of your PATH and run the tests again? E.g.,

$ export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
$ ./otp --run-tests

Let me know how it goes!

Mathew1988 commented 3 years ago

Hey.

You are right. The data which was used was localed at /bin/date. After adding the path in front of the PATH, everything is working fine.

Thanks a lot for the hint.