diff --git a/Gemfile b/Gemfile index fb8243e53..4f2c736a1 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem "bson_ext", "1.0.1" gem "haml" gem 'roxml', :git => "git://github.com/Empact/roxml.git" +gem 'gpgme' #mai crazy async stuff #gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git', :require => 'em-synchrony/em-http' diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index cf0e6b41e..56696fb84 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -12,7 +12,7 @@ class DashboardController < ApplicationController puts "SOMEONE JUST SENT ME: #{params[:xml]}" - store_objects_from_xml params[:xml) + store_objects_from_xml params[:xml] render :nothing => true end diff --git a/app/models/person.rb b/app/models/person.rb index 843486ad4..7743f7352 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -9,7 +9,8 @@ class Person key :email, String key :url, String key :active, Boolean, :default => false - + key :key_fingerprint, String + one :profile, :class_name => 'Profile', :foreign_key => :person_id many :posts, :class_name => 'Post', :foreign_key => :person_id @@ -27,13 +28,20 @@ class Person before_validation :clean_url + def real_name "#{profile.first_name.to_s} #{profile.last_name.to_s}" end + + def key + GPGME::Ctx.new.get_key key_fingerprint + end protected + + def url_unique? same_url = Person.first(:url => self.url) return same_url.nil? || same_url.id == self.id diff --git a/app/models/user.rb b/app/models/user.rb index 2723c8b5d..f3c695f3d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,6 +19,8 @@ class User < Person false end + before_create :assign_key + validates_presence_of :profile before_validation :do_bad_things @@ -29,5 +31,33 @@ class User < Person def mine?(post) self == post.person end + + protected + def assign_key + keys = GPGME.list_keys(nil, true) + if keys.empty? + generate_key + end + self.key_fingerprint = GPGME.list_keys(nil, true).first.subkeys.first.fingerprint + puts self.key_fingerprint + end + + def generate_key + puts "Yo, generating a key." + ctx = GPGME::Ctx.new + paramstring = " +Key-Type: DSA +Key-Length: 512 +Subkey-Type: ELG-E +Subkey-Length: 512 +Name-Real: #{self.real_name} +Name-Comment: #{self.url} +Name-Email: #{self.email} +Expire-Date: 0 +Passphrase: #{self.password} +" + ctx.genkey(paramstring, nil, nil) + + end end diff --git a/config/database.yml.sqlite b/config/database.yml.sqlite deleted file mode 100644 index 025d62a8d..000000000 --- a/config/database.yml.sqlite +++ /dev/null @@ -1,22 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3-ruby (not necessary on OS X Leopard) -development: - adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 - timeout: 5000 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 - -production: - adapter: sqlite3 - database: db/production.sqlite3 - pool: 5 - timeout: 5000 diff --git a/config/environment.rb b/config/environment.rb index 3303b3ac5..695be6a22 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,3 +3,6 @@ require File.expand_path('../application', __FILE__) Haml::Template.options[:format] = :html5 # Initialize the rails application Diaspora::Application.initialize! + +ENV['GNUPGHOME'] = File.expand_path("../../db/gpg-#{Rails.env}/", __FILE__) +GPGME::check_version({}) diff --git a/config/mongoid.yml b/config/mongoid.yml deleted file mode 100644 index e0df0977c..000000000 --- a/config/mongoid.yml +++ /dev/null @@ -1,26 +0,0 @@ -defaults: &defaults - host: localhost - allow_dynamic_fields: false - parameterize_keys: true - persist_in_safe_mode: true - raise_not_found_error: false - reconnect_time: 3 - use_object_ids: false - - -development: - <<: *defaults - database: diaspora_development - -test: - <<: *defaults - database: diaspora_test - -# set these environment variables on your prod server -production: - <<: *defaults - #host: <%= ENV['MONGOID_HOST'] %> - #port: <%= ENV['MONGOID_PORT'] %> - #username: <%= ENV['MONGOID_USERNAME'] %> - #password: <%= ENV['MONGOID_PASSWORD'] %> - #database: <%= ENV['MONGOID_DATABASE'] %> diff --git a/db/gpg-development/pubring.gpg b/db/gpg-development/pubring.gpg new file mode 100644 index 000000000..cb573f9bd Binary files /dev/null and b/db/gpg-development/pubring.gpg differ diff --git a/db/gpg-development/pubring.gpg~ b/db/gpg-development/pubring.gpg~ new file mode 100644 index 000000000..44ac03229 Binary files /dev/null and b/db/gpg-development/pubring.gpg~ differ diff --git a/db/gpg-development/random_seed b/db/gpg-development/random_seed new file mode 100644 index 000000000..4d35367ab Binary files /dev/null and b/db/gpg-development/random_seed differ diff --git a/db/gpg-development/secring.gpg b/db/gpg-development/secring.gpg new file mode 100644 index 000000000..4d44acc6b Binary files /dev/null and b/db/gpg-development/secring.gpg differ diff --git a/db/gpg-development/trustdb.gpg b/db/gpg-development/trustdb.gpg new file mode 100644 index 000000000..3e1b582af Binary files /dev/null and b/db/gpg-development/trustdb.gpg differ diff --git a/db/gpg-test/pubring.gpg b/db/gpg-test/pubring.gpg new file mode 100644 index 000000000..506acc069 Binary files /dev/null and b/db/gpg-test/pubring.gpg differ diff --git a/db/gpg-test/pubring.gpg~ b/db/gpg-test/pubring.gpg~ new file mode 100644 index 000000000..60008a7ba Binary files /dev/null and b/db/gpg-test/pubring.gpg~ differ diff --git a/db/gpg-test/random_seed b/db/gpg-test/random_seed new file mode 100644 index 000000000..335e73236 Binary files /dev/null and b/db/gpg-test/random_seed differ diff --git a/db/gpg-test/secring.gpg b/db/gpg-test/secring.gpg new file mode 100644 index 000000000..eaca4a8eb Binary files /dev/null and b/db/gpg-test/secring.gpg differ diff --git a/db/gpg-test/trustdb.gpg b/db/gpg-test/trustdb.gpg new file mode 100644 index 000000000..0afcfe942 Binary files /dev/null and b/db/gpg-test/trustdb.gpg differ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4d470af2..eac2acf4b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,7 +30,12 @@ RSpec.configure do |config| config.after(:each) do DatabaseCleaner.clean end - + config.after(:suite) do + gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) + ctx = GPGME::Ctx.new + keys = ctx.keys + keys.each{|k| ctx.delete_key(k, true)} + end end def stub_socket_controller mock_socket_controller = mock('socket mock') diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb new file mode 100644 index 000000000..518dc8ec3 --- /dev/null +++ b/spec/user_encryption_spec.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe 'user encryption' do + before :all do + @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 + @u.save + end + +# after :all do + #gpgdir = File.expand_path("../../db/gpg-#{Rails.env}", __FILE__) + #ctx = GPGME::Ctx.new + #keys = ctx.keys + #keys.each{|k| ctx.delete_key(k, true)} + #end + + it 'should have a key fingerprint' do + @u.key_fingerprint.should_not be nil + end + + it 'should retrieve a user key' do + @u.key.subkeys[0].fpr.should == @u.key_fingerprint + end + + +end