added secret_chat_rekey function

This commit is contained in:
Vysheng 2014-11-13 19:22:12 +03:00
parent 253b86377d
commit a65dcf16a7
2 changed files with 40 additions and 4 deletions

View File

@ -862,6 +862,15 @@ void do_create_secret_chat (int arg_num, struct arg args[], struct in_ev *ev) {
tgl_do_create_secret_chat (TLS, args[0].P->id, print_secret_chat_gw, ev); tgl_do_create_secret_chat (TLS, args[0].P->id, print_secret_chat_gw, ev);
} }
void do_secret_chat_rekey (int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num == 1);
tgl_peer_t *P = args[0].P;
if (P->encr_chat.state == sc_ok) {
vlogprintf (E_WARNING, "START REKEY\n");
tgl_do_request_exchange (TLS, (void *)P);
}
}
void do_chat_add_user (int arg_num, struct arg args[], struct in_ev *ev) { void do_chat_add_user (int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num == 3); assert (arg_num == 3);
if (ev) { ev->refcnt ++; } if (ev) { ev->refcnt ++; }
@ -1110,6 +1119,7 @@ struct command commands[] = {
{"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg <msg-id>\tRestores message. Only available shortly (one hour?) after deletion"}, {"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg <msg-id>\tRestores message. Only available shortly (one hour?) after deletion"},
{"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"}, {"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"},
{"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"}, {"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"},
{"secret_chat_rekey", { ca_secret_chat, ca_none}, do_secret_chat_rekey, "generate new key for active secret chat"},
{"send_audio", {ca_peer, ca_file_name_end, ca_none}, do_send_audio, "send_audio <peer> <file>\tSends audio to peer"}, {"send_audio", {ca_peer, ca_file_name_end, ca_none}, do_send_audio, "send_audio <peer> <file>\tSends audio to peer"},
{"send_contact", {ca_peer, ca_string, ca_string, ca_string, ca_none}, do_send_contact, "send_contact <peer> <phone> <first-name> <last-name>\tSends contact (not necessary telegram user)"}, {"send_contact", {ca_peer, ca_string, ca_string, ca_string, ca_none}, do_send_contact, "send_contact <peer> <phone> <first-name> <last-name>\tSends contact (not necessary telegram user)"},
{"send_document", {ca_peer, ca_file_name_end, ca_none}, do_send_document, "send_document <peer> <file>\tSends document to peer"}, {"send_document", {ca_peer, ca_file_name_end, ca_none}, do_send_document, "send_document <peer> <file>\tSends document to peer"},
@ -2641,8 +2651,21 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) {
mprintf (ev, " is "); mprintf (ev, " is ");
print_typing (ev, M->action.typing); print_typing (ev, M->action.typing);
break; break;
default: case tgl_message_action_noop:
assert (0); mprintf (ev, " noop\n");
break;
case tgl_message_action_request_key:
mprintf (ev, " request rekey #%016llx\n", M->action.exchange_id);
break;
case tgl_message_action_accept_key:
mprintf (ev, " accept rekey #%016llx\n", M->action.exchange_id);
break;
case tgl_message_action_commit_key:
mprintf (ev, " commit rekey #%016llx\n", M->action.exchange_id);
break;
case tgl_message_action_abort_key:
mprintf (ev, " abort rekey #%016llx\n", M->action.exchange_id);
break;
} }
mpop_color (ev); mpop_color (ev);
//print_end (); //print_end ();

17
loop.c
View File

@ -62,6 +62,8 @@
#include <tgl/tgl-net.h> #include <tgl/tgl-net.h>
#include <tgl/tgl-timers.h> #include <tgl/tgl-timers.h>
#include <openssl/sha.h>
int verbosity; int verbosity;
extern int readline_disabled; extern int readline_disabled;
@ -465,6 +467,7 @@ void write_secret_chat (tgl_peer_t *_P, void *extra) {
assert (write (fd, &P->state, 4) == 4); assert (write (fd, &P->state, 4) == 4);
assert (write (fd, &P->key_fingerprint, 8) == 8); assert (write (fd, &P->key_fingerprint, 8) == 8);
assert (write (fd, &P->key, 256) == 256); assert (write (fd, &P->key, 256) == 256);
assert (write (fd, &P->first_key_sha, 20) == 20);
assert (write (fd, &P->in_seq_no, 4) == 4); assert (write (fd, &P->in_seq_no, 4) == 4);
assert (write (fd, &P->last_in_seq_no, 4) == 4); assert (write (fd, &P->last_in_seq_no, 4) == 4);
assert (write (fd, &P->out_seq_no, 4) == 4); assert (write (fd, &P->out_seq_no, 4) == 4);
@ -476,7 +479,7 @@ void write_secret_chat_file (void) {
assert (secret_chat_fd >= 0); assert (secret_chat_fd >= 0);
int x = SECRET_CHAT_FILE_MAGIC; int x = SECRET_CHAT_FILE_MAGIC;
assert (write (secret_chat_fd, &x, 4) == 4); assert (write (secret_chat_fd, &x, 4) == 4);
x = 1; x = 2;
assert (write (secret_chat_fd, &x, 4) == 4); // version assert (write (secret_chat_fd, &x, 4) == 4); // version
assert (write (secret_chat_fd, &x, 4) == 4); // num assert (write (secret_chat_fd, &x, 4) == 4); // num
@ -574,6 +577,7 @@ void read_secret_chat (int fd, int v) {
long long access_hash, key_fingerprint; long long access_hash, key_fingerprint;
static char s[1000]; static char s[1000];
static unsigned char key[256]; static unsigned char key[256];
static unsigned char sha[20];
assert (read (fd, &id, 4) == 4); assert (read (fd, &id, 4) == 4);
//assert (read (fd, &flags, 4) == 4); //assert (read (fd, &flags, 4) == 4);
assert (read (fd, &l, 4) == 4); assert (read (fd, &l, 4) == 4);
@ -588,6 +592,9 @@ void read_secret_chat (int fd, int v) {
assert (read (fd, &state, 4) == 4); assert (read (fd, &state, 4) == 4);
assert (read (fd, &key_fingerprint, 8) == 8); assert (read (fd, &key_fingerprint, 8) == 8);
assert (read (fd, &key, 256) == 256); assert (read (fd, &key, 256) == 256);
if (v >= 2) {
assert (read (fd, sha, 20) == 20);
}
int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0; int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0;
if (v >= 1) { if (v >= 1) {
assert (read (fd, &in_seq_no, 4) == 4); assert (read (fd, &in_seq_no, 4) == 4);
@ -604,6 +611,12 @@ void read_secret_chat (int fd, int v) {
bl_do_encr_chat_set_access_hash (TLS, P, access_hash); bl_do_encr_chat_set_access_hash (TLS, P, access_hash);
bl_do_encr_chat_set_state (TLS, P, state); bl_do_encr_chat_set_state (TLS, P, state);
bl_do_encr_chat_set_key (TLS, P, key, key_fingerprint); bl_do_encr_chat_set_key (TLS, P, key, key_fingerprint);
if (v >= 2) {
bl_do_encr_chat_set_sha (TLS, P, sha);
} else {
SHA1 ((void *)key, 256, sha);
bl_do_encr_chat_set_sha (TLS, P, sha);
}
if (v >= 1) { if (v >= 1) {
bl_do_encr_chat_set_seq (TLS, P, in_seq_no, last_in_seq_no, out_seq_no); bl_do_encr_chat_set_seq (TLS, P, in_seq_no, last_in_seq_no, out_seq_no);
} }
@ -619,7 +632,7 @@ void read_secret_chat_file (void) {
if (x != SECRET_CHAT_FILE_MAGIC) { close (secret_chat_fd); return; } if (x != SECRET_CHAT_FILE_MAGIC) { close (secret_chat_fd); return; }
int v = 0; int v = 0;
assert (read (secret_chat_fd, &v, 4) == 4); assert (read (secret_chat_fd, &v, 4) == 4);
assert (v == 0 || v == 1); // version assert (v == 0 || v == 1 || v == 2); // version
assert (read (secret_chat_fd, &x, 4) == 4); assert (read (secret_chat_fd, &x, 4) == 4);
assert (x >= 0); assert (x >= 0);
while (x --> 0) { while (x --> 0) {