Browse Source

improved version reporting and test messages

added lua_functions with a facility to add global variables
Jaromil 1 year ago
parent
commit
589c8d13aa
5 changed files with 45 additions and 11 deletions
  1. 1 1
      VERSION
  2. 1 1
      src/Makefile
  3. 10 2
      src/decode-exec.c
  4. 28 0
      src/lua_functions.c
  5. 5 7
      test/test_luanacha.lua

+ 1 - 1
VERSION

@@ -1 +1 @@
1
-0.1
1
+DECODE-0.2

+ 1 - 1
src/Makefile

@@ -2,7 +2,7 @@ CC?=gcc
2 2
 VERSION := $(shell cat ../VERSION)
3 3
 
4 4
 CFLAGS  := -I. -I../lib/lua_sandbox/include
5
-SOURCES := jutils.o timing.o decode-exec.o
5
+SOURCES := jutils.o lua_functions.o decode-exec.o
6 6
 LDADD   := ../build/lua_sandbox/src/libluasandbox.a
7 7
 LDADD   += ../build/lua_sandbox/src/util/libluasandboxutil.a
8 8
 LDADD   += ../build/luanacha/libluanacha.a

+ 10 - 2
src/decode-exec.c

@@ -32,6 +32,8 @@
32 32
 
33 33
 extern const struct luaL_Reg luanachalib;
34 34
 
35
+// prototypes from lua_functions
36
+void lsb_setglobal_string(lsb_lua_sandbox *lsb, char *key, char *val);
35 37
 // from timing.c
36 38
 // extern int set_hook(lua_State *L);
37 39
 
@@ -41,7 +43,10 @@ extern const struct luaL_Reg luanachalib;
41 43
 
42 44
 void logger(void *context, const char *component,
43 45
                    int level, const char *fmt, ...) {
46
+	// suppress warnings about these unused paraments
44 47
 	(void)context;
48
+	(void)level;
49
+
45 50
 	va_list args;
46 51
 	// fprintf(stderr, "%lld [%d] %s ", (long long)time(NULL), level,
47 52
 	//         component ? component : "unnamed");
@@ -64,7 +69,7 @@ int main(int argc, char **argv) {
64 69
     const char *help =
65 70
 		"Usage: decode-exec [-c config] script.lua\n";
66 71
 
67
-	notice( "DECODE restricted execution environment v%s",VERSION);
72
+	notice( "LUA Restricted execution environment %s",VERSION);
68 73
 	act("Copyright (C) 2017 Dyne.org foundation");
69 74
 	do {
70 75
 		opt = getopt(argc, argv, short_options);
@@ -110,6 +115,10 @@ int main(int argc, char **argv) {
110 115
 			func("%s",lib->name);
111 116
 			lsb_add_function(lsb, lib->func, lib->name);
112 117
 		}
118
+
119
+		// initialise global variables
120
+		lsb_setglobal_string(lsb, "VERSION", VERSION);
121
+
113 122
 		r = lsb_init(lsb, NULL);
114 123
 		if(r) {
115 124
 			error(r);
@@ -126,7 +135,6 @@ int main(int argc, char **argv) {
126 135
 		act("executed operations: %u", u);
127 136
 	}
128 137
 
129
-teardown:
130 138
 	act("DECODE exec terminating.");
131 139
 	if(conf) free(conf);
132 140
 	if(lsb) {

+ 28 - 0
src/lua_functions.c

@@ -0,0 +1,28 @@
1
+/*  Lua based DECODE VM
2
+ *
3
+ *  (c) Copyright 2017 Dyne.org foundation
4
+ *  designed, written and maintained by Denis Roio <jaromil@dyne.org>
5
+ *
6
+ * This source code is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Public License as published
8
+ * by the Free Software Foundation; either version 3 of the License,
9
+ * or (at your option) any later version.
10
+ *
11
+ * This source code is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ * Please refer to the GNU Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Public License along with
17
+ * this source code; if not, write to:
18
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
+ */
20
+
21
+#include <luasandbox.h>
22
+#include <luasandbox/lua.h>
23
+
24
+void lsb_setglobal_string(lsb_lua_sandbox *lsb, char *key, char *val) {
25
+	lua_State* L = lsb_get_lua(lsb);
26
+	lua_pushstring(L, val);
27
+	lua_setglobal(L, key);
28
+}

+ 5 - 7
test/test_luanacha.lua

@@ -125,6 +125,7 @@ n2 = c:sub(1,24)
125 125
 m2 = unlock(k, n2, c, #n2)
126 126
 assert(m2 == m)
127 127
 
128
+print("OK")
128 129
 ------------------------------------------------------------------------
129 130
 -- blake2b tests
130 131
 
@@ -174,7 +175,7 @@ blake2b_update(ctx, "uick brown fox jumps over the lazy dog")
174 175
 dig55 = blake2b_final(ctx)
175 176
 assert(dig51==dig55)
176 177
 
177
-
178
+print("OK")
178 179
 ------------------------------------------------------------------------
179 180
 -- x25519 tests
180 181
 
@@ -188,7 +189,7 @@ k1 = key_exchange(ask, bpk)
188 189
 k2 = key_exchange(bsk, apk)
189 190
 assert(k1 == k2)
190 191
 
191
-
192
+print("OK")
192 193
 ------------------------------------------------------------------------
193 194
 -- ed25519 signature tests
194 195
 
@@ -209,7 +210,7 @@ assert(check(sig, pk, t))
209 210
 -- modified text doesn't check
210 211
 assert(not check(sig, pk, t .. "!"))
211 212
 
212
-
213
+print("OK")
213 214
 ------------------------------------------------------------------------
214 215
 -- password derivation argon2i tests
215 216
 
@@ -221,8 +222,5 @@ k = ""
221 222
 c0 = os.clock()
222 223
 k = argon2i(pw, salt, 100000, 10)
223 224
 assert(#k == 32)
224
-print("argon2i (100MB, 10 iter) Execution time (sec): ", os.clock()-c0)
225
-
226
-
227
-print("test_luanacha  ok")
225
+print("OK: argon2i (100MB, 10 iter) Execution time (sec): ", os.clock()-c0)
228 226
 print("------------------------------------------------------------")