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
|
protected
|
||||||
def sign_if_my_post
|
def sign_if_my_post
|
||||||
unless self.post.person.owner.nil?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,16 @@ class Person
|
||||||
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def key
|
def encryption_key
|
||||||
OpenSSL::PKey::RSA.new( serialized_key )
|
OpenSSL::PKey::RSA.new( serialized_key )
|
||||||
end
|
end
|
||||||
|
|
||||||
def key= new_key
|
def encryption_key= new_key
|
||||||
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
|
||||||
key.public_key.export
|
encryption_key.public_key.export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -107,7 +107,6 @@ class Person
|
||||||
end
|
end
|
||||||
|
|
||||||
def owns?(post)
|
def owns?(post)
|
||||||
puts self.class
|
|
||||||
self.id == post.person.id
|
self.id == post.person.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ class User
|
||||||
before_validation_on_create :assign_key
|
before_validation_on_create :assign_key
|
||||||
before_validation :do_bad_things
|
before_validation :do_bad_things
|
||||||
|
|
||||||
######## Posting ########
|
######## Making things work ########
|
||||||
|
|
||||||
key :email, String
|
key :email, String
|
||||||
|
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,17 @@
|
||||||
require 'config/environment'
|
require 'config/environment'
|
||||||
|
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.create( :password => "evankorth",
|
user = User.create( :email => "robert@joindiaspora.com",
|
||||||
:person => Person.create(
|
:password => "evankorth",
|
||||||
|
:person => Person.new(
|
||||||
:email => "robert@joindiaspora.com",
|
:email => "robert@joindiaspora.com",
|
||||||
:url => "http://localhost:3000/",
|
:url => "http://localhost:3000/",
|
||||||
:profile => Profile.new(
|
:profile => Profile.new(
|
||||||
:first_name => "bobert",
|
:first_name => "bobert",
|
||||||
:last_name => "brin" )))
|
:last_name => "brin" )))
|
||||||
|
|
||||||
puts user.save!
|
puts user.save
|
||||||
puts user.person.save
|
puts user.person.save!
|
||||||
puts user.save!
|
puts user.save!
|
||||||
puts user.person.inspect
|
puts user.person.inspect
|
||||||
puts user.inspect
|
puts user.inspect
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
if person.nil?
|
if person.nil?
|
||||||
Rails.logger.info("Verifying sig on #{signable_string} but no person is here")
|
Rails.logger.info("Verifying sig on #{signable_string} but no person is here")
|
||||||
return false
|
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")
|
Rails.logger.info("Verifying sig on #{signable_string} but #{person.real_name} has no key")
|
||||||
return false
|
return false
|
||||||
elsif signature.nil?
|
elsif signature.nil?
|
||||||
|
|
@ -18,14 +18,14 @@
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
Rails.logger.info("Verifying sig on #{signable_string} from person #{person.real_name}")
|
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}")
|
Rails.logger.info("Validity: #{validity}")
|
||||||
validity
|
validity
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def sign_if_mine
|
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
|
end
|
||||||
|
|
||||||
def sign_with_key(key)
|
def sign_with_key(key)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ describe 'user encryption' do
|
||||||
#keys.each{|k| ctx.delete_key(k, true)}
|
#keys.each{|k| ctx.delete_key(k, true)}
|
||||||
end
|
end
|
||||||
it 'should have a key' do
|
it 'should have a key' do
|
||||||
@user.key.should_not be nil
|
@user.encryption_key.should_not be nil
|
||||||
end
|
end
|
||||||
describe 'key exchange on friending' do
|
describe 'key exchange on friending' do
|
||||||
it 'should send over a public key' 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
|
it 'should receive and marshal a public key from a request' do
|
||||||
person = Factory.build(:person, :url => "http://test.url/" )
|
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
|
#should move this to friend request, but i found it here
|
||||||
id = person.id
|
id = person.id
|
||||||
original_key = person.export_key
|
original_key = person.export_key
|
||||||
|
|
@ -78,7 +78,7 @@ describe 'user encryption' do
|
||||||
|
|
||||||
it 'should verify a remote signature' do
|
it 'should verify a remote signature' do
|
||||||
message = Factory.build(:status_message, :person => @person)
|
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.save(:validate => false)
|
||||||
message.verify_creator_signature.should be true
|
message.verify_creator_signature.should be true
|
||||||
end
|
end
|
||||||
|
|
@ -86,14 +86,14 @@ describe 'user encryption' do
|
||||||
it 'should know if the signature is from the wrong person' do
|
it 'should know if the signature is from the wrong person' do
|
||||||
message = Factory.build(:status_message, :person => @person)
|
message = Factory.build(:status_message, :person => @person)
|
||||||
message.save(:validate => false)
|
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.person = @user
|
||||||
message.verify_creator_signature.should be false
|
message.verify_creator_signature.should be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should know if the signature is for the wrong text' do
|
it 'should know if the signature is for the wrong text' do
|
||||||
message = Factory.build(:status_message, :person => @person)
|
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.message = 'I love VENISON'
|
||||||
message.save(:validate => false)
|
message.save(:validate => false)
|
||||||
message.verify_creator_signature.should be false
|
message.verify_creator_signature.should be false
|
||||||
|
|
@ -121,7 +121,7 @@ describe 'user encryption' do
|
||||||
describe 'comments' do
|
describe 'comments' do
|
||||||
before do
|
before do
|
||||||
@remote_message = Factory.build(:status_message, :person => @person)
|
@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
|
@remote_message.save
|
||||||
@message = @user.post :status_message, :message => "hi"
|
@message = @user.post :status_message, :message => "hi"
|
||||||
end
|
end
|
||||||
|
|
@ -139,17 +139,17 @@ describe 'user encryption' do
|
||||||
|
|
||||||
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.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.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.verify_post_creator_signature.should be true
|
||||||
comment.valid?.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.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
|
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
|
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.key)
|
comment.creator_signature = comment.send(:sign_with_key,@person2.encryption_key)
|
||||||
comment.save.should be true
|
comment.save.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue