From 1bed575b907d06ef1300cab0e58461b15f3df83a Mon Sep 17 00:00:00 2001 From: ilya Date: Sat, 10 Jul 2010 06:09:53 -0400 Subject: [PATCH] Added the Key Fingerprint validation to the person model(defaults to empty string) --- app/models/person.rb | 10 +++++++--- app/models/request.rb | 4 +++- app/models/user.rb | 1 + gpg/diaspora-test/random_seed | Bin 600 -> 600 bytes spec/factories.rb | 4 +++- spec/models/request_spec.rb | 2 +- spec/user_encryption_spec.rb | 23 ++++++++++++++++++++++- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 48999c664..8a06ca688 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -6,11 +6,12 @@ class Person xml_accessor :url xml_accessor :profile, :as => Profile xml_accessor :_id + xml_accessor :key_fingerprint key :email, String key :url, String key :active, Boolean, :default => false - key :key_fingerprint, String + key :key_fingerprint, String, :default => "" one :profile, :class_name => 'Profile', :foreign_key => :person_id many :posts, :class_name => 'Post', :foreign_key => :person_id @@ -18,7 +19,7 @@ class Person timestamps! before_validation :clean_url - validates_presence_of :email, :url + validates_presence_of :email, :url, :key_fingerprint validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix @@ -36,7 +37,10 @@ class Person def key GPGME::Ctx.new.get_key key_fingerprint end - + + def export_key + GPGME::export(key_fingerprint, :armor => true) + end protected diff --git a/app/models/request.rb b/app/models/request.rb index 95623d9a8..ef935ac03 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -8,10 +8,12 @@ class Request xml_accessor :person, :as => Person xml_accessor :destination_url xml_accessor :callback_url + xml_accessor :exported_key, :cdata => true key :destination_url, String key :callback_url, String key :person_id, ObjectId + key :exported_key, String belongs_to :person @@ -22,7 +24,7 @@ class Request def self.instantiate(options ={}) person = options[:from] - self.new(:destination_url => options[:to], :callback_url => person.url, :person => person) + self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key) end def activate_friend diff --git a/app/models/user.rb b/app/models/user.rb index aa1cbb296..9c7393ecd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -57,6 +57,7 @@ class User < Person friend_request.activate_friend friend_request.destroy else + friend_request.person.save friend_request.save end end diff --git a/gpg/diaspora-test/random_seed b/gpg/diaspora-test/random_seed index 43eed01099182d4478a216fa9e71643377647dd7..3662498f087ad7b8c9e7148f3cbd05527aa1322a 100644 GIT binary patch literal 600 zcmV-e0;l~)hAhB1g_<%i~YBl>bey+a6{KbYx*!ym0_v-A0=-__a zD4VpV9J6DiHr!0hujp#g9cE#R59Do!h+G$&u$_oc4%n9tntZ%#Zv>>WNaf>|9w>Iw zbovO9nv$p0tB4};pqzC8Kt82~#IHo)$`?s;Z|?j&)RCe_8f_2ApCi!H_D4GVDWb`$ z_}FMt^j>>oU(T6EjMC$GnU-ErWl(s$$RtDA|5tnGowpfu5>%I-kx1DKBM47zE_$0v zSIR^!ru42gw)X9Z51g;Rrqp68_OJg!orB~rr(QB3BcTPsjOU{+DCoMkd7DaGJVSFB zfW-XgN-+s303=X#&Yshfp#Xul4FPRe@TRUl@brBa^(jHbb8`ejyGWrdr!u1t=^|1J za0L>zSZ{b4leLBI`kmSg70l$61_J@kMMcQgh3m_1m2^I#SF^S(HEa%XxWRwE(MB2b z0tbX2YJ95k+UC~5k{*2;*uG9X08_+qofZG= zycWIfP_vcdMW!X_09k>a@pIH`UgB5bcmtTOwpuuF<9Ayt#+cdU;I-1q8|x_K zr|B6VWdyxVGnj@n)>r$2U~J6s*>%PO>?KqYo`!U$#OU@rrI}N?M^4~NQA9lNj{%ZX zv@V?&(dCZTQ&Z{?Z9--vgSm6EM}ffDty#g*iKX^!A5<{B!M5qPT!v{n38v2>hCdCx zfU|`H=?x#(6R(Y+k{Z}x++ul8ZM(bIF5DA0V6y54X?nb|XkSjRiXMOAPv8N*t46s{ zG}H&4hodnF1b1d7pztn54ugcTC%LKde+!bUS31z>&+p+VZJiAS6lxD{RN)y#{D3l@ zE)TnCte<1qz3~!x`5J%o(eHoAtJdc_e6o|9|5Sh%R2h!TFL_b049dn8|M=m}E-tO9 z>uYHCRZpX}96AUhg;%Os*ssUoNeH!rkWy#14vZ45?r4dkx4b^Q1a0EO9k8dO@4M2F zXa=mhe$H^n>nwX`N_tprPY>0M;4^2~4KvCC-?Y%qw--2Z{otW8aXrM1|F=vkL7!)% zw9@;k>e2g!1BE$()I8?2jni72!}als|b>oUeGckiS*Qs-j>&4A> z1f&#==qwBkCJehSDU+P3PfQ2Dtx*BxB0|QqyN*1QPjiG0j+sU_od(Co44X=LO;r0C m0{fRQ?&6twInoX$edqg^80K_#9~BTs<#It7IsoB_8RBTBQZPCI diff --git a/spec/factories.rb b/spec/factories.rb index 5467a6b39..90eddd3ba 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -10,8 +10,9 @@ Factory.define :profile do |p| end Factory.define :person do |p| - p.email "bob@aol.com" + p.email "bob-person@aol.com" p.sequence(:url) {|n|"http://google-#{n}.com/"} + p.key_fingerprint GPGME::list_keys("Aditi").first.subkeys.first.fingerprint p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) end @@ -20,6 +21,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.profile Profile.new( :first_name => "Bob", :last_name => "Smith" ) end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index f3357fc73..a6289c4be 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -11,7 +11,7 @@ describe Request do end it 'should generate xml for the User as a Person' do - user = User.create(:email => "rob@bob.com") + user = Factory.build(:user, :email => "rob@bob.com") user.profile = Factory.create(:profile) diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index b07fb39d1..3d0a26685 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/spec_helper' +include ApplicationHelper describe 'user encryption' do before :all do @@ -28,7 +29,27 @@ describe 'user encryption' do end describe 'key exchange on friending' do - + it 'should send over a public key' do + Comment.send(:class_variable_get, :@@queue).stub!(:add_post_request) + request = @u.send_friend_request_to("http://example.com/") + Request.build_xml_for([request]).include?( @u.export_key).should be true + end + + it 'should receive and marshal a public key from a request' do + person = Factory.build(:person, :url => "http://test.url/" ) + original_key = person.export_key + + request = Request.instantiate(:to =>"http://www.google.com/", :from => person) + + xml = Request.build_xml_for [request] + puts xml + + person.destroy + store_objects_from_xml(xml) + + new_person = Person.first(:url => "http://test.url/") + new_person.export_key.should == original_key + end end describe 'signing and verifying' do