text
stringlengths
0
357
}
else if (strcasecmp(line, "Autocrypt-Prefer-Encrypt")==0) {
p2++;
dc_trim(p2);
if (ret_preferencrypt) {
*ret_preferencrypt = p2;
}
}
}
/* prepare for next line */
p1++;
line = p1;
line_chars = 0;
}
else {
p1++;
line_chars++;
}
}
if (headerline==NULL || base64==NULL) {
goto cleanup;
}
/* now, line points to beginning of base64 data, search end */
if ((p1=strstr(base64, "-----END "/*the trailing space makes sure, this is not a normal base64 sequence*/))==NULL
|| strncmp(p1+9, headerline+11, strlen(headerline+11))!=0) {
goto cleanup;
}
*p1 = 0;
dc_trim(base64);
if (ret_base64) {
*ret_base64 = base64;
}
success = 1;
cleanup:
return success;
}
#ifdef DC_USE_RPGP
/* returns 0 if there is no error, otherwise logs the error if a context is provided and returns 1*/
int dc_pgp_handle_rpgp_error(dc_context_t* context) {
int success = 0;
int len = 0;
char* msg = NULL;
len = rpgp_last_error_length();
if (len==0) {
goto cleanup;
}
msg = rpgp_last_error_message();
if (context != NULL) {
dc_log_info(context, 0, "[rpgp][error] %s", msg);
}
success = 1;
cleanup:
if (msg) { rpgp_string_drop(msg); }
return success;
}
#endif /* DC_USE_RPGP */
/*******************************************************************************
* Key generatation
******************************************************************************/
#ifdef DC_USE_RPGP
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key)
{
int success = 0;
rpgp_signed_secret_key* skey = NULL;
rpgp_signed_public_key* pkey = NULL;
rpgp_cvec* skey_bytes = NULL;
rpgp_cvec* pkey_bytes = NULL;
char* user_id = NULL;
/* Create the user id */
user_id = dc_mprintf("<%s>", addr);
/* Create the actual key */
skey = rpgp_create_rsa_skey(DC_KEYGEN_BITS, user_id);
if (dc_pgp_handle_rpgp_error(context)) {
goto cleanup;
}
/* Serialize secret key into bytes */
skey_bytes = rpgp_skey_to_bytes(skey);