mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 08:43:55 +01:00
switched key generation from secret key to pkc (sealed box)
This commit is contained in:
@ -4,15 +4,15 @@
|
||||
#include <sodium.h>
|
||||
|
||||
/* Local encryption key */
|
||||
#include "secretkey.h"
|
||||
#include "recipient_pk.h"
|
||||
|
||||
/* Exim4 dlfunc API header */
|
||||
#include <local_scan.h>
|
||||
|
||||
int kitencrypt(uschar **yield, int argc, uschar *argv[]) {
|
||||
int sinit;
|
||||
size_t inputlen;
|
||||
unsigned char * input;
|
||||
size_t messagelen;
|
||||
unsigned char * message;
|
||||
|
||||
sinit = sodium_init();
|
||||
if (sinit == -1 ) {
|
||||
@ -24,18 +24,19 @@ int kitencrypt(uschar **yield, int argc, uschar *argv[]) {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
input = argv[0];
|
||||
inputlen = strlen(input);
|
||||
// get cleartext message
|
||||
message = argv[0];
|
||||
messagelen = strlen(message);
|
||||
|
||||
unsigned char nonce[crypto_secretbox_NONCEBYTES];
|
||||
randombytes_buf(nonce, sizeof nonce);
|
||||
|
||||
unsigned int cipherlen = inputlen + crypto_secretbox_MACBYTES;
|
||||
// prepare buffer for ciphertext
|
||||
unsigned int cipherlen = messagelen + crypto_box_SEALBYTES;
|
||||
unsigned char * ciphertext = malloc(cipherlen);
|
||||
explicit_bzero(ciphertext, cipherlen);
|
||||
|
||||
crypto_secretbox_easy(ciphertext, input, inputlen, nonce, key);
|
||||
// encrypt message
|
||||
crypto_box_seal(ciphertext, message, messagelen, recipient_pk);
|
||||
|
||||
// base64-encode the ciphertext
|
||||
unsigned int outputsize = sodium_base64_ENCODED_LEN(cipherlen, sodium_base64_VARIANT_URLSAFE);
|
||||
unsigned char * outstring = malloc(outputsize);
|
||||
explicit_bzero(outstring, outputsize);
|
||||
|
||||
Reference in New Issue
Block a user