RS, IZ; Users now have keys, keyring now in db folder

This commit is contained in:
ilya 2010-07-08 19:57:10 -04:00
parent 1885b5b6b9
commit 9e8426ceb4
19 changed files with 81 additions and 51 deletions

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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 = "<GnupgKeyParms format=\"internal\">
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}
</GnupgKeyParms>"
ctx.genkey(paramstring, nil, nil)
end
end

View file

@ -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

View file

@ -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({})

View file

@ -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'] %>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
db/gpg-test/pubring.gpg Normal file

Binary file not shown.

BIN
db/gpg-test/pubring.gpg~ Normal file

Binary file not shown.

BIN
db/gpg-test/random_seed Normal file

Binary file not shown.

BIN
db/gpg-test/secring.gpg Normal file

Binary file not shown.

BIN
db/gpg-test/trustdb.gpg Normal file

Binary file not shown.

View file

@ -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')

View file

@ -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