From 73a6cd911bbda5e881f86a67cfd54969cec0f540 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Mon, 9 Aug 2010 10:46:02 -0700 Subject: [PATCH] DG, RS; User person delegation fixed --- app/models/comment.rb | 2 +- app/models/person.rb | 7 +++---- app/models/user.rb | 3 ++- db/seeds/dev.rb | 19 ++++++++++--------- lib/encryptable.rb | 6 +++--- spec/user_encryption_spec.rb | 20 ++++++++++---------- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index d374f13ed3..f2b6afacee 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -71,7 +71,7 @@ class Comment protected def sign_if_my_post unless self.post.person.owner.nil? - self.post_creator_signature = sign_with_key self.post.person.key + self.post_creator_signature = sign_with_key self.post.person.encryption_key end end diff --git a/app/models/person.rb b/app/models/person.rb index 196a249fa4..e10a4bbfb7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -40,16 +40,16 @@ class Person "#{profile.first_name.to_s} #{profile.last_name.to_s}" end - def key + def encryption_key OpenSSL::PKey::RSA.new( serialized_key ) end - def key= new_key + def encryption_key= new_key raise TypeError unless new_key.class == OpenSSL::PKey::RSA serialized_key = new_key.export end def export_key - key.public_key.export + encryption_key.public_key.export end @@ -107,7 +107,6 @@ class Person end def owns?(post) - puts self.class self.id == post.person.id end diff --git a/app/models/user.rb b/app/models/user.rb index 8b51c20dd8..8744699bc9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,8 @@ class User before_validation_on_create :assign_key before_validation :do_bad_things - ######## Posting ######## + ######## Making things work ######## + key :email, String def method_missing(method, *args) diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index f59cb78485..f13e27f4cd 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -9,16 +9,17 @@ require 'config/environment' # Create seed user -user = User.create( :password => "evankorth", - :person => Person.create( - :email => "robert@joindiaspora.com", - :url => "http://localhost:3000/", - :profile => Profile.new( - :first_name => "bobert", - :last_name => "brin" ))) +user = User.create( :email => "robert@joindiaspora.com", + :password => "evankorth", + :person => Person.new( + :email => "robert@joindiaspora.com", + :url => "http://localhost:3000/", + :profile => Profile.new( + :first_name => "bobert", + :last_name => "brin" ))) -puts user.save! -puts user.person.save +puts user.save +puts user.person.save! puts user.save! puts user.person.inspect puts user.inspect diff --git a/lib/encryptable.rb b/lib/encryptable.rb index b552a5ab48..6925b4cd04 100644 --- a/lib/encryptable.rb +++ b/lib/encryptable.rb @@ -10,7 +10,7 @@ if person.nil? Rails.logger.info("Verifying sig on #{signable_string} but no person is here") return false - elsif person.key.nil? + elsif person.encryption_key.nil? Rails.logger.info("Verifying sig on #{signable_string} but #{person.real_name} has no key") return false elsif signature.nil? @@ -18,14 +18,14 @@ return false end Rails.logger.info("Verifying sig on #{signable_string} from person #{person.real_name}") - validity = person.key.verify "SHA", Base64.decode64(signature), signable_string + validity = person.encryption_key.verify "SHA", Base64.decode64(signature), signable_string Rails.logger.info("Validity: #{validity}") validity end protected def sign_if_mine - self.creator_signature = sign_with_key(person.key) unless person.owner_id.nil? + self.creator_signature = sign_with_key(person.encryption_key) unless person.owner_id.nil? end def sign_with_key(key) diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index d112b726bf..2c7b8963b7 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -33,7 +33,7 @@ describe 'user encryption' do #keys.each{|k| ctx.delete_key(k, true)} end it 'should have a key' do - @user.key.should_not be nil + @user.encryption_key.should_not be nil end describe 'key exchange on friending' do it 'should send over a public key' do @@ -44,7 +44,7 @@ describe 'user encryption' do it 'should receive and marshal a public key from a request' do person = Factory.build(:person, :url => "http://test.url/" ) - person.key.nil?.should== false + person.encryption_key.nil?.should== false #should move this to friend request, but i found it here id = person.id original_key = person.export_key @@ -78,7 +78,7 @@ describe 'user encryption' do it 'should verify a remote signature' do message = Factory.build(:status_message, :person => @person) - message.creator_signature = message.send(:sign_with_key,@person.key) + message.creator_signature = message.send(:sign_with_key,@person.encryption_key) message.save(:validate => false) message.verify_creator_signature.should be true end @@ -86,14 +86,14 @@ describe 'user encryption' do it 'should know if the signature is from the wrong person' do message = Factory.build(:status_message, :person => @person) message.save(:validate => false) - message.creator_signature = message.send(:sign_with_key,@person.key) + message.creator_signature = message.send(:sign_with_key,@person.encryption_key) message.person = @user message.verify_creator_signature.should be false end it 'should know if the signature is for the wrong text' do message = Factory.build(:status_message, :person => @person) - message.creator_signature = message.send(:sign_with_key,@person.key) + message.creator_signature = message.send(:sign_with_key,@person.encryption_key) message.message = 'I love VENISON' message.save(:validate => false) message.verify_creator_signature.should be false @@ -121,7 +121,7 @@ describe 'user encryption' do describe 'comments' do before do @remote_message = Factory.build(:status_message, :person => @person) - @remote_message.creator_signature = @remote_message.send(:sign_with_key,@person.key) + @remote_message.creator_signature = @remote_message.send(:sign_with_key,@person.encryption_key) @remote_message.save @message = @user.post :status_message, :message => "hi" end @@ -139,17 +139,17 @@ describe 'user encryption' 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.creator_signature = comment.send(:sign_with_key,@person2.key) + comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key) comment.verify_creator_signature.should be true comment.valid?.should be false - comment.post_creator_signature = comment.send(:sign_with_key,@person.key) + 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 comment = Comment.new(:person => @person2, :text => "balls", :post => @remote_message) - comment.creator_signature = comment.send(:sign_with_key,@person2.key) + 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 @@ -157,7 +157,7 @@ describe 'user encryption' 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.creator_signature = comment.send(:sign_with_key,@person2.key) + comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key) comment.save.should be true end -- GitLab