summaryrefslogtreecommitdiffstats
path: root/friendfinder/msg_sender.c
diff options
context:
space:
mode:
Diffstat (limited to 'friendfinder/msg_sender.c')
-rw-r--r--friendfinder/msg_sender.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/friendfinder/msg_sender.c b/friendfinder/msg_sender.c
index 9ef7fc6..ca9bd5f 100644
--- a/friendfinder/msg_sender.c
+++ b/friendfinder/msg_sender.c
@@ -8,6 +8,7 @@
#include "msg_sender.h"
#include "gui.h"
#include "read_file.h"
+#include "cryptossl.h"
static irc_session_t *session;
irc_callbacks_t callbacks;
@@ -60,7 +61,7 @@ struct msg_part* prepare_msg(char *msg)
msg_p->part_count = (len / 6) - 1;
int inc_part_count = msg_p->part_count + 1;
- msg_p->msg_parts = (char(*)[inc_part_count]) malloc(sizeof(char*) * inc_part_count);
+ msg_p->msg_parts = (char(*)[inc_part_count]) malloc(sizeof(char*) * inc_part_count); // richtig: (char**) malloc(sizeof(....))
char *message = (char*) malloc(len + 1);
memcpy(message, msg, len + 1);
@@ -120,7 +121,7 @@ struct msg_part* prepare_msg(char *msg)
void repair_msg(char* inc_msg, char *msg)
{
printf("repair_msg: %s \n", msg);
-
+
if (strcmp(inc_msg, "//c//") != 0)
strcat(msg, inc_msg);
@@ -136,9 +137,10 @@ void set_txt_msg(char *msg)
struct msg_part *msg_p = (struct msg_part*) malloc(sizeof(struct msg_part));
msg_p = prepare_msg(msg);
send_message(session, msg_p);
- // free(msg_p);
}
else printf("MSG_SENDER: session not initialized \n");
+
+
}
void send_message(irc_session_t *session, struct msg_part *msg_p)
@@ -148,26 +150,35 @@ void send_message(irc_session_t *session, struct msg_part *msg_p)
for (int i = 0; i <= msg_p->part_count; i++)
{
char *crypted_msg = (char*) malloc(sizeof(char) * 8);
-
+ char *crypted_msg_base64 = (char*) malloc(sizeof(char) * 50);
+
if (msg_p->msg_parts[i] != NULL)
{
BF_ecb_encrypt(msg_p->msg_parts[i], crypted_msg, &key, BF_ENCRYPT);
- irc_cmd_msg(session, "#msg", crypted_msg);
+ to_base64(crypted_msg, strlen(crypted_msg), crypted_msg_base64, 50);
+ irc_cmd_msg(session, "#msg", crypted_msg_base64);
+
+ free(crypted_msg_base64);
free(crypted_msg);
}
}
char* eof = "//c//";
char *crypted_eof = (char*) malloc(sizeof(char) * sizeof(eof));
+ char *crypted_eof_base64 = (char*) malloc(sizeof(char) * 50);
+
BF_ecb_encrypt(eof, crypted_eof, &key, BF_ENCRYPT);
- irc_cmd_msg(session, "#msg", crypted_eof);
+ to_base64(crypted_eof, strlen(crypted_eof), crypted_eof_base64, 50);
+ irc_cmd_msg(session, "#msg", crypted_eof_base64);
free(crypted_eof);
+ free(crypted_eof_base64);
for (int i = 0; i < msg_p->part_count; i++)
{
free(msg_p->msg_parts[i]);
}
+
free(msg_p->msg_parts);
free(msg_p);
@@ -179,15 +190,13 @@ void send_message(irc_session_t *session, struct msg_part *msg_p)
void on_connect(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
struct key_data *keyd = (struct key_data*) malloc(sizeof(struct key_data));
- //keyd->key = (char*) malloc(sizeof(char) * 300);
keyd = read_key();
irc_cmd_join(session, "#msg", NULL);
irc_cmd_msg(session, "#msg", "connected");
-// printf("keyd->key %s :: keyd->key_length %i \n", keyd->key, keyd->key_length);
- BF_set_key(&key, keyd->key_length - 1, keyd->key);
+ BF_set_key(&key, keyd->key_length, keyd->key);
free(keyd->key);
free(keyd);
@@ -196,6 +205,7 @@ void on_connect(irc_session_t * session, const char * event, const char * origin
void on_channel(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
char *inc_msg = (char*) malloc(sizeof(char) * 8);
+ char *inc_msg_base64 = (char*) malloc(sizeof(char) * 50);
irc_target_get_nick(origin, sender_name, sizeof(sender_name));
@@ -208,9 +218,13 @@ void on_channel(irc_session_t * session, const char * event, const char * origin
else
{
- BF_ecb_encrypt(params[1], inc_msg, &key, BF_DECRYPT);
+ from_base64(params[1], strlen(params[1]), inc_msg_base64, 50);
+ BF_ecb_encrypt(inc_msg_base64, inc_msg, &key, BF_DECRYPT);
printf("%s \n", inc_msg);
repair_msg(inc_msg, msg);
+
+ free(inc_msg_base64);
+ free(inc_msg);
}
}
}