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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe0eb8578d0b1f0f41f18696580bf8b8bb26439d
4
- data.tar.gz: ab97b64f7519ea0b18e9f04c7b7fc52a6206917d
3
+ metadata.gz: 8a69be8244f05f17f48dc37898ebd7d180be43ed
4
+ data.tar.gz: ef009b4b827ba659167e73d69c16721ffaaadd56
5
5
  SHA512:
6
- metadata.gz: 0152af8e2cff5b277fdb40f02fc18732b14c6a249e33840587a682fc9a7ae9a5867301394ec049eacbed133f321f3d1a1877d982dddf7f9071839c91c5ceed6d
7
- data.tar.gz: 6d5ba75c705eb414ae87482f144f638001623b7d6250aa9dec2ee3addc156e862f58ea200ec1d376d818dc41da9374578991d03330016cffd546a5617b591508
6
+ metadata.gz: 06793a5e5a8216ed99477655b77a28f7dc970ae8db9c6ca9225b3562fad4688503851d68d20b9ec9e2a67ece57195002e9fba010a4dd0ce4ec17ed1e97db2a1b
7
+ data.tar.gz: 4c1f26fdb2435251ca550bb7320b31e812838da40a1030b4466ae9fd9ff20d65a84a0331790fbc332220e5e4d89242669136f6ba33d3a988afcfdbbb157a0be8
@@ -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
@@ -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 + key
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
@@ -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
- # Send challenge
258
- # XXX: this is notably not crytographically random,
259
- # but it's better than nothing against replay attacks
260
- salt = Random.new.bytes(@salt_size)
261
- SocketProtocol::Simple.send(c, salt, @timeout)
262
-
263
- # Receive encrypted challenge
264
- raw = SocketProtocol::Simple.recv(c, @timeout)
265
-
266
- # D/c if failed
267
- unless Encryption.decrypt(raw, @secret, salt) == @password
268
- SocketProtocol::Simple.send(c, SocketProtocol::AUTH_FAIL, @timeout) unless @fast_auth
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
@@ -15,6 +15,6 @@ require 'simplerpc/client'
15
15
  # and including it includes all other project files
16
16
  module SimpleRPC
17
17
 
18
- VERSION = '0.2.0'
18
+ VERSION = '0.2.1'
19
19
 
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplerpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Wattam