finish it

This commit is contained in:
dignifiedquire
2019-05-14 00:44:50 +02:00
parent a95d6f85cc
commit dfb989e0d0
25 changed files with 1051 additions and 2665 deletions

View File

@@ -148,30 +148,23 @@ pub unsafe fn dc_get_securejoin_qr(
}
unsafe fn get_self_fingerprint(context: &dc_context_t) -> *mut libc::c_char {
let self_addr: *mut libc::c_char;
let self_key: *mut dc_key_t = dc_key_new();
let mut fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
self_addr = dc_sqlite3_get_config(
let self_addr = dc_sqlite3_get_config(
context,
&context.sql.clone().read().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char,
);
if !(self_addr.is_null()
|| 0 == dc_key_load_self_public(
context,
self_key,
self_addr,
&context.sql.clone().read().unwrap(),
))
{
fingerprint = dc_key_get_fingerprint(context, self_key);
fingerprint.is_null();
if self_addr.is_null() {
return std::ptr::null_mut();
}
free(self_addr as *mut libc::c_void);
dc_key_unref(self_key);
fingerprint
if let Some(key) =
Key::from_self_public(context, self_addr, &context.sql.clone().read().unwrap())
{
return key.fingerprint_c();
}
std::ptr::null_mut()
}
pub unsafe fn dc_join_securejoin(context: &dc_context_t, qr: *const libc::c_char) -> uint32_t {
@@ -360,7 +353,7 @@ unsafe fn fingerprint_equals_sender(
let mut fingerprint_equal: libc::c_int = 0i32;
let contacts: *mut dc_array_t = dc_get_chat_contacts(context, contact_chat_id);
let contact: *mut dc_contact_t = dc_contact_new(context);
let peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context);
let mut peerstate = dc_apeerstate_new(context);
let mut fingerprint_normalized: *mut libc::c_char = 0 as *mut libc::c_char;
if !(dc_array_get_cnt(contacts) != 1) {
if !(!dc_contact_load_from_db(
@@ -369,13 +362,13 @@ unsafe fn fingerprint_equals_sender(
dc_array_get_id(contacts, 0i32 as size_t),
) || 0
== dc_apeerstate_load_by_addr(
peerstate,
&mut peerstate,
&context.sql.clone().read().unwrap(),
(*contact).addr,
))
{
fingerprint_normalized = dc_normalize_fingerprint(fingerprint);
if strcasecmp(fingerprint_normalized, (*peerstate).public_key_fingerprint) == 0i32 {
fingerprint_normalized = dc_normalize_fingerprint_c(fingerprint);
if strcasecmp(fingerprint_normalized, peerstate.public_key_fingerprint) == 0i32 {
fingerprint_equal = 1i32
}
}
@@ -984,19 +977,19 @@ unsafe fn mark_peer_as_verified(
let mut peerstate = dc_apeerstate_new(context);
if !(0
== dc_apeerstate_load_by_fingerprint(
peerstate,
&mut peerstate,
&context.sql.clone().read().unwrap(),
fingerprint,
))
{
if !(0 == dc_apeerstate_set_verified(peerstate, 1i32, fingerprint, 2i32)) {
(*peerstate).prefer_encrypt = 1i32;
(*peerstate).to_save |= 0x2i32;
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32);
if !(0 == dc_apeerstate_set_verified(&mut peerstate, 1i32, fingerprint, 2i32)) {
peerstate.prefer_encrypt = 1i32;
peerstate.to_save |= 0x2i32;
dc_apeerstate_save_to_db(&mut peerstate, &context.sql.clone().read().unwrap(), 0i32);
success = 1i32
}
}
dc_apeerstate_unref(peerstate);
dc_apeerstate_unref(&mut peerstate);
success
}
@@ -1054,45 +1047,43 @@ unsafe fn encrypted_and_signed(
1
}
pub unsafe fn dc_handle_degrade_event(context: &dc_context_t, peerstate: *mut dc_apeerstate_t) {
pub unsafe fn dc_handle_degrade_event(context: &dc_context_t, peerstate: &dc_apeerstate_t) {
let stmt;
let contact_id: uint32_t;
let mut contact_chat_id: uint32_t = 0i32 as uint32_t;
if !peerstate.is_null() {
// - 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 0 != (*peerstate).degrade_event & 0x2i32 {
stmt = dc_sqlite3_prepare(
// - 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 0 != peerstate.degrade_event & 0x2i32 {
stmt = dc_sqlite3_prepare(
context,
&context.sql.clone().read().unwrap(),
b"SELECT id FROM contacts WHERE addr=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_text(stmt, 1i32, peerstate.addr, -1i32, None);
sqlite3_step(stmt);
contact_id = sqlite3_column_int(stmt, 0i32) as uint32_t;
sqlite3_finalize(stmt);
if !(contact_id == 0i32 as libc::c_uint) {
dc_create_or_lookup_nchat_by_contact_id(
context,
&context.sql.clone().read().unwrap(),
b"SELECT id FROM contacts WHERE addr=?;\x00" as *const u8 as *const libc::c_char,
contact_id,
2i32,
&mut contact_chat_id,
0 as *mut libc::c_int,
);
let msg: *mut libc::c_char = dc_stock_str_repl_string(context, 37i32, peerstate.addr);
dc_add_device_msg(context, contact_chat_id, msg);
free(msg as *mut libc::c_void);
(context.cb)(
context,
Event::CHAT_MODIFIED,
contact_chat_id as uintptr_t,
0i32 as uintptr_t,
);
sqlite3_bind_text(stmt, 1i32, (*peerstate).addr, -1i32, None);
sqlite3_step(stmt);
contact_id = sqlite3_column_int(stmt, 0i32) as uint32_t;
sqlite3_finalize(stmt);
if !(contact_id == 0i32 as libc::c_uint) {
dc_create_or_lookup_nchat_by_contact_id(
context,
contact_id,
2i32,
&mut contact_chat_id,
0 as *mut libc::c_int,
);
let msg: *mut libc::c_char =
dc_stock_str_repl_string(context, 37i32, (*peerstate).addr);
dc_add_device_msg(context, contact_chat_id, msg);
free(msg as *mut libc::c_void);
(context.cb)(
context,
Event::CHAT_MODIFIED,
contact_chat_id as uintptr_t,
0i32 as uintptr_t,
);
}
}
};
}
}