Giter Club home page Giter Club logo

bitwarden-to-keepass's People

Contributors

davidnemec avatar diogotito avatar jabashque avatar rogsme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitwarden-to-keepass's Issues

Make custom fields hidden by default

I know very little about the keepass format but I think it makes sense to make all custom fields added in Bitwarden "hidden" (or is it "secret"?) by default in the exported database.

Potential content of these fields is TOTP seeds, answers to security questions, PINs, recovery codes.

IndexError: list index out of range

Hello,

I'm trying to setup your script. Thank you!

I've tried to run it with venv and docker with same result in both cases. Just after it creates keepass database script chashes with a "list index out of range" error:

python3 bitwarden-to-keepass.py --bw-session $BW_SESSION --database-path '$DATABASE_PATH' --database-password '$DATABASE_PASSWORD' --bw-path $BW_PATH
Traceback (most recent call last):
  File "src/lxml/builder.py", line 175, in lxml.builder.ElementMaker.__init__.add_text
  File "src/lxml/etree.pyx", line 1176, in lxml.etree._Element.__getitem__
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gmartin/bitwarden2keepass/bitwarden-to-keepass.py", line 179, in <module>
    check_args(args) and bitwarden_to_keepass(args)
  File "/home/gmartin/bitwarden2keepass/bitwarden-to-keepass.py", line 39, in bitwarden_to_keepass
    groups_by_id = load_folders(folders)
  File "/home/gmartin/bitwarden2keepass/bitwarden-to-keepass.py", line 127, in load_folders
    FolderType.bfs_traverse_execute(folder_root, add_keepass_group)
  File "/home/gmartin/bitwarden2keepass/folder.py", line 59, in bfs_traverse_execute
    callback(child)
  File "/home/gmartin/bitwarden2keepass/bitwarden-to-keepass.py", line 123, in add_keepass_group
    new_group: KPGroup = kp.add_group(parent_group, folder.name)
  File "/home/gmartin/bitwarden2keepass/.venv/lib/python3.9/site-packages/pykeepass/pykeepass.py", line 435, in add_group
    group = Group(name=group_name, notes=notes, kp=self)
  File "/home/gmartin/bitwarden2keepass/.venv/lib/python3.9/site-packages/pykeepass/group.py", line 30, in __init__
    self._element.append(E.Name(name))
  File "src/lxml/builder.py", line 228, in lxml.builder.ElementMaker.__call__
  File "src/lxml/builder.py", line 177, in lxml.builder.ElementMaker.__init__.add_text
  File "src/lxml/etree.pyx", line 1039, in lxml.etree._Element.text.__set__
  File "src/lxml/apihelpers.pxi", line 747, in lxml.etree._setNodeText
  File "src/lxml/apihelpers.pxi", line 735, in lxml.etree._createTextNode
  File "src/lxml/apihelpers.pxi", line 1540, in lxml.etree._utf8
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

I've tried this with two different accounts. First with hundreds of entries and another with only a few.

Let me know if you need more data.

i have problem when i try to run it:

Traceback (most recent call last):
File "/usr/bin/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/bin/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.9/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
self.send(msg)
File "/usr/lib/python3.9/http/client.py", line 950, in send
self.connect()
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/bin/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/bin/urllib3/util/retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/bin/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/usr/bin/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/bin/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.9/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
self.send(msg)
File "/usr/lib/python3.9/http/client.py", line 950, in send
self.connect()
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/api/client.py", line 214, in _retrieve_server_version
return self.version(api_version=False)["ApiVersion"]
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/api/daemon.py", line 181, in version
return self._result(self._get(url), json=True)
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/api/client.py", line 237, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/bin/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/bin/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/bin/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/bin/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/docker-compose", line 8, in
sys.exit(main())
File "/usr/bin/compose/cli/main.py", line 80, in main
command_func()
File "/usr/bin/compose/cli/main.py", line 189, in perform_command
project = project_from_options('.', options)
File "/usr/bin/compose/cli/command.py", line 60, in project_from_options
return get_project(
File "/usr/bin/compose/cli/command.py", line 152, in get_project
client = get_client(
File "/usr/bin/compose/cli/docker_client.py", line 41, in get_client
client = docker_client(
File "/usr/bin/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/api/client.py", line 197, in init
self._version = self._retrieve_server_version()
File "/home/xyz/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/docker/api/client.py", line 221, in _retrieve_server_version
raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Lots of BW folders show "[error: cannot decrypt]"

when i run this, it exports fine, however most folders are exported as below:
image

Weirdly, theres little to no pattern at all in terms of which ones do it, some are nested folders, where other folders nested within the same parent are displaying fine

Any and all passwords in the failed folder are diplaying correctly

Export Fails

Hey :)
unfortunately the export fails :(
Does anyone has an similar issue?

Server: OnPremise
Server Installed: 2023.10.3
Web Installed: 2023.10.2

Exporter Client:
OS: Debian 11
Docker: 24.0.7

source .env
$BW_PATH config server $BW_Server
Could not find dir, "/root/.config/Bitwarden CLI"; creating it instead.
Could not find data file, "/root/.config/Bitwarden CLI/data.json"; creating it instead.
Saved setting `config`.
$BW_PATH login --apikey
You are logged in!

To unlock your vault, use the `unlock` command. ex:
$ bw unlock
export BW_SESSION=`$BW_PATH unlock $BW_Password --raw`
bw login --check
You are logged in!
python3 bitwarden-to-keepass.py
2023-12-11 07:10:13 :: INFO :: KeePass database does not exist, creating a new one.
2023-12-11 07:10:16 :: INFO :: Folders done (1).
/usr/local/lib/node_modules/@bitwarden/cli/node_modules/proper-lockfile/lib/lockfile.js:68
                return callback(Object.assign(new Error('Lock file is already being held'), { code: 'ELOCKED', file }));
                                              ^

Error: Lock file is already being held
    at /usr/local/lib/node_modules/@bitwarden/cli/node_modules/proper-lockfile/lib/lockfile.js:68:47
    at callback (/usr/local/lib/node_modules/@bitwarden/cli/node_modules/graceful-fs/polyfills.js:306:20)
    at FSReqCallback.oncomplete (node:fs:208:5) {
  code: 'ELOCKED',
  file: '/root/.config/Bitwarden CLI/data.json'
}

Node.js v18.13.0
Traceback (most recent call last):
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 211, in <module>
    check_args(args) and bitwarden_to_keepass(args)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 42, in bitwarden_to_keepass
    items = subprocess.check_output([args.bw_path, 'list', 'items', '--session', args.bw_session], encoding='utf8')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/bw', 'list', 'items', '--session', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]' returned non-zero exit status 1.

Thanks in advance
Jockel

TypeError NoneType(None)

Tried running via docker compose. Any ideas?

I saw there was a closed issue with the same error but that looks like it was fixed.

Only thing I changed was adding an additional command to the docker compose to point it at my self hosted BW_RS.

2021-04-11 22:37:37 :: INFO :: KeePass database does not exist, creating a new one.
2021-04-11 22:37:41 :: INFO :: Folders done (26).
2021-04-11 22:37:45 :: INFO :: Starting to process 390 items.
Traceback (most recent call last):
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 147, in <module>
    check_args(args) and bitwarden_to_keepass(args)
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 78, in bitwarden_to_keepass
    entry.url = uri['uri']
  File "/usr/local/lib/python3.9/site-packages/pykeepass/entry.py", line 151, in url
    return self._set_string_field('URL', value)
  File "/usr/local/lib/python3.9/site-packages/pykeepass/entry.py", line 88, in _set_string_field
    self._element.append(E.String(E.Key(key), E.Value(value)))
  File "src/lxml/builder.py", line 226, in lxml.builder.ElementMaker.__call__
TypeError: bad argument type: NoneType(None)

use with selfhosted server

I've installed b2k because I would like to se with selfhosted server.
But I could not find where to put in the url for a selfhosted server.

Is this possible?

ValueError: All strings must be XML compatible

Don't know if this is worth bothering with. It might be helpful to at least trap these errors and print out the entry name that is causing the problem, to make it easier for a user to look into. Or a verbose mode that prints the data for each entry as it is read, so one can see where one is in case of a crash. I added a few prints to the code and tracked this down to note on a record that was simply: '\x10' (ascii character 16, or ^P). I have no idea how that got in my old crufty database, but it caused this:

INFO:root:Folders done (22).
INFO:root:Starting to process 1351 items.
Traceback (most recent call last):
  File "src/lxml/builder.py", line 175, in lxml.builder.ElementMaker.__init__.add_text
  File "src/lxml/etree.pyx", line 1161, in lxml.etree._Element.__getitem__
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/x/work/bitwarden-to-keepass/bitwarden-to-keepass.py", line 137, in <module>
    check_args(args) and bitwarden_to_keepass(args)
  File "/home/x/work/bitwarden-to-keepass/bitwarden-to-keepass.py", line 60, in bitwarden_to_keepass
    raise e
  File "/home/x/work/bitwarden-to-keepass/bitwarden-to-keepass.py", line 48, in bitwarden_to_keepass
    entry = kp.add_entry(
  File "/home/x/work/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/pykeepass/pykeepass.py", line 550, in add_entry
    entry = Entry(
  File "/home/x/work/bitwarden-to-keepass/.venv/lib/python3.9/site-packages/pykeepass/entry.py", line 57, in __init__
    self._element.append(E.String(E.Key('Notes'), E.Value(notes)))
  File "src/lxml/builder.py", line 228, in lxml.builder.ElementMaker.__call__
  File "src/lxml/builder.py", line 177, in lxml.builder.ElementMaker.__init__.add_text
  File "src/lxml/etree.pyx", line 1024, in lxml.etree._Element.text.__set__
  File "src/lxml/apihelpers.pxi", line 747, in lxml.etree._setNodeText
  File "src/lxml/apihelpers.pxi", line 735, in lxml.etree._createTextNode
  File "src/lxml/apihelpers.pxi", line 1540, in lxml.etree._utf8
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

bad argument type: NoneType(None)

unfortunately, the script crashes when I try to run it.
I used docker-compose run bitwarden-to-keepass.

After I enter my credentials, I get two infos:

INFO:root:Folders done (X).
INFO:root:Starting to process XXXX items.

Then a few warnings (all the same):


WARNING:root:Skipping credit card item "ZZZZZZZ".
WARNING:root:Skipping credit card item "YYYYYYY".

directly after these, this:

Traceback (most recent call last):
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 137, in <module>
    check_args(args) and bitwarden_to_keepass(args)
  File "/bitwarden-to-keepass/bitwarden-to-keepass.py", line 72, in bitwarden_to_keepass
    entry.set_custom_property(str(field['name']), field['value'])
  File "/usr/local/lib/python3.9/site-packages/pykeepass/entry.py", line 256, in set_custom_property
    return self._set_string_field(key, value)
  File "/usr/local/lib/python3.9/site-packages/pykeepass/entry.py", line 88, in _set_string_field
    self._element.append(E.String(E.Key(key), E.Value(value)))
  File "src/lxml/builder.py", line 226, in lxml.builder.ElementMaker.__call__
TypeError: bad argument type: NoneType(None)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.