Created
October 23, 2017 11:11
-
-
Save mar-v-in/15cfe19daf0c43a444cc7748f32c1461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
account=$1 | |
if [[ "" == "$account" ]]; then | |
echo "Usage:" | |
echo " $(basename $0) ACCOUNT" | |
echo "Transfer OMEMO key from Gajim account with JID ACCOUNT to Dino" | |
exit 1 | |
fi | |
dino_account_id=$(sqlite3 ~/.local/share/dino/dino.db "SELECT id FROM account WHERE bare_jid='$account'") | |
private_key=$(sqlite3 -newline '' ~/.local/share/gajim/omemo_$account.db "SELECT private_key FROM identities where recipient_id=-1" | base64) | |
public_key=$(sqlite3 -newline '' ~/.local/share/gajim/omemo_$account.db "SELECT public_key FROM identities where recipient_id=-1" | base64) | |
echo "OMEMO identity for $account in Gajim is:" | |
echo -n " " | |
echo -n "$public_key" | base64 -d | od -vt x1 -j1 | awk '{$1="";print}' | xargs echo | sed 's/[ \n]//g' | sed 's/\(........\)/\1 /g' | |
echo -n "Continue? (y/n) [y] " | |
read confirm | |
if [[ "n" == "$confirm" ]]; then | |
echo "Abort." | |
exit 2 | |
fi | |
old_public_key=$(sqlite3 ~/.local/share/dino/omemo.db "SELECT identity_key_public_base64 FROM identity WHERE account_id=$dino_account_id") | |
if [[ "" != "$old_public_key" ]]; then | |
echo "OMEMO identity in Dino already set up as:" | |
echo -n " " | |
echo -n "$old_public_key" | base64 -d | od -vt x1 -j1 | awk '{$1="";print}' | xargs echo | sed 's/[ \n]//g' | sed 's/\(........\)/\1 /g' | |
echo -n "Overwrite? (y/n) [n] " | |
read confirm | |
if [[ "y" != "$confirm" ]]; then | |
echo "Abort." | |
exit 2 | |
fi | |
sqlite3 ~/.local/share/dino/omemo.db "UPDATE identity SET identity_key_private_base64='$private_key', identity_key_public_base64='$public_key' WHERE account_id=$dino_account_id" && echo "Done." || echo "Failed." | |
else | |
device_id=$(dd if=/dev/urandom count=3 bs=1 2>/dev/null | od -t d | awk '{$1="";print}') | |
echo "Configuring new device id $device_id for $account" | |
sqlite3 ~/.local/share/dino/omemo.db "INSERT INTO identity(account_id,device_id,identity_key_private_base64,identity_key_public_base64) VALUES($dino_account_id,$device_id,'$private_key','$public_key')" && echo "Done." || echo "Failed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment