has_global_session 0.8.5 → 0.8.6

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.
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'has_global_session'
10
- s.version = '0.8.5'
11
- s.date = '2010-06-16'
10
+ s.version = '0.8.6'
11
+ s.date = '2010-06-17'
12
12
 
13
13
  s.authors = ['Tony Spataro']
14
14
  s.email = 'code@tracker.xeger.net'
@@ -1,14 +1,17 @@
1
1
  module HasGlobalSession
2
2
  module Configuration
3
- mattr_accessor :config_file
4
- mattr_accessor :environment
5
-
3
+ def self.environment; @environment; end
4
+ def self.environment=(value); @environment = value; end
5
+
6
+ def self.config_file; @config_file; end
7
+ def self.config_file=(value); @config_file= value; end
8
+
6
9
  def self.[](key)
7
10
  get(key, true)
8
11
  end
9
12
 
10
13
  def self.validate
11
- ['attributes/signed', 'integrated', 'cookie/name', 'cookie/domain'].each do |path|
14
+ ['attributes/signed', 'integrated', 'cookie/name', 'cookie/domain', 'timeout'].each do |path|
12
15
  elements = path.split '/'
13
16
  object = get(elements.shift, false)
14
17
  elements.each do |element|
@@ -31,12 +34,13 @@ module HasGlobalSession
31
34
  validate if validated
32
35
  end
33
36
  if @config.has_key?(environment) &&
34
- @config[environment].respond_to?(:has_key?) &&
35
37
  @config[environment].has_key?(key)
36
38
  return @config[environment][key]
37
39
  else
38
40
  @config['common'][key]
39
41
  end
42
+ rescue NoMethodError
43
+ raise MissingConfiguration, "Configuration key '#{key}' not found"
40
44
  end
41
45
  end
42
46
  end
@@ -20,7 +20,7 @@ module HasGlobalSession
20
20
  # and Filename Safe Alphabet," described in RFC4648, with the exception that
21
21
  # this scheme preserves the '=' padding characters due to limitations of
22
22
  # Ruby's built-in base64 encoding routines.
23
- class Base64
23
+ class Base64Cookie
24
24
  def self.load(string)
25
25
  tr = string.tr('-_', '+/')
26
26
  return tr.unpack('m')[0]
@@ -10,8 +10,8 @@ module HasGlobalSession
10
10
  attr_reader :id, :authority, :created_at, :expired_at
11
11
 
12
12
  def initialize(directory, cookie=nil)
13
- @schema_signed = Set.new((Configuration['attributes']['signed'] rescue []))
14
- @schema_insecure = Set.new((Configuration['attributes']['insecure'] rescue []))
13
+ @schema_signed = Set.new((Configuration['attributes']['signed']))
14
+ @schema_insecure = Set.new((Configuration['attributes']['insecure']))
15
15
  @directory = directory
16
16
 
17
17
  if cookie
@@ -46,7 +46,7 @@ module HasGlobalSession
46
46
  authority = @directory.local_authority_name
47
47
  hash['a'] = authority
48
48
  digest = digest(hash)
49
- signature = Encoding::Base64.dump(@directory.private_key.private_encrypt(digest))
49
+ signature = Encoding::Base64Cookie.dump(@directory.private_key.private_encrypt(digest))
50
50
  end
51
51
 
52
52
  hash['dx'] = @insecure
@@ -55,7 +55,7 @@ module HasGlobalSession
55
55
 
56
56
  json = Encoding::JSON.dump(hash)
57
57
  zbin = Zlib::Deflate.deflate(json, Zlib::BEST_COMPRESSION)
58
- return Encoding::Base64.dump(zbin)
58
+ return Encoding::Base64Cookie.dump(zbin)
59
59
  end
60
60
 
61
61
  def supports_key?(key)
@@ -107,7 +107,7 @@ module HasGlobalSession
107
107
 
108
108
  def renew!
109
109
  authority_check
110
- @expired_at = Configuration['timeout'].to_i.minutes.from_now.utc || 1.hours.from_now.utc
110
+ @expired_at = Configuration['timeout'].to_i.minutes.from_now.utc
111
111
  @dirty_secure = true
112
112
  end
113
113
 
@@ -144,14 +144,14 @@ module HasGlobalSession
144
144
  end
145
145
 
146
146
  def load_from_cookie(cookie)
147
- zbin = Encoding::Base64.load(cookie)
147
+ zbin = Encoding::Base64Cookie.load(cookie)
148
148
  json = Zlib::Inflate.inflate(zbin)
149
149
  hash = Encoding::JSON.load(json)
150
150
 
151
151
  id = hash['id']
152
152
  authority = hash['a']
153
- created_at = Time.at(hash['tc'].to_i)
154
- expired_at = Time.at(hash['te'].to_i)
153
+ created_at = Time.at(hash['tc'].to_i).utc
154
+ expired_at = Time.at(hash['te'].to_i).utc
155
155
  signed = hash['ds']
156
156
  insecure = hash.delete('dx')
157
157
  signature = hash.delete('s')
@@ -160,7 +160,7 @@ module HasGlobalSession
160
160
  expected = digest(hash)
161
161
  signer = @directory.authorities[authority]
162
162
  raise SecurityError, "Unknown signing authority #{authority}" unless signer
163
- got = signer.public_decrypt(Encoding::Base64.load(signature))
163
+ got = signer.public_decrypt(Encoding::Base64Cookie.load(signature))
164
164
  unless (got == expected)
165
165
  raise SecurityError, "Signature mismatch on global session cookie; tampering suspected"
166
166
  end
@@ -184,6 +184,13 @@ module HasGlobalSession
184
184
  @insecure = insecure
185
185
  @signature = signature
186
186
  @cookie = cookie
187
+
188
+ #Auto-renew session if needed
189
+ renew = Configuration['renew']
190
+ if @directory.local_authority_name &&
191
+ renew && @expired_at < renew.to_i.minutes.from_now.utc
192
+ renew!
193
+ end
187
194
  end
188
195
 
189
196
  def create_from_scratch
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_global_session
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 5
10
- version: 0.8.5
9
+ - 6
10
+ version: 0.8.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-16 00:00:00 -07:00
18
+ date: 2010-06-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency