text
stringlengths
0
357
send_handshake_msg(context, contact_chat_id, join_vg? "vg-request-with-auth" : "vc-request-with-auth",
auth, own_fingerprint, grpid); // Bob -> Alice
}
else if (strcmp(step, "vg-request-with-auth")==0 || strcmp(step, "vc-request-with-auth")==0)
{
/* ============================================================
==== Alice - the inviter side ====
==== Steps 5+6 in "Setup verified contact" protocol ====
==== Step 6 in "Out-of-band verified groups" protocol ====
============================================================ */
// verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob
const char* fingerprint = NULL;
if ((fingerprint=lookup_field(mimeparser, "Secure-Join-Fingerprint"))==NULL) {
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint not provided.");
goto cleanup;
}
if (!encrypted_and_signed(mimeparser, fingerprint)) {
could_not_establish_secure_connection(context, contact_chat_id, "Auth not encrypted.");
goto cleanup;
}
if (!fingerprint_equals_sender(context, fingerprint, contact_chat_id)) {
// MitM?
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint mismatch on inviter-side.");
goto cleanup;
}
dc_log_info(context, 0, "Fingerprint verified.");
// verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code
const char* auth = NULL;
if ((auth=lookup_field(mimeparser, "Secure-Join-Auth"))==NULL) {
could_not_establish_secure_connection(context, contact_chat_id, "Auth not provided.");
goto cleanup;
}
if (dc_token_exists(context, DC_TOKEN_AUTH, auth)==0) {
could_not_establish_secure_connection(context, contact_chat_id, "Auth invalid.");
goto cleanup;
}
if (!mark_peer_as_verified(context, fingerprint)) {
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint mismatch on inviter-side."); // should not happen, we've compared the fingerprint some lines above
goto cleanup;
}
dc_scaleup_contact_origin(context, contact_id, DC_ORIGIN_SECUREJOIN_INVITED);
dc_log_info(context, 0, "Auth verified.");
secure_connection_established(context, contact_chat_id);
context->cb(context, DC_EVENT_CONTACTS_CHANGED, contact_id/*selected contact*/, 0);
context->cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 600);
if (join_vg) {
// the vg-member-added message is special: this is a normal Chat-Group-Member-Added message with an additional Secure-Join header
grpid = dc_strdup(lookup_field(mimeparser, "Secure-Join-Group"));
uint32_t group_chat_id = dc_get_chat_id_by_grpid(context, grpid, NULL, NULL);
if (group_chat_id==0) {
dc_log_error(context, 0, "Chat %s not found.", grpid);
goto cleanup;
}
dc_add_contact_to_chat_ex(context, group_chat_id, contact_id, DC_FROM_HANDSHAKE); // Alice -> Bob and all members
}
else {
send_handshake_msg(context, contact_chat_id, "vc-contact-confirm",
NULL, NULL, NULL); // Alice -> Bob
context->cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 1000); // done contact joining
}
}
else if (strcmp(step, "vg-member-added")==0 || strcmp(step, "vc-contact-confirm")==0)
{
/* ==========================================================
==== Bob - the joiner's side =====
==== Step 7 in "Setup verified contact" protocol =====
========================================================== */
if (join_vg) {
// vg-member-added is just part of a Chat-Group-Member-Added which should be kept in any way, eg. for multi-client
ret = DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING;
}
if (context->bob_expects!=DC_VC_CONTACT_CONFIRM) {
dc_log_info(context, 0, "Message belongs to a different handshake.");
goto cleanup;
}
LOCK_QR
if (context->bobs_qr_scan==NULL || (join_vg && context->bobs_qr_scan->state!=DC_QR_ASK_VERIFYGROUP)) {
dc_log_warning(context, 0, "Message out of sync or belongs to a different handshake.");
goto cleanup;
}
scanned_fingerprint_of_alice = dc_strdup(context->bobs_qr_scan->fingerprint);
if (join_vg) {
grpid = dc_strdup(context->bobs_qr_scan->text2);
}
UNLOCK_QR