Skip to content

Commit 8c65e08

Browse files
committed
Description: yaSSL was only handling the cases of zero or
one leading zeros for the key agreement instead of potentially any number. There is about 1 in 50,000 connections to fail when using DHE cipher suites. The second problem was the case where a server would send a public value shorter than the prime value, causing about 1 in 128 client connections to fail, and also caused the yaSSL client to read off the end of memory. All client side DHE cipher suite users should update. Note: The patch is received from YaSSL people
1 parent cb15cce commit 8c65e08

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

extra/yassl/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ before calling SSL_new();
1212

1313
*** end Note ***
1414

15+
yaSSL Release notes, version 2.3.9 (12/01/2015)
16+
This release of yaSSL fixes two client side Diffie-Hellman problems.
17+
yaSSL was only handling the cases of zero or one leading zeros for the key
18+
agreement instead of potentially any number. This caused about 1 in 50,000
19+
connections to fail when using DHE cipher suites. The second problem was
20+
the case where a server would send a public value shorter than the prime
21+
value, causing about 1 in 128 client connections to fail, and also
22+
caused the yaSSL client to read off the end of memory. All client side
23+
DHE cipher suite users should update.
24+
Thanks to Adam Langely ([email protected]) for the detailed report!
25+
1526
yaSSL Release notes, version 2.3.8 (9/17/2015)
1627
This release of yaSSL fixes a high security vulnerability. All users
1728
SHOULD update. If using yaSSL for TLS on the server side with private

extra/yassl/include/crypto_wrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ class DiffieHellman {
378378

379379
uint get_agreedKeyLength() const;
380380
const byte* get_agreedKey() const;
381+
uint get_publicKeyLength() const;
381382
const byte* get_publicKey() const;
382383
void makeAgreement(const byte*, unsigned int);
383384

extra/yassl/include/openssl/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "rsa.h"
3636

3737

38-
#define YASSL_VERSION "2.3.8"
38+
#define YASSL_VERSION "2.3.9"
3939

4040

4141
#if defined(__cplusplus)

extra/yassl/src/crypto_wrapper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,10 @@ struct DiffieHellman::DHImpl {
751751
byte* publicKey_;
752752
byte* privateKey_;
753753
byte* agreedKey_;
754+
uint pubKeyLength_;
754755

755756
DHImpl(TaoCrypt::RandomNumberGenerator& r) : ranPool_(r), publicKey_(0),
756-
privateKey_(0), agreedKey_(0) {}
757+
privateKey_(0), agreedKey_(0), pubKeyLength_(0) {}
757758
~DHImpl()
758759
{
759760
ysArrayDelete(agreedKey_);
@@ -762,7 +763,7 @@ struct DiffieHellman::DHImpl {
762763
}
763764

764765
DHImpl(const DHImpl& that) : dh_(that.dh_), ranPool_(that.ranPool_),
765-
publicKey_(0), privateKey_(0), agreedKey_(0)
766+
publicKey_(0), privateKey_(0), agreedKey_(0), pubKeyLength_(0)
766767
{
767768
uint length = dh_.GetByteLength();
768769
AllocKeys(length, length, length);
@@ -810,7 +811,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
810811
using TaoCrypt::Integer;
811812

812813
pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref());
813-
pimpl_->publicKey_ = NEW_YS opaque[pubSz];
814+
pimpl_->publicKey_ = NEW_YS opaque[pimpl_->pubKeyLength_ = pubSz];
814815
memcpy(pimpl_->publicKey_, pub, pubSz);
815816
}
816817

@@ -869,6 +870,10 @@ const byte* DiffieHellman::get_agreedKey() const
869870
return pimpl_->agreedKey_;
870871
}
871872

873+
uint DiffieHellman::get_publicKeyLength() const
874+
{
875+
return pimpl_->pubKeyLength_;
876+
}
872877

873878
const byte* DiffieHellman::get_publicKey() const
874879
{

extra/yassl/src/yassl_imp.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,12 @@ void ClientDiffieHellmanPublic::build(SSL& ssl)
109109
uint keyLength = dhClient.get_agreedKeyLength(); // pub and agree same
110110

111111
alloc(keyLength, true);
112-
dhClient.makeAgreement(dhServer.get_publicKey(), keyLength);
112+
dhClient.makeAgreement(dhServer.get_publicKey(),
113+
dhServer.get_publicKeyLength());
113114
c16toa(keyLength, Yc_);
114115
memcpy(Yc_ + KEY_OFFSET, dhClient.get_publicKey(), keyLength);
115116

116-
// because of encoding first byte might be zero, don't use it for preMaster
117-
if (*dhClient.get_agreedKey() == 0)
118-
ssl.set_preMaster(dhClient.get_agreedKey() + 1, keyLength - 1);
119-
else
120-
ssl.set_preMaster(dhClient.get_agreedKey(), keyLength);
117+
ssl.set_preMaster(dhClient.get_agreedKey(), keyLength);
121118
}
122119

123120

@@ -321,11 +318,7 @@ void ClientDiffieHellmanPublic::read(SSL& ssl, input_buffer& input)
321318
}
322319
dh.makeAgreement(Yc_, keyLength);
323320

324-
// because of encoding, first byte might be 0, don't use for preMaster
325-
if (*dh.get_agreedKey() == 0)
326-
ssl.set_preMaster(dh.get_agreedKey() + 1, dh.get_agreedKeyLength() - 1);
327-
else
328-
ssl.set_preMaster(dh.get_agreedKey(), dh.get_agreedKeyLength());
321+
ssl.set_preMaster(dh.get_agreedKey(), dh.get_agreedKeyLength());
329322
ssl.makeMasterSecret();
330323
}
331324

extra/yassl/src/yassl_int.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,19 @@ void SSL::set_random(const opaque* random, ConnectionEnd sender)
807807
// store client pre master secret
808808
void SSL::set_preMaster(const opaque* pre, uint sz)
809809
{
810+
uint i(0); // trim leading zeros
811+
uint fullSz(sz);
812+
813+
while (i++ < fullSz && *pre == 0) {
814+
sz--;
815+
pre++;
816+
}
817+
818+
if (sz == 0) {
819+
SetError(bad_input);
820+
return;
821+
}
822+
810823
secure_.use_connection().AllocPreSecret(sz);
811824
memcpy(secure_.use_connection().pre_master_secret_, pre, sz);
812825
}
@@ -924,6 +937,8 @@ void SSL::order_error()
924937
// Create and store the master secret see page 32, 6.1
925938
void SSL::makeMasterSecret()
926939
{
940+
if (GetError()) return;
941+
927942
if (isTLS())
928943
makeTLSMasterSecret();
929944
else {

0 commit comments

Comments
 (0)