aboutsummaryrefslogtreecommitdiffstats
path: root/examples/self.x509
diff options
context:
space:
mode:
Diffstat (limited to 'examples/self.x509')
-rwxr-xr-xexamples/self.x50919
1 files changed, 16 insertions, 3 deletions
diff --git a/examples/self.x509 b/examples/self.x509
index b2d14f9..37b12c7 100755
--- a/examples/self.x509
+++ b/examples/self.x509
@@ -7,15 +7,28 @@
-- CSR generation.
--
+local keytype = ...
+
+local openssl = require"openssl"
local pkey = require"openssl.pkey"
local x509 = require"openssl.x509"
local name = require"openssl.x509.name"
local altname = require"openssl.x509.altname"
-- generate our public/private key pair
---local key = pkey.new{ type = "RSA", bits = 1024 }
---local key = pkey.new{ type = "DSA", bits = 1024 }
-local key = pkey.new{ type = "EC", curve = "prime192v1" }
+local function genkey(type)
+ type = string.upper(type or (not openssl.NO_EC and "EC") or "RSA")
+
+ if type == "RSA" then
+ return pkey.new{ type = "RSA", bits = 1024 }
+ elseif type == "DSA" then
+ return pkey.new{ type = "DSA", bits = 1024 }
+ else
+ return pkey.new{ type = "EC", curve = "prime192v1" }
+ end
+end
+
+local key = genkey(keytype)
-- our Subject and Issuer DN (self-signed, so same)
local dn = name.new()