示例#1
0
/* Force a context into the OTRL_MSGSTATE_FINISHED state. */
void otrl_context_force_finished(ConnContext *context)
{
    context->msgstate = OTRL_MSGSTATE_FINISHED;
    otrl_auth_clear(&(context->auth));
    free(context->fragment);
    context->fragment = NULL;
    context->fragment_len = 0;
    context->fragment_n = 0;
    context->fragment_k = 0;
    context->active_fingerprint = NULL;
    context->their_keyid = 0;
    gcry_mpi_release(context->their_y);
    context->their_y = NULL;
    gcry_mpi_release(context->their_old_y);
    context->their_old_y = NULL;
    context->our_keyid = 0;
    otrl_dh_keypair_free(&(context->our_dh_key));
    otrl_dh_keypair_free(&(context->our_old_dh_key));
    otrl_dh_session_free(&(context->sesskeys[0][0]));
    otrl_dh_session_free(&(context->sesskeys[0][1]));
    otrl_dh_session_free(&(context->sesskeys[1][0]));
    otrl_dh_session_free(&(context->sesskeys[1][1]));
    memset(context->sessionid, 0, 20);
    context->sessionid_len = 0;
    free(context->preshared_secret);
    context->preshared_secret = NULL;
    context->preshared_secret_len = 0;
    context->protocol_version = 0;
    context->numsavedkeys = 0;
    free(context->saved_mac_keys);
    context->saved_mac_keys = NULL;
    gcry_free(context->lastmessage);
    context->lastmessage = NULL;
    context->may_retransmit = 0;
    otrl_sm_state_free(context->smstate);
}
示例#2
0
/* Make a new DH key for us, and rotate old old ones.  Be sure to keep
 * the sesskeys array in sync. */
static gcry_error_t rotate_dh_keys(ConnContext *context)
{
    gcry_error_t err;

    /* Rotate the keypair */
    otrl_dh_keypair_free(&(context->context_priv->our_old_dh_key));
    memmove(&(context->context_priv->our_old_dh_key),
	    &(context->context_priv->our_dh_key),
	    sizeof(DH_keypair));

    /* Rotate the session keys */
    err = reveal_macs(context, &(context->context_priv->sesskeys[1][0]),
	    &(context->context_priv->sesskeys[1][1]));
    if (err) return err;
    otrl_dh_session_free(&(context->context_priv->sesskeys[1][0]));
    otrl_dh_session_free(&(context->context_priv->sesskeys[1][1]));
    memmove(&(context->context_priv->sesskeys[1][0]),
	    &(context->context_priv->sesskeys[0][0]),
	    sizeof(DH_sesskeys));
    memmove(&(context->context_priv->sesskeys[1][1]),
	    &(context->context_priv->sesskeys[0][1]),
	    sizeof(DH_sesskeys));

    /* Create a new DH key */
    otrl_dh_gen_keypair(DH1536_GROUP_ID, &(context->context_priv->our_dh_key));
    context->context_priv->our_keyid++;

    /* Make the session keys */
    if (context->context_priv->their_y) {
	err = otrl_dh_session(&(context->context_priv->sesskeys[0][0]),
		&(context->context_priv->our_dh_key),
		context->context_priv->their_y);
	if (err) return err;
    } else {
	otrl_dh_session_blank(&(context->context_priv->sesskeys[0][0]));
    }
    if (context->context_priv->their_old_y) {
	err = otrl_dh_session(&(context->context_priv->sesskeys[0][1]),
		&(context->context_priv->our_dh_key),
		context->context_priv->their_old_y);
	if (err) return err;
    } else {
	otrl_dh_session_blank(&(context->context_priv->sesskeys[0][1]));
    }
    return gcry_error(GPG_ERR_NO_ERROR);
}