Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos, links, errors, warnings, safety #182

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install:
install -d "$(DESTDIR)$(BASHCOMPDIR)/"
install -m 644 pass-otp.bash.completion "$(DESTDIR)$(BASHCOMPDIR)/pass-otp"
@echo
@echo "pass-$(PROG) is installed succesfully"
@echo "pass-$(PROG) is installed successfully"
@echo

uninstall:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ apt install pass-extension-otp

### Fedora

`pass-otp` is available in Fedora 28 and up, under the package name `pass-otp` according to [Fedora Apps](https://apps.fedoraproject.org/packages/pass-otp).
`pass-otp` is available in Fedora 28 and up, under the package name `pass-otp` according to [Fedora Apps](https://packages.fedoraproject.org/pkgs/pass-otp/).

```
dnf install pass-otp
Expand All @@ -183,7 +183,7 @@ with pkgs;
pass.withExtensions (exts: [ exts.pass-otp ])
```

The above can be installed imperatively via `nix-env` or ran in a temprorary
The above can be installed imperatively via `nix-env` or ran in a temporary
environment via `nix-shell`.

### macOS
Expand Down
3 changes: 1 addition & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
, gnupg
, pass
, shellcheck
, which
}:

stdenv.mkDerivation {
Expand All @@ -33,7 +32,7 @@ stdenv.mkDerivation {
doCheck = true;

patchPhase = ''
sed -i -e 's|OATH=\$(which oathtool)|OATH=${oathToolkit}/bin/oathtool|' otp.bash
sed -i -e 's|OATH=\$(command -v oathtool)|OATH=${oathToolkit}/bin/oathtool|' otp.bash
'';

checkPhase = ''
Expand Down
52 changes: 37 additions & 15 deletions otp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# []

VERSION="1.1.2"
OATH=$(which oathtool)
OTPTOOL=$(which otptool)
OATH=$(command -v oathtool)
OTPTOOL=$(command -v otptool)

## source: https://gist.github.com/cdown/1163649
urlencode() {
Expand Down Expand Up @@ -314,7 +314,7 @@ cmd_otp_append() {
}

cmd_otp_code() {
[[ -z "$OATH" ]] && die "Failed to generate OTP code: oathtool is not installed."
[[ -z "$OATH" && -z "$OTPTOOL" ]] && die "Failed to generate OTP code: oathtool or otptool is not installed."

local opts clip=0 quiet=0
opts="$($GETOPT -o cq -l clip,quiet -n "$PROGRAM" -- "$@")"
Expand Down Expand Up @@ -342,31 +342,53 @@ cmd_otp_code() {
fi
done < <(echo "$contents")

# Check oathtool for stdin secrets feature
OATH_SAFE_VERSION=2.6.5
OATH_VERSION=$("$OATH" --version | head -n1 | tr ' ' '\n' | tail -n1)
printf -v OATH_VERSIONS '%s\n%s' "$OATH_SAFE_VERSION" "$OATH_VERSION"
[[ "$OATH_VERSIONS" = "$(sort -n <<< "$OATH_VERSIONS")" ]] && OATH_SAFE=1

local cmd
case "$otp_type" in
totp)
cmd="$OATH -b --totp"
[[ -n "$otp_algorithm" ]] && cmd+=$(echo "=${otp_algorithm}"|tr "[:upper:]" "[:lower:]")
[[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s
[[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits"
cmd+=" $otp_secret"
[[ -n "$OTPTOOL" ]] && cmd="$OTPTOOL $uri"
cmd=("$OATH" --base32)
[[ -z "$otp_algorithm" ]] && cmd+=(--totp)
[[ -n "$otp_algorithm" ]] && cmd+=(--totp="$(echo "${otp_algorithm}"|tr "[:upper:]" "[:lower:]")")
[[ -n "$otp_period" ]] && cmd+=(--time-step-size="$otp_period"s)
[[ -n "$otp_digits" ]] && cmd+=(--digits="$otp_digits")
if [[ -n "$OATH_SAFE" ]] ; then
cmd+=(-) # secrets on stdin
unset OTPTOOL
else
cmd+=("$otp_secret")
fi
[[ -n "$OTPTOOL" ]] && cmd=("$OTPTOOL" "$uri")
;;

hotp)
local counter=$((otp_counter+1))
cmd="$OATH -b --hotp --counter=$counter"
[[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits"
cmd+=" $otp_secret"
[[ -n "$OTPTOOL" ]] && cmd="$OTPTOOL $uri"
cmd=("$OATH" --base32 --hotp --counter="$counter")
[[ -n "$otp_digits" ]] && cmd+=(--digits="$otp_digits")
if [[ -n "$OATH_SAFE" ]] ; then
cmd+=(-) # secrets on stdin
unset OTPTOOL
else
cmd+=("$otp_secret")
fi
[[ -n "$OTPTOOL" ]] && cmd=("$OTPTOOL" "$uri")
;;

*)
die "$path: OTP secret not found."
;;
esac

local out; out=$($cmd) || die "$path: failed to generate OTP code."
local out
if [[ -n "$OATH" && -n "$OATH_SAFE" && -z "$OTPTOOL" ]] ; then
out=$("${cmd[@]}" <<< "$otp_secret") || die "$path: failed to generate OTP code."
else
out=$("${cmd[@]}") || die "$path: failed to generate OTP code."
fi

if [[ "$otp_type" == "hotp" ]]; then
# Increment HOTP counter in-place
Expand Down
2 changes: 1 addition & 1 deletion pass-otp.1
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ 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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 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/ .
# along with this program. If not, see https://www.gnu.org/licenses/ .

SHELL ?= /bin/bash
SHELL_PATH ?= $(SHELL)
Expand Down