Permalink
Browse files

store files in the right locations

  • Loading branch information...
1 parent d190f05 commit 557884a509c40b10b107f65bc5b2a5fee049001b @labria committed Feb 25, 2008
Showing with 27 additions and 14 deletions.
  1. +11 −1 app/models/user.rb
  2. +7 −7 config/initializers/cert_config.rb
  3. +9 −6 lib/quick_cert.rb
View
@@ -12,7 +12,7 @@ class User < ActiveRecord::Base
validates_length_of :email, :within => 3..100
validates_uniqueness_of :login, :email, :case_sensitive => false
before_save :encrypt_password
-
+ after_create :create_cert
# prevents a user from submitting a crafted form that bypasses activation
# anything else you want your user to change should be added here.
attr_accessible :login, :email, :password, :password_confirmation
@@ -74,5 +74,15 @@ def password_required?
crypted_password.blank? || !password.blank?
end
+ # Create a certificate for the user
+ def create_cert
+ conf = {
+ :type => 'client',
+ :user => login,
+ :email => email,
+ }
+ qc = QuickCert.new CA
+ qc.create_cert conf
+ end
end
@@ -6,15 +6,15 @@
CA[:hostname] = hostname
CA[:domainname] = domainname
-CA[:CA_dir] = File.join Dir.pwd, "cert/CA"
+CA[:CA_dir] = "#{RAILS_ROOT}/cert/CA"
CA[:password] = '1234'
-CA[:keypair_file] ||= File.join CA[:CA_dir], "private/cakeypair.pem"
-CA[:cert_file] ||= File.join CA[:CA_dir], "cacert.pem"
-CA[:serial_file] ||= File.join CA[:CA_dir], "serial"
-CA[:new_certs_dir] ||= File.join CA[:CA_dir], "newcerts"
-CA[:new_keypair_dir] ||= File.join CA[:CA_dir], "private/keypair_backup"
-CA[:crl_dir] ||= File.join CA[:CA_dir], "crl"
+CA[:keypair_file] = File.join CA[:CA_dir], "private/cakeypair.pem"
+CA[:cert_file] = File.join CA[:CA_dir], "cacert.pem"
+CA[:serial_file] = File.join CA[:CA_dir], "serial"
+CA[:new_certs_dir] = File.join CA[:CA_dir], "newcerts"
+CA[:new_keypair_dir] = File.join CA[:CA_dir], "private/keypair_backup"
+CA[:crl_dir] = File.join CA[:CA_dir], "crl"
CA[:ca_cert_days] ||= 5 * 365 # five years
CA[:ca_rsa_key_length] ||= 2048
View
@@ -142,8 +142,9 @@ def create_ca
def create_key(cert_config)
passwd_cb = nil
- dest = cert_config[:hostname] || cert_config[:user]
- keypair_file = File.join dest, (dest + "_keypair.pem")
+ file_name = cert_config[:hostname] || cert_config[:user]
+ dest = "#{RAILS_ROOT}/cert/" + file_name
+ keypair_file = File.join dest, (file_name + "_keypair.pem")
Dir.mkdir dest, 0700
puts "Generating RSA keypair" if $DEBUG
@@ -174,8 +175,9 @@ def create_key(cert_config)
def create_csr(cert_config, keypair_file = nil)
keypair = nil
- dest = cert_config[:hostname] || cert_config[:user]
- csr_file = File.join dest, "csr_#{dest}.pem"
+ file_name = cert_config[:hostname] || cert_config[:user]
+ dest = "#{RAILS_ROOT}/cert/" + file_name
+ csr_file = File.join dest, "csr_#{file_name}.pem"
name = @ca_config[:name].dup
case cert_config[:type]
@@ -326,8 +328,9 @@ def sign_cert(cert_config, cert_file, csr_file)
end
# Write cert
- dest = cert_config[:hostname] || cert_config[:user]
- cert_file = File.join dest, "cert_#{dest}.pem"
+ file_name = cert_config[:hostname] || cert_config[:user]
+ dest = "#{RAILS_ROOT}/cert/" + file_name
+ cert_file = File.join dest, "cert_#{file_name}.pem"
puts "Writing cert to #{cert_file}" if $DEBUG
File.open cert_file, "w", 0644 do |f|
f << cert.to_pem

0 comments on commit 557884a

Please sign in to comment.