Giter VIP home page Giter VIP logo

libcotp's Issues

improve docu

specify that input value must be base32 encoded

base32_encode returns an error when the leading byte is 0

base32_encode passes the byte array to check_input, which returns an error if the first byte is 0.

This fails when it shouldn't i.e. 0 is a valid secret.

uint8_t secret_bytes[] = {0, 0, 0, 0};
cotp_error_t err_code;
base32_encode(secret_bytes, 4, &err_code);
// err_code = EMPTY_STRING

Error during compilation!

When I am using libgcrypto to compiling (with cmake command "cmake . -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=$PWD/built -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DGCRYPT_LIBRARIES=build/lib -DGCRYPT_INCLUDE_DIR=build/include") , gcc throwed an error:

D:\Desktop\libcotp\src\whmac.h:27:1: error: unknown type name 'ssize_t'
27 | ssize_t whmac_finalize (whmac_handle_t *hd,
| ^
D:\Desktop\libcotp\src\otp.c:239:12: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated.
Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
239 | return strdup (code);
| ^
E:\Windows Kits\10\Include\10.0.22621.0\ucrt\string.h:531:20: note: 'strdup' has been explicitly marked deprecated here
531 | Check_return _CRT_NONSTDC_DEPRECATE(_strdup)
| ^
E:\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt.h:428:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
428 | #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(
| ^
E:\Microsoft Visual Studio\Community\VC\Tools\MSVC\14.39.33519\include\vcruntime.h:345:47: note: expanded from macro
'_CRT_DEPRECATE_TEXT'
345 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
D:\Desktop\libcotp\src\otp.c:302:5: error: use of undeclared identifier 'ssize_t'; did you mean 'sizeof'?
302 | ssize_t flen = whmac_finalize (hd, hmac, dlen);
| ^~~~~~~
| sizeof
D:\Desktop\libcotp\src\otp.c:302:13: error: use of undeclared identifier 'flen'; did you mean 'dlen'?
302 | ssize_t flen = whmac_finalize (hd, hmac, dlen);
| ^~~~
| dlen
D:\Desktop\libcotp\src\otp.c:294:12: note: 'dlen' declared here
294 | size_t dlen = whmac_getlen (hd);
| ^
D:\Desktop\libcotp\src\otp.c:303:9: error: use of undeclared identifier 'flen'; did you mean 'dlen'?
303 | if (flen < 0) {
| ^~~~
| dlen
D:\Desktop\libcotp\src\otp.c:294:12: note: 'dlen' declared here
294 | size_t dlen = whmac_getlen (hd);
| ^
1 warning and 4 errors generated.

PS: I am Chinese, so my English is not very well. Don't care please : )

Tests should not need install to build

Similar to paolostivanin/libbaseencode#20, when running tests with:

mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX="./install" -DBUILD_TESTING=ON ..
make

I get:

[ 25%] Building C object CMakeFiles/cotp.dir/src/otp.c.o
[ 50%] Linking C shared library libcotp.so
[ 50%] Built target cotp
Scanning dependencies of target test_cotp
[ 75%] Building C object tests/CMakeFiles/test_cotp.dir/test_otp.c.o
/home/yoshi/tmp/otpclient/libcotp/tests/test_otp.c:3:10: fatal error: cotp.h: No such file or directory
    3 | #include <cotp.h>
      |          ^~~~~~~~
compilation terminated.
make[2]: *** [tests/CMakeFiles/test_cotp.dir/build.make:63: tests/CMakeFiles/test_cotp.dir/test_otp.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:123: tests/CMakeFiles/test_cotp.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

Replacing the line with #include "../src/cotp.h" fixes the error but I then get:

[ 25%] Building C object CMakeFiles/cotp.dir/src/otp.c.o
[ 50%] Linking C shared library libcotp.so
[ 50%] Built target cotp
Scanning dependencies of target test_cotp
[ 75%] Building C object tests/CMakeFiles/test_cotp.dir/test_otp.c.o
[100%] Linking C executable test_cotp
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lcotp
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/test_cotp.dir/build.make:84: tests/test_cotp] Error 1
make[1]: *** [CMakeFiles/Makefile2:123: tests/CMakeFiles/test_cotp.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

I fixed this error by adding target_link_directories (test_cotp PRIVATE ${PROJECT_BINARY_DIR}) to tests/CMakeLists.txt.

error while building

CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message): Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Call Stack (most recent call first): /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.16/Modules/FindPkgConfig.cmake:41 (find_package_handle_standard_args) CMakeLists.txt:8 (find_package)

Any idea why this error and how to fix this?

Exception running...

#include <stdio.h>
#include <cotp.h>
#include <time.h>
int main() {

    const char *base32_encoded_secret = "1234567890";
    int digits = 5;
    int period = 20;
    int algo = SHA1;
    cotp_error_t *err = NULL;
    char *fds = "1234";
    printf("%s", fds);
//    char *totp = get_steam_totp(base32_encoded_secret, 3, err);
    char *totp = get_hotp(base32_encoded_secret, digits, period, SHA512, err);
    printf("%s", totp);

}

image
Is there anything wrong with the parameters I filled in?

Tests are failing

Since v1.2.7, tests are failing:

$ ./tests/test_cotp
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 755224
[----]   
[----] ../tests/test_otp.c:189: Assertion Failed
[----]   
[----]   Expected 22222 to be equal to YRGQJ
[----]   
[----] ../tests/test_otp.c:35: Assertion Failed
[----]   
[----]   Expected 0000000000 to be equal to 0689005924
[----]   
[----] ../tests/test_otp.c:213: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 360094
[----]   
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 94287082
[----]   
[----] ../tests/test_otp.c:154: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 488431
[----]   
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 46119246
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 287082
[----]   
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 07081804
[----]   
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 68084774
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 359152
[----]   
[FAIL] totp_generic::test_steam_totp: (0.00s)
[FAIL] totp_rfc6238::test_10_digits_sha1: (0.00s)
[FAIL] totp_rfc6238::test_60seconds: (0.00s)
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 14050471
[----]   
[FAIL] totp_generic::test_secret_with_space: (0.00s)
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 67062674
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 969429
[----]   
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 89005924
[----]   
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 91819424
[----]   
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 90693936
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 338314
[----]   
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 69279037
[----]   
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 90698825
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 254676
[----]   
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 25091201
[----]   
[----] ../tests/test_otp.c:18: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 65353130
[----]   
[----] ../tests/test_otp.c:53: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 77737706
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 287922
[----]   
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 99943326
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 162583
[----]   
[FAIL] totp_rfc6238::test_8_digits_sha1: (0.00s)
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 93441116
[----]   
[FAIL] totp_rfc6238::test_8_digits_sha256: (0.00s)
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 399871
[----]   
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 38618901
[----]   
[----] ../tests/test_otp.c:89: Assertion Failed
[----]   
[----]   Expected 000000 to be equal to 520489
[----]   
[----] ../tests/test_otp.c:71: Assertion Failed
[----]   
[----]   Expected 00000000 to be equal to 47863826
[----]   
[FAIL] totp_rfc6238::test_8_digits_sha512: (0.00s)
[FAIL] hotp_rfc::test_6_digits: (0.01s)
[====] Synthesis: Tested: 15 | Passing: 7 | Failing: 8 | Crashing: 0 

Build log:

$ cmake -DBUILD_TESTING=ON ..
-- The C compiler identification is Clang 15.0.6
-- The CXX compiler identification is Clang 15.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/yoshi/.local/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/yoshi/.local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.0") 
-- Found Gcrypt: /usr/lib64/libgcrypt.so (Required is at least version "1.6.0") 
-- Checking for module 'baseencode>=1.0.14'
--   Found baseencode, version 1.0.15
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yoshi/Downloads/libcotp/build

$ make
[ 25%] Building C object CMakeFiles/cotp.dir/src/otp.c.o
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
[ 50%] Linking C shared library libcotp.so
[ 50%] Built target cotp
[ 75%] Building C object tests/CMakeFiles/test_cotp.dir/test_otp.c.o
/home/yoshi/Downloads/libcotp/tests/test_otp.c:13:36: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *K_base32 = base32_encode(K, strlen(K)+1, &base_err);
                                   ^
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
/home/yoshi/Downloads/libcotp/tests/test_otp.c:31:36: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *K_base32 = base32_encode(K, strlen(K)+1, &base_err);
                                   ^
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
/home/yoshi/Downloads/libcotp/tests/test_otp.c:48:36: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *K_base32 = base32_encode(K, strlen(K)+1, &base_err);
                                   ^
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
/home/yoshi/Downloads/libcotp/tests/test_otp.c:66:36: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *K_base32 = base32_encode(K, strlen(K)+1, &base_err);
                                   ^
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
/home/yoshi/Downloads/libcotp/tests/test_otp.c:84:36: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *K_base32 = base32_encode(K, strlen(K)+1, &base_err);
                                   ^
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
/home/yoshi/Downloads/libcotp/tests/test_otp.c:209:41: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
    char *secret_base32 = base32_encode(secret, strlen(secret)+1, &base_err);
                                        ^~~~~~
/usr/include/baseencode.h:14:54: note: passing argument to parameter 'user_data' here
char            *base32_encode (const unsigned char *user_data,
                                                     ^
6 warnings generated.
[100%] Linking C executable test_cotp
[100%] Built target test_cotp

Some of the tests were fixed when I changed compute_hmac not to call gcry_md_close.
It looks like the later frees the buffer returned by gcry_md_read.

pkg-config file is broken when CMAKE_INSTALL_{INCLUDE,LIB}DIR is absolute

As per title: cotp.pc.in has

prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

and so can’t handle absolute paths in CMAKE_INSTALL_{INCLUDE,LIB}DIR. This leads to broken .pc files on NixOS in particular.

Identical to paolostivanin/libbaseencode#25. See “Concatenating paths when building pkg-config files” for a thorough discussion of the problem and a suggested fix, or KDE’s extra-cmake-modules for a simpler approach.

SOVERSION should be set manually

Hello, i think that SOVERSION in CMakeLists.txt should be set manually as a standalone number and bumped when ABI changes, because now after transition from 1.0.14 to 1.1.0 SOVERSION stays the same, which is wrong because of these ABI changes.

set_target_properties(cotp PROPERTIES VERSION ${BUILD_VERSION} SOVERSION ${BUILD_MAJOR})

or maybe change BUILD_MAJOR to BUILD_MINOR?

License collision with libbaseencode

According to libbaseencode license and GNU licenses FAQ, libbaseencode license is incompatible with libcotp license, because libbaseencode is under the GPL license, which means that all code linked to libbaseencode must be under GPL as well.

If you agree with my analysis, either libcotp license should be changed to GPL, or libcotp should use another base32 libraries with a compatible license.

For example, Google Authenticator PAM module has base32 functionalities under apache license, so a solution could be to reuse Google Authenticator PAM module base32 implementation in libcotp.

If you're ok, I can provide a pull request to remove libbaseencode dependency?

[macOS] build fails: `ld: unknown options: --no-add-needed --as-needed -z -z`

[100%] Linking C shared library libcotp.dylib
/opt/local/bin/cmake -E cmake_link_script CMakeFiles/cotp.dir/link.txt --verbose=ON
/usr/bin/clang -pipe -Os -DNDEBUG -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -mmacosx-version-min=14.0 -dynamiclib -Wl,-headerpad_max_install_names -Wl,--no-add-needed -Wl,--as-needed -Wl,-z,relro,-z,now -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -compatibility_version 2.0.0 -current_version 2.0.1 -o libcotp.2.0.1.dylib -install_name @rpath/libcotp.2.dylib CMakeFiles/cotp.dir/src/otp.c.o CMakeFiles/cotp.dir/src/utils/base32.c.o  -Wl,-rpath,/opt/local/lib /opt/local/lib/libgcrypt.dylib 
ld: unknown options: --no-add-needed --as-needed -z -z 
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libcotp.2.0.1.dylib] Error 1

No package 'baseencode' found

Hello. I'm getting the error No package 'baseencode' found trying to update libcotp/otpclient. I can install libbaseencode manually, but not this package afterward, either manually or through a package manager.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.