DG, RS; User person delegation fixed
This commit is contained in:
parent
890f927492
commit
73a6cd911b
6 changed files with 29 additions and 28 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue