text
stringlengths
0
357
/**
* @name Secure Join
* @{
*/
/*******************************************************************************
* Tools: Handle degraded keys and lost verificaton
******************************************************************************/
void dc_handle_degrade_event(dc_context_t* context, dc_apeerstate_t* peerstate)
{
sqlite3_stmt* stmt = NULL;
uint32_t contact_id = 0;
uint32_t contact_chat_id = 0;
if (context==NULL || peerstate==NULL) {
goto cleanup;
}
// - we do not issue an warning for DC_DE_ENCRYPTION_PAUSED as this is quite normal
// - currently, we do not issue an extra warning for DC_DE_VERIFICATION_LOST - this always comes
// together with DC_DE_FINGERPRINT_CHANGED which is logged, the idea is not to bother
// with things they cannot fix, so the user is just kicked from the verified group
// (and he will know this and can fix this)
if (peerstate->degrade_event & DC_DE_FINGERPRINT_CHANGED)
{
stmt = dc_sqlite3_prepare(context->sql, "SELECT id FROM contacts WHERE addr=?;");
sqlite3_bind_text(stmt, 1, peerstate->addr, -1, SQLITE_STATIC);
sqlite3_step(stmt);
contact_id = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
if (contact_id==0) {
goto cleanup;
}
dc_create_or_lookup_nchat_by_contact_id(context, contact_id, DC_CHAT_DEADDROP_BLOCKED, &contact_chat_id, NULL);
char* msg = dc_stock_str_repl_string(context, DC_STR_CONTACT_SETUP_CHANGED, peerstate->addr);
dc_add_device_msg(context, contact_chat_id, msg);
free(msg);
context->cb(context, DC_EVENT_CHAT_MODIFIED, contact_chat_id, 0);
}
cleanup:
;
}
/*******************************************************************************
* Tools: Misc.
******************************************************************************/
static int encrypted_and_signed(dc_mimeparser_t* mimeparser, const char* expected_fingerprint)
{
if (!mimeparser->e2ee_helper->encrypted) {
dc_log_warning(mimeparser->context, 0, "Message not encrypted.");
return 0;
}
if (dc_hash_cnt(mimeparser->e2ee_helper->signatures)<=0) {
dc_log_warning(mimeparser->context, 0, "Message not signed.");
return 0;
}
if (expected_fingerprint==NULL) {
dc_log_warning(mimeparser->context, 0, "Fingerprint for comparison missing.");
return 0;
}
if (dc_hash_find_str(mimeparser->e2ee_helper->signatures, expected_fingerprint)==NULL) {
dc_log_warning(mimeparser->context, 0, "Message does not match expected fingerprint %s.", expected_fingerprint);
return 0;
}
return 1;
}
static char* get_self_fingerprint(dc_context_t* context)
{
char* self_addr = NULL;
dc_key_t* self_key = dc_key_new();
char* fingerprint = NULL;
if ((self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL
|| !dc_key_load_self_public(self_key, self_addr, context->sql)) {
goto cleanup;
}
if ((fingerprint=dc_key_get_fingerprint(self_key))==NULL) {
goto cleanup;
}