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

AttributeError: 'NoneType' object has no attribute 'close' #110

Closed
gbrindisi opened this issue May 15, 2018 · 5 comments
Closed

AttributeError: 'NoneType' object has no attribute 'close' #110

gbrindisi opened this issue May 15, 2018 · 5 comments

Comments

@gbrindisi
Copy link

Hey,
can't get rid of this error when trying to setup an otp slot in a YubiKey 4C.

OSX 10.13.3, ykman 0.7.0 installed from brew

ykman -d XYZ info
Device type: YubiKey 4
Serial number: XYZ
Firmware version: 4.3.7
Enabled USB interfaces: OTP+FIDO+CCID

Applications
OTP     	Enabled
FIDO U2F	Enabled
OpenPGP 	Enabled
PIV     	Enabled
OATH    	Enabled
FIDO2   	Not available
$ ykman -d XYZ otp static --generate 1
Traceback (most recent call last):
  File "/usr/local/bin/ykman", line 11, in <module>
    load_entry_point('yubikey-manager==0.7.0', 'console_scripts', 'ykman')()
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/__main__.py", line 211, in main
    cli(obj={})
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 1063, in invoke
    Command.invoke(self, ctx)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/util.py", line 77, in inner
    f(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/__main__.py", line 157, in cli
    ctx.call_on_close(dev.close)
AttributeError: 'NoneType' object has no attribute 'close'
@dagheyman
Copy link
Contributor

Thanks!

I can't reproduce the crash on my mac (10.13.4) with the brew installation of ykman though, I get

$ ykman -d 7072205 otp static --generate 1
Usage: ykman otp static [OPTIONS] SLOT [PASSWORD]

Error: Provide a length for the generated password.

Note that the generate flag currently requires the length option as well, so the correct syntax for generating a 38 character static password in slot 1 would be:
$ ykman -d [SERIAL] otp static 1 --generate --length 38

Could you try running the command with --log-level DEBUG ?
Like this:
$ ykman --log-level DEBUG -d [SERIAL] otp static 1 --generate --length 38

@gbrindisi
Copy link
Author

Here you go:

$ ykman --log-level DEBUG -d XYZ otp static 1 --generate --length 38
2018-05-16T12:55:14+0200 INFO [ykman.logging_setup.setup:59] Initialized logging for ykman version: 0.7.0
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:160] Opening driver for transports: TRANSPORT.OTP, serial: XYZ, pid: None
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 1 of 10
2018-05-16T12:55:14+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.100000 s
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 2 of 10
2018-05-16T12:55:14+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.200000 s
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 3 of 10
2018-05-16T12:55:14+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.300000 s
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 4 of 10
2018-05-16T12:55:14+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:14+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.400000 s
2018-05-16T12:55:15+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 5 of 10
2018-05-16T12:55:15+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:15+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.500000 s
2018-05-16T12:55:15+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 6 of 10
2018-05-16T12:55:15+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:15+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.600000 s
2018-05-16T12:55:16+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 7 of 10
2018-05-16T12:55:16+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:16+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.700000 s
2018-05-16T12:55:17+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 8 of 10
2018-05-16T12:55:17+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:17+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.800000 s
2018-05-16T12:55:18+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 9 of 10
2018-05-16T12:55:18+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:18+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 0.900000 s
2018-05-16T12:55:18+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 10 of 10
2018-05-16T12:55:18+0200 DEBUG [ykman.driver_otp.open_devices:178] Failed to open key at position 0
2018-05-16T12:55:18+0200 DEBUG [ykman.descriptor._open_driver:179] Sleeping for 1.000000 s
2018-05-16T12:55:19+0200 DEBUG [ykman.descriptor._open_driver:181] No driver found for serial: XYZ, pid: None
2018-05-16T12:55:19+0200 DEBUG [ykman.descriptor._open_driver:160] Opening driver for transports: 7, serial: XYZ, pid: None
2018-05-16T12:55:19+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 1 of 10
2018-05-16T12:55:19+0200 DEBUG [ykman.device.__init__:196] Read config from device...
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 00a4040008a000000527471117
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 5669727475616c206d6772202d2046572076657273696f6e20342e332e379000
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 001d000000
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 0c0101ff02040066500903013f9000
2018-05-16T12:55:19+0200 DEBUG [ykman.device.__init__:198] Success!
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 00a4040007a0000005272001
2018-05-16T12:55:19+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 040307010500060f00009000
2018-05-16T12:55:19+0200 DEBUG [ykman.descriptor._open_driver:166] Found driver: <ykman.driver_ccid.CCIDDriver object at 0x106a41c10> serial: XYZ, pid: PID.YK4_OTP_FIDO_CCID
2018-05-16T12:55:20+0200 DEBUG [ykman.device.__init__:196] Read config from device...
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 00a4040008a000000527471117
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 5669727475616c206d6772202d2046572076657273696f6e20342e332e379000
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 001d000000
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 0c0101ff02040066500903013f9000
2018-05-16T12:55:20+0200 DEBUG [ykman.device.__init__:198] Success!
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:168] SEND: 00a4040007a0000005272001
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.send_apdu:170] RECV: 040307010500060f00009000
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.__del__:213] Destroy <ykman.driver_ccid.CCIDDriver object at 0x106a41c10>
2018-05-16T12:55:20+0200 DEBUG [ykman.driver_ccid.close:209] Close <ykman.driver_ccid.CCIDDriver object at 0x106a41c10>
Traceback (most recent call last):
  File "/usr/local/bin/ykman", line 11, in <module>
    load_entry_point('yubikey-manager==0.7.0', 'console_scripts', 'ykman')()
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/__main__.py", line 211, in main
    cli(obj={})
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 1063, in invoke
    Command.invoke(self, ctx)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/util.py", line 77, in inner
    f(*args, **kwargs)
  File "/usr/local/Cellar/ykman/0.7.0/libexec/lib/python2.7/site-packages/ykman/cli/__main__.py", line 157, in cli
    ctx.call_on_close(dev.close)
AttributeError: 'NoneType' object has no attribute 'close'

@dagheyman
Copy link
Contributor

There seem to be a problem opening the key over the OTP interface.
Does this commands work?

$ ykinfo -s -v

Does the YubiKey Personalization GUI recognise the key?

@gbrindisi
Copy link
Author

I've figured it out, I guess.

I've installed the Yubikey Personalization Tool and I got a Unknown Error occurred there as well.
Digging around the problem seemed related to this: Yubico/yubikey-personalization#34

And this is the resolution that worked for me: Yubico/yubikey-personalization-gui#25 (comment)

Removing everything that was altering the keyboard events (I had a small homemade thing running that I forgot) solved the problem:

$ ykinfo -s -v
serial: XYZ
version: 4.3.7
$ ykman --log-level DEBUG -d XYZ otp static 1 --generate --length 38
2018-05-18T14:26:58+0200 INFO [ykman.logging_setup.setup:59] Initialized logging for ykman version: 0.7.0
2018-05-18T14:26:58+0200 DEBUG [ykman.descriptor._open_driver:160] Opening driver for transports: TRANSPORT.OTP, serial: XYZ, pid: None
2018-05-18T14:26:58+0200 DEBUG [ykman.descriptor._open_driver:162] Attempt 1 of 10
2018-05-18T14:26:58+0200 DEBUG [ykman.driver_otp.open_devices:180] Success in opening key at position 0
2018-05-18T14:26:58+0200 DEBUG [ykman.device.__init__:196] Read config from device...
2018-05-18T14:26:58+0200 DEBUG [ykman.device.__init__:198] Success!
2018-05-18T14:26:58+0200 DEBUG [ykman.descriptor._open_driver:166] Found driver: <ykman.driver_otp.OTPDriver object at 0x10309e5d0> serial: XYZ, pid: PID.YK4_OTP_FIDO_CCID
2018-05-18T14:26:58+0200 DEBUG [ykman.device.__init__:196] Read config from device...
2018-05-18T14:26:58+0200 DEBUG [ykman.device.__init__:198] Success!
Slot 1 is already configured. Overwrite configuration? [y/N]:

Thank you!

@dagheyman
Copy link
Contributor

Glad it worked out. I'll make sure that ykman at least doesn't crash in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants