Skip to content

Commit

Permalink
generate random 128 bit serial
Browse files Browse the repository at this point in the history
  • Loading branch information
malvads committed Jul 16, 2024
1 parent af3b0f0 commit dfbf9d0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resources/libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module Helper
require 'openssl'
require 'resolv'
require 'base64'
require 'securerandom'

def create_cert(cn)
# Return a hash with private key and certificate in x509 format
key = OpenSSL::PKey::RSA.new 4096
name = OpenSSL::X509::Name.parse "CN=#{cn}/DC=redborder"
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.serial = SecureRandom.random_number(2**128)
cert.not_before = Time.now
cert.not_after = Time.now + (3600 * 24 * 365 * 10)
cert.public_key = key.public_key
Expand Down

0 comments on commit dfbf9d0

Please sign in to comment.