proposal: Copy SPI and proposal number from correct proposal in select()

If charon.prefer_configured_proposals is disabled select() is called on
the received proposal. This incorrectly set the SPI to 0 as the
configured proposal has no SPI set.

Fixes #2190.
This commit is contained in:
Tobias Brunner
2017-02-06 11:14:31 +01:00
parent b062d3cc44
commit 22f13dcecd
5 changed files with 47 additions and 8 deletions
+1 -1
View File
@@ -249,7 +249,7 @@ METHOD(child_cfg_t, select_proposal, proposal_t*,
{
proposal->strip_dh(proposal, MODP_NONE);
}
selected = proposal->select(proposal, match, private);
selected = proposal->select(proposal, match, prefer_self, private);
if (selected)
{
DBG2(DBG_CFG, "received proposals: %#P", proposals);
+1 -1
View File
@@ -339,7 +339,7 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
}
while (match_enum->enumerate(match_enum, (void**)&match))
{
selected = proposal->select(proposal, match, private);
selected = proposal->select(proposal, match, prefer_self, private);
if (selected)
{
DBG2(DBG_CFG, "received proposals: %#P", proposals);
+13 -3
View File
@@ -273,7 +273,8 @@ static bool select_algo(private_proposal_t *this, proposal_t *other,
}
METHOD(proposal_t, select_proposal, proposal_t*,
private_proposal_t *this, proposal_t *other, bool private)
private_proposal_t *this, proposal_t *other, bool other_remote,
bool private)
{
proposal_t *selected;
@@ -285,7 +286,17 @@ METHOD(proposal_t, select_proposal, proposal_t*,
return NULL;
}
selected = proposal_create(this->protocol, other->get_number(other));
if (other_remote)
{
selected = proposal_create(this->protocol, other->get_number(other));
selected->set_spi(selected, other->get_spi(other));
}
else
{
selected = proposal_create(this->protocol, this->number);
selected->set_spi(selected, this->spi);
}
if (!select_algo(this, other, selected, ENCRYPTION_ALGORITHM, private) ||
!select_algo(this, other, selected, PSEUDO_RANDOM_FUNCTION, private) ||
@@ -298,7 +309,6 @@ METHOD(proposal_t, select_proposal, proposal_t*,
}
DBG2(DBG_CFG, " proposal matches");
selected->set_spi(selected, other->get_spi(other));
return selected;
}
+7 -2
View File
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009-2016 Tobias Brunner
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -124,10 +125,14 @@ struct proposal_t {
* in common, a resulting proposal of this kind is created.
*
* @param other proposal to compare against
* @param other_remote whether other is the remote proposal from which to
* copy SPI and proposal number to the result,
* otherwise copy from this proposal
* @param private accepts algorithms allocated in a private range
* @return selected proposal, NULL if proposals don't match
*/
proposal_t *(*select) (proposal_t *this, proposal_t *other, bool private);
proposal_t *(*select)(proposal_t *this, proposal_t *other,
bool other_remote, bool private);
/**
* Get the protocol ID of the proposal.