|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
require 'openssl' |
|
|
|
|
|
|
|
|
class CertificatesController < ApplicationController |
|
|
class CertificatesController < ApplicationController |
|
|
before_action :set_certificate, only: [:show, :edit, :update, :destroy] |
|
|
before_action :set_certificate, only: [:show, :edit, :update, :destroy] |
|
|
|
|
|
|
|
|
@ -26,6 +28,22 @@ class CertificatesController < ApplicationController |
|
|
def create |
|
|
def create |
|
|
@certificate = Certificate.new(certificate_params) |
|
|
@certificate = Certificate.new(certificate_params) |
|
|
|
|
|
|
|
|
|
|
|
key = OpenSSL::PKey::RSA.new 4096 |
|
|
|
|
|
name = OpenSSL::X509::Name.parse 'CN=lex-deeit/DC=weird-web-workers/DC=org' |
|
|
|
|
|
|
|
|
|
|
|
cert = OpenSSL::X509::Certificate.new |
|
|
|
|
|
cert.version = 2 |
|
|
|
|
|
cert.serial = 0 |
|
|
|
|
|
cert.not_before = Time.now |
|
|
|
|
|
cert.not_after = Time.now + 3600 |
|
|
|
|
|
|
|
|
|
|
|
cert.public_key = key.public_key |
|
|
|
|
|
cert.subject = name |
|
|
|
|
|
cert.sign key, OpenSSL::Digest::SHA256.new |
|
|
|
|
|
|
|
|
|
|
|
@certificate.key = key.to_pem |
|
|
|
|
|
@certificate.cert = cert.to_pem |
|
|
|
|
|
|
|
|
respond_to do |format| |
|
|
respond_to do |format| |
|
|
if @certificate.save |
|
|
if @certificate.save |
|
|
format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' } |
|
|
format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' } |
|
|
@ -72,3 +90,5 @@ class CertificatesController < ApplicationController |
|
|
params.require(:certificate).permit(:key, :cert, :active) |
|
|
params.require(:certificate).permit(:key, :cert, :active) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# vim: set et ts=2 sw=2: |