Encryption removed from callbacks, except retractions sort of. verification is in user.receive

This commit is contained in:
Raphael 2010-08-16 17:23:54 -07:00
parent fbee1aabb1
commit eae4053902
9 changed files with 43 additions and 69 deletions

View file

@ -33,9 +33,6 @@ class Comment
#ENCRYPTION
before_validation :sign_if_mine, :sign_if_my_post
validates_true_for :post_creator_signature, :logic => lambda {self.verify_post_creator_signature}
xml_accessor :creator_signature
xml_accessor :post_creator_signature
@ -57,11 +54,7 @@ class Comment
end
def verify_post_creator_signature
if person.owner.nil?
verify_signature(post_creator_signature, post.person)
else
true
end
end

View file

@ -51,6 +51,7 @@ class Person
raise TypeError unless new_key.class == OpenSSL::PKey::RSA
serialized_key = new_key.export
end
def export_key
encryption_key.public_key.export
end
@ -61,6 +62,7 @@ class Person
options[:person] = self
model_class = class_name.to_s.camelize.constantize
post = model_class.instantiate(options)
post.creator_signature = post.sign_with_key(encryption_key)
post.notify_people
post.socket_to_uid owner.id if (owner_id && post.respond_to?( :socket_to_uid))
post
@ -70,6 +72,7 @@ class Person
def comment(text, options = {})
raise "must comment on something!" unless options[:on]
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
c.creator_signature = c.sign_with_key(encryption_key)
if c.save
dispatch_comment c
@ -83,8 +86,11 @@ class Person
def dispatch_comment( c )
if owns? c.post
c.post_creator_signature = c.sign_with_key(encryption_key)
c.save
c.push_downstream
elsif owns? c
c.save
c.push_upstream
end
end

View file

@ -21,7 +21,7 @@ class Post
timestamps!
before_destroy :propagate_retraction
before_destroy :propogate_retraction
after_destroy :destroy_comments
def self.instantiate params
@ -38,9 +38,6 @@ class Post
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
@ -70,11 +67,8 @@ protected
comments.each{|c| c.destroy}
end
def propagate_retraction
Retraction.for(self).notify_people
end
def propogate_retraction
self.person.owner.retract(self)
end
end

View file

@ -13,7 +13,6 @@ class Retraction
retraction.type = object.class.to_s
end
retraction.person_id = person_id_from(object)
retraction.send(:sign_if_mine)
retraction
end
@ -60,21 +59,7 @@ class Retraction
end
#ENCRYPTION
xml_reader :creator_signature
def creator_signature
object = self.type.constantize.first(:id => post_id)
if object.class == Person && person_id == object.id
@creator_signature || sign_with_key(object.key)
elsif person_id == object.person.id
@creator_signature || sign_if_mine
end
end
def creator_signature= input
@creator_signature = input
end
xml_accessor :creator_signature
def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition|
@ -86,7 +71,8 @@ class Retraction
def signable_string
signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';'
(self.send accessor.to_sym).to_s
}.join ';'
end
end

View file

@ -37,6 +37,14 @@ class User
Group.create(opts)
end
######### Posts and Such ###############
def retract( post )
retraction = Retraction.for(post)
retraction.creator_signature = retraction.sign_with_key( encryption_key )
retraction.notify_people
retraction
end
######### Friend Requesting ###########
def send_friend_request_to(friend_url, group_id)
unless self.friends.detect{ |x| x.receive_url == friend_url}
@ -105,7 +113,9 @@ class User
def unfriend(bad_friend)
Rails.logger.info("#{self.real_name} is unfriending #{bad_friend.inspect}")
Retraction.for(self).push_to_url(bad_friend.receive_url)
retraction = Retraction.for(self)
retraction.creator_signature = retraction.sign_with_key(encryption_key)
retraction.push_to_url(bad_friend.receive_url)
remove_friend(bad_friend)
end
@ -170,9 +180,12 @@ class User
person.profile = object
person.save
elsif object.is_a?(Comment) && object.verify_post_creator_signature
if object.verify_creator_signature || object.person.nil?
dispatch_comment object if !owns?(object)
dispatch_comment object unless owns?(object)
end
elsif object.verify_creator_signature == true
Rails.logger.debug("Saving object: #{object}")
object.save

View file

@ -1,6 +1,6 @@
module Encryptable
def signable_string
""
raise NotImplementedException("Override this in your encryptable class")
end
def verify_creator_signature
verify_signature(creator_signature, person)
@ -23,15 +23,9 @@
validity
end
protected
def sign_if_mine
self.creator_signature = sign_with_key(person.encryption_key) unless person.owner_id.nil?
end
def sign_with_key(key)
Rails.logger.debug("Signing #{signable_string}")
Base64.encode64(key.sign "SHA", signable_string)
end
end

View file

@ -13,17 +13,6 @@ describe Diaspora::Parser do
@user2 = Factory.create(:user)
end
it "should associate the post with a group" do
@user.activate_friend(@person, @group)
status_message = Factory.build(:status_message, :message => "hey!", :person => @person)
@user.receive status_message.to_diaspora_xml
@user.posts.count.should == 1
end
describe 'with encryption' do
before do
unstub_mocha_stubs

View file

@ -86,7 +86,7 @@ describe Photo do
end
it 'should save a signed photo to GridFS' do
photo = Photo.create(:person => @user.person, :album => @album, :image => File.open(@fixture_name))
photo = @user.post(:photo, :album => @album, :user_file => [File.open(@fixture_name)])
photo.save.should == true
photo.verify_creator_signature.should be true
end

View file

@ -69,7 +69,7 @@ describe 'user encryption' do
message = @user.post :status_message, :message => "hi"
retraction = Retraction.for(message)
retraction = @user.retract(message)
retraction.verify_creator_signature.should be true
end
@ -150,10 +150,9 @@ describe 'user encryption' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
comment.verify_creator_signature.should be true
comment.valid?.should be false
comment.verify_post_creator_signature.should be false
comment.post_creator_signature = comment.send(:sign_with_key,@person.encryption_key)
comment.verify_post_creator_signature.should be true
comment.valid?.should be true
end
it 'should reject comments on a remote post with only a creator sig' do
@ -161,13 +160,13 @@ describe 'user encryption' do
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
comment.verify_creator_signature.should be true
comment.verify_post_creator_signature.should be false
comment.save.should be false
end
it 'should receive remote comments on a user post with a creator sig' do
comment = Comment.new(:person => @person2, :text => "balls", :post => @message)
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
comment.save.should be true
comment.verify_creator_signature.should be true
comment.verify_post_creator_signature.should be false
end
end