nixio: Add support for DER certificates, PX5G fix Certmaster
authorSteven Barth <steven@midlink.org>
Sun, 7 Jun 2009 10:15:12 +0000 (10:15 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 7 Jun 2009 10:15:12 +0000 (10:15 +0000)
libs/nixio/root/etc/nixio/.nixio_stamp [new file with mode: 0644]
libs/nixio/src/tls-context.c
libs/px5g/lua/px5g/util.lua
libs/px5g/root/usr/sbin/px5g-genkeys
libs/px5g/src/px5g.c

diff --git a/libs/nixio/root/etc/nixio/.nixio_stamp b/libs/nixio/root/etc/nixio/.nixio_stamp
new file mode 100644 (file)
index 0000000..e69de29
index e55de05cc7c2b638947798969840997770eca393..235a723824019ae1635e096595b07df721deb5c2 100644 (file)
@@ -113,7 +113,22 @@ static int nixio_tls_ctx_create(lua_State *L) {
 static int nixio_tls_ctx_set_cert(lua_State *L) {
        SSL_CTX *ctx = nixio__checktlsctx(L);
        const char *cert = luaL_checkstring(L, 2);
-       return nixio__tls_pstatus(L, SSL_CTX_use_certificate_chain_file(ctx, cert));
+       const char *type = luaL_optstring(L, 3, "chain");
+       int ktype;
+
+       if (!strcmp(type, "chain")) {
+               return nixio__tls_pstatus(L,
+                               SSL_CTX_use_certificate_chain_file(ctx, cert));
+       } else if (!strcmp(type, "pem")) {
+               ktype = SSL_FILETYPE_PEM;
+       } else if (!strcmp(type, "asn1")) {
+               ktype = SSL_FILETYPE_ASN1;
+       } else {
+               return luaL_argerror(L, 3, "supported values: chain, pem, asn1");
+       }
+
+       return nixio__tls_pstatus(L,
+                       SSL_CTX_use_certificate_file(ctx, cert, ktype));
 }
 
 static int nixio_tls_ctx_set_key(lua_State *L) {
index e94fb650760c06af1b5b14c42536e2139c6f5d32..0f07c81b8ccf376f0adf4bd47babca28a91447ee 100644 (file)
@@ -29,7 +29,7 @@ function der2pem(data, type)
        local b64 = nixio.bin.b64encode(data)
        
        local outdata = {preamble[type]}
-       for i = 1, 64, #b64 + 63 do
+       for i = 1, #b64, 64 do
                outdata[#outdata + 1] = b64:sub(i, i + 63) 
        end
        outdata[#outdata + 1] = postamble[type]
@@ -37,3 +37,8 @@ function der2pem(data, type)
        
        return table.concat(outdata, "\n")
 end
+
+function pem2der(data)
+       local b64 = data:gsub({["\n"] = "", ["%-%-%-%-%-.-%-%-%-%-%-"] = ""})
+       return nixio.bin.b64decode(b64)
+end
\ No newline at end of file
index 29906577f39f88d174cee7d47cbab836fa919f9b..87a66bfe26b7517e93988ee22a05144ac3d68688 100755 (executable)
@@ -6,6 +6,7 @@ local px5g = require "px5g"
 local nixio = require "nixio"
 local fs = require "nixio.fs"
 local os = require "os"
+nixio.umask(77)
 
 if not fs.access(certfile) then
        local key = px5g.genkey(2048)
index 20ae7957f1ada71ff9c96872aa3d93ea18fc1ceb..feecd01275c22e616890dda2dd9aab57125c2f35 100644 (file)
@@ -85,21 +85,22 @@ static int px5g_rsa_create_selfsigned(lua_State *L) {
                strftime(tstr, sizeof(tstr), "%F %H:%M:%S", gmtime(&to)),
        4, "Invalid Time");
 
+       size_t join = 1;
        lua_pushliteral(L, "");
        for (int i = 0; i < (sizeof(xfields) / sizeof(*xfields)); i++) {
                lua_pushstring(L, xfields[i]);
                lua_rawget(L, 2);
                if (lua_isstring(L, -1)) {
                        const char *val = lua_tostring(L, -1);
-                       luaL_argcheck(L, !strchr(val, '\''), 2, "Invalid Value");
-                       lua_pushfstring(L, "%s%s='%s';",
-                               lua_tostring(L, -2), xfields[i], val);
-                       lua_remove(L, -2);
+                       luaL_argcheck(L, !strchr(val, ';'), 2, "Invalid Value");
+                       lua_pushfstring(L, "%s=%s;", xfields[i], val);
                        lua_remove(L, -2);
+                       join++;
                } else {
                        lua_pop(L, 1);
                }
        }
+       lua_concat(L, join);
 
        x509_raw cert;
        x509write_init_raw(&cert);