tadfisher / pass-otp

A pass extension for managing one-time-password (OTP) tokens
GNU General Public License v3.0
1.28k stars 85 forks source link

Documentation of andOTP migration #136

Open BenSartor opened 3 years ago

BenSartor commented 3 years ago

Hi,

thanks a lot for pass-otp!

Here is a little script, I used to migrate from andOTP.

#! /bin/bash

## exit if an error occurs or on unset variables
set -eu -o pipefail

## example usage
## gpg --decrypt otp_accounts_2021-01-09_16-20-41.json.gpg.pgp | ./andOTP2pass-otp.sh

jq -c '.[]' | while read ENTRY; do
    TYPE=$(echo "${ENTRY}" | jq -r .type | tr "[:upper:]" "[:lower:]")
    LABEL=$(echo "${ENTRY}" | jq -r .label)
    LABEL_ESCAPED=$(echo "${LABEL}" | jq -Rr @uri)
    LABEL_FILE=$(echo "${LABEL}" | tr "[:upper:]" "[:lower:]" | sed "s/[[:space:]]/_/g" | sed "s/:/-/g" | sed "s/\./-/g" | sed "s/@/-/g" | sed "s/ö/oe/g")
    SECRET=$(echo "${ENTRY}" | jq -r .secret)
    ISSUER=$(echo "${ENTRY}" | jq -r .issuer)
    DIGITS=$(echo "${ENTRY}" | jq -r .digits)
    PERIOD=$(echo "${ENTRY}" | jq -r .period)
    ALGORITHM=$(echo "${ENTRY}" | jq -r .algorithm)

    KEY_URI="otpauth://${TYPE}/${LABEL_ESCAPED}?secret=${SECRET}"
    if [ -n "${ISSUER}" ] ; then
        KEY_URI="${KEY_URI}&issuer=${ISSUER}"
    fi
    if [ -n "${DIGITS}" ] ; then
        KEY_URI="${KEY_URI}&digits=${DIGITS}"
    fi
    if [ -n "${PERIOD}" ] ; then
        KEY_URI="${KEY_URI}&period=${PERIOD}"
    fi
    if [ -n "${ALGORITHM}" ] ; then
        KEY_URI="${KEY_URI}&algorithm=${ALGORITHM}"
    fi

    echo "${KEY_URI}" #| pass otp insert "andOTP/${LABEL_FILE}"
done