Activating a user key in admin causes error: object of type 'NoneType' has no len() #1072

Closed
opened 2025-12-29 16:28:32 +01:00 by adam · 6 comments
Owner

Originally created by @quentinsch on GitHub (Jul 3, 2017).

Python version: 2.7.5
NetBox version: 2.0.7

When activating a user key in the admin backend it causes an error:

<type 'exceptions.TypeError'>
object of type 'NoneType' has no len()

I pasted the private key in the field and when activating this error occurs. Also see screenshot for error message.

schermafbeelding 2017-07-03 om 13 50 48

Originally created by @quentinsch on GitHub (Jul 3, 2017). Python version: 2.7.5 NetBox version: 2.0.7 When activating a user key in the admin backend it causes an error: <type 'exceptions.TypeError'> object of type 'NoneType' has no len() I pasted the private key in the field and when activating this error occurs. Also see screenshot for error message. ![schermafbeelding 2017-07-03 om 13 50 48](https://user-images.githubusercontent.com/7438854/27791780-09697d16-5ff7-11e7-8526-f2e2125f0f08.png)
adam added the type: bug label 2025-12-29 16:28:32 +01:00
adam closed this issue 2025-12-29 16:28:32 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 3, 2017):

Please provide the exact steps needed to recreate this issue.

@jeremystretch commented on GitHub (Jul 3, 2017): Please provide the exact steps needed to recreate this issue.
Author
Owner

@quentinsch commented on GitHub (Jul 3, 2017):

Ok, figured it out. It was a stupid mistake on my side, but throwing a nicer error message would be better. I pasted the private key of the user to activate the key, but of course you'll need to paste the private key of the logged in admin user to activate a user key.
After doing the steps below, but pasted the right key the key for the user can be activated.

Below the steps to recreate the error:

1: Go to admin
2: Click "add user" and fill in required info
3: Just leave user with basic privileges
4: Login as created user
5: Go to your users profile
6: Go to "User Key"
7: Create a new key pair
8: Save the private key
9: Login as an admin user
10: Go to admin
11: Go to "User keys"
12: Check box for user to activate key
13: Select in dropdown menu "Activate selected user keys"
14: Click "Go"
15: Paste private key saved earlier from the user (this is where it goes wrong)
16: Click "Activate user keys"
17: Error will show as described in earlier comment

@quentinsch commented on GitHub (Jul 3, 2017): Ok, figured it out. It was a stupid mistake on my side, but throwing a nicer error message would be better. I pasted the private key of the user to activate the key, but of course you'll need to paste the private key of the logged in admin user to activate a user key. After doing the steps below, but pasted the right key the key for the user can be activated. Below the steps to recreate the error: 1: Go to admin 2: Click "add user" and fill in required info 3: Just leave user with basic privileges 4: Login as created user 5: Go to your users profile 6: Go to "User Key" 7: Create a new key pair 8: Save the private key 9: Login as an admin user 10: Go to admin 11: Go to "User keys" 12: Check box for user to activate key 13: Select in dropdown menu "Activate selected user keys" 14: Click "Go" 15: Paste private key saved earlier from the user (this is where it goes wrong) 16: Click "Activate user keys" 17: Error will show as described in earlier comment
Author
Owner

@jeremystretch commented on GitHub (Jul 3, 2017):

Awesome, thanks!

but throwing a nicer error message would be better

Yep, absolutely. Ideally a user should never see a server error.

@jeremystretch commented on GitHub (Jul 3, 2017): Awesome, thanks! > but throwing a nicer error message would be better Yep, absolutely. Ideally a user should never see a server error.
Author
Owner

@jeremystretch commented on GitHub (Jul 5, 2017):

I'm not able to replicate this error using the steps provided. Could you please try again and post the entire stack trace? (You can find this in the admin email or set DEBUG=True in configuration.py.)

@jeremystretch commented on GitHub (Jul 5, 2017): I'm not able to replicate this error using the steps provided. Could you please try again and post the entire stack trace? (You can find this in the admin email or set `DEBUG=True` in configuration.py.)
Author
Owner

@quentinsch commented on GitHub (Jul 11, 2017):

Sure, here it is:

TypeError at /admin/secrets/userkey/
object of type 'NoneType' has no len()
Request Method:	POST
Request URL:	https://dcim.testdomain.net/admin/secrets/userkey/
Django Version:	1.10.7
Exception Type:	TypeError
Exception Value:	
object of type 'NoneType' has no len()
Exception Location:	/usr/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt, line 139
Python Executable:	/usr/bin/python
Python Version:	2.7.5
Python Path:	
['/opt/netbox/netbox',
 '/opt/netbox/netbox',
 '/usr/bin',
 '/usr/lib64/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages']
Server time:	Tue, 11 Jul 2017 15:12:56 +0200
Traceback Switch to copy-and-paste view

/usr/lib/python2.7/site-packages/django/core/handlers/exception.py in inner
            response = get_response(request) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/core/handlers/base.py in _get_response
                response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/core/handlers/base.py in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in wrapper
                return self.admin_site.admin_view(view)(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/views/decorators/cache.py in _wrapped_view_func
        response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/sites.py in inner
            return view(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapper
            return bound_func(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in bound_func
                return func.__get__(self, type(self))(*args2, **kwargs2) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in changelist_view
                response = self.response_action(request, queryset=cl.get_queryset(request)) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in response_action
            response = func(self, request, queryset) ...
▶ Local vars
/opt/netbox/netbox/secrets/admin.py in activate_selected
                        uk.activate(master_key) ...
▶ Local vars
/opt/netbox/netbox/secrets/models.py in activate
        self.master_key_cipher = encrypt_master_key(master_key, self.public_key) ...
▶ Local vars
/opt/netbox/netbox/secrets/models.py in encrypt_master_key
    return cipher.encrypt(master_key) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt
        mLen = len(message) ...
▶ Local vars
@quentinsch commented on GitHub (Jul 11, 2017): Sure, here it is: ``` TypeError at /admin/secrets/userkey/ object of type 'NoneType' has no len() Request Method: POST Request URL: https://dcim.testdomain.net/admin/secrets/userkey/ Django Version: 1.10.7 Exception Type: TypeError Exception Value: object of type 'NoneType' has no len() Exception Location: /usr/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt, line 139 Python Executable: /usr/bin/python Python Version: 2.7.5 Python Path: ['/opt/netbox/netbox', '/opt/netbox/netbox', '/usr/bin', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages'] Server time: Tue, 11 Jul 2017 15:12:56 +0200 Traceback Switch to copy-and-paste view /usr/lib/python2.7/site-packages/django/core/handlers/exception.py in inner response = get_response(request) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/core/handlers/base.py in _get_response response = self.process_exception_by_middleware(e, request) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/core/handlers/base.py in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/contrib/admin/options.py in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view response = view_func(request, *args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/views/decorators/cache.py in _wrapped_view_func response = view_func(request, *args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/contrib/admin/sites.py in inner return view(request, *args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapper return bound_func(*args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view response = view_func(request, *args, **kwargs) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/utils/decorators.py in bound_func return func.__get__(self, type(self))(*args2, **kwargs2) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/contrib/admin/options.py in changelist_view response = self.response_action(request, queryset=cl.get_queryset(request)) ... ▶ Local vars /usr/lib/python2.7/site-packages/django/contrib/admin/options.py in response_action response = func(self, request, queryset) ... ▶ Local vars /opt/netbox/netbox/secrets/admin.py in activate_selected uk.activate(master_key) ... ▶ Local vars /opt/netbox/netbox/secrets/models.py in activate self.master_key_cipher = encrypt_master_key(master_key, self.public_key) ... ▶ Local vars /opt/netbox/netbox/secrets/models.py in encrypt_master_key return cipher.encrypt(master_key) ... ▶ Local vars /usr/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt mLen = len(message) ... ▶ Local vars ```
Author
Owner

@jeremystretch commented on GitHub (Jul 12, 2017):

15: Paste private key saved earlier from the user (this is where it goes wrong)

Ok, so this is the issue. The person activating another user's key needs to provide his or her own private key. (No one is ever required to reveal his or her private key to another user.)

But yes, this should be caught and a validation error should be raised.

@jeremystretch commented on GitHub (Jul 12, 2017): > 15: Paste private key saved earlier from the user (this is where it goes wrong) Ok, so this is the issue. The person activating another user's key needs to provide his or her own private key. (No one is ever required to reveal his or her private key to another user.) But yes, this should be caught and a validation error should be raised.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1072