Skip to content

Commit

Permalink
Add some documentation and tiny fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mawashii committed Mar 24, 2019
1 parent 67bd197 commit c84a536
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ http://fish.secure.la/

This version uses a separate blowfish library to allow usage of keys with a length of up to 72 bytes.

v0.10
----
Secured data
------------
Can use [weechat secured data][weechat-secure] to store keys. To encrypt keys:
```
/secure set fish *********
Expand All @@ -25,10 +25,27 @@ To return to storing in plain text:
/set fish.secure.key ""
```

CBC
---
This supports ECB and CBC modes for encryption. To indicate CBC mode you need to prefix a key with `cbc:`

The default for DH1080 key exchange is to indicate that CBC is supported. If you deal with people that have incompatible installations of DH1080 you can force the *old* style of DH1080 key exchange messages by prodiving the argument `-ecb` to the blowkey exchange command.

Normal key exchange the same way [flakes/mirc_fish_10][flakes-fish10] does it, indicating CBC support with a suffixed `CBC` tag:
```
/blowkey exchange
```

Old-style blowkey exchange with no indication of CBC support:
```
/blowkey exchange -ecb
```

Install
------
Run `make` then if you store your weechat scripts in the standard location `~/.weechat/python`, just run `make install`.
Run `make` to compile the custom blowfish library. If you store your weechat scripts in the standard location `~/.weechat/python`, just run `make install`.

Otherwise copy the resulting `fish.py` and `weechat.so` to your weechat installations `python` directory.

[weechat-secure]: http://dev.weechat.org/post/2013/08/04/Secured-data
[flakes-fish10]: https://github.com/flakes/mirc_fish_10
23 changes: 14 additions & 9 deletions fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
try:
import Crypto.Cipher.Blowfish
except:
print("PyCryptodome must be installed to use fish")
print("PyCryptodome or PyCrypto must be installed to use fish")
import_ok = False

try:
Expand Down Expand Up @@ -254,13 +254,10 @@ def __init__(self, key):
if key[0:4] == "cbc:":
self.mode = Blowfish.MODE_CBC
key = key[4:]
keylimit = 56
else:
self.mode = Blowfish.MODE_ECB

if self.mode == Blowfish.MODE_ECB:
keylimit = 72
else:
keylimit = 56

if len(key) > keylimit:
key = key[:keylimit]
Expand Down Expand Up @@ -1009,6 +1006,12 @@ def fish_cmd_blowkey(data, buffer, args):
else:
server_name = weechat.buffer_get_string(buffer, "localvar_server")

if argv[0] == "exchange":
cbc_mode = True
if len(argv) >= 2 and argv[1] == "-ecb":
cbc_mode = False
del argv[1]

buffer_type = weechat.buffer_get_string(buffer, "localvar_type")
# if no target user has been specified grab the one from the buffer if it is private
if argv[0] == "exchange" and len(argv) == 1 and buffer_type == "private":
Expand Down Expand Up @@ -1062,8 +1065,9 @@ def fish_cmd_blowkey(data, buffer, args):
if server_name == "":
return weechat.WEECHAT_RC_ERROR

weechat.prnt(buffer, "Initiating DH1080 Exchange with %s" % target)
fish_DH1080ctx[targetl] = DH1080Ctx(cbc=True)
cbc_msg = "CBC" if cbc_mode else "ECB"
weechat.prnt(buffer, "Initiating %s DH1080 Exchange with %s" % (cbc_msg, target))
fish_DH1080ctx[targetl] = DH1080Ctx(cbc=cbc_mode)
msg = dh1080_pack(fish_DH1080ctx[targetl])
weechat.command(buffer, "/mute -all notice -server %s %s %s" % (server_name, target_user, msg))

Expand Down Expand Up @@ -1273,7 +1277,7 @@ def fish_msg_wo_marker(msg):
weechat.hook_command("blowkey", "Manage FiSH keys",
"[list] | [genkey] |set [-server <server>] [<target>] <key> "
"| remove [-server <server>] <target> "
"| exchange [-server <server>] [<nick>]",
"| exchange [-server <server>] [-ecb] [<nick>]",
"Add, change or remove key for target or perform DH1080\n"
"keyexchange with <nick>.\n"
"Target can be a channel or a nick.\n"
Expand All @@ -1287,12 +1291,13 @@ def fish_msg_wo_marker(msg):
"List all keys: /blowkey\n\n"
"\n** stores keys in plaintext by default **\n\n"
"DH1080: /blowkey exchange nick\n"
"DH1080 (no CBC): /blowkey exchange -ecb nick\n"
"\nPlease read the source for a note about DH1080 key exchange\n",
"list"
"|| genkey"
"|| set %(irc_channel)|%(nicks)|-server %(irc_servers) %- "
"|| remove %(irc_channel)|%(nicks)|-server %(irc_servers) %- "
"|| exchange %(nick)|-server %(irc_servers) %-",
"|| exchange %(nick)|-server %(irc_servers) %-|-ecb",
"fish_cmd_blowkey", "")

fish_config_init()
Expand Down

0 comments on commit c84a536

Please sign in to comment.