aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2012-11-14 22:49:41 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2012-11-14 23:08:26 +0100
commit9298117acdf82c9529a12a3ab41baf9d1e86c2f4 (patch)
tree0bbd1e0513c8e8a57cb841ae83e3e99b7e874e86 /app
parentc07fcb616e0db81472889488189dc2f440020ef6 (diff)
downloadecs2-9298117acdf82c9529a12a3ab41baf9d1e86c2f4.tar.gz
ecs2-9298117acdf82c9529a12a3ab41baf9d1e86c2f4.zip
Introduced security fix for redirects.
Now redirects are integrity secured by sha1 message digest. A redirecting participant uses the /sys/auths resource realm attribute to store a message digest over all relevant redirect parameters (for details see [1]). The target participant uses this message digest again and verifies the integrity of the received redirect parameters (Location-Header). [1] see ECSA documentation at ECS->System resources->Auths
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb7
-rw-r--r--app/models/message.rb22
2 files changed, 24 insertions, 5 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b098493..ab65daa 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -116,26 +116,31 @@ protected
# error pages
def rescue_body_401
+ @http_error= $!
logger.error $!.to_s
render :text => "#{$!.to_s}\n", :layout => false, :status => 401
end
def rescue_body_500
+ @http_error= $!
logger.error $!.to_s
render :text => "#{$!.to_s}\n", :layout => false, :status => 500
end
def rescue_body_400
+ @http_error= $!
logger.error $!.to_s
render :text => "#{$!.to_s}\n" , :layout => false, :status => 400
end
def rescue_body_403
+ @http_error= $!
logger.error $!.to_s
render :text => "#{$!.to_s}\n" , :layout => false, :status => 403
end
def rescue_body_404
+ @http_error= $!
logger.error $!.to_s
if $!.to_s.blank?
render :text => "The server does not know the ressource\nor the message queue in question is empty.\n" , :layout => false, :status => 404
@@ -145,11 +150,13 @@ protected
end
def rescue_body_409
+ @http_error= $!
logger.error $!.to_s
render :text => "#{$!.to_s}\n" , :layout => false, :status => 409
end
def rescue_body_415(controller_binding)
+ @http_error= $!
logger.error $!.to_s
if $!.to_s.blank?
render :text => "The format of the client data is not supported by the server.\nIf your format is right please doublecheck the encoding !\nIt has to be UTF8 !\n", :layout => false, :status => 415
diff --git a/app/models/message.rb b/app/models/message.rb
index 4a89778..69067d0 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -200,7 +200,8 @@ class Message < ActiveRecord::Base
# Preprocess request body if it's a /sys/auths resource.
# Generate a one touch token (hash)
def post_create_auths_resource(participant)
- ttl = 60.seconds
+ ttl_min = 5.seconds
+ ttl = ttl_min + 60.seconds
unless Mime::Type.lookup(self.content_type).to_sym == :json
raise Ecs::InvalidMimetypeException, "Body format has to be in JSON"
end
@@ -210,9 +211,17 @@ class Message < ActiveRecord::Base
raise Ecs::InvalidMessageException, "Invalid JSON body"
end
bks = b.keys
- unless bks.include?("url")
- raise Ecs::InvalidMessageException, "Missing url key"
+
+ # NOTE Assures that there are at least url or realm set -> backward compatibility
+ unless bks.include?("url") or bks.include?("realm")
+ raise Ecs::InvalidMessageException, "You have to provide realm or url attribute"
+ end
+ if bks.include?("realm") and !b["realm"].empty? and !bks.include?("url")
+ b["url"]= b["realm"]
+ elsif bks.include?("url") and !b["url"].empty? and !bks.include?("realm")
+ b["realm"]= b["url"]
end
+
#msg_id = URI.split(b["url"])[5][1..-1].sub(/[^\/]*\/[^\/]*\/(.*)/, '\1').to_i
#begin
# Message.find(msg_id)
@@ -224,10 +233,13 @@ class Message < ActiveRecord::Base
b["sov"] = Time.now.xmlschema
b["eov"] = (Time.now + ttl).xmlschema
when (bks.include?("sov") and !bks.include?("eov"))
+ if Time.parse(b["sov"]) < Time.now
+ raise Ecs::InvalidMessageException, 'sov time is younger then current time'
+ end
b["eov"] = (Time.parse(b["sov"]) + ttl).xmlschema
when (!bks.include?("sov") and bks.include?("eov"))
- if Time.parse(b["eov"]) < Time.now
- raise Ecs::InvalidMessageException, 'eov time is younger then current time'
+ if Time.parse(b["eov"]) < (Time.now + ttl_min)
+ raise Ecs::InvalidMessageException, 'eov time is too young'
end
b["sov"] = Time.now.xmlschema
when (bks.include?("sov") and bks.include?("eov"))