diff --git a/.gitignore b/.gitignore index 872e37d3a..6b3124602 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ db/*.sqlite3 log/*.log tmp/**/* +gpg/diaspora*/* 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/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 33c2bd369..c5508d51c 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -8,7 +8,10 @@ class DashboardsController < ApplicationController end def receive - store_objects_from_xml CGI::escape( params[:xml] ) + + puts "SOMEONE JUST SENT ME: #{params[:xml]}" + + store_objects_from_xml params[:xml] render :nothing => true end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1da4454c5..99f155736 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,5 +4,8 @@ class UsersController < ApplicationController def index @users = User.sort(:created_at.desc).all end - + def show + @user= Person.where(:id => params[:id]).first + @user_profile = @user.profile + end end diff --git a/app/models/person.rb b/app/models/person.rb index 06b1c691c..624f9f85a 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 ce7c8da7c..c348a0d10 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,7 @@ class User < Person :recoverable, :rememberable, :trackable, :validatable + before_create :assign_key validates_presence_of :profile before_validation :do_bad_things @@ -30,6 +31,11 @@ class User < Person if p.save p.push_to_url friend_url end + end + + + def do_bad_things + self.password_confirmation = self.password end def accept_friend_request(friend_request_id) @@ -54,10 +60,31 @@ class User < Person self == post.person end - private - def do_bad_things - self.password_confirmation = self.password + 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 + end + + def generate_key + puts "Generating 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/app/views/users/show.html.haml b/app/views/users/show.html.haml index 01cfb9999..f922e19b8 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1 +1,12 @@ %h1 user page! +.span-18.last + %h1= "#{@user.real_name}" +- if @user_profile + %p + %b url + %p + = @user.url + %p + %b Key Fingerprint + %p + = @user.key_fingerprint 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..cfcd106aa 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("../../gpg/diaspora-#{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/config/sprinkle/packages/essential.rb b/config/sprinkle/packages/essential.rb index 395c8309e..293898abd 100644 --- a/config/sprinkle/packages/essential.rb +++ b/config/sprinkle/packages/essential.rb @@ -10,5 +10,5 @@ end package :tools do description 'Useful tools' - apt 'psmisc htop' + apt 'psmisc htop elinks' end diff --git a/config/sprinkle/packages/ruby.rb b/config/sprinkle/packages/ruby.rb index bba403f3b..644781e7a 100644 --- a/config/sprinkle/packages/ruby.rb +++ b/config/sprinkle/packages/ruby.rb @@ -33,7 +33,7 @@ end package :diaspora_dependencies do description 'random dependencies' - apt %w(libxslt1.1 libxslt1-dev libxml2) + apt %w(libxslt1.1 libxslt1-dev libxml2 libgpgme11-dev) end #package :diaspora do # description 'Diaspora' diff --git a/config/sprinkle/provision.rb b/config/sprinkle/provision.rb index a2f89d829..215ca83f1 100644 --- a/config/sprinkle/provision.rb +++ b/config/sprinkle/provision.rb @@ -33,7 +33,7 @@ require "#{File.dirname(__FILE__)}/packages/ruby" # If there's only one implementation of a virtual package, it's selected automatically, otherwise # the user is requested to select which one to use. -policy :diaspora, :roles => :tom, :backer do +policy :diaspora, :roles => [:tom, :backer] do # requires :clean_dreamhost requires :tools requires :rubygems @@ -43,7 +43,7 @@ policy :diaspora, :roles => :tom, :backer do requires :webserver requires :scm end - +=begin policy :ci, :roles => :ci do requires :tools requires :rubygems @@ -54,7 +54,7 @@ policy :ci, :roles => :ci do requires :scm #add sqlite end - +=end # Deployment # # Defines script wide settings such as a delivery mechanism for executing commands on the target diff --git a/lib/tasks/gpg.rake b/lib/tasks/gpg.rake new file mode 100644 index 000000000..9d7e82223 --- /dev/null +++ b/lib/tasks/gpg.rake @@ -0,0 +1,8 @@ +namespace :gpg do + desc 'Clear the gpg keyrings' + task :clear do + ctx = GPGME::Ctx.new + keys = ctx.keys + keys.each{|k| ctx.delete_key(k, true)} + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3983336f1..cf8bb59d7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,7 +30,6 @@ RSpec.configure do |config| config.after(:each) do DatabaseCleaner.clean end - end def stub_sockets_controller mock_sockets_controller = mock('sockets mock') diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb new file mode 100644 index 000000000..a106b2725 --- /dev/null +++ b/spec/user_encryption_spec.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe 'user encryption' do + before :all do + ctx = GPGME::Ctx.new + keys = ctx.keys + keys.each{|k| ctx.delete_key(k, true)} + @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