signing tests sort of almost done
This commit is contained in:
parent
b9146cbb41
commit
6d431e9459
6 changed files with 19 additions and 11 deletions
|
|
@ -47,16 +47,18 @@ class Post
|
|||
key :owner_signature, String
|
||||
def verify_signature
|
||||
return false unless owner_signature && person.key_fingerprint
|
||||
puts to_xml.to_s
|
||||
puts owner_signature
|
||||
GPGME::verify(owner_signature, nil, {:armor => true, :always_trust => true}){ |signature|
|
||||
validity = nil
|
||||
message = GPGME::verify(owner_signature, nil, {:armor => true, :always_trust => true}){ |signature|
|
||||
puts signature
|
||||
puts signature.inspect
|
||||
return signature.status == GPGME::GPG_ERR_NO_ERROR &&
|
||||
validity = signature.status == GPGME::GPG_ERR_NO_ERROR &&
|
||||
#signature.to_s.include?("Good signature from ") &&
|
||||
signature.fpr == person.key_fingerprint
|
||||
#validity = validity && person.key_fingerprint == signature.fpr
|
||||
}
|
||||
puts message
|
||||
puts to_xml.to_s
|
||||
return validity && message == to_xml.to_s
|
||||
#validity = validity && (signed_text == to_xml.to_s)
|
||||
end
|
||||
protected
|
||||
|
|
|
|||
|
|
@ -91,11 +91,11 @@ class User < Person
|
|||
protected
|
||||
|
||||
def assign_key
|
||||
keys = GPGME.list_keys(nil, true)
|
||||
keys = GPGME.list_keys(real_name, true)
|
||||
if keys.empty?
|
||||
generate_key
|
||||
end
|
||||
self.key_fingerprint = GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
|
||||
self.key_fingerprint = GPGME.list_keys(real_name, true).first.subkeys.first.fingerprint
|
||||
end
|
||||
|
||||
def generate_key
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -83,12 +83,18 @@ describe 'user encryption' do
|
|||
end
|
||||
|
||||
it 'should verify a remote signature' do
|
||||
person = Factory.create(:person, :key_fingerprint => GPGME.list_keys("Ilya").first.subkeys.first.fpr)
|
||||
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.detached.asc").read)
|
||||
person = Factory.create(:person,
|
||||
:key_fingerprint => GPGME.list_keys("Remote Friend").first.subkeys.first.fpr,
|
||||
:profile => Profile.create(:first_name => 'Remote',
|
||||
:last_name => 'Friend'),
|
||||
:email => 'somewhere@else.com',
|
||||
:url => 'http://distant-example.com/',
|
||||
:key_fingerprint => '57F553EE2C230991566B7C60D3638485F3960087')
|
||||
puts person.inspect
|
||||
message = Factory.create(:status_message, :person => person)
|
||||
message.owner_signature = GPGME.sign(message.to_xml.to_s, nil, {:armor => true, :signers => [person.key]})
|
||||
message.save # :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)
|
||||
|
||||
message.verify_signature.should be true
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue