bitwarden

This is a solution that uses bitwarden terminal client bw, fzf and gnugpg to get passwords a lot faster. Before this I used the python program bitwarden-menu but it was for some reason too slow. I then realized that since bw list items outputs all data about your passwords in a json format and it was just a matter of protecting this file and extracting the data from it using grep, cut, the usual shell stuff.

function bwupdate() {
  bw list items > /tmp/result.json
  [[ -z /tmp/result.json ]] && return
  jq -r '.[] | .login.username as $username | .login.password as $password | .id as $id | .login.uris[] | "\($id) \($username) \($password) \(.uri)"' /tmp/result.json > /home/vector/.bw-entries
  rm /tmp/result.json
  [[ -z /tmp/.bw-entries ]] && return
  gpg --symmetric --cipher-algo AES256 /home/vector/.bw-entries
  rm /home/vector/.bw-entries
}

function getpasswd() {
  read -s "password?password: " || return
  gpg --batch --passphrase "$password" --decrypt ~/.bw-entries.gpg > /tmp/decrypted-bw-entries.txt

  if ! [ $? -eq 0 ];
  then
    echo "GPG decryption failed."
    unset password
    return 1
  else
  fi
  unset password

  CHOICE=$(cat /tmp/decrypted-bw-entries.txt | cut -d' ' -f2- | fzf)
  [[ -z $CHOICE ]] && return
  LOGINID=$(cut -d' ' -f1 <<<$CHOICE)
  BWPASSWORD=$(cut -d' ' -f2 <<<$CHOICE)
  LINK=$(cut -d' ' -f3- <<<$CHOICE)
  echo $BWPASSWORD | xclip -i -selection clipboard
  echo $LOGINID | xclip -i -selection primary
  echo $LINK
  notify-send "$LINK: $LOGINID"

  [[ -e /tmp/decrypted-bw-entries.txt ]] && rm /tmp/decrypted-bw-entries.txt 
}

the PKGBUILD I had put together to install bitwarden-menu:

pkgname=python-bitwarden-dmenu
pkgver=0.1
pkgrel=1
pkgdesc='Dmenu/Rofi frontend for managing Bitwarden vaults'
arch=('any')
url='https://github.com/firecat53/bitwarden-menu'
license=('MIT')
source=("${pkgname}.zip"::"https://github.com/firecat53/bitwarden-menu/archive/refs/heads/main.zip")
depends=('python-xdg-base-dirs')
makedepends=('python-hatch-vcs')
sha256sums=('SKIP')

build() {
  cd "bitwarden-menu-main"
  python -m build --wheel --no-isolation
}

package() {
  cd "bitwarden-menu-main"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dvm644 'README.md' -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dvm644 'LICENSE' -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

Comments