Ejemplo n.º 1
0
/* Create a new connection context. */
static ConnContext * new_context(const char * user, const char * accountname,
	const char * protocol)
{
    ConnContext * context;
    OtrlSMState *smstate;
    context = malloc(sizeof(*context));
    assert(context != NULL);
    context->username = strdup(user);
    context->accountname = strdup(accountname);
    context->protocol = strdup(protocol);
    context->fragment = NULL;
    context->fragment_len = 0;
    context->fragment_n = 0;
    context->fragment_k = 0;
    context->msgstate = OTRL_MSGSTATE_PLAINTEXT;
    otrl_auth_new(&(context->auth));

    smstate = malloc(sizeof(OtrlSMState));
    assert(smstate != NULL);
    otrl_sm_state_new(smstate);
    context->smstate = smstate;

    context->fingerprint_root.fingerprint = NULL;
    context->fingerprint_root.context = context;
    context->fingerprint_root.next = NULL;
    context->fingerprint_root.tous = NULL;
    context->active_fingerprint = NULL;
    context->their_keyid = 0;
    context->their_y = NULL;
    context->their_old_y = NULL;
    context->our_keyid = 0;
    context->our_dh_key.groupid = 0;
    context->our_dh_key.priv = NULL;
    context->our_dh_key.pub = NULL;
    context->our_old_dh_key.groupid = 0;
    context->our_old_dh_key.priv = NULL;
    context->our_old_dh_key.pub = NULL;
    otrl_dh_session_blank(&(context->sesskeys[0][0]));
    otrl_dh_session_blank(&(context->sesskeys[0][1]));
    otrl_dh_session_blank(&(context->sesskeys[1][0]));
    otrl_dh_session_blank(&(context->sesskeys[1][1]));
    memset(context->sessionid, 0, 20);
    context->sessionid_len = 0;
    context->protocol_version = 0;
    context->numsavedkeys = 0;
    context->preshared_secret = NULL;
    context->preshared_secret_len = 0;
    context->saved_mac_keys = NULL;
    context->generation = 0;
    context->lastsent = 0;
    context->lastmessage = NULL;
    context->may_retransmit = 0;
    context->otr_offer = OFFER_NOT;
    context->app_data = NULL;
    context->app_data_free = NULL;
    context->next = NULL;
    return context;
}
Ejemplo n.º 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);
}