Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#check_client(name) ⇒ Object



7
8
9
10
# File 'lib/functions.rb', line 7

def check_client name
  abort "Error: client should have an alphanumeric name" unless name
  check_crt(name)
end

#check_crt(filename) ⇒ Object



1
2
3
4
5
# File 'lib/functions.rb', line 1

def check_crt filename
  ['key', 'crt'].each {|ext|
    abort "#{filename}.#{ext} already exists, exiting" if File.exist? "#{filename}.#{ext}"
  }
end

#create_dir(name) ⇒ Object



43
44
45
46
47
48
# File 'lib/functions.rb', line 43

def create_dir name
  unless Dir.exist? name
    Dir.mkdir name
    puts "Created directory: #{name}"
  end
end

#exe(cmd) ⇒ Object



12
13
14
# File 'lib/functions.rb', line 12

def exe cmd
  system(cmd) or abort "error executing: #{cmd}"
end

#gen_and_sign(type, certname, no_password) ⇒ Object



16
17
18
19
# File 'lib/functions.rb', line 16

def gen_and_sign type, certname, no_password
  gen_key(certname, no_password)
  sign_key(type, certname, certname)
end

#gen_crlObject



39
40
41
# File 'lib/functions.rb', line 39

def gen_crl
  exe "#{OPENSSL} ca -gencrl -out crl.pem -config #{SSL_CONF}"
end

#gen_key(certname, no_password) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/functions.rb', line 21

def gen_key certname, no_password
  if no_password
    exe "#{OPENSSL} genrsa -out '#{certname}.key' #{KEY_SIZE}"
  else
    exe "#{OPENSSL} genrsa -#{ENCRYPT} -out '#{certname}.key' #{KEY_SIZE}"
  end
end

#sign_key(type, certname, cn) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/functions.rb', line 29

def sign_key type, certname, cn
  if certname == 'ca'
    exe "#{OPENSSL} req -new -x509 -key '#{certname}.key' -out '#{certname}.crt' -config #{SSL_CONF} -subj '/CN=#{cn}#{REQ}' -extensions ext.#{type} -days #{CA_DAYS}"
  else
    exe "#{OPENSSL} req -new -key '#{certname}.key' -out '#{certname}.csr' -config #{SSL_CONF} -subj '/CN=#{cn}#{REQ}' -extensions ext.#{type}"
    exe "#{OPENSSL} ca -in '#{certname}.csr' -out '#{certname}.crt' -config #{SSL_CONF} -extensions ext.#{type} -batch"
    File.delete "#{certname}.csr"
  end
end