OpenSIPS / opensips-cli

OpenSIPS CLI tool - an interactive command line tool that can be used to control and monitor OpenSIPS servers.
GNU General Public License v3.0
84 stars 46 forks source link

error creating user with sqlite db #98

Open MenschLink opened 2 years ago

MenschLink commented 2 years ago

errors creating user with sqlite

after initializing my sqlite-db, I want to start creating users. These two errors occurr when I attempt to execute opensips-cli -x user add

ERROR: cannot execute query: SELECT table_version FROM version WHERE table_name = 'subscriber'
ERROR: (sqlite3.OperationalError) no such table: version [SQL: "SELECT table_version FROM version WHERE table_name = 'subscriber'"]
ERROR: cannot execute query: SELECT count(*) FROM subscriber WHERE username = 'example' AND domain = 'example.tldf'
ERROR: (sqlite3.OperationalError) no such table: subscriber [SQL: "SELECT count(*) FROM subscriber WHERE username = 'examplel' AND domain = 'example.tld'"]

and after supplying passwords:

ValueError: unsupported hash type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/opensips-cli", line 9, in <module>
    run_console()
  File "/usr/bin/opensips-cli", line 6, in run_console
    main.main()
  File "/usr/lib/python3/dist-packages/opensipscli/main.py", line 78, in main
    sys.exit(shell.cmdloop())
  File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 242, in cmdloop
    ret = self.run_command(module, command, modifiers, params)
  File "/usr/lib/python3/dist-packages/opensipscli/cli.py", line 404, in run_command
    return mod[0].__invoke__(cmd, params, modifiers)
  File "/usr/lib/python3/dist-packages/opensipscli/module.py", line 36, in __invoke__
    return f(params, modifiers)
  File "/usr/lib/python3/dist-packages/opensipscli/modules/user.py", line 168, in do_add
    self.user_get_ha1_sha512t256(username, domain, password)
  File "/usr/lib/python3/dist-packages/opensipscli/modules/user.py", line 119, in user_get_ha1_sha512t256
    o = hashlib.new("sha512_256")
  File "/usr/lib/python3.6/hashlib.py", line 156, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/usr/lib/python3.6/hashlib.py", line 113, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512_256
liviuchircu commented 2 years ago

Hi, @MenschLink and thanks for the report! Indeed... it seems the SHA-512-256 hash is only available on higher Python 3 releases. I get the same error when I use Python 3.6, however it works on 3.8:

~ 16:46:35$ python3.6 -c 'import hashlib; o = hashlib.new("sha512_256"); print(o)'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/hashlib.py", line 150, in __hash_new
    return _hashlib.new(name, data)
ValueError: unsupported hash type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.6/hashlib.py", line 156, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/usr/local/lib/python3.6/hashlib.py", line 113, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512_256
~ 16:46:36$
~ 16:46:36$
~ 16:46:58$ python3.8 -c 'import hashlib; o = hashlib.new("sha512_256"); print(o)'
<sha512_256 HASH object @ 0x7f3899398f90>

I will add some handling for this exception, maybe print out an error & keep the sha_512t256 column empty, so the user at least knows to upgrade to a more modern Python environment, if they need that hash. Thanks!

MenschLink commented 2 years ago

@liviuchircu thanks, I actually solved it in python 3.7, by replacing sha512_256 with sha512-256. I sort of also figured out how to fix the subscriber SQL error, but it doesn't feel quite right because I also get a 500 error when I try to register with the newly added user... maybe I'm not deploying the sqlite database setup correctly? Is there an example how that should work with the config?

[default]
#database_modules: acc clusterer dialog dialplan dispatcher domain rtpproxy usr>
database_modules: ALL

#database_admin_url: postgres://root@localhost
database_admin_url: sqlite:////opt/opensips.sqlite

database_url: sqlite:////opt/opensips.sqlite

this is what my /etc/opensips-cli.cfg currently looks like