Skip to content

Instantly share code, notes, and snippets.

@criztovyl
Last active January 20, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criztovyl/e1aedcee89df1b9b0c0c8aa980d5f596 to your computer and use it in GitHub Desktop.
Save criztovyl/e1aedcee89df1b9b0c0c8aa980d5f596 to your computer and use it in GitHub Desktop.
Utility to firefox_decrypt.py
#!/bin/bash
# Utility to firefox_decrypt.py
# Copyright (C) 2016 Christoph criztovyl Schulz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You will need to source this from your .bashrc.
password()
{
[[ "$1" =~ -{0,2}h(elp)? ]] &&
echo "$0 [profile] [password var] [grepExpr]" &&
echo " profile: Profile number (starts from 1); will ask user if not given" &&
echo " password var: Name of variable that stores the profile's master password; defaults to FD_FF_PW_[profile number]" &&
echo ' grepExpr: when starts with "u:" will only grep usernames, "w:" only websites; to disable this, use "-:"' && exit 0
local profile=$1
local password_var=$2
local grepExpr=$3
# Commands
FIREFOX_DECRYPT="firefox_decrypt"
if [ -z "$profile" ]; then
local maxProfile=$($FIREFOX_DECRYPT -l | wc -l)
$FIREFOX_DECRYPT -l
read -p "Choose which profile to use: " profile
if [ ! "$profile" ] || [ $profile -lt 1 ] || [ $profile -gt $maxProfile ]; then
echo "Invalid profile \"$profile\"" >&2
return 1
fi
fi
[ -z "$password_var" ] &&
password_var="FD_FF_PW_$profile"
[ -z "${!password_var}" ] &&
read -sp "Enter your profile's master password: " $password_var && echo
export $password_var
[ -z "$grepExpr" ] && echo "Enter grep Expression (can be empty; 'u:' username only, 'w:' for website and '-:' if password starts with u:, w: or -:):" && read grepExpr
local grepContext
case ${grepExpr:0:2} in
"u:")
grepExpr="Username: '.*${grepExpr:2}.*"
grepContext="-C 1"
;;
"w:")
grepExpr="Website: .*${grepExpr:2}.*"
grepContext="--after 2"
;;
"-:")
grepExpr="${grepExpr:2}"
grepContext="-C 2"
;;
esac
echo "${!password_var}" | $FIREFOX_DECRYPT -c $profile | grep "$grepExpr" $grepContext
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment