ruby-easyrsa

Build Status

Dependency Status

Gem Version

Generate OpenVPN certificate and keys with Ruby using this gem.

Installation

Via command line use gem:

gem install easyrsa

or add it to your projects Gemfile:

gem 'easyrsa'

and simply require it in your code:

require 'easyrsa'

Usage

First, set your issuer configuration like so:

EasyRSA.configure do |issuer|
  issuer.email = '[email protected]'
  issuer.server = 'vpnserver.company.com'
  issuer.country = 'US'
  issuer.city = 'New York'
  issuer.company = 'My Company'
  issuer.orgunit = 'IT'
end

then use the EasyRSA::Certificate class to generate the certificate:

cn = 'Users Common Name'
email = '[email protected]'
easyrsa = EasyRSA::Certificate.new(@ca_cert, @ca_key, cn, email)
g = easyrsa.generate
 #=> [:key => '...RSA KEY...', :crt => '...CERTIFICATE...']

Note ca_cert and ca_key should point to the same certificate and keys that are included in your OpenVPN configuration file.

Generate the CA files

The following can be used to create a Certificate Authority:

ca = EasyRSA::CA.new('CN=openvpn/DC=example/DC=com')
g = ca.generate
 #=> [:key => '...RSA KEY...', :crt => '...CERTIFICATE...']