diff --git a/app/models/request.rb b/app/models/request.rb index 5a81be719..f39d1267f 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -3,6 +3,7 @@ class Request include MongoMapper::Document include Diaspora::Webhooks include ROXML + include Encryptable xml_accessor :_id xml_accessor :person, :as => Person @@ -38,7 +39,26 @@ class Request p.save end +#ENCRYPTION + before_validation :sign_if_mine + validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature} + + xml_accessor :creator_signature + key :creator_signature, String + + def signable_accessors + accessors = self.class.roxml_attrs.collect{|definition| + definition.accessor} + accessors.delete 'person' + accessors.delete 'creator_signature' + accessors + end + def signable_string + signable_accessors.collect{|accessor| + (self.send accessor.to_sym).to_s}.join ';' + end + protected def clean_link diff --git a/app/models/retraction.rb b/app/models/retraction.rb index 2e9a29f77..b096be75d 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -1,12 +1,13 @@ class Retraction include ROXML include Diaspora::Webhooks + include Encryptable def self.for(object) retraction = self.new retraction.post_id= object.id retraction.person_id = person_id_from(object) - retraction.type = self.type_name(object) + retraction.type = object.class.to_s retraction end @@ -19,7 +20,13 @@ class Retraction attr_accessor :type def perform - self.type.constantize.destroy(self.post_id) + return unless verify_signature(@creator_signature, Post.first(:id => post_id).person) + + begin + self.type.constantize.destroy(self.post_id) + rescue NameError + Rails.logger.info("Retraction for unknown type recieved.") + end end def self.person_id_from(object) @@ -30,15 +37,28 @@ class Retraction end end - - def self.type_name(object) - if object.is_a? Post - object.class - elsif object.is_a? Person - 'Person' - else - 'Clowntown' +#ENCRYPTION + xml_reader :creator_signature + + def creator_signature + @creator_signature ||= sign if person_id == User.owner.id end - end + def creator_signature= input + @creator_signature = input + end + + def signable_accessors + accessors = self.class.roxml_attrs.collect{|definition| + definition.accessor} + accessors.delete 'person' + accessors.delete 'creator_signature' + accessors + end + + def signable_string + signable_accessors.collect{|accessor| + (self.send accessor.to_sym).to_s}.join ';' + end + end diff --git a/lib/encryptable.rb b/lib/encryptable.rb index 98ffdd7a2..632c3e6a2 100644 --- a/lib/encryptable.rb +++ b/lib/encryptable.rb @@ -31,7 +31,7 @@ end def sign_with_key(key) - Rails.logger.info("Signing #{signable_string} with key for person #{self.person.real_name}") + Rails.logger.info("Signing #{signable_string}") GPGME::sign(signable_string,nil, {:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]}) end diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 3f0cf9e93..9335a088f 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -206,11 +206,12 @@ ul.comment_set { padding: 0.6em; border-bottom: 1px solid #cccccc; } ul.comment_set li.comment .from { - color: #666666; font-weight: normal; } ul.comment_set li.comment .from a { - color: #333333; font-weight: bold; } + ul.comment_set li.comment div.time { + color: #666666; + font-size: 70%; } ul.comment_set li.comment form { margin-top: -5px; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index fb2204dd5..0225b383a 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -249,13 +249,15 @@ ul.comment_set :bottom 1px solid #ccc .from - :color #666 :font :weight normal a - :color #333 :font :weight bold + + div.time + :color #666 + :font-size 70% form :margin