simplerpc 0.2.0 → 0.2.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/lib/simplerpc/client.rb +2 -0
- data/lib/simplerpc/encryption.rb +2 -5
- data/lib/simplerpc/server.rb +19 -13
- data/lib/simplerpc/socket_protocol.rb +4 -4
- data/lib/simplerpc.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a69be8244f05f17f48dc37898ebd7d180be43ed
|
4
|
+
data.tar.gz: ef009b4b827ba659167e73d69c16721ffaaadd56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06793a5e5a8216ed99477655b77a28f7dc970ae8db9c6ca9225b3562fad4688503851d68d20b9ec9e2a67ece57195002e9fba010a4dd0ce4ec17ed1e97db2a1b
|
7
|
+
data.tar.gz: 4c1f26fdb2435251ca550bb7320b31e812838da40a1030b4466ae9fd9ff20d65a84a0331790fbc332220e5e4d89242669136f6ba33d3a988afcfdbbb157a0be8
|
data/lib/simplerpc/client.rb
CHANGED
@@ -157,6 +157,7 @@ module SimpleRPC
|
|
157
157
|
# [:password] The password clients need to connect
|
158
158
|
# [:secret] The encryption key used during password authentication.
|
159
159
|
# Should be some long random string that matches the server's.
|
160
|
+
# This should be ASCII-8bit encoded (it will be converted if not)
|
160
161
|
# [:fast_auth] Use a slightly faster auth system that is incapable of knowing if it has failed or not.
|
161
162
|
# By default this is off.
|
162
163
|
# [:threaded] Support multiple connections to the server (default is on)
|
@@ -393,6 +394,7 @@ module SimpleRPC
|
|
393
394
|
if @password && @secret
|
394
395
|
salt = SocketProtocol::Simple.recv(s, @timeout)
|
395
396
|
challenge = Encryption.encrypt(@password, @secret, salt)
|
397
|
+
|
396
398
|
SocketProtocol::Simple.send(s, challenge, @timeout)
|
397
399
|
|
398
400
|
# Check return if not @fast_auth
|
data/lib/simplerpc/encryption.rb
CHANGED
@@ -21,8 +21,6 @@ module SimpleRPC
|
|
21
21
|
cipher.encrypt
|
22
22
|
cipher.key = salt_key(salt, secret)
|
23
23
|
return cipher.update(password) + cipher.final
|
24
|
-
rescue StandardError
|
25
|
-
return nil # Don't allow anyone to deliberately cause lockups
|
26
24
|
end
|
27
25
|
|
28
26
|
# Decrypt data
|
@@ -32,14 +30,13 @@ module SimpleRPC
|
|
32
30
|
decipher.decrypt
|
33
31
|
decipher.key = salt_key(salt, secret)
|
34
32
|
return decipher.update(raw) + decipher.final
|
35
|
-
rescue StandardError
|
36
|
-
return nil # Don't allow anyone to deliberately cause lockups
|
37
33
|
end
|
38
34
|
|
39
35
|
# Salt a key by simply adding the two
|
40
36
|
# together
|
41
37
|
def self.salt_key(salt, key)
|
42
|
-
return salt +
|
38
|
+
return salt.encode('ASCII-8BIT', :undef => :replace, :invalid => :replace) +
|
39
|
+
key.encode('ASCII-8BIT', :undef => :replace, :invalid => :replace)
|
43
40
|
end
|
44
41
|
|
45
42
|
end
|
data/lib/simplerpc/server.rb
CHANGED
@@ -99,6 +99,7 @@ module SimpleRPC
|
|
99
99
|
# Default is on.
|
100
100
|
# [:password] The password clients need to connect
|
101
101
|
# [:secret] The encryption key used during password authentication. Should be some long random string.
|
102
|
+
# This should be ASCII-8bit encoded (it will be converted if not)
|
102
103
|
# [:salt_size] The size of the string used as a nonce during password auth. Defaults to 10 chars
|
103
104
|
# [:fast_auth] Use a slightly faster auth system that is incapable of knowing if it has failed or not.
|
104
105
|
# By default this is off.
|
@@ -254,21 +255,26 @@ module SimpleRPC
|
|
254
255
|
|
255
256
|
# Encrypted password auth
|
256
257
|
if @password && @secret
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
258
|
+
begin
|
259
|
+
# Send challenge
|
260
|
+
# XXX: this is notably not crytographically random,
|
261
|
+
# but it's better than nothing against replay attacks
|
262
|
+
salt = Random.new.bytes(@salt_size)
|
263
|
+
SocketProtocol::Simple.send(c, salt, @timeout)
|
264
|
+
|
265
|
+
# Receive encrypted challenge
|
266
|
+
raw = SocketProtocol::Simple.recv(c, @timeout)
|
267
|
+
|
268
|
+
# D/c if failed
|
269
|
+
unless Encryption.decrypt(raw, @secret, salt) == @password
|
270
|
+
SocketProtocol::Simple.send(c, SocketProtocol::AUTH_FAIL, @timeout) unless @fast_auth
|
271
|
+
return
|
272
|
+
end
|
273
|
+
SocketProtocol::Simple.send(c, SocketProtocol::AUTH_SUCCESS, @timeout) unless @fast_auth
|
274
|
+
rescue
|
275
|
+
# Auth failure is silent for the server
|
269
276
|
return
|
270
277
|
end
|
271
|
-
SocketProtocol::Simple.send(c, SocketProtocol::AUTH_SUCCESS, @timeout) unless @fast_auth
|
272
278
|
end
|
273
279
|
|
274
280
|
# Handle requests
|
@@ -10,11 +10,11 @@ module SimpleRPC
|
|
10
10
|
#
|
11
11
|
module SocketProtocol
|
12
12
|
|
13
|
-
# Sent when auth succeeds
|
14
|
-
AUTH_SUCCESS = 'C'
|
13
|
+
# Sent when auth succeeds (ASCII to match simple protocol)
|
14
|
+
AUTH_SUCCESS = 'C'.encode('ASCII-8BIT', :undef => :replace, :invalid => :replace)
|
15
15
|
|
16
|
-
# Sent when auth fails
|
17
|
-
AUTH_FAIL = 'F'
|
16
|
+
# Sent when auth fails (ASCII to match simple protocol)
|
17
|
+
AUTH_FAIL = 'F'.encode('ASCII-8BIT', :undef => :replace, :invalid => :replace)
|
18
18
|
|
19
19
|
# The request succeeded
|
20
20
|
REQUEST_SUCCESS = 0
|
data/lib/simplerpc.rb
CHANGED