It generates a QR code (or a string) to verify OMEMO fingerprints.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

omemo-qrcode-gen 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # Author: Bandie <bandie@chaospott.de>
  3. # License: GPL-3
  4. QR_TEXT="Type \"qr\" for displaying the QR code on your command line only.\n"
  5. STDOUT_TEXT="Type \"stdout\" to just put the string into stdout.\n"
  6. function helpme() {
  7. echo "$0 [ Jabber ID ] [ Device ID ] [ Fingerprint ] [ [ Filename.png ] | [ qr ] | [ stdout ] ]"
  8. echo "You can use $0 without any arguments or put all the needed arguments in here."
  9. echo "Don't forget the quotation marks. ;)"
  10. echo "Requires qrencode and/or qr or even nothing."
  11. echo -e "\nExample:"
  12. echo -e "# $0 [ Jabber ID ] [ Device ID ] \"[ Fingerprint ]\" [ filename.png or \"qr\" or \"stdout\" ] "
  13. echo "# This will use qr to generate the QR code."
  14. echo -e "$0 bandie@example.com 9876543210 \"12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12\" qr"
  15. echo "# This will use qrencode to generate the QR code and will save it into foo.png"
  16. echo -e "$0 bandie@example.com 9876543210 \"12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12\" foo.png"
  17. echo "# This will put the string into stdout"
  18. echo -e "$0 bandie@example.com 9876543210 \"12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12 12345678 ABCDEF12\" stdout"
  19. }
  20. function gen() {
  21. if [[ "$3" =~ [G-Zg-z] ]]; then
  22. echo "$0: Error: This is not a valid fingerprint."
  23. exit 1
  24. fi
  25. FP=$(echo "$3" | sed 's/ //g' | tr '[:upper:]' '[:lower:]')
  26. OMEMOSTR="xmpp:$1?omemo-sid-$2=$FP"
  27. if [ -n "$QR" ]; then
  28. if [ "$4" = "qr" ]; then
  29. echo "$OMEMOSTR" | $QR
  30. exit 0
  31. fi
  32. fi
  33. if [ "$4" = "stdout" ]; then
  34. echo "$OMEMOSTR"
  35. exit 0
  36. fi
  37. if [ -n "$QRENCODE" ]; then
  38. echo "$OMEMOSTR" | $QRENCODE -s 5 -o "$4"
  39. exit 0
  40. fi
  41. }
  42. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  43. helpme
  44. exit 0
  45. fi
  46. export QR=$(which qr)
  47. export QRENCODE=$(which qrencode)
  48. if [ -z "$1" ]; then
  49. if [ -n "$QRENCODE" ]; then
  50. echo -en "Enter a filename.\n"
  51. fi
  52. if [ -n "$QR" ]; then
  53. echo -en "$QR_TEXT"
  54. fi
  55. echo -en "$STDOUT_TEXT"
  56. if [ -n "$QRENCODE" ]; then
  57. echo -en "(output.png)"
  58. fi
  59. echo -en ": "
  60. read file
  61. if [ -z "$file" ]; then
  62. file="output.png"
  63. fi
  64. read -p "Enter your Jabber-ID (JID): " jid
  65. read -p "Enter your device ID: " did
  66. IFS="$(echo -e "\n")"
  67. read -p "Enter your fingerprint of this device: " fp
  68. gen "$jid" "$did" "$fp" "$file"
  69. exit 0
  70. else
  71. if [ -n "$2" ] && [ -n "$3" ] && [ -n "$4" ]; then
  72. gen "$1" "$2" "$3" "$4"
  73. exit 0
  74. else
  75. echo -e "$0: Error. To few arguments.\nTry running \"$0 --help\""
  76. exit 1
  77. fi
  78. fi