Commit Graph

108 Commits

Author SHA1 Message Date
eb9123b3f6 Fix apt interactivity in Ubuntu 2021-08-21 23:10:05 +02:00
abba591c01 CI: Support ancient meson versions 2021-08-21 23:04:57 +02:00
3e73cc6ee1 CI: Support ancient meson versions 2021-08-21 23:04:47 +02:00
26a591bedd CI: Install pkg-config 2021-08-21 23:00:13 +02:00
f8f2a06abc Update .gitlab-ci.yml file 2021-08-21 22:58:16 +02:00
276ddf35aa Switched build system to meson. 2021-08-21 22:57:01 +02:00
70bdb895a5 2021-08-21 19:19:53 +02:00
0530681a39 Added more version workarounds for compilation, late binding and type casting. 2021-08-21 19:11:08 +02:00
6a352fb855 Fix #5 by shortening the cmdline parameters 2021-08-21 18:53:11 +02:00
7eed55a274 Added missing definitions for local_scan ABI version 3 (used in Ubuntu Focal) 2021-08-21 03:56:34 +02:00
ef1afd5be2 Merge branch 'real_tests' into 'master'
Return error code on test failure

See merge request mail/exim-encrypt-dlfunc!2
2021-08-21 03:15:34 +02:00
02d679ddcd Return error code on test failure 2021-08-21 03:14:09 +02:00
d544a00e02 Merge branch 'ci2' 2021-08-21 02:46:23 +02:00
359710e1fd Merge branch 'master' into 'ci2'
# Conflicts:
#   src/Makefile
2021-08-21 00:44:11 +00:00
3053df107a Removed all optimization flags from Makefile. 2021-08-21 02:32:11 +02:00
4c6091c227 Update .gitlab-ci.yml file 2021-08-21 02:28:02 +02:00
9925009fcc Update .gitlab-ci.yml file 2021-08-21 02:18:00 +02:00
09ad1ea5a0 Update .gitlab-ci.yml file 2021-08-21 02:10:54 +02:00
d868072802 Update Makefile 2021-08-21 00:11:09 +02:00
98d2e6ee53 Update Makefile 2021-08-21 00:10:37 +02:00
1942bd8f5b Update .gitlab-ci.yml file 2021-08-21 00:07:29 +02:00
d630289f91 Added target "all" to Makefile 2021-08-21 00:04:06 +02:00
3a437a5bf0 Changed unsigned int to size_t where appropriate (see #4) 2021-08-20 23:10:15 +02:00
05d5a5080d Added debian default compiler and linker options (from dpkg-buildflags --get CFLAGS) 2021-08-20 23:09:40 +02:00
508b985b0e Handle exim local_scan API version changes 2021-08-20 12:00:22 +02:00
6b8e0d948d README.md: typo 2021-08-20 10:39:25 +02:00
ad6b2799d8 Deleted unused header file 2021-08-20 03:05:28 +02:00
c3696498ef fix: typo 2021-08-20 03:02:33 +02:00
44bb873b04 Added first incomplete example to README.md 2021-08-20 02:48:08 +02:00
464e94f402 Added README.md 2021-08-20 02:14:12 +02:00
4969b9277f Removed debug symbols from final library. 2021-08-20 01:49:41 +02:00
a4fd2f5483 Add LICENSE 2021-08-20 01:25:15 +02:00
cd70628822
diff --git a/src/debug_helpers.c b/src/debug_helpers.c
index a461043..329fd64 100644
--- a/src/debug_helpers.c
+++ b/src/debug_helpers.c
@@ -4,12 +4,12 @@
  * Use like this:
  * log_write(0, LOG_MAIN, "DEBUG: %s", string2hex(var, var_len));
 */
-char * string2hex(unsigned char * input, size_t length) {
+char *string2hex(unsigned char *input, size_t length) {
     const int growth = 3;
-    char * outstring = store_get(growth*length+1);
-    memset(outstring, 0, 3*length+1);
-    for (int i =0; i<length; i++) {
-        sprintf(outstring+i*growth, "%02x ", input[i]);
+    char *outstring = store_get(growth * length + 1);
+    memset(outstring, 0, 3 * length + 1);
+    for (int i = 0; i < length; i++) {
+        sprintf(outstring + i * growth, "%02x ", input[i]);
     }
     return outstring;
 }
2021-08-20 01:13:21 +02:00
86639a1896
diff --git a/src/Makefile b/src/Makefile
index 6e01d42..1e3d0a3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,9 +7,6 @@ LDFLAGS_LIB=-I/usr/include/exim4 -fpic -shared -export-dynamic

 .DEFAULT_GOAL := libs

-#libexim-kitencrypt-dlfunc.so: libexim-kitencrypt-dlfunc.c
-#	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_LIB) -o $@ $<
-
 libexim-encrypt-dlfunc.so: libexim-encrypt-dlfunc.c
 	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_LIB) -o $@ $<

diff --git a/src/genkey.c b/src/genkey.c
index c169f30..972e613 100644
--- a/src/genkey.c
+++ b/src/genkey.c
@@ -32,6 +32,24 @@ void
 dump_key_as_exim_config(FILE * f, const char *name, unsigned char *key,
 			unsigned int keylen)
 {
+    // write a comment with C variable declaration
+    fprintf(f, "# const unsigned char %s[%d] = { ", name, keylen);
+    for (int i = 0; i < keylen; i++) {
+        fprintf(f, "0x%02x", key[i]);
+        if (i < keylen - 1) {
+            fprintf(f, ", ");
+        }
+    }
+    fprintf(f, " }; const unsigned int %s_length = %d;\n", name, keylen);
+    // encode with base64
+    unsigned int b64len = sodium_base64_ENCODED_LEN(keylen, sodium_base64_VARIANT_ORIGINAL);
+    unsigned char *b64string = malloc(b64len);
+    sodium_bin2base64((char *const) b64string, b64len,
+                      key, keylen,
+                      sodium_base64_VARIANT_ORIGINAL);
+    fprintf(f, "%s = \"%s\"\n", name, b64string);
+
+    free(b64string);
     // write a comment with C variable declaration
     fprintf(f, "# const unsigned char %s[%d] = { ", name, keylen);
     for (int i = 0; i < keylen; i++) {
@@ -98,7 +116,7 @@ void create_cryptobox_keys(const char *filebase, const char *varname)
 	unsigned char recipient_pk[crypto_box_PUBLICKEYBYTES];
 	unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];

-	crypto_box_keypair(recipient_pk, recipient_sk);
+    crypto_box_keypair(recipient_pk, recipient_sk);

 	char pk_filename[4096];
 	char pk_varname[4096];
@@ -118,28 +136,27 @@ void create_cryptobox_keys(const char *filebase, const char *varname)
 }

 void create_secretbox_key(const char *filebase, const char *varname) {
-	unsigned char key[crypto_secretbox_KEYBYTES];
+    unsigned char key[crypto_secretbox_KEYBYTES];

     crypto_secretbox_keygen(key);

-	char key_filename[4096];
-	char key_varname[4096];
+    char key_filename[4096];
+    char key_varname[4096];

-	sprintf(key_filename, "%s_secretbox", filebase);
-	sprintf(key_varname, "%s_key", varname);
+    sprintf(key_filename, "%s_secretbox", filebase);
+    sprintf(key_varname, "%s_key", varname);

-	write_key_files(key_filename, key_varname, key, crypto_secretbox_KEYBYTES);
+    write_key_files(key_filename, key_varname, key, crypto_secretbox_KEYBYTES);
 }

-int main(int argc, char *argv[])
-{
-	if (sodium_init() < 0) {
-		fputs("Unable to initialize libsodium", stderr);
-		exit(128);
-	}
+int main(int argc, char *argv[]) {
+    if (sodium_init() < 0) {
+        fputs("Unable to initialize libsodium", stderr);
+        exit(128);
+    }

-	fputs("=== Creating cryptobox key pair ===\n", stderr);
-	create_cryptobox_keys("cryptobox_recipient", "cryptobox_recipient");
+    fputs("=== Creating cryptobox key pair ===\n", stderr);
+    create_cryptobox_keys("cryptobox_recipient", "cryptobox_recipient");

-	exit(EXIT_SUCCESS);
+    exit(EXIT_SUCCESS);
 }
diff --git a/src/libexim-encrypt-dlfunc.c b/src/libexim-encrypt-dlfunc.c
index 99a31ea..042e72f 100644
--- a/src/libexim-encrypt-dlfunc.c
+++ b/src/libexim-encrypt-dlfunc.c
@@ -233,7 +233,7 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {

     // get and convert private key
     unsigned char *skb64 = argv[0];
-    size_t skb64_len = strlen((const char *)skb64);
+    size_t skb64_len = strlen((const char *) skb64);
     // reserve space for conversion
     unsigned int sk_buffer_len = crypto_box_SECRETKEYBYTES;// skb64_len / 4 * 3;
     unsigned char *sk = (unsigned char *) store_get(sk_buffer_len);
@@ -242,7 +242,7 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
     int b64err = sodium_base642bin(sk, sk_buffer_len,
                                    (const char *) skb64, skb64_len,
                                    NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL);
-    if(b64err == -1) {
+    if (b64err == -1) {
         *yield = string_copy((unsigned char *) "Error decoding private key");
         return ERROR;
     }
@@ -256,8 +256,8 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
     sodium_memzero(pk, pk_buffer_len);
     // convert encoded key to raw form
     b64err = sodium_base642bin(pk, pk_buffer_len,
-                                   (const char *) pkb64, pkb64_len,
-                                   NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL);
+                               (const char *) pkb64, pkb64_len,
+                               NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL);
     if (b64err == -1) {
         *yield = string_copy((unsigned char *) "Error decoding public key");
         return ERROR;
@@ -273,9 +273,9 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
     size_t ciphertextlen;
     sodium_memzero(ciphertext, ciphertextbuflen);
     b64err = sodium_base642bin(ciphertext, ciphertextbuflen,
-                      (const char *) ciphertextb64, ciphertextb64_len,
-                      NULL, &ciphertextlen, NULL,
-                      sodium_base64_VARIANT_ORIGINAL);
+                               (const char *) ciphertextb64, ciphertextb64_len,
+                               NULL, &ciphertextlen, NULL,
+                               sodium_base64_VARIANT_ORIGINAL);
     if (b64err == -1) {
         *yield = string_copy((unsigned char *) "Error decoding base64 encoded ciphertext");
         return ERROR;
2021-08-20 01:12:36 +02:00
d8b209ba33 Removed debugging statements. 2021-08-20 01:04:19 +02:00
4ff77be04a 2021-08-20 00:48:18 +02:00
4acdfffc65 2021-08-17 20:57:58 +02:00
0fe7274c92 Added simple test. 2021-08-17 03:21:43 +02:00
6dc3e1e2f9 First working version of sodium_crypto_secretbox_encrypt_password() and
sodium_crypto_secretbox_decrypt_password().
2021-08-17 03:04:58 +02:00
9112222ac9 Removed obsolete target libexim-kitencrypt-dlfunc.so 2021-08-17 03:04:13 +02:00
8e9a92ce3e Streamlined key generation. Added \0-check for keys. 2021-08-16 10:35:57 +02:00
1e2ec834d2 refactored sodium_crypto_secretbox() into separate source file. 2021-08-11 05:28:39 +02:00
f5727effcf Added proof-of-concept decoder in Python 3 2021-08-11 01:58:07 +02:00
72549d0649 fix: Standardized indention using "indent -linux" 2021-08-11 01:52:11 +02:00
675b37002e 2021-08-11 01:45:30 +02:00
b5cc3f8361 fix: fixed types to satisfy -Wall. Renamed dumpkey() to dump_key_as_c_code(). 2021-08-11 01:42:46 +02:00
abab627bf1 fix: cleaned up Makefile 2021-08-11 01:39:46 +02:00
9dd6e1288d Removed unused libexim-kitencrypt-dlfunc.h 2021-08-11 01:38:10 +02:00
a42610dfb2 Stripped Makefile to prevent automatic key generation 2021-08-07 13:17:15 +02:00
a10ec5bdd4 switched key generation from secret key to pkc (sealed box) 2021-08-07 13:15:14 +02:00