Encryption removed from callbacks, except retractions sort of. verification is in user.receive
This commit is contained in:
parent
fbee1aabb1
commit
eae4053902
9 changed files with 43 additions and 69 deletions
|
|
@ -33,9 +33,6 @@ class Comment
|
||||||
|
|
||||||
#ENCRYPTION
|
#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 :creator_signature
|
||||||
xml_accessor :post_creator_signature
|
xml_accessor :post_creator_signature
|
||||||
|
|
||||||
|
|
@ -57,11 +54,7 @@ class Comment
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_post_creator_signature
|
def verify_post_creator_signature
|
||||||
if person.owner.nil?
|
verify_signature(post_creator_signature, post.person)
|
||||||
verify_signature(post_creator_signature, post.person)
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ class Person
|
||||||
raise TypeError unless new_key.class == OpenSSL::PKey::RSA
|
raise TypeError unless new_key.class == OpenSSL::PKey::RSA
|
||||||
serialized_key = new_key.export
|
serialized_key = new_key.export
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_key
|
def export_key
|
||||||
encryption_key.public_key.export
|
encryption_key.public_key.export
|
||||||
end
|
end
|
||||||
|
|
@ -61,6 +62,7 @@ class Person
|
||||||
options[:person] = self
|
options[:person] = self
|
||||||
model_class = class_name.to_s.camelize.constantize
|
model_class = class_name.to_s.camelize.constantize
|
||||||
post = model_class.instantiate(options)
|
post = model_class.instantiate(options)
|
||||||
|
post.creator_signature = post.sign_with_key(encryption_key)
|
||||||
post.notify_people
|
post.notify_people
|
||||||
post.socket_to_uid owner.id if (owner_id && post.respond_to?( :socket_to_uid))
|
post.socket_to_uid owner.id if (owner_id && post.respond_to?( :socket_to_uid))
|
||||||
post
|
post
|
||||||
|
|
@ -70,6 +72,7 @@ class Person
|
||||||
def comment(text, options = {})
|
def comment(text, options = {})
|
||||||
raise "must comment on something!" unless options[:on]
|
raise "must comment on something!" unless options[:on]
|
||||||
c = Comment.new(:person_id => self.id, :text => text, :post => 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
|
if c.save
|
||||||
dispatch_comment c
|
dispatch_comment c
|
||||||
|
|
||||||
|
|
@ -83,8 +86,11 @@ class Person
|
||||||
|
|
||||||
def dispatch_comment( c )
|
def dispatch_comment( c )
|
||||||
if owns? c.post
|
if owns? c.post
|
||||||
|
c.post_creator_signature = c.sign_with_key(encryption_key)
|
||||||
|
c.save
|
||||||
c.push_downstream
|
c.push_downstream
|
||||||
elsif owns? c
|
elsif owns? c
|
||||||
|
c.save
|
||||||
c.push_upstream
|
c.push_upstream
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ class Post
|
||||||
@@per_page = 10
|
@@per_page = 10
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
before_destroy :propagate_retraction
|
before_destroy :propogate_retraction
|
||||||
after_destroy :destroy_comments
|
after_destroy :destroy_comments
|
||||||
|
|
||||||
def self.instantiate params
|
def self.instantiate params
|
||||||
|
|
@ -38,9 +38,6 @@ class Post
|
||||||
end
|
end
|
||||||
|
|
||||||
#ENCRYPTION
|
#ENCRYPTION
|
||||||
before_validation :sign_if_mine
|
|
||||||
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
|
||||||
|
|
||||||
xml_accessor :creator_signature
|
xml_accessor :creator_signature
|
||||||
key :creator_signature, String
|
key :creator_signature, String
|
||||||
|
|
||||||
|
|
@ -70,11 +67,8 @@ protected
|
||||||
comments.each{|c| c.destroy}
|
comments.each{|c| c.destroy}
|
||||||
end
|
end
|
||||||
|
|
||||||
def propagate_retraction
|
def propogate_retraction
|
||||||
Retraction.for(self).notify_people
|
self.person.owner.retract(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ class Retraction
|
||||||
retraction.type = object.class.to_s
|
retraction.type = object.class.to_s
|
||||||
end
|
end
|
||||||
retraction.person_id = person_id_from(object)
|
retraction.person_id = person_id_from(object)
|
||||||
retraction.send(:sign_if_mine)
|
|
||||||
retraction
|
retraction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -60,21 +59,7 @@ class Retraction
|
||||||
end
|
end
|
||||||
|
|
||||||
#ENCRYPTION
|
#ENCRYPTION
|
||||||
xml_reader :creator_signature
|
xml_accessor :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
|
|
||||||
|
|
||||||
def signable_accessors
|
def signable_accessors
|
||||||
accessors = self.class.roxml_attrs.collect{|definition|
|
accessors = self.class.roxml_attrs.collect{|definition|
|
||||||
|
|
@ -86,7 +71,8 @@ class Retraction
|
||||||
|
|
||||||
def signable_string
|
def signable_string
|
||||||
signable_accessors.collect{|accessor|
|
signable_accessors.collect{|accessor|
|
||||||
(self.send accessor.to_sym).to_s}.join ';'
|
(self.send accessor.to_sym).to_s
|
||||||
|
}.join ';'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,14 @@ class User
|
||||||
Group.create(opts)
|
Group.create(opts)
|
||||||
end
|
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 ###########
|
######### Friend Requesting ###########
|
||||||
def send_friend_request_to(friend_url, group_id)
|
def send_friend_request_to(friend_url, group_id)
|
||||||
unless self.friends.detect{ |x| x.receive_url == friend_url}
|
unless self.friends.detect{ |x| x.receive_url == friend_url}
|
||||||
|
|
@ -105,7 +113,9 @@ class User
|
||||||
|
|
||||||
def unfriend(bad_friend)
|
def unfriend(bad_friend)
|
||||||
Rails.logger.info("#{self.real_name} is unfriending #{bad_friend.inspect}")
|
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)
|
remove_friend(bad_friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -170,9 +180,12 @@ class User
|
||||||
person.profile = object
|
person.profile = object
|
||||||
person.save
|
person.save
|
||||||
elsif object.is_a?(Comment) && object.verify_post_creator_signature
|
elsif object.is_a?(Comment) && object.verify_post_creator_signature
|
||||||
|
|
||||||
if object.verify_creator_signature || object.person.nil?
|
if object.verify_creator_signature || object.person.nil?
|
||||||
dispatch_comment object if !owns?(object)
|
dispatch_comment object unless owns?(object)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif object.verify_creator_signature == true
|
elsif object.verify_creator_signature == true
|
||||||
Rails.logger.debug("Saving object: #{object}")
|
Rails.logger.debug("Saving object: #{object}")
|
||||||
object.save
|
object.save
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
module Encryptable
|
module Encryptable
|
||||||
def signable_string
|
def signable_string
|
||||||
""
|
raise NotImplementedException("Override this in your encryptable class")
|
||||||
end
|
end
|
||||||
def verify_creator_signature
|
def verify_creator_signature
|
||||||
verify_signature(creator_signature, person)
|
verify_signature(creator_signature, person)
|
||||||
|
|
@ -23,15 +23,9 @@
|
||||||
validity
|
validity
|
||||||
end
|
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)
|
def sign_with_key(key)
|
||||||
Rails.logger.debug("Signing #{signable_string}")
|
Rails.logger.debug("Signing #{signable_string}")
|
||||||
Base64.encode64(key.sign "SHA", signable_string)
|
Base64.encode64(key.sign "SHA", signable_string)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,6 @@ describe Diaspora::Parser do
|
||||||
@user2 = Factory.create(:user)
|
@user2 = Factory.create(:user)
|
||||||
end
|
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
|
describe 'with encryption' do
|
||||||
before do
|
before do
|
||||||
unstub_mocha_stubs
|
unstub_mocha_stubs
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ describe Photo do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save a signed photo to GridFS' do
|
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.save.should == true
|
||||||
photo.verify_creator_signature.should be true
|
photo.verify_creator_signature.should be true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ describe 'user encryption' do
|
||||||
message = @user.post :status_message, :message => "hi"
|
message = @user.post :status_message, :message => "hi"
|
||||||
|
|
||||||
|
|
||||||
retraction = Retraction.for(message)
|
retraction = @user.retract(message)
|
||||||
retraction.verify_creator_signature.should be true
|
retraction.verify_creator_signature.should be true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -145,29 +145,28 @@ describe 'user encryption' do
|
||||||
message.comments.first.verify_creator_signature.should be true
|
message.comments.first.verify_creator_signature.should be true
|
||||||
message.comments.first.verify_post_creator_signature.should be true
|
message.comments.first.verify_post_creator_signature.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should verify a comment made on a remote post by a different friend' do
|
it 'should verify a comment made on a remote post by a different friend' do
|
||||||
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
|
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
|
||||||
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
||||||
comment.verify_creator_signature.should be true
|
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.post_creator_signature = comment.send(:sign_with_key,@person.encryption_key)
|
||||||
comment.verify_post_creator_signature.should be true
|
comment.verify_post_creator_signature.should be true
|
||||||
comment.valid?.should be true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should reject comments on a remote post with only a creator sig' do
|
it 'should reject comments on a remote post with only a creator sig' do
|
||||||
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
|
comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message)
|
||||||
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
||||||
comment.verify_creator_signature.should be true
|
comment.verify_creator_signature.should be true
|
||||||
comment.verify_post_creator_signature.should be false
|
comment.verify_post_creator_signature.should be false
|
||||||
comment.save.should be false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should receive remote comments on a user post with a creator sig' do
|
it 'should receive remote comments on a user post with a creator sig' do
|
||||||
comment = Comment.new(:person => @person2, :text => "balls", :post => @message)
|
comment = Comment.new(:person => @person2, :text => "balls", :post => @message)
|
||||||
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue