Skip to content

Commit a72c633

Browse files
authored
fix: double request send on quick reinitialization of sesame dhke (#1064)
fix: double request send on quick reinitialization of sesame diffie hellman
1 parent 2e785d3 commit a72c633

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

services/util/EchoPolicyDiffieHellman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ namespace services
3838

3939
void EchoPolicyDiffieHellman::Initialized()
4040
{
41+
if (busy)
42+
DiffieHellmanKeyEstablishmentProxy::Rpc().CancelRequestSend(*this);
43+
4144
initializingKeys = true;
4245
nextKeyPair.reset();
46+
verifier.reset();
4347

4448
keyExchange.emplace(keyExchangeCreator, randomDataGenerator);
4549

50+
busy = true;
4651
DiffieHellmanKeyEstablishmentProxy::RequestSend([this]()
4752
{
4853
DiffieHellmanKeyEstablishmentProxy::PresentCertificate(dsaCertificate);
@@ -53,6 +58,7 @@ namespace services
5358
auto [r, s] = signer.Sign(encodedDhPublicKey);
5459

5560
DiffieHellmanKeyEstablishmentProxy::Exchange(encodedDhPublicKey, r, s);
61+
busy = false;
5662
});
5763
});
5864
}

services/util/EchoPolicyDiffieHellman.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace services
7878
infra::Function<void(ServiceProxy& proxy)> onRequest;
7979

8080
bool initializingKeys = true;
81+
bool busy = false;
8182
std::optional<std::pair<std::array<uint8_t, 16>, std::array<uint8_t, 16>>> nextKeyPair;
8283
infra::IntrusiveList<ServiceProxy> waitingProxies;
8384

services/util/test/TestEchoPolicyDiffieHellman.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ TEST_F(EchoPolicyDiffieHellmanTest, send_and_receive)
165165
ExchangeData();
166166
}
167167

168+
TEST_F(EchoPolicyDiffieHellmanTest, intialize_while_initializing_starts_over)
169+
{
170+
Initialized(); // second initialization
171+
172+
EXPECT_CALL(echoPolicyLeft, KeyExchangeSuccessful());
173+
EXPECT_CALL(echoPolicyRight, KeyExchangeSuccessful());
174+
175+
ExchangeData();
176+
}
177+
168178
namespace
169179
{
170180
class DiffieHellmanKeyEstablishmentMock

0 commit comments

Comments
 (0)