text
stringlengths
0
357
int join_vg = 0;
char* scanned_fingerprint_of_alice = NULL;
char* auth = NULL;
char* own_fingerprint = NULL;
uint32_t contact_chat_id = 0;
int contact_chat_id_blocked = 0;
char* grpid = NULL;
int ret = 0;
dc_contact_t* contact = NULL;
if (context==NULL || mimeparser==NULL || contact_id <= DC_CONTACT_ID_LAST_SPECIAL) {
goto cleanup;
}
if ((step=lookup_field(mimeparser, "Secure-Join"))==NULL) {
goto cleanup;
}
dc_log_info(context, 0, ">>>>>>>>>>>>>>>>>>>>>>>>> secure-join message '%s' received", step);
join_vg = (strncmp(step, "vg-", 3)==0);
dc_create_or_lookup_nchat_by_contact_id(context, contact_id, DC_CHAT_NOT_BLOCKED, &contact_chat_id, &contact_chat_id_blocked);
if (contact_chat_id_blocked) {
dc_unblock_chat(context, contact_chat_id);
}
ret = DC_HANDSHAKE_STOP_NORMAL_PROCESSING;
if (strcmp(step, "vg-request")==0 || strcmp(step, "vc-request")==0)
{
/* =========================================================
==== Alice - the inviter side ====
==== Step 3 in "Setup verified contact" protocol ====
========================================================= */
// this message may be unencrypted (Bob, the joinder and the sender, might not have Alice's key yet)
// it just ensures, we have Bobs key now. If we do _not_ have the key because eg. MitM has removed it,
// send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here.
// verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code
const char* invitenumber = NULL;
if ((invitenumber=lookup_field(mimeparser, "Secure-Join-Invitenumber"))==NULL) {
dc_log_warning(context, 0, "Secure-join denied (invitenumber missing)."); // do not raise an error, this might just be spam or come from an old request
goto cleanup;
}
if (dc_token_exists(context, DC_TOKEN_INVITENUMBER, invitenumber)==0) {
dc_log_warning(context, 0, "Secure-join denied (bad invitenumber)."); // do not raise an error, this might just be spam or come from an old request
goto cleanup;
}
dc_log_info(context, 0, "Secure-join requested.");
context->cb(context, DC_EVENT_SECUREJOIN_INVITER_PROGRESS, contact_id, 300);
send_handshake_msg(context, contact_chat_id, join_vg? "vg-auth-required" : "vc-auth-required",
NULL, NULL, NULL); // Alice -> Bob
}
else if (strcmp(step, "vg-auth-required")==0 || strcmp(step, "vc-auth-required")==0)
{
/* ==========================================================
==== Bob - the joiner's side =====
==== Step 4 in "Setup verified contact" protocol =====
========================================================== */
// verify that Alice's Autocrypt key and fingerprint matches the QR-code
LOCK_QR
if ( context->bobs_qr_scan==NULL
|| context->bob_expects!=DC_VC_AUTH_REQUIRED
|| (join_vg && context->bobs_qr_scan->state!=DC_QR_ASK_VERIFYGROUP)) {
dc_log_warning(context, 0, "auth-required message out of sync.");
goto cleanup; // no error, just aborted somehow or a mail from another handshake
}
scanned_fingerprint_of_alice = dc_strdup(context->bobs_qr_scan->fingerprint);
auth = dc_strdup(context->bobs_qr_scan->auth);
if (join_vg) {
grpid = dc_strdup(context->bobs_qr_scan->text2);
}
UNLOCK_QR
if (!encrypted_and_signed(mimeparser, scanned_fingerprint_of_alice)) {
could_not_establish_secure_connection(context, contact_chat_id, mimeparser->e2ee_helper->encrypted? "No valid signature." : "Not encrypted.");
end_bobs_joining(context, DC_BOB_ERROR);
goto cleanup;
}
if (!fingerprint_equals_sender(context, scanned_fingerprint_of_alice, contact_chat_id)) {
// MitM?
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint mismatch on joiner-side.");
end_bobs_joining(context, DC_BOB_ERROR);
goto cleanup;
}
dc_log_info(context, 0, "Fingerprint verified.");
own_fingerprint = get_self_fingerprint(context);
context->cb(context, DC_EVENT_SECUREJOIN_JOINER_PROGRESS, contact_id, 400);
context->bob_expects = DC_VC_CONTACT_CONFIRM;