ircblowfish 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ircblowfish.gemspec +6 -0
- data/lib/ircblowfish.rb +21 -2
- data/lib/ircblowfish/base64.rb +7 -0
- data/lib/ircblowfish/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce1340544a3a148cd88f1fefed6d5b0df176a8ff
|
|
4
|
+
data.tar.gz: b41fc84584e98a0c89d702713de8e8c135035ebe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfeff05298530252bf7e47c2d324d5a108a684afd5bcdf05a802a5d2126222f8e1a049138457b6c10e77760677230bfc423d160a7474f07135ff969b39725ab4
|
|
7
|
+
data.tar.gz: 81bb0336a1bd40ee44372b9bdce6cd3b17538cfa1fdae20eb772db284770967b9a0ee85ca5776a41a52dee0f495ec4d56a88998627404d6ea4025dca71fe4ecb
|
data/CHANGELOG.md
CHANGED
data/ircblowfish.gemspec
CHANGED
|
@@ -15,11 +15,17 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.test_files = `git ls-files -z {test,spec,features}/*`.split("\x0")
|
|
18
19
|
spec.bindir = "exe"
|
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
21
|
spec.require_paths = ["lib"]
|
|
21
22
|
|
|
23
|
+
# May work on older versions, but this is the oldest I tested
|
|
24
|
+
spec.required_ruby_version = ">= 1.9.3"
|
|
25
|
+
|
|
22
26
|
spec.add_development_dependency "bundler", "~> 1.12"
|
|
23
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
29
|
+
|
|
30
|
+
spec.requirements << 'openssl'
|
|
25
31
|
end
|
data/lib/ircblowfish.rb
CHANGED
|
@@ -6,16 +6,26 @@ require "openssl"
|
|
|
6
6
|
require "securerandom"
|
|
7
7
|
|
|
8
8
|
module IrcBlowfish
|
|
9
|
+
# Encrypts a message using the specified key
|
|
10
|
+
# @param msg [String] the message to be encrypted
|
|
11
|
+
# @param key [String] the key used for encryption
|
|
12
|
+
# @return [String] the encrypted message
|
|
9
13
|
def self.encrypt(msg, key)
|
|
10
14
|
return encrypt_ecb(msg, key) if key =~ /^(?:old|ecb):/
|
|
11
15
|
return encrypt_cbc(msg, key)
|
|
12
16
|
end
|
|
13
17
|
|
|
18
|
+
# Decrypts a message using the specified key
|
|
19
|
+
# @param msg [String] the message to be decrypted
|
|
20
|
+
# @param key [String] the key used for decryption
|
|
21
|
+
# @return [String] the decrypted message
|
|
14
22
|
def self.decrypt(msg, key)
|
|
15
23
|
return decrypt_ecb(msg, key) if key =~ /^(?:old|ecb):/
|
|
16
24
|
return decrypt_cbc(msg, key)
|
|
17
25
|
end
|
|
18
26
|
|
|
27
|
+
# (see #encrypt)
|
|
28
|
+
# @note Forces the use of Blowfish-ECB despite the key passed
|
|
19
29
|
def self.encrypt_ecb(msg, key)
|
|
20
30
|
return msg if key.nil? or key == ''
|
|
21
31
|
return msg if msg.nil? or msg == ''
|
|
@@ -41,13 +51,15 @@ module IrcBlowfish
|
|
|
41
51
|
'+OK ' + IrcBlowfish::Base64.encode(cipher.update(plaintext))
|
|
42
52
|
end
|
|
43
53
|
|
|
54
|
+
# (see #decrypt)
|
|
55
|
+
# @note Forces the use of Blowfish-ECB despite the key passed
|
|
44
56
|
def self.decrypt_ecb(msg, key)
|
|
45
57
|
return msg if key.nil? or key == ''
|
|
46
58
|
return msg if msg.nil? or msg == ''
|
|
47
59
|
|
|
48
60
|
# Ensure the message is a valid Blowfish-ECB message and remove the prefix
|
|
49
61
|
ciphertext = msg.dup
|
|
50
|
-
return msg unless ciphertext.sub! %r{^\+OK }, ''
|
|
62
|
+
return msg unless ciphertext.sub! %r{^\+(?:OK|mcps) }, ''
|
|
51
63
|
return msg if ciphertext[0] == '*' # Dump if this is actually a Blowfish-CBC message
|
|
52
64
|
return '' if ciphertext == '' # I've seen some clients send "+OK " for null messages
|
|
53
65
|
|
|
@@ -66,6 +78,8 @@ module IrcBlowfish
|
|
|
66
78
|
cipher.update(IrcBlowfish::Base64.decode(ciphertext)).sub! %r{\x00*$}, ''
|
|
67
79
|
end
|
|
68
80
|
|
|
81
|
+
# (see #encrypt)
|
|
82
|
+
# @note Forces the use of Blowfish-CBC despite the key passed
|
|
69
83
|
def self.encrypt_cbc(msg, key)
|
|
70
84
|
return msg if key.nil? or key == ''
|
|
71
85
|
return msg if msg.nil? or msg == ''
|
|
@@ -95,13 +109,15 @@ module IrcBlowfish
|
|
|
95
109
|
'+OK *' + ::Base64.encode64(iv + cipher.update(plaintext)).gsub!(/\n/, '')
|
|
96
110
|
end
|
|
97
111
|
|
|
112
|
+
# (see #decrypt)
|
|
113
|
+
# @note Forces the use of Blowfish-CBC despite the key passed
|
|
98
114
|
def self.decrypt_cbc(msg, key)
|
|
99
115
|
return msg if key.nil? or key == ''
|
|
100
116
|
return msg if msg.nil? or msg == ''
|
|
101
117
|
|
|
102
118
|
# Ensure the message is a valid Blowfish-CBC message and remove the prefix
|
|
103
119
|
ciphertext = msg.dup
|
|
104
|
-
return msg unless ciphertext.sub! %r{^\+OK \*}, ''
|
|
120
|
+
return msg unless ciphertext.sub! %r{^\+(?:OK|mcps) \*}, ''
|
|
105
121
|
|
|
106
122
|
# Remove the cbc: prefix if it's used
|
|
107
123
|
key = key.sub %r{^cbc:}, ''
|
|
@@ -131,6 +147,9 @@ module IrcBlowfish
|
|
|
131
147
|
|
|
132
148
|
private
|
|
133
149
|
|
|
150
|
+
# Generates a random string used for the IV in Blowfish-CBC
|
|
151
|
+
# @param len [Integer] the length of the desired string
|
|
152
|
+
# @return [String] the random string
|
|
134
153
|
def self.random_iv(len)
|
|
135
154
|
# Valid characters for IRC Blowfish-CBC IV: a-z A-Z 0-9 _
|
|
136
155
|
letters = [('a'..'z'),('A'..'Z'),('0'..'9')].map { |i| i.to_a }.flatten << '_'
|
data/lib/ircblowfish/base64.rb
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
module IrcBlowfish
|
|
2
2
|
module Base64
|
|
3
|
+
# The Base64 characters modified for IRC Blowfish-ECB
|
|
3
4
|
B64 = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.freeze
|
|
4
5
|
|
|
6
|
+
# Encodes a binary string in modified IRC Blowfish-ECB Base64
|
|
7
|
+
# @param bin [String] binary encoded string to be encoded
|
|
8
|
+
# @return [String] the Base64 encoded string
|
|
5
9
|
def self.encode(bin)
|
|
6
10
|
str = ''
|
|
7
11
|
|
|
@@ -24,6 +28,9 @@ module IrcBlowfish
|
|
|
24
28
|
str
|
|
25
29
|
end
|
|
26
30
|
|
|
31
|
+
# Decodes an IRC Blowfish-ECB Base64 string
|
|
32
|
+
# @param str [String] the Base64 encoded string
|
|
33
|
+
# @return [String] the decoded string
|
|
27
34
|
def self.decode(str)
|
|
28
35
|
bin = ''
|
|
29
36
|
|
data/lib/ircblowfish/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ircblowfish
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Iverson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -85,13 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
85
85
|
requirements:
|
|
86
86
|
- - ">="
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version:
|
|
88
|
+
version: 1.9.3
|
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements:
|
|
91
91
|
- - ">="
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
93
|
version: '0'
|
|
94
|
-
requirements:
|
|
94
|
+
requirements:
|
|
95
|
+
- openssl
|
|
95
96
|
rubyforge_project:
|
|
96
97
|
rubygems_version: 2.5.1
|
|
97
98
|
signing_key:
|