Libnitrokey on Ubuntu 16.04

Hi,

I am trying to use Nitrokey Storage HOTP feature using python library. I am using Ubuntu 16.04 inside Virtualbox 5.2, running on mac.

I am running into following issue.

First when I try compile the libnitrokey, -DLIBNITROKEY_STATIC=OFF doesn’t seem to exist.

zs@mac:~/libnitrokey/build$ cmake … -DLIBNITROKEY_STATIC=OFF
libnitrokey: Build type: RelWithDebInfo
– Configuring done
– Generating done
CMake Warning:
Manually-specified variables were not used by the project:

LIBNITROKEY_STATIC

– Build files have been written to: /home/zs/libnitrokey/build

zs@mac:~/libnitrokey/build$ cmake … -L
libnitrokey: Build type: RelWithDebInfo
– Configuring done
– Generating done
– Build files have been written to: /home/zs/libnitrokey/build
– Cache values
ADD_ASAN:BOOL=OFF
ADD_TSAN:BOOL=OFF
BUILD_SHARED_LIBS:BOOL=ON
CMAKE_BUILD_TYPE:STRING=
CMAKE_INSTALL_PREFIX:PATH=/usr/local
COMPILE_OFFLINE_TESTS:BOOL=OFF
COMPILE_TESTS:BOOL=OFF
ERROR_ON_WARNING:BOOL=OFF
LOG_VOLATILE_DATA:BOOL=OFF
NO_LOG:BOOL=OFF

So when I continued with compiling using cmake ..

zs@mac:~/libnitrokey$ lsusb
Bus 001 Device 002: ID 20a0:4109 Clay Logic
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

I had to also comment out like 74 regarding the debug log message. But after that I get the following error.

zs@mac:~/libnitrokey$ ./python_bindings_example.py
Warning!
This example will change your configuration on inserted stick and overwrite your HOTP#2 slot.
Please write “continue” to continue or any other string to quit
continue
Please enter your admin PIN (empty string uses 12345678)12345678
Should log messages be shown (please write “yes” to enable)?yes
./build/libnitrokey-log.so
File does not exist: ./build/libnitrokey-log.so
Trying another
./build/libnitrokey.so
Traceback (most recent call last):
File “./python_bindings_example.py”, line 83, in
device_connected = libnitrokey.NK_login_auto() # connect to any Nitrokey Stick
File “/home/zs/.local/lib/python2.7/site-packages/cffi/api.py”, line 875, in getattr
make_accessor(name)
File “/home/zs/.local/lib/python2.7/site-packages/cffi/api.py”, line 870, in make_accessor
raise AttributeError(name)
AttributeError: NK_login_auto

1 Like

Hi!
Turned out the C API header processing part of the example script was not updated. Recently mentioned file was reformatted, which confused the implementation in the example. Fix is already added to repository (copied from unittest/conftest.py) - please download latest master. In case any other thing would not work please let me know. Test files: unittest/test_pro.py and test_storage.py uses this solution extensively.

Regarding LIBNITROKEY_STATIC, recently the name was changed to BUILD_SHARED_LIBS. Sorry for confusion. I will update the Readme.

Issue link: #82

Thank you for reporting!

Thanks. I am able to compile the library, moved pass the previous error, but the python script now failing at below:

zs@ubuntuvm:~/libnitrokey$ ./python_bindings_example.py
Warning!
This example will change your configuration on inserted stick and overwrite your HOTP#2 slot.
Please write “continue” to continue or any other string to quit
continue
Please enter your admin PIN (empty string uses 12345678)
Should log messages be shown (please write “yes” to enable)?
Imported 56 declarations
./build/libnitrokey-log.so
File does not exist: ./build/libnitrokey-log.so
Trying another
./build/libnitrokey.so
Connected to Nitrokey device!
Your PIN is correct!
Getting HOTP code from Nitrokey Pro (RFC test, 8 digits):
Traceback (most recent call last):
File “./python_bindings_example.py”, line 116, in
print(’%d: %d, should be %s’ % (i, hotp_slot_1_code, str(test_data[i])[-8:] ))
TypeError: %d format: a number is required, not _cffi_backend.CData

Hi!
Sorry about that. I had no device for tests at that moment. I have just updated the example on master branch and tested it with Storage v0.48 and Pro v0.7 (under Ubuntu 17.04).

Edit: readme file updated.

1 Like