diff options
author | william <william@25tandclement.com> | 2014-09-22 15:37:29 -0700 |
---|---|---|
committer | william <william@25tandclement.com> | 2014-09-22 15:37:29 -0700 |
commit | 920118b13d4ec90c5b36a682bc002868b8fff877 (patch) | |
tree | c7e5e6691cd3d87353d6334082c849bc1c4a903d /examples | |
parent | d4914b31664e771ae93b88f6f83fb24c616b20fd (diff) | |
download | luaossl-920118b13d4ec90c5b36a682bc002868b8fff877.tar.gz luaossl-920118b13d4ec90c5b36a682bc002868b8fff877.tar.bz2 luaossl-920118b13d4ec90c5b36a682bc002868b8fff877.zip |
make default key algorithm in self.x509 and vrfy.sig examples depend on whether EC is supported locally
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/self.x509 | 19 | ||||
-rwxr-xr-x | examples/vrfy.sig | 19 |
2 files changed, 33 insertions, 5 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 @@ | |||
7 | -- CSR generation. | 7 | -- CSR generation. |
8 | -- | 8 | -- |
9 | 9 | ||
10 | local keytype = ... | ||
11 | |||
12 | local openssl = require"openssl" | ||
10 | local pkey = require"openssl.pkey" | 13 | local pkey = require"openssl.pkey" |
11 | local x509 = require"openssl.x509" | 14 | local x509 = require"openssl.x509" |
12 | local name = require"openssl.x509.name" | 15 | local name = require"openssl.x509.name" |
13 | local altname = require"openssl.x509.altname" | 16 | local altname = require"openssl.x509.altname" |
14 | 17 | ||
15 | -- generate our public/private key pair | 18 | -- generate our public/private key pair |
16 | --local key = pkey.new{ type = "RSA", bits = 1024 } | 19 | local function genkey(type) |
17 | --local key = pkey.new{ type = "DSA", bits = 1024 } | 20 | type = string.upper(type or (not openssl.NO_EC and "EC") or "RSA") |
18 | local key = pkey.new{ type = "EC", curve = "prime192v1" } | 21 | |
22 | if type == "RSA" then | ||
23 | return pkey.new{ type = "RSA", bits = 1024 } | ||
24 | elseif type == "DSA" then | ||
25 | return pkey.new{ type = "DSA", bits = 1024 } | ||
26 | else | ||
27 | return pkey.new{ type = "EC", curve = "prime192v1" } | ||
28 | end | ||
29 | end | ||
30 | |||
31 | local key = genkey(keytype) | ||
19 | 32 | ||
20 | -- our Subject and Issuer DN (self-signed, so same) | 33 | -- our Subject and Issuer DN (self-signed, so same) |
21 | local dn = name.new() | 34 | local dn = name.new() |
diff --git a/examples/vrfy.sig b/examples/vrfy.sig index cf60995..258490a 100755 --- a/examples/vrfy.sig +++ b/examples/vrfy.sig | |||
@@ -3,15 +3,30 @@ | |||
3 | -- Example public-key signature verification. | 3 | -- Example public-key signature verification. |
4 | -- | 4 | -- |
5 | 5 | ||
6 | local keytype = ... | ||
7 | |||
8 | local openssl = require"openssl" | ||
6 | local pkey = require"openssl.pkey" | 9 | local pkey = require"openssl.pkey" |
7 | local digest = require"openssl.digest" | 10 | local digest = require"openssl.digest" |
8 | 11 | ||
9 | -- generate a public/private key pair | 12 | -- generate a public/private key pair |
10 | local key = pkey.new{ type = "EC", curve = "prime192v1" } | 13 | local function genkey(type) |
14 | type = string.upper(type or (not openssl.NO_EC and "EC") or "RSA") | ||
15 | |||
16 | if type == "RSA" then | ||
17 | return pkey.new{ type = "RSA", bits = 1024 }, "sha256" | ||
18 | elseif type == "DSA" then | ||
19 | return pkey.new{ type = "DSA", bits = 1024 }, "dss1" | ||
20 | else | ||
21 | return pkey.new{ type = "EC", curve = "prime192v1" }, "ecdsa-with-SHA1" | ||
22 | end | ||
23 | end | ||
24 | |||
25 | local key, hash = genkey(keytype) | ||
11 | 26 | ||
12 | -- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC; | 27 | -- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC; |
13 | -- "dss1" for DSA; and "sha1", "sha256", etc for RSA). | 28 | -- "dss1" for DSA; and "sha1", "sha256", etc for RSA). |
14 | local data = digest.new"ecdsa-with-SHA1" | 29 | local data = digest.new(hash) |
15 | data:update(... or "hello world") | 30 | data:update(... or "hello world") |
16 | 31 | ||
17 | -- generate a signature for our data | 32 | -- generate a signature for our data |