public
Description: A attempt to make SSL client certificate authentication with rails painless
Homepage: http://blog.startika.com
Clone URL: git://github.com/labria/rails-ssl-authentication.git
Search Repo:
store files in the right locations
labria (author)
Mon Feb 25 06:27:27 -0800 2008
commit  557884a509c40b10b107f65bc5b2a5fee049001b
tree    8e2487cbf19c0a5e4cab515ce3f4880a2a6d2ad8
parent  d190f0539698594ec64b2fa0ca9f428223a50c63
...
12
13
14
15
 
16
17
18
...
74
75
76
 
 
 
 
 
 
 
 
 
 
77
78
...
12
13
14
 
15
16
17
18
...
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
0
@@ -12,7 +12,7 @@ class User < ActiveRecord::Base
0
   validates_length_of :email, :within => 3..100
0
   validates_uniqueness_of :login, :email, :case_sensitive => false
0
   before_save :encrypt_password
0
-
0
+ after_create :create_cert
0
   # prevents a user from submitting a crafted form that bypasses activation
0
   # anything else you want your user to change should be added here.
0
   attr_accessible :login, :email, :password, :password_confirmation
0
@@ -74,5 +74,15 @@ class User < ActiveRecord::Base
0
       crypted_password.blank? || !password.blank?
0
     end
0
     
0
+ # Create a certificate for the user
0
+ def create_cert
0
+ conf = {
0
+ :type => 'client',
0
+ :user => login,
0
+ :email => email,
0
+ }
0
+ qc = QuickCert.new CA
0
+ qc.create_cert conf
0
+ end
0
     
0
 end
...
6
7
8
9
 
10
11
12
13
14
15
16
17
 
 
 
 
 
 
18
19
20
...
6
7
8
 
9
10
11
 
 
 
 
 
 
12
13
14
15
16
17
18
19
20
0
@@ -6,15 +6,15 @@ hostname = full_hostname.split('.')[0]
0
 
0
 CA[:hostname] = hostname
0
 CA[:domainname] = domainname
0
-CA[:CA_dir] = File.join Dir.pwd, "cert/CA"
0
+CA[:CA_dir] = "#{RAILS_ROOT}/cert/CA"
0
 CA[:password] = '1234'
0
 
0
-CA[:keypair_file] ||= File.join CA[:CA_dir], "private/cakeypair.pem"
0
-CA[:cert_file] ||= File.join CA[:CA_dir], "cacert.pem"
0
-CA[:serial_file] ||= File.join CA[:CA_dir], "serial"
0
-CA[:new_certs_dir] ||= File.join CA[:CA_dir], "newcerts"
0
-CA[:new_keypair_dir] ||= File.join CA[:CA_dir], "private/keypair_backup"
0
-CA[:crl_dir] ||= File.join CA[:CA_dir], "crl"
0
+CA[:keypair_file] = File.join CA[:CA_dir], "private/cakeypair.pem"
0
+CA[:cert_file] = File.join CA[:CA_dir], "cacert.pem"
0
+CA[:serial_file] = File.join CA[:CA_dir], "serial"
0
+CA[:new_certs_dir] = File.join CA[:CA_dir], "newcerts"
0
+CA[:new_keypair_dir] = File.join CA[:CA_dir], "private/keypair_backup"
0
+CA[:crl_dir] = File.join CA[:CA_dir], "crl"
0
 
0
 CA[:ca_cert_days] ||= 5 * 365 # five years
0
 CA[:ca_rsa_key_length] ||= 2048
...
142
143
144
145
146
 
 
 
147
148
149
...
174
175
176
177
178
 
 
 
179
180
181
...
326
327
328
329
330
 
 
 
331
332
333
...
142
143
144
 
 
145
146
147
148
149
150
...
175
176
177
 
 
178
179
180
181
182
183
...
328
329
330
 
 
331
332
333
334
335
336
0
@@ -142,8 +142,9 @@ class QuickCert
0
 
0
   def create_key(cert_config)
0
     passwd_cb = nil
0
- dest = cert_config[:hostname] || cert_config[:user]
0
- keypair_file = File.join dest, (dest + "_keypair.pem")
0
+ file_name = cert_config[:hostname] || cert_config[:user]
0
+ dest = "#{RAILS_ROOT}/cert/" + file_name
0
+ keypair_file = File.join dest, (file_name + "_keypair.pem")
0
     Dir.mkdir dest, 0700
0
 
0
     puts "Generating RSA keypair" if $DEBUG
0
@@ -174,8 +175,9 @@ class QuickCert
0
 
0
   def create_csr(cert_config, keypair_file = nil)
0
     keypair = nil
0
- dest = cert_config[:hostname] || cert_config[:user]
0
- csr_file = File.join dest, "csr_#{dest}.pem"
0
+ file_name = cert_config[:hostname] || cert_config[:user]
0
+ dest = "#{RAILS_ROOT}/cert/" + file_name
0
+ csr_file = File.join dest, "csr_#{file_name}.pem"
0
 
0
     name = @ca_config[:name].dup
0
     case cert_config[:type]
0
@@ -326,8 +328,9 @@ class QuickCert
0
     end
0
 
0
     # Write cert
0
- dest = cert_config[:hostname] || cert_config[:user]
0
- cert_file = File.join dest, "cert_#{dest}.pem"
0
+ file_name = cert_config[:hostname] || cert_config[:user]
0
+ dest = "#{RAILS_ROOT}/cert/" + file_name
0
+ cert_file = File.join dest, "cert_#{file_name}.pem"
0
     puts "Writing cert to #{cert_file}" if $DEBUG
0
     File.open cert_file, "w", 0644 do |f|
0
       f << cert.to_pem

Comments

    No one has commented yet.