-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.lua
64 lines (54 loc) · 1.61 KB
/
encrypt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local http = require("http")
--[[
A command to send an encrypted username to a user via keybase.
What this command does:
- Fetches a public key of a user from keybase.
- Imports the key into gpg
- Encrypts and armors the message with gpg.
- Sends a message to the current connection and channel with the encrypted message.
Try out this script by running `/require path/to/examples/encrypt.lua`, and running `/encrypt`!
--]]
command("encrypt",
"Send an encrypted message to another user via keybase",
"<keybase username> <message>",
function(args)
username = args[2]
message = args[3]
if not username or not message then
error("ERROR: please specify a username and message! /encrypt <username> <message>")
else
print("Fetching key for "..username.."...")
response, err = http.request("GET", "https://keybase.io/"..username.."/key.asc")
if err then
error(err)
else
print("Got key for "..username..". Importing into gpg...")
cert = response.body
message = "foo"
_, err = shell("which", "gpg")
if err then
error("Please install gpg and make sure it's in your path!")
return
end
-- First, import the certificate
_, err = shell("sh", "-c", "echo '"..cert.."' | gpg --import")
if err then
error(err)
return
end
-- Then, encrypt the thing
print("Encrypting...")
output, err = shell(
"sh", "-c",
"echo '"..message.."' | gpg --encrypt --armor --recipient keybase.io/"..username.." --trust-model always"
)
if err then
error(err)
return
end
clear()
sendmessage("```\n"..output.."\n```")
end
end
end
)