diff --git a/app/models/post.rb b/app/models/post.rb index 425c6c199..ae6d11af3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -46,16 +46,12 @@ class Post before_save :sign_if_mine key :owner_signature, String def verify_signature - validity = true - signed_text = GPGME.verify(){ |signature| - if signature.validity == GPGME::VALIDITY_FULL - validity = validity && true - else - validity = validity && false - end + return false unless owner_signature && person.key_fingerprint + GPGME.verify(owner_signature){ |signature| + return signature.validity == GPGME::VALIDITY_FULL + #validity = validity && person.key_fingerprint == signature.fpr } - validity = validity && (signed_text == to_xml.to_s) - validity + #validity = validity && (signed_text == to_xml.to_s) end protected def sign_if_mine diff --git a/gpg/diaspora-test/pubring.gpg b/gpg/diaspora-test/pubring.gpg index 33ce2b7d9..da64a4ec3 100644 Binary files a/gpg/diaspora-test/pubring.gpg and b/gpg/diaspora-test/pubring.gpg differ diff --git a/gpg/diaspora-test/random_seed b/gpg/diaspora-test/random_seed index bf240de51..6239b704b 100644 Binary files a/gpg/diaspora-test/random_seed and b/gpg/diaspora-test/random_seed differ diff --git a/gpg/diaspora-test/trustdb.gpg b/gpg/diaspora-test/trustdb.gpg index 5a8d5b325..f52c08a1d 100644 Binary files a/gpg/diaspora-test/trustdb.gpg and b/gpg/diaspora-test/trustdb.gpg differ diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 4298cb785..ad841d22b 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -5,17 +5,13 @@ describe 'user encryption' do #ctx = GPGME::Ctx.new #keys = ctx.keys #keys.each{|k| ctx.delete_key(k, true)} - @u = User.new - @u.email = "george@aol.com" - @u.password = "bluepin7" - @u.password_confirmation = "bluepin7" - @u.url = "www.example.com" - @u.profile = Profile.new( :first_name => "Bob", :last_name => "Smith" ) - @u.profile.save + + end + before do + @u = Factory.create(:user) @u.send(:assign_key) @u.save end - # after :all do #gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) #ctx = GPGME::Ctx.new @@ -30,9 +26,23 @@ describe 'user encryption' do it 'should retrieve a user key' do @u.key.subkeys[0].fpr.should == @u.key_fingerprint end - - it 'should sign a message' do - message = Factory.create(:status_message, :person => @u) - message.verify_signature.should == true + describe 'signing and verifying' do + + it 'should sign a message on create' do + message = Factory.create(:status_message, :person => @u) + message.verify_signature.should be true + end + + it 'should not be able to verify a message from a person without a key' do + person = Factory.create(:person) + message = Factory.create(:status_message, :person => person) + message.verify_signature.should be false + end + + it 'should know if the signature is from the wrong person' do + pending + my_message = Factory.create( + end + end end