rs iz ; the signature of the signable_accessors are now in the xml
This commit is contained in:
parent
add9961ca4
commit
964ee65b11
3 changed files with 19 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ class Post
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
|
||||||
xml_accessor :_id
|
xml_accessor :_id
|
||||||
|
xml_accessor :owner_signature
|
||||||
xml_accessor :person, :as => Person
|
xml_accessor :person, :as => Person
|
||||||
|
|
||||||
key :person_id, ObjectId
|
key :person_id, ObjectId
|
||||||
|
|
@ -51,6 +52,7 @@ class Post
|
||||||
accessors = self.class.roxml_attrs.collect{|definition|
|
accessors = self.class.roxml_attrs.collect{|definition|
|
||||||
definition.accessor}
|
definition.accessor}
|
||||||
accessors.delete 'person'
|
accessors.delete 'person'
|
||||||
|
accessors.delete 'owner_signature'
|
||||||
accessors
|
accessors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -62,16 +64,19 @@ class Post
|
||||||
def verify_signature
|
def verify_signature
|
||||||
return false unless owner_signature && person.key_fingerprint
|
return false unless owner_signature && person.key_fingerprint
|
||||||
validity = nil
|
validity = nil
|
||||||
GPGME::verify(owner_signature, signable_string, {:armor => true, :always_trust => true}){ |signature|
|
GPGME::verify(owner_signature, signable_string,
|
||||||
validity = signature.status == GPGME::GPG_ERR_NO_ERROR &&
|
{:armor => true, :always_trust => true}){ |signature|
|
||||||
signature.fpr == person.key_fingerprint
|
puts signature
|
||||||
|
validity = signature.status == GPGME::GPG_ERR_NO_ERROR &&
|
||||||
|
signature.fpr == person.key_fingerprint
|
||||||
|
puts validity
|
||||||
}
|
}
|
||||||
return validity
|
return validity
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def sign_if_mine
|
def sign_if_mine
|
||||||
if self.person == User.first
|
if self.person == User.owner
|
||||||
self.owner_signature = GPGME::sign(signable_string,nil,
|
self.owner_signature = GPGME::sign(signable_string,nil,
|
||||||
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH})
|
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ Factory.define :user do |u|
|
||||||
u.password "bluepin7"
|
u.password "bluepin7"
|
||||||
u.password_confirmation "bluepin7"
|
u.password_confirmation "bluepin7"
|
||||||
u.url "www.example.com/"
|
u.url "www.example.com/"
|
||||||
u.key_fingerprint GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
|
u.key_fingerprint GPGME.list_keys("Smith", true).first.subkeys.first.fingerprint
|
||||||
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ describe 'user encryption' do
|
||||||
end
|
end
|
||||||
it 'should sign a message on create' do
|
it 'should sign a message on create' do
|
||||||
message = Factory.create(:status_message, :person => @u)
|
message = Factory.create(:status_message, :person => @u)
|
||||||
|
puts message.owner_signature
|
||||||
message.verify_signature.should be true
|
message.verify_signature.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -115,4 +116,12 @@ describe 'user encryption' do
|
||||||
message.verify_signature.should be false
|
message.verify_signature.should be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'sending and recieving signatures' do
|
||||||
|
it 'should contain the signature in the xml' do
|
||||||
|
message = Factory.create(:status_message, :person => @u)
|
||||||
|
xml = message.to_xml.to_s
|
||||||
|
xml.include?(message.owner_signature).should be true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue