You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lua_rsa.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file lua_rsa.c
  18. * This module exports routines to load rsa keys, check inline or external
  19. * rsa signatures. It assumes sha256 based signatures.
  20. */
  21. #include "lua_common.h"
  22. #include "unix-std.h"
  23. #include <openssl/err.h>
  24. #include <openssl/pem.h>
  25. #include <openssl/sha.h>
  26. #include <openssl/rsa.h>
  27. LUA_FUNCTION_DEF (rsa_pubkey, load);
  28. LUA_FUNCTION_DEF (rsa_pubkey, create);
  29. LUA_FUNCTION_DEF (rsa_pubkey, gc);
  30. LUA_FUNCTION_DEF (rsa_privkey, load_file);
  31. LUA_FUNCTION_DEF (rsa_privkey, load_pem);
  32. LUA_FUNCTION_DEF (rsa_privkey, load_raw);
  33. LUA_FUNCTION_DEF (rsa_privkey, load_base64);
  34. LUA_FUNCTION_DEF (rsa_privkey, create);
  35. LUA_FUNCTION_DEF (rsa_privkey, gc);
  36. LUA_FUNCTION_DEF (rsa_signature, create);
  37. LUA_FUNCTION_DEF (rsa_signature, load);
  38. LUA_FUNCTION_DEF (rsa_signature, save);
  39. LUA_FUNCTION_DEF (rsa_signature, base64);
  40. LUA_FUNCTION_DEF (rsa_signature, gc);
  41. LUA_FUNCTION_DEF (rsa, verify_memory);
  42. LUA_FUNCTION_DEF (rsa, sign_memory);
  43. static const struct luaL_reg rsalib_f[] = {
  44. LUA_INTERFACE_DEF (rsa, verify_memory),
  45. LUA_INTERFACE_DEF (rsa, sign_memory),
  46. {NULL, NULL}
  47. };
  48. static const struct luaL_reg rsapubkeylib_f[] = {
  49. LUA_INTERFACE_DEF (rsa_pubkey, load),
  50. LUA_INTERFACE_DEF (rsa_pubkey, create),
  51. {NULL, NULL}
  52. };
  53. static const struct luaL_reg rsapubkeylib_m[] = {
  54. {"__tostring", rspamd_lua_class_tostring},
  55. {"__gc", lua_rsa_pubkey_gc},
  56. {NULL, NULL}
  57. };
  58. static const struct luaL_reg rsaprivkeylib_f[] = {
  59. LUA_INTERFACE_DEF (rsa_privkey, load_file),
  60. LUA_INTERFACE_DEF (rsa_privkey, load_pem),
  61. LUA_INTERFACE_DEF (rsa_privkey, load_raw),
  62. LUA_INTERFACE_DEF (rsa_privkey, load_base64),
  63. LUA_INTERFACE_DEF (rsa_privkey, create),
  64. {NULL, NULL}
  65. };
  66. static const struct luaL_reg rsaprivkeylib_m[] = {
  67. {"__tostring", rspamd_lua_class_tostring},
  68. {"__gc", lua_rsa_privkey_gc},
  69. {NULL, NULL}
  70. };
  71. static const struct luaL_reg rsasignlib_f[] = {
  72. LUA_INTERFACE_DEF (rsa_signature, load),
  73. LUA_INTERFACE_DEF (rsa_signature, create),
  74. {NULL, NULL}
  75. };
  76. static const struct luaL_reg rsasignlib_m[] = {
  77. LUA_INTERFACE_DEF (rsa_signature, save),
  78. LUA_INTERFACE_DEF (rsa_signature, base64),
  79. {"__tostring", rspamd_lua_class_tostring},
  80. {"__gc", lua_rsa_signature_gc},
  81. {NULL, NULL}
  82. };
  83. static RSA *
  84. lua_check_rsa_pubkey (lua_State * L, int pos)
  85. {
  86. void *ud = rspamd_lua_check_udata (L, pos, "rspamd{rsa_pubkey}");
  87. luaL_argcheck (L, ud != NULL, 1, "'rsa_pubkey' expected");
  88. return ud ? *((RSA **)ud) : NULL;
  89. }
  90. static RSA *
  91. lua_check_rsa_privkey (lua_State * L, int pos)
  92. {
  93. void *ud = rspamd_lua_check_udata (L, pos, "rspamd{rsa_privkey}");
  94. luaL_argcheck (L, ud != NULL, 1, "'rsa_privkey' expected");
  95. return ud ? *((RSA **)ud) : NULL;
  96. }
  97. static rspamd_fstring_t *
  98. lua_check_rsa_sign (lua_State * L, int pos)
  99. {
  100. void *ud = rspamd_lua_check_udata (L, pos, "rspamd{rsa_signature}");
  101. luaL_argcheck (L, ud != NULL, 1, "'rsa_signature' expected");
  102. return ud ? *((rspamd_fstring_t **)ud) : NULL;
  103. }
  104. static gint
  105. lua_rsa_pubkey_load (lua_State *L)
  106. {
  107. RSA *rsa = NULL, **prsa;
  108. const gchar *filename;
  109. FILE *f;
  110. filename = luaL_checkstring (L, 1);
  111. if (filename != NULL) {
  112. f = fopen (filename, "r");
  113. if (f == NULL) {
  114. msg_err ("cannot open pubkey from file: %s, %s",
  115. filename,
  116. strerror (errno));
  117. lua_pushnil (L);
  118. }
  119. else {
  120. if (!PEM_read_RSA_PUBKEY (f, &rsa, NULL, NULL)) {
  121. msg_err ("cannot open pubkey from file: %s, %s", filename,
  122. ERR_error_string (ERR_get_error (), NULL));
  123. lua_pushnil (L);
  124. }
  125. else {
  126. prsa = lua_newuserdata (L, sizeof (RSA *));
  127. rspamd_lua_setclass (L, "rspamd{rsa_pubkey}", -1);
  128. *prsa = rsa;
  129. }
  130. fclose (f);
  131. }
  132. }
  133. else {
  134. lua_pushnil (L);
  135. }
  136. return 1;
  137. }
  138. static gint
  139. lua_rsa_pubkey_create (lua_State *L)
  140. {
  141. RSA *rsa = NULL, **prsa;
  142. const gchar *buf;
  143. BIO *bp;
  144. buf = luaL_checkstring (L, 1);
  145. if (buf != NULL) {
  146. bp = BIO_new_mem_buf ((void *)buf, -1);
  147. if (!PEM_read_bio_RSA_PUBKEY (bp, &rsa, NULL, NULL)) {
  148. msg_err ("cannot parse pubkey: %s",
  149. ERR_error_string (ERR_get_error (), NULL));
  150. lua_pushnil (L);
  151. }
  152. else {
  153. prsa = lua_newuserdata (L, sizeof (RSA *));
  154. rspamd_lua_setclass (L, "rspamd{rsa_pubkey}", -1);
  155. *prsa = rsa;
  156. }
  157. BIO_free (bp);
  158. }
  159. else {
  160. lua_pushnil (L);
  161. }
  162. return 1;
  163. }
  164. static gint
  165. lua_rsa_pubkey_gc (lua_State *L)
  166. {
  167. RSA *rsa = lua_check_rsa_pubkey (L, 1);
  168. if (rsa != NULL) {
  169. RSA_free (rsa);
  170. }
  171. return 0;
  172. }
  173. static gint
  174. lua_rsa_privkey_load_file (lua_State *L)
  175. {
  176. RSA *rsa = NULL, **prsa;
  177. const gchar *filename;
  178. FILE *f;
  179. filename = luaL_checkstring (L, 1);
  180. if (filename != NULL) {
  181. f = fopen (filename, "r");
  182. if (f == NULL) {
  183. msg_err ("cannot open private key from file: %s, %s",
  184. filename,
  185. strerror (errno));
  186. lua_pushnil (L);
  187. }
  188. else {
  189. if (!PEM_read_RSAPrivateKey (f, &rsa, NULL, NULL)) {
  190. msg_err ("cannot open private key from file: %s, %s", filename,
  191. ERR_error_string (ERR_get_error (), NULL));
  192. lua_pushnil (L);
  193. }
  194. else {
  195. prsa = lua_newuserdata (L, sizeof (RSA *));
  196. rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
  197. *prsa = rsa;
  198. }
  199. fclose (f);
  200. }
  201. }
  202. else {
  203. lua_pushnil (L);
  204. }
  205. return 1;
  206. }
  207. static gint
  208. lua_rsa_privkey_load_pem (lua_State *L)
  209. {
  210. RSA *rsa = NULL, **prsa;
  211. BIO *b;
  212. struct rspamd_lua_text *t;
  213. const gchar *data;
  214. gsize len;
  215. if (lua_isuserdata (L, 1)) {
  216. t = lua_check_text (L, 1);
  217. if (!t) {
  218. return luaL_error (L, "invalid arguments");
  219. }
  220. data = t->start;
  221. len = t->len;
  222. }
  223. else {
  224. data = luaL_checklstring (L, 1, &len);
  225. }
  226. if (data != NULL) {
  227. b = BIO_new_mem_buf (data, len);
  228. if (!PEM_read_bio_RSAPrivateKey (b, &rsa, NULL, NULL)) {
  229. msg_err ("cannot open private key from data, %s",
  230. ERR_error_string (ERR_get_error (), NULL));
  231. lua_pushnil (L);
  232. }
  233. else {
  234. prsa = lua_newuserdata (L, sizeof (RSA *));
  235. rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
  236. *prsa = rsa;
  237. }
  238. BIO_free (b);
  239. }
  240. else {
  241. return luaL_error (L, "invalid arguments");
  242. }
  243. return 1;
  244. }
  245. static gint
  246. lua_rsa_privkey_load_raw (lua_State *L)
  247. {
  248. RSA *rsa = NULL, **prsa;
  249. BIO *b;
  250. struct rspamd_lua_text *t;
  251. const gchar *data;
  252. gsize len;
  253. if (lua_isuserdata (L, 1)) {
  254. t = lua_check_text (L, 1);
  255. if (!t) {
  256. return luaL_error (L, "invalid arguments");
  257. }
  258. data = t->start;
  259. len = t->len;
  260. }
  261. else {
  262. data = luaL_checklstring (L, 1, &len);
  263. }
  264. if (data != NULL) {
  265. b = BIO_new_mem_buf (data, len);
  266. rsa = d2i_RSAPrivateKey_bio (b, NULL);
  267. if (rsa == NULL) {
  268. msg_err ("cannot open private key from data, %s",
  269. ERR_error_string (ERR_get_error (), NULL));
  270. lua_pushnil (L);
  271. }
  272. else {
  273. prsa = lua_newuserdata (L, sizeof (RSA *));
  274. rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
  275. *prsa = rsa;
  276. }
  277. BIO_free (b);
  278. }
  279. else {
  280. return luaL_error (L, "invalid arguments");
  281. }
  282. return 1;
  283. }
  284. static gint
  285. lua_rsa_privkey_load_base64 (lua_State *L)
  286. {
  287. RSA *rsa = NULL, **prsa;
  288. BIO *b;
  289. EVP_PKEY *evp = NULL;
  290. struct rspamd_lua_text *t;
  291. const gchar *data;
  292. guchar *decoded;
  293. gsize len, dec_len;
  294. if (lua_isuserdata (L, 1)) {
  295. t = lua_check_text (L, 1);
  296. if (!t) {
  297. return luaL_error (L, "invalid arguments");
  298. }
  299. data = t->start;
  300. len = t->len;
  301. }
  302. else {
  303. data = luaL_checklstring (L, 1, &len);
  304. }
  305. if (data != NULL) {
  306. decoded = g_malloc (len);
  307. if (!rspamd_cryptobox_base64_decode (data, len, decoded, &dec_len)) {
  308. g_free (decoded);
  309. return luaL_error (L, "invalid base64 encoding");
  310. }
  311. b = BIO_new_mem_buf (decoded, dec_len);
  312. if (d2i_PrivateKey_bio (b, &evp) != NULL) {
  313. rsa = EVP_PKEY_get1_RSA (evp);
  314. if (rsa == NULL) {
  315. msg_err ("cannot open RSA private key from data, %s",
  316. ERR_error_string (ERR_get_error (), NULL));
  317. lua_pushnil (L);
  318. }
  319. else {
  320. prsa = lua_newuserdata (L, sizeof (RSA *));
  321. rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
  322. *prsa = rsa;
  323. }
  324. EVP_PKEY_free (evp);
  325. }
  326. else {
  327. msg_err ("cannot open EVP private key from data, %s",
  328. ERR_error_string (ERR_get_error (), NULL));
  329. lua_pushnil (L);
  330. }
  331. BIO_free (b);
  332. g_free (decoded);
  333. }
  334. else {
  335. return luaL_error (L, "invalid arguments");
  336. }
  337. return 1;
  338. }
  339. static gint
  340. lua_rsa_privkey_create (lua_State *L)
  341. {
  342. RSA *rsa = NULL, **prsa;
  343. const gchar *buf;
  344. BIO *bp;
  345. buf = luaL_checkstring (L, 1);
  346. if (buf != NULL) {
  347. bp = BIO_new_mem_buf ((void *)buf, -1);
  348. if (!PEM_read_bio_RSAPrivateKey (bp, &rsa, NULL, NULL)) {
  349. msg_err ("cannot parse private key: %s",
  350. ERR_error_string (ERR_get_error (), NULL));
  351. lua_pushnil (L);
  352. }
  353. else {
  354. prsa = lua_newuserdata (L, sizeof (RSA *));
  355. rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
  356. *prsa = rsa;
  357. }
  358. BIO_free (bp);
  359. }
  360. else {
  361. lua_pushnil (L);
  362. }
  363. return 1;
  364. }
  365. static gint
  366. lua_rsa_privkey_gc (lua_State *L)
  367. {
  368. RSA *rsa = lua_check_rsa_privkey (L, 1);
  369. if (rsa != NULL) {
  370. RSA_free (rsa);
  371. }
  372. return 0;
  373. }
  374. static gint
  375. lua_rsa_signature_load (lua_State *L)
  376. {
  377. rspamd_fstring_t *sig, **psig;
  378. const gchar *filename;
  379. gpointer data;
  380. int fd;
  381. struct stat st;
  382. filename = luaL_checkstring (L, 1);
  383. if (filename != NULL) {
  384. fd = open (filename, O_RDONLY);
  385. if (fd == -1) {
  386. msg_err ("cannot open signature file: %s, %s", filename,
  387. strerror (errno));
  388. lua_pushnil (L);
  389. }
  390. else {
  391. if (fstat (fd, &st) == -1 ||
  392. (data =
  393. mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))
  394. == MAP_FAILED) {
  395. msg_err ("cannot mmap file %s: %s", filename, strerror (errno));
  396. lua_pushnil (L);
  397. }
  398. else {
  399. sig = rspamd_fstring_new_init (data, st.st_size);
  400. psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
  401. rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
  402. *psig = sig;
  403. munmap (data, st.st_size);
  404. }
  405. close (fd);
  406. }
  407. }
  408. else {
  409. lua_pushnil (L);
  410. }
  411. return 1;
  412. }
  413. static gint
  414. lua_rsa_signature_save (lua_State *L)
  415. {
  416. rspamd_fstring_t *sig;
  417. gint fd, flags;
  418. const gchar *filename;
  419. gboolean forced = FALSE, res = TRUE;
  420. sig = lua_check_rsa_sign (L, 1);
  421. filename = luaL_checkstring (L, 2);
  422. if (lua_gettop (L) > 2) {
  423. forced = lua_toboolean (L, 3);
  424. }
  425. if (sig != NULL && filename != NULL) {
  426. flags = O_WRONLY | O_CREAT;
  427. if (forced) {
  428. flags |= O_TRUNC;
  429. }
  430. else {
  431. flags |= O_EXCL;
  432. }
  433. fd = open (filename, flags, 00644);
  434. if (fd == -1) {
  435. msg_err ("cannot create a signature file: %s, %s",
  436. filename,
  437. strerror (errno));
  438. lua_pushboolean (L, FALSE);
  439. }
  440. else {
  441. while (write (fd, sig->str, sig->len) == -1) {
  442. if (errno == EINTR) {
  443. continue;
  444. }
  445. msg_err ("cannot write to a signature file: %s, %s",
  446. filename,
  447. strerror (errno));
  448. res = FALSE;
  449. break;
  450. }
  451. lua_pushboolean (L, res);
  452. close (fd);
  453. }
  454. }
  455. else {
  456. lua_pushboolean (L, FALSE);
  457. }
  458. return 1;
  459. }
  460. static gint
  461. lua_rsa_signature_create (lua_State *L)
  462. {
  463. rspamd_fstring_t *sig, **psig;
  464. const gchar *data;
  465. gsize dlen;
  466. data = luaL_checklstring (L, 1, &dlen);
  467. if (data != NULL) {
  468. sig = rspamd_fstring_new_init (data, dlen);
  469. psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
  470. rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
  471. *psig = sig;
  472. }
  473. return 1;
  474. }
  475. static gint
  476. lua_rsa_signature_gc (lua_State *L)
  477. {
  478. rspamd_fstring_t *sig = lua_check_rsa_sign (L, 1);
  479. rspamd_fstring_free (sig);
  480. return 0;
  481. }
  482. static gint
  483. lua_rsa_signature_base64 (lua_State *L)
  484. {
  485. rspamd_fstring_t *sig = lua_check_rsa_sign (L, 1);
  486. guint boundary = 0;
  487. gchar *b64;
  488. gsize outlen;
  489. enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
  490. if (lua_isnumber (L, 2)) {
  491. boundary = lua_tonumber (L, 2);
  492. }
  493. if (lua_isstring (L, 3)) {
  494. const gchar *how_str = lua_tostring (L, 3);
  495. if (strcmp (how_str, "cr") == 0) {
  496. how = RSPAMD_TASK_NEWLINES_CR;
  497. }
  498. else if (strcmp (how_str, "lf") == 0) {
  499. how = RSPAMD_TASK_NEWLINES_LF;
  500. }
  501. else {
  502. how = RSPAMD_TASK_NEWLINES_CRLF;
  503. }
  504. }
  505. b64 = rspamd_encode_base64_fold (sig->str, sig->len, boundary, &outlen, how);
  506. if (b64) {
  507. lua_pushlstring (L, b64, outlen);
  508. g_free (b64);
  509. }
  510. else {
  511. lua_pushnil (L);
  512. }
  513. return 1;
  514. }
  515. /**
  516. * Check memory using specified rsa key and signature
  517. *
  518. * arguments:
  519. * (rsa_pubkey, rsa_signature, string)
  520. *
  521. * returns:
  522. * true - if string match rsa signature
  523. * false - otherwise
  524. */
  525. static gint
  526. lua_rsa_verify_memory (lua_State *L)
  527. {
  528. RSA *rsa;
  529. rspamd_fstring_t *signature;
  530. const gchar *data;
  531. gsize sz;
  532. gint ret;
  533. rsa = lua_check_rsa_pubkey (L, 1);
  534. signature = lua_check_rsa_sign (L, 2);
  535. data = luaL_checklstring (L, 3, &sz);
  536. if (rsa != NULL && signature != NULL && data != NULL) {
  537. ret = RSA_verify (NID_sha256, data, sz,
  538. signature->str, signature->len, rsa);
  539. if (ret == 0) {
  540. lua_pushboolean (L, FALSE);
  541. lua_pushstring (L, ERR_error_string (ERR_get_error (), NULL));
  542. return 2;
  543. }
  544. else {
  545. lua_pushboolean (L, TRUE);
  546. }
  547. }
  548. else {
  549. lua_pushnil (L);
  550. }
  551. return 1;
  552. }
  553. /**
  554. * Sign memory using specified rsa key and signature
  555. *
  556. * arguments:
  557. * (rsa_privkey, string)
  558. *
  559. * returns:
  560. * rspamd_signature object
  561. * nil - otherwise
  562. */
  563. static gint
  564. lua_rsa_sign_memory (lua_State *L)
  565. {
  566. RSA *rsa;
  567. rspamd_fstring_t *signature, **psig;
  568. const gchar *data;
  569. gsize sz;
  570. gint ret;
  571. rsa = lua_check_rsa_privkey (L, 1);
  572. data = luaL_checklstring (L, 2, &sz);
  573. if (rsa != NULL && data != NULL) {
  574. signature = rspamd_fstring_sized_new (RSA_size (rsa));
  575. guint siglen = signature->len;
  576. ret = RSA_sign (NID_sha256, data, sz,
  577. signature->str, &siglen, rsa);
  578. if (ret != 1) {
  579. rspamd_fstring_free (signature);
  580. return luaL_error (L, "cannot sign: %s",
  581. ERR_error_string (ERR_get_error (), NULL));
  582. }
  583. else {
  584. signature->len = siglen;
  585. psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
  586. rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
  587. *psig = signature;
  588. }
  589. }
  590. else {
  591. return luaL_error (L, "invalid arguments");
  592. }
  593. return 1;
  594. }
  595. static gint
  596. lua_load_pubkey (lua_State * L)
  597. {
  598. lua_newtable (L);
  599. luaL_register (L, NULL, rsapubkeylib_f);
  600. return 1;
  601. }
  602. static gint
  603. lua_load_privkey (lua_State * L)
  604. {
  605. lua_newtable (L);
  606. luaL_register (L, NULL, rsaprivkeylib_f);
  607. return 1;
  608. }
  609. static gint
  610. lua_load_signature (lua_State * L)
  611. {
  612. lua_newtable (L);
  613. luaL_register (L, NULL, rsasignlib_f);
  614. return 1;
  615. }
  616. static gint
  617. lua_load_rsa (lua_State * L)
  618. {
  619. lua_newtable (L);
  620. luaL_register (L, NULL, rsalib_f);
  621. return 1;
  622. }
  623. void
  624. luaopen_rsa (lua_State * L)
  625. {
  626. rspamd_lua_new_class (L, "rspamd{rsa_pubkey}", rsapubkeylib_m);
  627. lua_pop (L, 1);
  628. rspamd_lua_add_preload (L, "rspamd_rsa_pubkey", lua_load_pubkey);
  629. rspamd_lua_new_class (L, "rspamd{rsa_privkey}", rsaprivkeylib_m);
  630. lua_pop (L, 1);
  631. rspamd_lua_add_preload (L, "rspamd_rsa_privkey", lua_load_privkey);
  632. rspamd_lua_new_class (L, "rspamd{rsa_signature}", rsasignlib_m);
  633. lua_pop (L, 1);
  634. rspamd_lua_add_preload (L, "rspamd_rsa_signature", lua_load_signature);
  635. rspamd_lua_add_preload (L, "rspamd_rsa", lua_load_rsa);
  636. lua_settop (L, 0);
  637. }