Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake does not find installed HIDAPI on macOS #140

Open
muellermartin opened this issue Jan 14, 2019 · 9 comments · May be fixed by #141
Open

CMake does not find installed HIDAPI on macOS #140

muellermartin opened this issue Jan 14, 2019 · 9 comments · May be fixed by #141
Milestone

Comments

@muellermartin
Copy link
Contributor

muellermartin commented Jan 14, 2019

When HIDAPI is installed externally (e.g. via a package manager like Homebrew: brew install hidapi) and the tarball of libnitrokey is used, the current version of the CMakeLists.txt is not able to find this installation and fails with an error message like this:

CMake Error at CMakeLists.txt:78 (add_library):
  Cannot find source file:

    hidapi/mac/hid.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at CMakeLists.txt:78 (add_library):
  No SOURCES given to target: hidapi-libusb

This is because the CMake script searches for hidapi/mac/hid.c (see CMakeLists.txt line 78) in the current directory.

@szszszsz
Copy link
Member

Hi @muellermartin !
Thank you for the report. This actually is done on purpose, since the original hidapi library / Homebrew provided is not working in our case. For libnitrokey we use our fork - https://github.com/Nitrokey/hidapi.

Was your build working for you?

@szszszsz
Copy link
Member

To do:

  • Add a comment in the Readme about used hidapi library, and the reason, to avoid confusion.

@muellermartin
Copy link
Contributor Author

muellermartin commented Jan 14, 2019

I'm using hidapi stable 0.8.0-rc1 from Homebrew with my patch in PR #141 and the build works so far, although I did not test it extensively.

As you mentioned, I didn't know that the upstream hidapi is known not to work because this is not documented in an obvious way.

Was your build working for you?

Yes, I've successfully built libnitrokey with COMPILE_TESTS=ON and ran ./test_safe with following result:

[Mon Jan 14 11:58:18 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
..........
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	Busy retry: status 2, 80ms, counter 54, progress: 0
...
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	=> GET_PASSWORD_RETRY_COUNT
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	<= GET_PASSWORD_RETRY_COUNT 0 0
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
.....
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
[Mon Jan 14 11:58:19 2019][DEBUG_L1]	=> GET_USER_PASSWORD_RETRY_COUNT
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	<= GET_USER_PASSWORD_RETRY_COUNT 0 0
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
.....
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
 transmission_data.dissect():	_padding:
0000	00 00 00 00 00 00 00 00 00 00 00 00 00 03 2e 01   ................
0010	00 00 -- -- -- -- -- -- -- -- -- -- -- -- -- --   ..
 (int) SendCounter_u8:	0
 (int) SendDataType_u8:	3
 (int) FollowBytesFlag_u8:	0
 (int) SendSize_u8:	28

 MagicNumber_StickConfig_u16:	13080
 (int) ReadWriteFlagUncryptedVolume_u8:	0
 (int) ReadWriteFlagCryptedVolume_u8:	0
 (int) ReadWriteFlagHiddenVolume_u8:	0
 (int) versionInfo.major:	0
 (int) versionInfo.minor:	53
 (int) versionInfo.build_iteration:	0
 (int) FirmwareLocked_u8:	0
 (int) NewSDCardFound_u8:	1
 (int) NewSDCardFound_st.NewCard:	1
 (int) NewSDCardFound_st.Counter:	0
 (int) SDFillWithRandomChars_u8:	1
 ActiveSD_CardID_u32:	748145556
 (int) VolumeActiceFlag_u8:	1
 (int) VolumeActiceFlag_st.unencrypted:	1
 (int) VolumeActiceFlag_st.encrypted:	0
 (int) VolumeActiceFlag_st.hidden:	0
 (int) NewSmartCardFound_u8:	0
 (int) UserPwRetryCount:	3
 (int) AdminPwRetryCount:	3
 ActiveSmartCardID_u32:	327680
 (int) StickKeysNotInitiated:	0

[Mon Jan 14 11:58:20 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
......
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
00050000
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
......
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
[Mon Jan 14 11:58:20 2019][DEBUG_L1]	=> GET_DEVICE_STATUS
......
[Mon Jan 14 11:58:21 2019][DEBUG_L1]	<= GET_DEVICE_STATUS 0 1
===============================================================================
All tests passed (18 assertions in 6 test cases)

If you want, I could also run the other tests.

@szszszsz
Copy link
Member

Thank you for the details! That is odd, I will check on my side.

If you are interested, and have no own data on the Storage device yet, it would be helpful to run other tests as well. I am specifically interested in Python's test_pro.py and test_storage.py, as mentioned in https://github.com/Nitrokey/libnitrokey#python-tests - whether it mostly passes or fails.
I remember from my last testing with the homebrew's version, that some cases were not passing.
Note: some TOTP related tests may fail (due to the device's internal clock, and making the tests on the edge of time window), as well as slot edition. Please make sure the PINs are set to default.

Related: d-e-s-o/nitrocli#39

@muellermartin
Copy link
Contributor Author

I only have a Nitrokey Storage 2, should I only run test_storage.py then?

@szszszsz
Copy link
Member

For Storage device, both test_pro and test_storage are usable.

@muellermartin
Copy link
Contributor Author

As requested, here are the log files for the test_pro and test_storage tests. I did the test once for the HIDAPI by Nitrokey and the upstream version provided by Homebrew:

Apparently there are only a few differences in the test_pro test, but I don't know how to interpret them. Mosty it's xfail vs. XPASS – maybe that's what was noted for the TOTP related test…

Note: I've created the log file with script to preserve the ANSI color code sequences for easier readability e.g. with less (created with script -q test_pro_nitrokey_hidapi_$(date '+%Y-%m-%d-%H-%M-%S').log py.test -v test_pro.py).

@szszszsz
Copy link
Member

Thank you! It looks like indeed everything works on your side. I will update here once confirmed in my environment.

@muellermartin
Copy link
Contributor Author

You're welcome.

I've already a Homebrew Formula ready, but with a patch for this issue, which from my experience will lead to rejection. Therefore I will wait with the submission of the Formula until this is confirmed and resolved.

@szszszsz szszszsz added this to the v3.6 milestone Jul 10, 2019
sgued pushed a commit to sgued/libnitrokey that referenced this issue Feb 14, 2022
setup for the new ci server
@szszszsz szszszsz modified the milestones: v3.7, v3.8 Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants