RS IZ; now signatures work like in real life

This commit is contained in:
ilya 2010-07-12 20:42:22 -07:00
parent 406c00aeb6
commit b9146cbb41
4 changed files with 30 additions and 9 deletions

View file

@ -47,8 +47,11 @@ class Post
key :owner_signature, String key :owner_signature, String
def verify_signature def verify_signature
return false unless owner_signature && person.key_fingerprint return false unless owner_signature && person.key_fingerprint
puts to_xml.to_s
GPGME::verify(owner_signature, {:always_trust => true}){ |signature| puts owner_signature
GPGME::verify(owner_signature, nil, {:armor => true, :always_trust => true}){ |signature|
puts signature
puts signature.inspect
return signature.status == GPGME::GPG_ERR_NO_ERROR && return signature.status == GPGME::GPG_ERR_NO_ERROR &&
#signature.to_s.include?("Good signature from ") && #signature.to_s.include?("Good signature from ") &&
signature.fpr == person.key_fingerprint signature.fpr == person.key_fingerprint
@ -60,7 +63,7 @@ class Post
def sign_if_mine def sign_if_mine
if self.person == User.first if self.person == User.first
self.owner_signature = GPGME::sign(to_xml.to_s,nil,{ self.owner_signature = GPGME::sign(to_xml.to_s,nil,{
:armor=> true, :mode => GPGME::SIG_MODE_DETACH}) :armor=> true})
end end
end end

14
spec/fixtures/msg.xml vendored Normal file
View file

@ -0,0 +1,14 @@
<status_message>
<message>jimmy's 1 whales</message>
<_id>4c3b7cf9312f91367f000004</_id>
<person>
<email>bob1@aol.com</email>
<url>http://www.example.com/</url>
<_id>4c3b7c64312f913664000005</_id>
<key_fingerprint>0264242496D4B585297BF236BEEFE6DEBE3407AA</key_fingerprint>
<profile>
<first_name>Bob</first_name>
<last_name>Smith</last_name>
</profile>
</person>
</status_message>

View file

@ -1,7 +1,7 @@
-----BEGIN PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux) Version: GnuPG v1.4.10 (GNU/Linux)
iEYEABECAAYFAkw7p+YACgkQ5hWCpTN+yRIrHgCghpIwNtqODBwaEjL6duFNcTKv iEYEABECAAYFAkw72oUACgkQ5hWCpTN+yRLSuwCgwphc3LWMM0LOZ5wreKjNeaja
+XYAoKWvcAz76dmAvD71QkTue5F67cq8 BCsAoIzYO9AG3fgV0KbtIFAtuwlNiFxt
=jIOx =W2K4
-----END PGP SIGNATURE----- -----END PGP SIGNATURE-----

View file

@ -85,7 +85,7 @@ describe 'user encryption' do
it 'should verify a remote signature' do it 'should verify a remote signature' do
person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr) person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr)
message = Factory.create(:status_message, :person => person, message = Factory.create(:status_message, :person => person,
:owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.normal.asc").read) :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.normal.asc").read)
# :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.detached.asc").read) # :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.detached.asc").read)
# :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.clear.asc").read) # :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.clear.asc").read)
@ -95,7 +95,7 @@ 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
person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr) person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr)
message = Factory.create(:status_message, :person => person, message = Factory.create(:status_message, :person => person,
:owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.normal.asc").read) :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.normal.asc").read)
# :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.detached.asc").read) # :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.detached.asc").read)
# :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.clear.asc").read) # :owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.clear.asc").read)
@ -104,7 +104,11 @@ describe 'user encryption' do
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
pending person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr)
message = Factory.create(:status_message, :message => 'I love VENISON', :person => person,
:owner_signature => File.open(File.dirname(__FILE__) + "/fixtures/msg.xml.normal.asc").read)
message.verify_signature.should be false
end end
end end
end end