Skip to content

Commit 3ce8554

Browse files
Bug#20201864 : UPGRADE TO YASSL 2.3.7
Upgrading YaSSL from 2.3.5 to 2.3.7 Reviewed-by : Kristofer Pettersson <[email protected]> Reviewed-by : Vamsikrishna Bhagi <[email protected]>
1 parent 5da083e commit 3ce8554

File tree

11 files changed

+342
-20
lines changed

11 files changed

+342
-20
lines changed

extra/yassl/README

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

1313
*** end Note ***
1414

15+
yaSSL Release notes, version 2.3.7 (12/10/2014)
16+
This release of yaSSL fixes the potential to process duplicate handshake
17+
messages by explicitly marking/checking received handshake messages.
18+
19+
yaSSL Release notes, version 2.3.6 (11/25/2014)
20+
21+
This release of yaSSL fixes some valgrind warnings/errors including
22+
uninitialized reads and off by one index errors induced from fuzzing
23+
the handshake. These were reported by Oracle.
24+
1525
yaSSL Release notes, version 2.3.5 (9/29/2014)
1626

1727
This release of yaSSL fixes an RSA Padding check vulnerability reported by

extra/yassl/examples/client/client.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
/* client.cpp */
2020

21+
// takes an optional command line argument of cipher list to make scripting
22+
// easier
23+
24+
2125
#include "../../testsuite/test.hpp"
2226

2327
//#define TEST_RESUME
@@ -73,11 +77,16 @@ void client_test(void* args)
7377
#ifdef NON_BLOCKING
7478
tcp_set_nonblocking(sockfd);
7579
#endif
76-
7780
SSL_METHOD* method = TLSv1_client_method();
7881
SSL_CTX* ctx = SSL_CTX_new(method);
7982

8083
set_certs(ctx);
84+
if (argc >= 2) {
85+
printf("setting cipher list to %s\n", argv[1]);
86+
if (SSL_CTX_set_cipher_list(ctx, argv[1]) != SSL_SUCCESS) {
87+
ClientError(ctx, NULL, sockfd, "set_cipher_list error\n");
88+
}
89+
}
8190
SSL* ssl = SSL_new(ctx);
8291

8392
SSL_set_fd(ssl, sockfd);

extra/yassl/examples/server/server.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
/* server.cpp */
2020

21+
// takes 2 optional command line argument to make scripting
22+
// if the first command line argument is 'n' client auth is disabled
23+
// if the second command line argument is 'd' DSA certs are used instead of RSA
2124

2225
#include "../../testsuite/test.hpp"
2326

@@ -69,6 +72,9 @@ THREAD_RETURN YASSL_API server_test(void* args)
6972
char** argv = 0;
7073

7174
set_args(argc, argv, *static_cast<func_args*>(args));
75+
#ifdef SERVER_READY_FILE
76+
set_file_ready("server_ready", *static_cast<func_args*>(args));
77+
#endif
7278
tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args));
7379

7480
tcp_close(sockfd);
@@ -77,8 +83,21 @@ THREAD_RETURN YASSL_API server_test(void* args)
7783
SSL_CTX* ctx = SSL_CTX_new(method);
7884

7985
//SSL_CTX_set_cipher_list(ctx, "RC4-SHA:RC4-MD5");
80-
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
81-
set_serverCerts(ctx);
86+
87+
// should we disable client auth
88+
if (argc >= 2 && argv[1][0] == 'n')
89+
printf("disabling client auth\n");
90+
else
91+
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
92+
93+
// are we using DSA certs
94+
if (argc >= 3 && argv[2][0] == 'd') {
95+
printf("using DSA certs\n");
96+
set_dsaServerCerts(ctx);
97+
}
98+
else {
99+
set_serverCerts(ctx);
100+
}
82101
DH* dh = set_tmpDH(ctx);
83102

84103
SSL* ssl = SSL_new(ctx);

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.5"
38+
#define YASSL_VERSION "2.3.7"
3939

4040

4141
#if defined(__cplusplus)

extra/yassl/include/yassl_int.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ enum AcceptState {
107107
};
108108

109109

110+
// track received messages to explicitly disallow duplicate messages
111+
struct RecvdMessages {
112+
uint8 gotClientHello_;
113+
uint8 gotServerHello_;
114+
uint8 gotCert_;
115+
uint8 gotServerKeyExchange_;
116+
uint8 gotCertRequest_;
117+
uint8 gotServerHelloDone_;
118+
uint8 gotCertVerify_;
119+
uint8 gotClientKeyExchange_;
120+
uint8 gotFinished_;
121+
RecvdMessages() : gotClientHello_(0), gotServerHello_(0), gotCert_(0),
122+
gotServerKeyExchange_(0), gotCertRequest_(0),
123+
gotServerHelloDone_(0), gotCertVerify_(0),
124+
gotClientKeyExchange_(0), gotFinished_(0)
125+
{}
126+
};
127+
128+
110129
// combines all states
111130
class States {
112131
RecordLayerState recordLayer_;
@@ -115,6 +134,7 @@ class States {
115134
ServerState serverState_;
116135
ConnectState connectState_;
117136
AcceptState acceptState_;
137+
RecvdMessages recvdMessages_;
118138
char errorString_[MAX_ERROR_SZ];
119139
YasslError what_;
120140
public:
@@ -137,6 +157,7 @@ class States {
137157
AcceptState& UseAccept();
138158
char* useString();
139159
void SetError(YasslError);
160+
int SetMessageRecvd(HandShakeType);
140161
private:
141162
States(const States&); // hide copy
142163
States& operator=(const States&); // and assign

extra/yassl/src/yassl_imp.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void EncryptedPreMasterSecret::read(SSL& ssl, input_buffer& input)
242242
}
243243

244244
opaque preMasterSecret[SECRET_LEN];
245+
memset(preMasterSecret, 0, sizeof(preMasterSecret));
245246
rsa.decrypt(preMasterSecret, secret_, length_,
246247
ssl.getCrypto().get_random());
247248

@@ -300,6 +301,11 @@ void ClientDiffieHellmanPublic::read(SSL& ssl, input_buffer& input)
300301
tmp[1] = input[AUTO];
301302
ato16(tmp, keyLength);
302303

304+
if (keyLength < dh.get_agreedKeyLength()/2) {
305+
ssl.SetError(bad_input);
306+
return;
307+
}
308+
303309
alloc(keyLength);
304310
input.read(Yc_, keyLength);
305311
if (input.get_error()) {
@@ -408,6 +414,10 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
408414
tmp[1] = input[AUTO];
409415
ato16(tmp, length);
410416

417+
if (length == 0) {
418+
ssl.SetError(bad_input);
419+
return;
420+
}
411421
signature_ = NEW_YS byte[length];
412422
input.read(signature_, length);
413423
if (input.get_error()) {
@@ -864,6 +874,12 @@ void ChangeCipherSpec::Process(input_buffer& input, SSL& ssl)
864874
return;
865875
}
866876

877+
// detect duplicate change_cipher
878+
if (ssl.getSecurity().get_parms().pending_ == false) {
879+
ssl.order_error();
880+
return;
881+
}
882+
867883
ssl.useSecurity().use_parms().pending_ = false;
868884
if (ssl.getSecurity().get_resuming()) {
869885
if (ssl.getSecurity().get_parms().entity_ == client_end)
@@ -2047,12 +2063,8 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request)
20472063
tmp[0] = input[AUTO];
20482064
tmp[1] = input[AUTO];
20492065
ato16(tmp, dnSz);
2050-
2051-
DistinguishedName dn;
2052-
request.certificate_authorities_.push_back(dn = NEW_YS
2053-
byte[REQUEST_HEADER + dnSz]);
2054-
memcpy(dn, tmp, REQUEST_HEADER);
2055-
input.read(&dn[REQUEST_HEADER], dnSz);
2066+
2067+
input.set_current(input.get_current() + dnSz);
20562068

20572069
sz -= dnSz + REQUEST_HEADER;
20582070

@@ -2191,6 +2203,11 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request)
21912203
ato16(tmp, sz);
21922204
request.set_length(sz);
21932205

2206+
if (sz == 0) {
2207+
input.set_error();
2208+
return input;
2209+
}
2210+
21942211
request.signature_ = NEW_YS byte[sz];
21952212
input.read(request.signature_, sz);
21962213

extra/yassl/src/yassl_int.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,77 @@ void States::SetError(YasslError ye)
255255
}
256256

257257

258+
// mark message recvd, check for duplicates, return 0 on success
259+
int States::SetMessageRecvd(HandShakeType hst)
260+
{
261+
switch (hst) {
262+
case hello_request:
263+
break; // could send more than one
264+
265+
case client_hello:
266+
if (recvdMessages_.gotClientHello_)
267+
return -1;
268+
recvdMessages_.gotClientHello_ = 1;
269+
break;
270+
271+
case server_hello:
272+
if (recvdMessages_.gotServerHello_)
273+
return -1;
274+
recvdMessages_.gotServerHello_ = 1;
275+
break;
276+
277+
case certificate:
278+
if (recvdMessages_.gotCert_)
279+
return -1;
280+
recvdMessages_.gotCert_ = 1;
281+
break;
282+
283+
case server_key_exchange:
284+
if (recvdMessages_.gotServerKeyExchange_)
285+
return -1;
286+
recvdMessages_.gotServerKeyExchange_ = 1;
287+
break;
288+
289+
case certificate_request:
290+
if (recvdMessages_.gotCertRequest_)
291+
return -1;
292+
recvdMessages_.gotCertRequest_ = 1;
293+
break;
294+
295+
case server_hello_done:
296+
if (recvdMessages_.gotServerHelloDone_)
297+
return -1;
298+
recvdMessages_.gotServerHelloDone_ = 1;
299+
break;
300+
301+
case certificate_verify:
302+
if (recvdMessages_.gotCertVerify_)
303+
return -1;
304+
recvdMessages_.gotCertVerify_ = 1;
305+
break;
306+
307+
case client_key_exchange:
308+
if (recvdMessages_.gotClientKeyExchange_)
309+
return -1;
310+
recvdMessages_.gotClientKeyExchange_ = 1;
311+
break;
312+
313+
case finished:
314+
if (recvdMessages_.gotFinished_)
315+
return -1;
316+
recvdMessages_.gotFinished_ = 1;
317+
break;
318+
319+
320+
default:
321+
return -1;
322+
323+
}
324+
325+
return 0;
326+
}
327+
328+
258329
sslFactory::sslFactory() :
259330
messageFactory_(InitMessageFactory),
260331
handShakeFactory_(InitHandShakeFactory),
@@ -1199,6 +1270,11 @@ void SSL::verifyState(const HandShakeHeader& hsHeader)
11991270
return;
12001271
}
12011272

1273+
if (states_.SetMessageRecvd(hsHeader.get_handshakeType()) != 0) {
1274+
order_error();
1275+
return;
1276+
}
1277+
12021278
if (secure_.get_parms().entity_ == client_end)
12031279
verifyClientState(hsHeader.get_handshakeType());
12041280
else

extra/yassl/taocrypt/src/asn.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ word32 CertDecoder::GetSignature()
672672
}
673673

674674
sigLength_ = GetLength(source_);
675-
if (sigLength_ == 0 || source_.IsLeft(sigLength_) == false) {
675+
if (sigLength_ <= 1 || source_.IsLeft(sigLength_) == false) {
676676
source_.SetError(CONTENT_E);
677677
return 0;
678678
}
@@ -1001,11 +1001,17 @@ bool CertDecoder::ConfirmSignature(Source& pub)
10011001
RSA_PublicKey pubKey(pub);
10021002
RSAES_Encryptor enc(pubKey);
10031003

1004+
if (pubKey.FixedCiphertextLength() != sigLength_) {
1005+
source_.SetError(SIG_LEN_E);
1006+
return false;
1007+
}
1008+
10041009
return enc.SSL_Verify(build.get_buffer(), build.size(), signature_);
10051010
}
10061011
else { // DSA
10071012
// extract r and s from sequence
10081013
byte seqDecoded[DSA_SIG_SZ];
1014+
memset(seqDecoded, 0, sizeof(seqDecoded));
10091015
DecodeDSA_Signature(seqDecoded, signature_, sigLength_);
10101016

10111017
DSA_PublicKey pubKey(pub);

extra/yassl/taocrypt/src/integer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,18 +2605,20 @@ void Integer::Decode(Source& source)
26052605
void Integer::Decode(const byte* input, unsigned int inputLen, Signedness s)
26062606
{
26072607
unsigned int idx(0);
2608-
byte b = input[idx++];
2608+
byte b = 0;
2609+
if (inputLen>0)
2610+
b = input[idx]; // peek
26092611
sign_ = ((s==SIGNED) && (b & 0x80)) ? NEGATIVE : POSITIVE;
26102612

26112613
while (inputLen>0 && (sign_==POSITIVE ? b==0 : b==0xff))
26122614
{
2613-
inputLen--;
2614-
b = input[idx++];
2615+
idx++; // skip
2616+
if (--inputLen>0)
2617+
b = input[idx]; // peek
26152618
}
26162619

26172620
reg_.CleanNew(RoundupSize(BytesToWords(inputLen)));
26182621

2619-
--idx;
26202622
for (unsigned int i=inputLen; i > 0; i--)
26212623
{
26222624
b = input[idx++];

0 commit comments

Comments
 (0)