text
stringlengths
0
357
outlen = strlen(out.buf);
if (outlen==4 || outlen==9 || outlen==14 || outlen==19 || outlen==24 || outlen==29 || outlen==34 || outlen==39) {
dc_strbuilder_cat(&out, "-");
}
}
p1++;
}
return out.buf;
}
/**
* Initiate Autocrypt Setup Transfer.
* Before starting the setup transfer with this function, the user should be asked:
*
* ~~~
* "An 'Autocrypt Setup Message' securely shares your end-to-end setup with other Autocrypt-compliant apps.
* The setup will be encrypted by a setup code which is displayed here and must be typed on the other device.
* ~~~
*
* After that, this function should be called to send the Autocrypt Setup Message.
* The function creates the setup message and waits until it is really sent.
* As this may take a while, it is recommended to start the function in a separate thread;
* to interrupt it, you can use dc_stop_ongoing_process().
*
* After everything succeeded, the required setup code is returned in the following format:
*
* ~~~
* 1234-1234-1234-1234-1234-1234-1234-1234-1234
* ~~~
*
* The setup code should be shown to the user then:
*
* ~~~
* "Your key has been sent to yourself. Switch to the other device and
* open the setup message. You should be prompted for a setup code. Type
* the following digits into the prompt:
*
* 1234 - 1234 - 1234 -
* 1234 - 1234 - 1234 -
* 1234 - 1234 - 1234
*
* Once you're done, your other device will be ready to use Autocrypt."
* ~~~
*
* On the _other device_ you will call dc_continue_key_transfer() then
* for setup messages identified by dc_msg_is_setupmessage().
*
* For more details about the Autocrypt setup process, please refer to
* https://autocrypt.org/en/latest/level1.html#autocrypt-setup-message
*
* @memberof dc_context_t
* @param context The context object.
* @return The setup code. Must be free()'d after usage.
* On errors, eg. if the message could not be sent, NULL is returned.
*/
char* dc_initiate_key_transfer(dc_context_t* context)
{
int success = 0;
char* setup_code = NULL;
char* setup_file_content = NULL;
char* setup_file_name = NULL;
uint32_t chat_id = 0;
dc_msg_t* msg = NULL;
uint32_t msg_id = 0;
if (!dc_alloc_ongoing(context)) {
return 0; /* no cleanup as this would call dc_free_ongoing() */
}
#define CHECK_EXIT if (context->shall_stop_ongoing) { goto cleanup; }
if ((setup_code=dc_create_setup_code(context))==NULL) { /* this may require a keypair to be created. this may take a second ... */
goto cleanup;
}
CHECK_EXIT
if ((setup_file_content=dc_render_setup_file(context, setup_code))==NULL) { /* encrypting may also take a while ... */
goto cleanup;
}
CHECK_EXIT
if ((setup_file_name=dc_get_fine_pathNfilename(context, "$BLOBDIR", "autocrypt-setup-message.html"))==NULL
|| !dc_write_file(context, setup_file_name, setup_file_content, strlen(setup_file_content))) {
goto cleanup;
}
if ((chat_id=dc_create_chat_by_contact_id(context, DC_CONTACT_ID_SELF))==0) {
goto cleanup;
}
msg = dc_msg_new_untyped(context);
msg->type = DC_MSG_FILE;
dc_param_set (msg->param, DC_PARAM_FILE, setup_file_name);
dc_param_set (msg->param, DC_PARAM_MIMETYPE, "application/autocrypt-setup");
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_AUTOCRYPT_SETUP_MESSAGE);
dc_param_set_int(msg->param, DC_PARAM_FORCE_PLAINTEXT, DC_FP_NO_AUTOCRYPT_HEADER);