From 8c45dd47022afdbc1a9369b244e9499e1f06ea69 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 9 Jul 2010 18:15:17 -0400 Subject: [PATCH] testing signing --- app/models/post.rb | 21 +++++++++++++++++++-- gpg/diaspora-test/random_seed | Bin 600 -> 600 bytes spec/user_encryption_spec.rb | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index ca6e1ee83..425c6c199 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -9,7 +9,6 @@ class Post xml_accessor :person, :as => Person key :person_id, ObjectId - key :owner_signature, String many :comments, :class_name => 'Comment', :foreign_key => :post_id belongs_to :person, :class_name => 'Person' @@ -43,10 +42,28 @@ class Post self.newest(Person.first(:email => email)) end +#ENCRYPTION + before_save :sign_if_mine + key :owner_signature, String def verify_signature - GPGME.verify(owner + validity = true + signed_text = GPGME.verify(){ |signature| + if signature.validity == GPGME::VALIDITY_FULL + validity = validity && true + else + validity = validity && false + end + } + validity = validity && (signed_text == to_xml.to_s) + validity end protected + def sign_if_mine + if self.person == User.first + self.owner_signature = GPGME::sign(to_xml.to_s,nil,{:armor=> true}) + end + end + def destroy_comments comments.each{|c| c.destroy} end diff --git a/gpg/diaspora-test/random_seed b/gpg/diaspora-test/random_seed index 506a7c40031f6d9ed4e2126782dd16058d0c54ca..bf240de5179db612deaa37991110b80cc901d49b 100644 GIT binary patch literal 600 zcmV-e0;m08U3uPed_I(wQQ(|D>j5UY8i5X$mV11NU2RpTo~Aq(5H=`ZdmkxV3O@qc z5(jtBHY8h%Gs`N6ZYPtcXB6$I+8=|4Luvoz-wlk%UBtSH7j}Uz)I23$xPE@dOonb! zC<^nd6^W^^3|rv1l`Mw45i|Xo8iN}Z@ZW0t7Z%NA0a}AZab1iZ=ja&n5WntU#7Cu{ zl*n+iQ85F%5nY-?M64yNsi+Z?_XH;}@*XXQ03i zU@}MSF=PAnhTpsfg~TOxLM?)<4>;OooAr<8*>8S!13CPQB%1>={O4#dkrCCLWS3Lq zNmbra6sL^U&maQQ8^1lDtUUMIS=Kmr*fbxvqwqiT?=giKp)y*yVExZ>hDh_4nxqUb z9`8CFc4lZ59fHy-MHayLQzF(b0jD!%QTe0Dj)TN_;~tt(u7*1YmSN?zO)zAw)j6&w msfPJ)JW5l1<1i5re3lGzU@PD+5E!zf*I2A4j0t4>3h7Stc^dox literal 600 zcmV-e0;m0FWcFY%lza+p6ZedPRfHU;TXAFCEd z?>r$nSBSGsoHCIRx#c$aW6L;1^(h_}g~`^Rm3dQYBb~qI^PzzH8t55_hX+=Bzoq&{ z4*FtIyaw$9|74e^!x0}1EKO-rI&d<*skN;+Z+ z-*BWJ#$%LJKC_#yB!2Q@_!`LCoWV0NRR$2~PyjD%(V0ukhjW13sFN{z0zywL~OUj~uY7J5V3BYV~=Y mUQl&@tiPaFlu=GwdJ-+-uA6}c4nume-Y6}FFQTV`ob(p!6()!P diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 02baba68a..d23705946 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -31,7 +31,7 @@ describe 'user encryption' do end it 'should sign a message' do - message = Factory.create(:status_message, :user => @u) + message = Factory.create(:status_message, :person => @u) message.verify_signature.should == true end end