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