]> granicus.if.org Git - neomutt/commitdiff
Get keybase to work with mutt
authorJakkin <dracogoyle@gmail.com>
Sun, 19 Jun 2016 01:18:19 +0000 (20:18 -0500)
committerRichard Russon <rich@flatcap.org>
Thu, 18 Aug 2016 14:49:13 +0000 (15:49 +0100)
13 files changed:
contrib/keybase/.muttrc [new file with mode: 0644]
contrib/keybase/KeybaseAndMutt.md [new file with mode: 0644]
contrib/keybase/LICENSE [new file with mode: 0644]
contrib/keybase/README.md [new file with mode: 0644]
contrib/keybase/decrypt.sh [new file with mode: 0755]
contrib/keybase/images/attachmentView.png [new file with mode: 0644]
contrib/keybase/images/pagerMode.png [new file with mode: 0644]
contrib/keybase/install.sh [new file with mode: 0644]
contrib/keybase/keybase.py [new file with mode: 0644]
contrib/keybase/pagerMode.png [new file with mode: 0644]
contrib/keybase/pgpdecrypt.sh [new file with mode: 0755]
contrib/keybase/pgpverify.sh [new file with mode: 0755]
contrib/keybase/verify.sh [new file with mode: 0755]

diff --git a/contrib/keybase/.muttrc b/contrib/keybase/.muttrc
new file mode 100644 (file)
index 0000000..ff65db9
--- /dev/null
@@ -0,0 +1,2 @@
+set editor = 'echo %s > ~/.mutt/keybaseMutt/.tmp; vim %s'
+macro compose K "<enter-command>unset wait_key<enter><shell-escape>python ~/.mutt/keybaseMutt/keybase.py<enter><enter-command>set wait_key<enter>
diff --git a/contrib/keybase/KeybaseAndMutt.md b/contrib/keybase/KeybaseAndMutt.md
new file mode 100644 (file)
index 0000000..f23df9b
--- /dev/null
@@ -0,0 +1,39 @@
+To use Keybase in Mutt, the first thing that must be done (before even the macro) is setting your editor. This is important because we can replace the editor with any command we could think of. Mine looks like this.
+
+`set editor = 'echo %s > ~/.mutt/keybaseMutt/.tmp; vim %s'`
+
+It is crucially important, without this line nothing will work.
+
+What is really happening in that line is this. The echo command is echoing the contents of %s into a file. Typically, an editor will use %s to open the temporary file to let you create an email. We've just used it to work with a python script later on.
+
+Next, set a macro in the .muttrc
+
+`macro compose K "<enter-command>unset wait_key<enter><shell-escape>python ~/.mutt/keybaseMutt/keybase.py<enter><enter-command>set wait_key<enter>`
+
+You will need to place the python script in your ~/.mutt/keybaseMutt directory, creating it if it doesn't exist. If you wish to place the script elsewhere, change the macro to point to the script.
+
+The python script will take certain Keybase commands and run them. (Right now it will only let you encrypt or sign a message.)
+
+The output of the script will be written directly into the email. (Thank the devs for using /tmp/mutt* files.) As you may have guessed, the you will only be able to send inline encrypted messages. No MIME attachments.
+
+Creating encrypted email is now quite easy. All you need to do is press "K" and type something to the effect of `keybase encrypt [user]` or `keybase pgp encrypt [user]`.
+
+The script will direct all output into the temporary file and replace your message with an encrypted version.
+
+Signing is done the same way.
+
+Decryption and verification is a bit more tricky. Unfortunately, mutt doesn't use /tmp/mutt* files for emails that you receive, and I don't understand mutt well enough to find the email on the drive.
+
+To work around that, I've created several scripts to decrypt or verify messages. While you are reading an email that's been encrypted, use the pipe command in mutt ("|").
+
+You will be able to pipe the contents of the email into one of the scripts to decrypt or verify the message.
+
+How you do that is up to you, if you want to feed it the explicit location of the script, that will work fine. (Something like this `/home/[user]/path/to/script.sh`.)
+
+Or, if you know how to create paths (or if you put it in the `/bin` directory), you only need to feed it the name of the script (`script.sh`). Look it up if you don't know how. Its fun!
+
+There will be four separate scripts: verify.sh, decrypt.sh, pgpverify.sh, pgpdecrypt.sh
+
+Unfortunately, I wasn't able to find a way to condense them into one script. (Mainly because I'm a little short on time. That may change later.)
+
+Each script should be decently self-explanatory. The verify and decrypt scripts will work on keybase messages, while the pgpverify and pgpdecrypt scripts will work on keybase pgp messages.
diff --git a/contrib/keybase/LICENSE b/contrib/keybase/LICENSE
new file mode 100644 (file)
index 0000000..cf1ab25
--- /dev/null
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org>
diff --git a/contrib/keybase/README.md b/contrib/keybase/README.md
new file mode 100644 (file)
index 0000000..3a2525b
--- /dev/null
@@ -0,0 +1,45 @@
+# KeybaseMutt
+
+A work in progress. KeybaseMutt exists to let its users utilize Keybase within mutt. (Unfortunately, not natively (yet).)
+
+## Quick start
+
+Run the install script. It will set up the directory's and paths for you. Do what it says or suffer the consequences!
+
+Then just throw these into your .muttrc
+
+`set editor = 'echo %s > ~/.mutt/keybaseMutt/.tmp; vim %s'`
+
+`macro compose K "<enter-command>unset wait_key<enter><shell-escape>python ~/.mutt/keybaseMutt/keybase.py<enter><enter-command>set wait_key<enter>`
+
+Done!
+
+## How to use KeybaseMutt
+
+Write an email. In the screen right before you send your email (called the pager mode), press "K".
+
+![](/images/pagerMode.png)
+(Press 'K' when you're here)
+
+You can now use four Keybase commands in this "shell". (I thought it best to limit the user to four commands for security reasons. Running unusual commands would overwrite the email, forcing the user to rewrite the email again.)
+
+The commands are:
+- `keybase encrypt [user]`
+- `keybase pgp encrypt [user]`
+- `keybase sign`
+- `keybase pgp sign`
+
+
+## Decrypting and verifying messages
+
+Unfortunately, there isn't an easy way to decrypt or verify messages through a macro. Instead, you'll need to use the pipe feature of mutt.
+
+Opening the email, you'll need to navigate to the actual attachment. (Press "V" when you're reading the email.)
+
+![](/images/attachmentView.png)
+
+Then pipe ("|") it through the one of the scripts. (like "pgpverify.sh" or "decrypt.sh")
+
+Please note, using an attachment is very important when decrypting emails that include html. The scripts are unable to seperate html and text.
+
+Make sure that the attachment is "text/plain" rather than "text/html".
diff --git a/contrib/keybase/decrypt.sh b/contrib/keybase/decrypt.sh
new file mode 100755 (executable)
index 0000000..56f8f21
--- /dev/null
@@ -0,0 +1,2 @@
+#! /usr/bin/bash
+sed -n 's/^.*BEGIN KEYBASE/BEGIN KEYBASE/p' | keybase decrypt
diff --git a/contrib/keybase/images/attachmentView.png b/contrib/keybase/images/attachmentView.png
new file mode 100644 (file)
index 0000000..5caf908
Binary files /dev/null and b/contrib/keybase/images/attachmentView.png differ
diff --git a/contrib/keybase/images/pagerMode.png b/contrib/keybase/images/pagerMode.png
new file mode 100644 (file)
index 0000000..52d5989
Binary files /dev/null and b/contrib/keybase/images/pagerMode.png differ
diff --git a/contrib/keybase/install.sh b/contrib/keybase/install.sh
new file mode 100644 (file)
index 0000000..2165938
--- /dev/null
@@ -0,0 +1,59 @@
+#! /usr/bin/bash
+
+# If no directory exists, make it exist.
+if [ -d "$HOME/.mutt/keybaseMutt" ]; then
+
+       # If someone already has a backup, complain.
+       if [ -d "$HOME/.mutt/keybaseMuttBACKUP" ]; then
+               #echo "$HOME/.mutt/keybaseMuttBACKUP exists"
+               echo "You are going to overwrite your backup. Are you sure you want to do this? [y|n]"
+               read overwrite
+
+               # If they want to delete their backup.
+               if [ $overwrite == 'y' ]; then
+                       cp -R $HOME/.mutt/keybaseMutt $HOME/.mutt/keybaseMuttBACKUP
+                       rm -r $HOME/.mutt/keybaseMutt
+                       mkdir -p $HOME/.mutt/keybaseMutt/scripts
+
+               # Otherwise, abort mission.
+               else
+                       echo "ABORT! ABORT! ABORT!"
+                       exit 1
+               fi
+
+       elif [ ! -d "$HOME/.mutt/keybaseMuttBACKUP" ]; then
+               echo "Backing up previous install."
+               cp -R $HOME/.mutt/keybaseMutt $HOME/.mutt/keybaseMuttBACKUP
+               rm -r $HOME/.mutt/keybaseMutt
+               mkdir -p $HOME/.mutt/keybaseMutt/scripts
+       fi
+# Otherwise, make a backup
+elif [ ! -d "$HOME/.mutt/keybaseMutt" ]; then
+       echo "Installing your program..."
+       mkdir -p $HOME/.mutt/keybaseMutt/scripts
+
+fi
+
+# Copy my directory to your directory.
+cp ./keybase.py  $HOME/.mutt/keybaseMutt
+cp ./pgpdecrypt.sh $HOME/.mutt/keybaseMutt/scripts
+cp ./decrypt.sh $HOME/.mutt/keybaseMutt/scripts
+cp ./verify.sh $HOME/.mutt/keybaseMutt/scripts
+cp ./pgpverify.sh $HOME/.mutt/keybaseMutt/scripts
+
+# Yay! Stuff's installed!
+echo "You'll need to include a path to '~/.mutt/keybase/scripts' in your shell's rc file. If you've done this previously on your computer, press 'n'."
+echo "Do you use [b]ash, [k]sh, or [z]sh? [n]"
+echo "(You use $SHELL)"
+read shellInput
+if [ $shellInput == 'b' ]; then
+       echo 'export PATH="$PATH:~/.mutt/keybaseMutt/scripts"' >> $HOME/.bashrc
+elif [ $shellInput == 'k' ]; then
+       echo 'export PATH="$PATH:~/.mutt/keybaseMutt/scripts"' >> $HOME/.kshrc
+elif [ $shellInput == 'z' ]; then
+       echo 'export PATH="$PATH:~/.mutt/keybaseMutt/scripts"' >> $HOME/.zshrc
+else 
+       echo "If you use something another shell, you'll need to add the path manually."
+fi
+
+echo "Please restart your shell to be able to use the scripts (closing and reopening the terminal is easiest)."
diff --git a/contrib/keybase/keybase.py b/contrib/keybase/keybase.py
new file mode 100644 (file)
index 0000000..33a6e1d
--- /dev/null
@@ -0,0 +1,60 @@
+#! /usr/bin/env python
+# Written by Joshua Jordi
+
+import os
+
+def helpfunc():
+    print("Run keybase commands here as if you were using keybase. WARNING: this program is not capable of MIME formatting. Only inline.")
+    print("To encrypt, use keybase syntax. (ie. 'keybase encrypt jakkinstewart' or 'keybase pgp encrypt jakkinstewart') Do not include a '-i' or '-o'. This script uses them in the background. Including either flag will mess with the script. (Unless that's what you want to do.)")
+    print("Don't worry about finding or attaching the file, the macro will take care of that.")
+    print("To sign, give it the style ('sign' or 'pgp sign'. It will automatically include the signature in the file.")
+    print("This program will not be able to decrypt or verify messages. I've created separate scripts for that.")
+    print('Type "quit" to quit.')
+
+def encryptSign(parameters):
+    os.system('echo $HOME > .file')
+    directory = open('.file', 'r')
+    pwd = directory.read().strip('\n')
+    directory.close()
+    tmp = open("%s/.mutt/keybaseMutt/.tmp" % pwd, "r")
+    tmp = tmp.read().strip("\n")
+    print("Working....")
+    os.system('%s -i %s -o %s' % (parameters, tmp, tmp))
+    print("Done!")
+
+#def sign(parameters):
+#    os.system('pwd > .file')
+#    directory = open('.file', 'r')
+#    pwd = directory.read().strip('\n')
+#    directory.close()
+#    tmp = open('%s/.mutt/keybaseMutt/.tmp' % pwd, 'r')
+#    tmp = tmp.read().strip('\n')
+#    print("Working...")
+#    os.system('%s -i %s -o %s' % (parameters, tmp, tmp))
+#    print("Done!")
+
+exitVar = ''
+
+print("Type help to learn how to use me.")
+
+while exitVar.lower() != 'quit':
+    inputStuffs = input('mutt#: ')
+    if (inputStuffs.lower() == 'help'):
+        helpfunc()
+
+    elif ('encrypt' in inputStuffs):
+        encryptSign(inputStuffs)
+
+    #elif ('decrypt' in inputStuffs):
+    #    decrypt(inputStuffs)
+
+    elif ('sign' in inputStuffs):
+        encryptSign(inputStuffs)
+
+    elif ('quit' in inputStuffs or 'exit' in inputStuffs):
+        exitVar = 'quit'
+
+    else:
+        print("You didn't use a known keybase command.")
+
+os.system('rm .file')
diff --git a/contrib/keybase/pagerMode.png b/contrib/keybase/pagerMode.png
new file mode 100644 (file)
index 0000000..67bbaaa
Binary files /dev/null and b/contrib/keybase/pagerMode.png differ
diff --git a/contrib/keybase/pgpdecrypt.sh b/contrib/keybase/pgpdecrypt.sh
new file mode 100755 (executable)
index 0000000..e36e5fe
--- /dev/null
@@ -0,0 +1,3 @@
+#! /usr/bin/bash
+
+gawk '/BEGIN/{y=1}y' | keybase pgp decrypt
diff --git a/contrib/keybase/pgpverify.sh b/contrib/keybase/pgpverify.sh
new file mode 100755 (executable)
index 0000000..ebacffb
--- /dev/null
@@ -0,0 +1,2 @@
+#! /usr/bin/bash
+gawk '/BEGIN/{y=1}y' | keybase pgp verify
diff --git a/contrib/keybase/verify.sh b/contrib/keybase/verify.sh
new file mode 100755 (executable)
index 0000000..c9813eb
--- /dev/null
@@ -0,0 +1,2 @@
+#! /usr/bin/bash
+sed -n 's/^.*BEGIN KEYBASE/BEGIN KEYBASE/p' | keybase verify