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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue