]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix lua RSA verify and its tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Mar 2018 14:24:39 +0000 (15:24 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Mar 2018 14:24:39 +0000 (15:24 +0100)
src/libcryptobox/base64/base64.c
src/lua/lua_rsa.c
test/lua/unit/rsa.lua

index a0a68d7d635ee167cb2ff0f7211c3f5e6c4bd0e2..b4ddd3135b8c249afbbf2cd54e202cbc2d2936aa 100644 (file)
@@ -131,7 +131,6 @@ base64_test (bool generic, size_t niters, size_t len)
 
        impl = generic ? &base64_list[0] : base64_opt;
 
-       printf("hui: %s\n", impl->desc);
        out = rspamd_encode_base64 (in, len, 0, &outlen);
        impl->decode (out, outlen, tmp, &len);
 
index b7ccf87092f7086292c2e592fb31d0f775949e51..938fabec2a907b80e23c938bd1626e6eebcc71dd 100644 (file)
@@ -585,7 +585,7 @@ lua_rsa_verify_memory (lua_State *L)
        data = luaL_checkstring (L, 3);
 
        if (rsa != NULL && signature != NULL && data != NULL) {
-               ret = RSA_verify (NID_sha1, data, strlen (data),
+               ret = RSA_verify (NID_sha256, data, strlen (data),
                                signature->str, signature->len, rsa);
 
                if (ret == 0) {
index caf017118bdb9a580cd73013c7204182a9da4815..9620772421d10c097b2148dc27c625e437c81292 100644 (file)
@@ -5,6 +5,7 @@ context("RSA signature verification test", function()
   local rsa_pubkey = require "rspamd_rsa_pubkey"
   local rsa_signature = require "rspamd_rsa_signature"
   local rsa = require "rspamd_rsa"
+  local hash = require "rspamd_cryptobox_hash"
   local pubkey = 'testkey.pub'
   local privkey = 'testkey'
   local data = 'test.data'
@@ -14,19 +15,26 @@ context("RSA signature verification test", function()
   
   test("RSA sign", function()
     -- Signing test
-    local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey))
+    rsa_key = rsa_privkey.load_file(string.format('%s/%s', test_dir, privkey))
     assert_not_nil(rsa_key)
-    local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data))
-    assert_not_nil(rsa_sig)
-    rsa_sig:save(string.format('%s/%s', test_dir, signature), true)
+
+    local h = hash.create_specific('sha256')
+    local d = io.open(string.format('%s/%s', test_dir, data), "rb"):read "*a"
+    h:update(d)
+    local sig = rsa.sign_memory(rsa_key, h:bin())
+    assert_not_nil(sig)
+    sig:save(string.format('%s/%s', test_dir, signature), true)
   end)
   
   test("RSA verify", function()
     -- Verifying test
+    local h = hash.create_specific('sha256')
+    local d = io.open(string.format('%s/%s', test_dir, data), "rb"):read "*a"
+    h:update(d)
     rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey))
     assert_not_nil(rsa_key)
     rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature))
     assert_not_nil(rsa_sig)
-    assert_true(rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)))
+    assert_true(rsa.verify_memory(rsa_key, rsa_sig, h:bin()))
   end)
 end)