Skip to content

Commit

Permalink
Generate certificate serial number
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed May 18, 2023
1 parent 13e868a commit 41734ad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jls/net/secure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,14 @@ local function createCertificate(options)
local cadn = opensslLib.x509.name.new(names)
local pkey = options.privateKey or createPrivateKey()
local req = opensslLib.x509.req.new(cadn, pkey)
local cacert = opensslLib.x509.new(1, req)
local duration = options.duration or (3600 * 24 * (365 + 31)) -- one year
local time = os.time()
local serialNumber = options.serialNumber
if not serialNumber then
local d = os.date('*t', time)
serialNumber = math.random(0xffffffff) * 0x10000 + d.year * 12 + d.month
end
local cacert = opensslLib.x509.new(serialNumber, req)
local duration = options.duration or (3600 * 24 * (365 + 31)) -- one year
cacert:validat(time, time + duration)
cacert:sign(pkey, cacert) -- self sign
return cacert, pkey
Expand Down

0 comments on commit 41734ad

Please sign in to comment.