From 964ee65b110393b7770d5a8e1294e0f21c013e09 Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 13 Jul 2010 12:20:00 -0700 Subject: [PATCH] rs iz ; the signature of the signable_accessors are now in the xml --- app/models/post.rb | 13 +++++++++---- spec/factories.rb | 2 +- spec/user_encryption_spec.rb | 9 +++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 23ed10167..5a576e9bc 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -6,6 +6,7 @@ class Post include Diaspora::Webhooks xml_accessor :_id + xml_accessor :owner_signature xml_accessor :person, :as => Person key :person_id, ObjectId @@ -51,6 +52,7 @@ class Post accessors = self.class.roxml_attrs.collect{|definition| definition.accessor} accessors.delete 'person' + accessors.delete 'owner_signature' accessors end @@ -62,16 +64,19 @@ class Post def verify_signature return false unless owner_signature && person.key_fingerprint validity = nil - GPGME::verify(owner_signature, signable_string, {:armor => true, :always_trust => true}){ |signature| - validity = signature.status == GPGME::GPG_ERR_NO_ERROR && - signature.fpr == person.key_fingerprint + GPGME::verify(owner_signature, signable_string, + {:armor => true, :always_trust => true}){ |signature| + puts signature + validity = signature.status == GPGME::GPG_ERR_NO_ERROR && + signature.fpr == person.key_fingerprint + puts validity } return validity end protected def sign_if_mine - if self.person == User.first + if self.person == User.owner self.owner_signature = GPGME::sign(signable_string,nil, {:armor=> true, :mode => GPGME::SIG_MODE_DETACH}) end diff --git a/spec/factories.rb b/spec/factories.rb index 240dfb017..9780f2b09 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -24,7 +24,7 @@ Factory.define :user do |u| u.password "bluepin7" u.password_confirmation "bluepin7" 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" ) end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index bb02e29b0..670c37328 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -81,6 +81,7 @@ describe 'user encryption' do end it 'should sign a message on create' do message = Factory.create(:status_message, :person => @u) + puts message.owner_signature message.verify_signature.should be true end @@ -115,4 +116,12 @@ describe 'user encryption' do message.verify_signature.should be false 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