Error activating user secret key #261

Closed
opened 2025-12-29 16:20:16 +01:00 by adam · 14 comments
Owner

Originally created by @augustocarlson on GitHub (Jul 20, 2016).

Hello!

I created a key for my netbox user to be able to use secrets. The key is inactive.

When I try to activate the key from the admin panel with my own user I receive an error (debug below) . If I try to activate using the admin user the message You do not have an active User Key. appears on the top of the page without any debug error.

Netbox v1.3.0.

  • Debug output:
TypeError at /admin/secrets/userkey/

object of type 'NoneType' has no len()

Request Method:     POST
Request URL:    https://netbox.mpsc.mp.br/admin/secrets/userkey/
Django Version:     1.9.7
Exception Type:     TypeError
Exception Value:    

object of type 'NoneType' has no len()

Exception Location:     /usr/local/lib/python2.7/dist-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt, line 139
Python Executable:  /usr/bin/python
Python Version:     2.7.6
Python Path:    

['/opt/netbox/netbox/netbox',
 '/opt/netbox/netbox',
 '/usr/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages']

Server time:    Wed, 20 Jul 2016 16:47:32 -0300
Originally created by @augustocarlson on GitHub (Jul 20, 2016). Hello! I created a key for my netbox user to be able to use secrets. The key is inactive. When I try to activate the key from the admin panel with my own user I receive an error (debug below) . If I try to activate using the _admin_ user the message **You do not have an active User Key.** appears on the top of the page without any debug error. Netbox v1.3.0. - Debug output: ``` TypeError at /admin/secrets/userkey/ object of type 'NoneType' has no len() Request Method: POST Request URL: https://netbox.mpsc.mp.br/admin/secrets/userkey/ Django Version: 1.9.7 Exception Type: TypeError Exception Value: object of type 'NoneType' has no len() Exception Location: /usr/local/lib/python2.7/dist-packages/Crypto/Cipher/PKCS1_OAEP.py in encrypt, line 139 Python Executable: /usr/bin/python Python Version: 2.7.6 Python Path: ['/opt/netbox/netbox/netbox', '/opt/netbox/netbox', '/usr/bin', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages'] Server time: Wed, 20 Jul 2016 16:47:32 -0300 ```
adam closed this issue 2025-12-29 16:20:16 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 21, 2016):

Could you provide the traceback as well please? That will help me figure out where the error is occurring.

@jeremystretch commented on GitHub (Jul 21, 2016): Could you provide the traceback as well please? That will help me figure out where the error is occurring.
Author
Owner

@augustocarlson commented on GitHub (Jul 21, 2016):

Traceback:

Environment:


Request Method: POST
Request URL: https://netbox.mpsc.mp.br/admin/secrets/userkey/

Django Version: 1.9.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'debug_toolbar',
 'django_tables2',
 'rest_framework',
 'rest_framework_swagger',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'users',
 'utilities')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.LoginRequiredMiddleware')



Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
  541.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  244.             return view(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view
  1512.                 response = self.response_action(request, queryset=cl.get_queryset(request))

File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in response_action
  1245.             response = func(self, request, queryset)

File "/opt/netbox/netbox/secrets/admin.py" in activate_selected
  46.                         uk.activate(master_key)

File "/opt/netbox/netbox/secrets/models.py" in activate
  159.         self.master_key_cipher = encrypt_master_key(master_key, self.public_key)

File "/opt/netbox/netbox/secrets/models.py" in encrypt_master_key
  32.     return cipher.encrypt(master_key)

File "/usr/local/lib/python2.7/dist-packages/Crypto/Cipher/PKCS1_OAEP.py" in encrypt
  139.         mLen = len(message)

Exception Type: TypeError at /admin/secrets/userkey/
Exception Value: object of type 'NoneType' has no len()
@augustocarlson commented on GitHub (Jul 21, 2016): Traceback: ``` Environment: Request Method: POST Request URL: https://netbox.mpsc.mp.br/admin/secrets/userkey/ Django Version: 1.9.7 Python Version: 2.7.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'debug_toolbar', 'django_tables2', 'rest_framework', 'rest_framework_swagger', 'circuits', 'dcim', 'ipam', 'extras', 'secrets', 'users', 'utilities') Installed Middleware: (u'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'utilities.middleware.LoginRequiredMiddleware') Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 149. response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 147. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper 541. return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner 244. return view(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view 1512. response = self.response_action(request, queryset=cl.get_queryset(request)) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in response_action 1245. response = func(self, request, queryset) File "/opt/netbox/netbox/secrets/admin.py" in activate_selected 46. uk.activate(master_key) File "/opt/netbox/netbox/secrets/models.py" in activate 159. self.master_key_cipher = encrypt_master_key(master_key, self.public_key) File "/opt/netbox/netbox/secrets/models.py" in encrypt_master_key 32. return cipher.encrypt(master_key) File "/usr/local/lib/python2.7/dist-packages/Crypto/Cipher/PKCS1_OAEP.py" in encrypt 139. mLen = len(message) Exception Type: TypeError at /admin/secrets/userkey/ Exception Value: object of type 'NoneType' has no len() ```
Author
Owner

@jeremystretch commented on GitHub (Jul 21, 2016):

I need to add some error handling there, but it looks like the private key provided is invalid. Are you able to decrypt secrets using the private key?

@jeremystretch commented on GitHub (Jul 21, 2016): I need to add some error handling there, but it looks like the private key provided is invalid. Are you able to decrypt secrets using the private key?
Author
Owner

@augustocarlson commented on GitHub (Jul 21, 2016):

When I try to unlock a secret, the private key is requested. The Unlock button changes to Lock and no error is throw, but the secret remains a secret (sequence of asterisks).
Only the user that has created the user key in earlier release is has the status as active. The user key was probably create using v1.2.1 or v1.2.2 (14 july). All others users have the user key status as inactive.

@augustocarlson commented on GitHub (Jul 21, 2016): When I try to unlock a secret, the private key is requested. The **Unlock** button changes to **Lock** and no error is throw, but the secret remains a secret (sequence of asterisks). Only the user that has created the user key in earlier release is has the status as _active_. The user key was probably create using v1.2.1 or v1.2.2 (14 july). All others users have the user key status as _inactive_.
Author
Owner

@jeremystretch commented on GitHub (Jul 22, 2016):

It sounds like the private RSA key you've provided isn't valid. Are you sure you're using the correct key? If so, try deleting all secrets and userkeys and starting over.

We need to improve error reporting when an invalid key is used.

@jeremystretch commented on GitHub (Jul 22, 2016): It sounds like the private RSA key you've provided isn't valid. Are you sure you're using the correct key? If so, try deleting all secrets and userkeys and starting over. We need to improve error reporting when an invalid key is used.
Author
Owner

@augustocarlson commented on GitHub (Jul 22, 2016):

I already tried to delete the keys and add a new one generated by netbox. I also tried to use a key pair created out of netbox and the same happens.

I also tried to use the key pair from the user that has the key status as active. No success...

@augustocarlson commented on GitHub (Jul 22, 2016): I already tried to delete the keys and add a new one generated by netbox. I also tried to use a key pair created out of netbox and the same happens. I also tried to use the key pair from the user that has the key status as active. No success...
Author
Owner

@jpanos commented on GitHub (Jul 25, 2016):

This happened on my instance as well. However I was able to fix it by purging the database and then only using keys provided by netbox rather than my own RSA key. I don't know if that helps to reach a solution but it should at least help augustocarlson

@jpanos commented on GitHub (Jul 25, 2016): This happened on my instance as well. However I was able to fix it by purging the database and then only using keys provided by netbox rather than my own RSA key. I don't know if that helps to reach a solution but it should at least help augustocarlson
Author
Owner

@augustocarlson commented on GitHub (Jul 25, 2016):

@jpanos do you mean purging all data from the userkey table? or the entire database?

@augustocarlson commented on GitHub (Jul 25, 2016): @jpanos do you mean purging all data from the userkey table? or the entire database?
Author
Owner

@jpanos commented on GitHub (Jul 25, 2016):

@augustocarlson I purged and repopulated entire database because it got to a point where my main userkey wasn't working which meant that I could no longer access my secrets or activate others keys.

@jpanos commented on GitHub (Jul 25, 2016): @augustocarlson I purged and repopulated entire database because it got to a point where my main userkey wasn't working which meant that I could no longer access my secrets or activate others keys.
Author
Owner

@jeremystretch commented on GitHub (Jul 29, 2016):

@augustocarlson Are you able to replicate this on a clean install? I have not been able to.

@jeremystretch commented on GitHub (Jul 29, 2016): @augustocarlson Are you able to replicate this on a clean install? I have not been able to.
Author
Owner

@augustocarlson commented on GitHub (Jul 29, 2016):

@jeremystretch Yes. I just did a full new install. The first user to create an user key, the key is activated just after the creation. The others users have the key set as inactive after the creation. When trying to activate, the error is throw.

@augustocarlson commented on GitHub (Jul 29, 2016): @jeremystretch Yes. I just did a full new install. The first user to create an user key, the key is activated just after the creation. The others users have the key set as inactive after the creation. When trying to activate, the error is throw.
Author
Owner

@jeremystretch commented on GitHub (Jul 29, 2016):

Could you please describe exactly what you're doing? I don't encounter any problem doing the following on v1.3.2.

  1. Log in as the superuser created during install (admin).
  2. Go to admin's profile page and create a user key. Generate an RSA key pair from NetBox and save the private key.
  3. Admin now has an active user key.
  4. Create a second user (bob) via the admin UI.
  5. Log in as bob in a separate browser session.
  6. Go to bob's profile page and create a user key. Generate an RSA key pair from NetBox just as I did with admin. Bob now has an inactive user key.
  7. As admin, select bob's private key from the list in the admin UI and select "activate selected user keys" from the dropdown menu.
  8. Ensure that user bob is selected and paste admin's private RSA key into the box labeled "your private key" and click activate. Bob's user key is now active.
@jeremystretch commented on GitHub (Jul 29, 2016): Could you please describe exactly what you're doing? I don't encounter any problem doing the following on v1.3.2. 1. Log in as the superuser created during install (admin). 2. Go to admin's profile page and create a user key. Generate an RSA key pair from NetBox and save the private key. 3. Admin now has an active user key. 4. Create a second user (bob) via the admin UI. 5. Log in as bob in a separate browser session. 6. Go to bob's profile page and create a user key. Generate an RSA key pair from NetBox just as I did with admin. Bob now has an inactive user key. 7. As admin, select bob's private key from the list in the admin UI and select "activate selected user keys" from the dropdown menu. 8. Ensure that user bob is selected and paste admin's private RSA key into the box labeled "your private key" and click activate. Bob's user key is now active.
Author
Owner

@augustocarlson commented on GitHub (Jul 29, 2016):

@jeremystretch It worked. It was a problem with the incorrect key during a copy/paste. I was able to replicate the same mistake when I did the new install. Shame on me! Thank you for your support and patience.

@augustocarlson commented on GitHub (Jul 29, 2016): @jeremystretch It worked. It was a problem with the incorrect key during a copy/paste. I was able to replicate the same mistake when I did the new install. **Shame on me!** Thank you for your support and patience.
Author
Owner

@jeremystretch commented on GitHub (Jul 30, 2016):

Cool, glad you got it working! The whole process is no doubt worth expanding on in the documentation.

@jeremystretch commented on GitHub (Jul 30, 2016): Cool, glad you got it working! The whole process is no doubt worth expanding on in the documentation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#261