Software /
code /
prosody
Comparison
util/x509.lua @ 6157:44de98f516f5
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 27 Apr 2014 01:02:54 +0200 |
parent | 6153:8fb54ec34741 |
child | 6708:d2beb98ece29 |
comparison
equal
deleted
inserted
replaced
6151:a34a14054532 | 6157:44de98f516f5 |
---|---|
18 -- [LDAP] - http://tools.ietf.org/html/rfc4519 | 18 -- [LDAP] - http://tools.ietf.org/html/rfc4519 |
19 -- [PKIX] - http://tools.ietf.org/html/rfc5280 | 19 -- [PKIX] - http://tools.ietf.org/html/rfc5280 |
20 | 20 |
21 local nameprep = require "util.encodings".stringprep.nameprep; | 21 local nameprep = require "util.encodings".stringprep.nameprep; |
22 local idna_to_ascii = require "util.encodings".idna.to_ascii; | 22 local idna_to_ascii = require "util.encodings".idna.to_ascii; |
23 local base64 = require "util.encodings".base64; | |
23 local log = require "util.logger".init("x509"); | 24 local log = require "util.logger".init("x509"); |
24 local pairs, ipairs = pairs, ipairs; | |
25 local s_format = string.format; | 25 local s_format = string.format; |
26 local t_insert = table.insert; | |
27 local t_concat = table.concat; | |
28 | 26 |
29 module "x509" | 27 module "x509" |
30 | 28 |
31 local oid_commonname = "2.5.4.3"; -- [LDAP] 2.3 | 29 local oid_commonname = "2.5.4.3"; -- [LDAP] 2.3 |
32 local oid_subjectaltname = "2.5.29.17"; -- [PKIX] 4.2.1.6 | 30 local oid_subjectaltname = "2.5.29.17"; -- [PKIX] 4.2.1.6 |
212 | 210 |
213 -- If all else fails, well, why should we be any different? | 211 -- If all else fails, well, why should we be any different? |
214 return false | 212 return false |
215 end | 213 end |
216 | 214 |
215 local pat = "%-%-%-%-%-BEGIN ([A-Z ]+)%-%-%-%-%-\r?\n".. | |
216 "([0-9A-Za-z+/=\r\n]*)\r?\n%-%-%-%-%-END %1%-%-%-%-%-"; | |
217 | |
218 function pem2der(pem) | |
219 local typ, data = pem:match(pat); | |
220 if typ and data then | |
221 return base64.decode(data), typ; | |
222 end | |
223 end | |
224 | |
225 local wrap = ('.'):rep(64); | |
226 local envelope = "-----BEGIN %s-----\n%s\n-----END %s-----\n" | |
227 | |
228 function der2pem(data, typ) | |
229 typ = typ and typ:upper() or "CERTIFICATE"; | |
230 data = base64.encode(data); | |
231 return s_format(envelope, typ, data:gsub(wrap, '%0\n', (#data-1)/64), typ); | |
232 end | |
233 | |
217 return _M; | 234 return _M; |