mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 10:13:56 +01:00
Removed debugging statements.
This commit is contained in:
26
src/debug_helpers.c
Normal file
26
src/debug_helpers.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Convert a string to its hexadecimal representation.
|
||||||
|
*
|
||||||
|
* Use like this:
|
||||||
|
* log_write(0, LOG_MAIN, "DEBUG: %s", string2hex(var, var_len));
|
||||||
|
*/
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
return outstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* How to debug this library:
|
||||||
|
*
|
||||||
|
* 1. Add this code to the first “breakpoint”:
|
||||||
|
* log_write(0, LOG_MAIN, "pid: %d", getpid()); int busywait = 0; while (busywait == 0) {}
|
||||||
|
* 2. Compile.
|
||||||
|
* 3. Run “exim -be […]” to call the lib; see simple_exim_test.sh for details.
|
||||||
|
* 4. Read exim pid from log output. Attach to the looping exim process with “gdb -p PID”
|
||||||
|
* 5. Prepare breakpoints, watches, etc. Set busywait to 1 and continue.
|
||||||
|
*/
|
||||||
8
src/debug_helpers.h
Normal file
8
src/debug_helpers.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// Created by sprawl on 20/08/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef EXIM_ENCRYPT_DLFUNC_DEBUG_HELPERS_H
|
||||||
|
#define EXIM_ENCRYPT_DLFUNC_DEBUG_HELPERS_H
|
||||||
|
|
||||||
|
#endif //EXIM_ENCRYPT_DLFUNC_DEBUG_HELPERS_H
|
||||||
@ -9,16 +9,6 @@
|
|||||||
/* Exim4 dlfunc API header */
|
/* Exim4 dlfunc API header */
|
||||||
#include <local_scan.h>
|
#include <local_scan.h>
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
return outstring;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypt message using crypto_secretbox_easy().
|
* Encrypt message using crypto_secretbox_easy().
|
||||||
*
|
*
|
||||||
@ -194,14 +184,10 @@ int sodium_crypto_box_seal(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_write(0, LOG_MAIN, "[encrypt] PK: %s", string2hex(pk, pk_buffer_len));
|
|
||||||
|
|
||||||
// get cleartext message
|
// get cleartext message
|
||||||
unsigned char *message = argv[1];
|
unsigned char *message = argv[1];
|
||||||
size_t messagelen = strlen((const char *) message);
|
size_t messagelen = strlen((const char *) message);
|
||||||
|
|
||||||
log_write(0, LOG_MAIN, "[encrypt] cleartext: %s", message);
|
|
||||||
|
|
||||||
// prepare buffer for ciphertext
|
// prepare buffer for ciphertext
|
||||||
unsigned int cipherlen = messagelen + crypto_box_SEALBYTES;
|
unsigned int cipherlen = messagelen + crypto_box_SEALBYTES;
|
||||||
unsigned char *ciphertext = store_get(cipherlen);
|
unsigned char *ciphertext = store_get(cipherlen);
|
||||||
@ -213,8 +199,6 @@ int sodium_crypto_box_seal(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_write(0, LOG_MAIN, "[encrypt] ciphertext: %s", string2hex(ciphertext, cipherlen));
|
|
||||||
|
|
||||||
// base64-encode the ciphertext
|
// base64-encode the ciphertext
|
||||||
unsigned int outputsize = sodium_base64_ENCODED_LEN(cipherlen,
|
unsigned int outputsize = sodium_base64_ENCODED_LEN(cipherlen,
|
||||||
sodium_base64_VARIANT_ORIGINAL);
|
sodium_base64_VARIANT_ORIGINAL);
|
||||||
@ -262,7 +246,6 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
*yield = string_copy((unsigned char *) "Error decoding private key");
|
*yield = string_copy((unsigned char *) "Error decoding private key");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
log_write(0, LOG_MAIN, "[decrypt] SK: %s", string2hex(sk, sk_buffer_len));
|
|
||||||
|
|
||||||
// get and convert public key
|
// get and convert public key
|
||||||
unsigned char *pkb64 = argv[1];
|
unsigned char *pkb64 = argv[1];
|
||||||
@ -280,8 +263,6 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_write(0, LOG_MAIN, "[decrypt] PK: %s", string2hex(pk, pk_buffer_len));
|
|
||||||
|
|
||||||
// get encrypted message
|
// get encrypted message
|
||||||
unsigned char *ciphertextb64 = argv[2];
|
unsigned char *ciphertextb64 = argv[2];
|
||||||
size_t ciphertextb64_len = strlen((const char *) ciphertextb64);
|
size_t ciphertextb64_len = strlen((const char *) ciphertextb64);
|
||||||
@ -300,18 +281,12 @@ int sodium_crypto_box_seal_open(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_write(0, LOG_MAIN, "[encrypt] ciphertext: %s", string2hex(ciphertext, ciphertextlen));
|
|
||||||
|
|
||||||
// prepare buffer for cleartext
|
// prepare buffer for cleartext
|
||||||
unsigned int cleartextlen = ciphertextlen - crypto_box_SEALBYTES;
|
unsigned int cleartextlen = ciphertextlen - crypto_box_SEALBYTES;
|
||||||
unsigned char *cleartext = (unsigned char *) store_get(cleartextlen + 1);
|
unsigned char *cleartext = (unsigned char *) store_get(cleartextlen + 1);
|
||||||
sodium_memzero(cleartext, cleartextlen + 1);
|
sodium_memzero(cleartext, cleartextlen + 1);
|
||||||
|
|
||||||
// decrypt message
|
// decrypt message
|
||||||
//#define DEBUG
|
|
||||||
#ifdef DEBUG
|
|
||||||
log_write(0, LOG_MAIN, "pid: %d", getpid()); int busywait = 0; while (busywait == 0) {}
|
|
||||||
#endif
|
|
||||||
if (crypto_box_seal_open(cleartext, ciphertext, ciphertextlen, pk, sk) != 0) {
|
if (crypto_box_seal_open(cleartext, ciphertext, ciphertextlen, pk, sk) != 0) {
|
||||||
*yield = string_copy((unsigned char *) "Decryption error after crypto_box_seal_open()");
|
*yield = string_copy((unsigned char *) "Decryption error after crypto_box_seal_open()");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
|||||||
Reference in New Issue
Block a user