Skip to content

Commit 2b74a6c

Browse files
author
Yashwant Sahu
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 4f8c44a + 1661320 commit 2b74a6c

File tree

9 files changed

+90
-34
lines changed

9 files changed

+90
-34
lines changed

extra/yassl/README

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

1313
*** end Note ***
1414

15+
yaSSL Release notes, version 2.3.9b (2/03/2016)
16+
This release of yaSSL fixes the OpenSSL compatibility function
17+
X509_NAME_get_index_by_NID() to use the actual index of the common name
18+
instead of searching on the format prefix. Thanks for the report from
19+
[email protected] . Anyone using this function should update.
20+
1521
yaSSL Release notes, version 2.3.9 (12/01/2015)
1622
This release of yaSSL fixes two client side Diffie-Hellman problems.
1723
yaSSL was only handling the cases of zero or one leading zeros for the key

extra/yassl/include/openssl/ssl.h

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

3636

37-
#define YASSL_VERSION "2.3.9"
37+
#define YASSL_VERSION "2.3.9b"
3838

3939

4040
#if defined(__cplusplus)

extra/yassl/include/yassl_int.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,19 @@ class sslFactory {
191191
class X509_NAME {
192192
char* name_;
193193
size_t sz_;
194+
int cnPosition_; // start of common name, -1 is none
195+
int cnLen_; // length of above
194196
ASN1_STRING entry_;
195197
public:
196-
X509_NAME(const char*, size_t sz);
198+
X509_NAME(const char*, size_t sz, int pos, int len);
197199
~X509_NAME();
198200

199201
const char* GetName() const;
200202
ASN1_STRING* GetEntry(int i);
201203
size_t GetLength() const;
204+
int GetCnPosition() const { return cnPosition_; }
205+
int GetCnLength() const { return cnLen_; }
206+
202207
private:
203208
X509_NAME(const X509_NAME&); // hide copy
204209
X509_NAME& operator=(const X509_NAME&); // and assign
@@ -226,7 +231,7 @@ class X509 {
226231
StringHolder afterDate_; // not valid after
227232
public:
228233
X509(const char* i, size_t, const char* s, size_t,
229-
ASN1_STRING *b, ASN1_STRING *a);
234+
ASN1_STRING *b, ASN1_STRING *a, int, int, int, int);
230235
~X509() {}
231236

232237
X509_NAME* GetIssuer();

extra/yassl/src/cert_wrapper.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ int CertManager::Validate()
304304
afterDate.type= cert.GetAfterDateType();
305305
afterDate.length= strlen((char *) afterDate.data) + 1;
306306
peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
307-
sSz, &beforeDate, &afterDate);
307+
sSz, &beforeDate, &afterDate,
308+
cert.GetIssuerCnStart(), cert.GetIssuerCnLength(),
309+
cert.GetSubjectCnStart(), cert.GetSubjectCnLength()
310+
);
308311

309312
if (err == TaoCrypt::SIG_OTHER_E && verifyCallback_) {
310313
X509_STORE_CTX store;
@@ -350,7 +353,9 @@ int CertManager::SetPrivateKey(const x509& key)
350353
afterDate.type= cd.GetAfterDateType();
351354
afterDate.length= strlen((char *) afterDate.data) + 1;
352355
selfX509_ = NEW_YS X509(cd.GetIssuer(), iSz, cd.GetCommonName(),
353-
sSz, &beforeDate, &afterDate);
356+
sSz, &beforeDate, &afterDate,
357+
cd.GetIssuerCnStart(), cd.GetIssuerCnLength(),
358+
cd.GetSubjectCnStart(), cd.GetSubjectCnLength());
354359
}
355360
return 0;
356361
}
@@ -367,7 +372,9 @@ void CertManager::setPeerX509(X509* x)
367372
ASN1_STRING* after = x->GetAfter();
368373

369374
peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(),
370-
subject->GetName(), subject->GetLength(), before, after);
375+
subject->GetName(), subject->GetLength(), before, after,
376+
issuer->GetCnPosition(), issuer->GetCnLength(),
377+
subject->GetCnPosition(), subject->GetCnLength());
371378
}
372379

373380

extra/yassl/src/ssl.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,9 @@ X509* X509_Copy(X509 *x)
645645

646646
X509 *newX509 = NEW_YS X509(issuer->GetName(), issuer->GetLength(),
647647
subject->GetName(), subject->GetLength(),
648-
before, after);
648+
before, after,
649+
issuer->GetCnPosition(), issuer->GetCnLength(),
650+
subject->GetCnPosition(), subject->GetCnLength());
649651

650652
return newX509;
651653
}
@@ -713,7 +715,10 @@ X509* PEM_read_X509(FILE *fp, X509 *x,
713715
afterDate.length = strlen((char *) afterDate.data) + 1;
714716

715717
X509 *thisX509 = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
716-
sSz, &beforeDate, &afterDate);
718+
sSz, &beforeDate, &afterDate,
719+
cert.GetIssuerCnStart(), cert.GetIssuerCnLength(),
720+
cert.GetSubjectCnStart(), cert.GetSubjectCnLength());
721+
717722

718723
ysDelete(ptr);
719724
return thisX509;
@@ -1444,16 +1449,14 @@ int ASN1_STRING_type(ASN1_STRING *x)
14441449
int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos)
14451450
{
14461451
int idx = -1; // not found
1447-
const char* start = &name->GetName()[lastpos + 1];
1452+
int cnPos = -1;
14481453

14491454
switch (nid) {
14501455
case NID_commonName:
1451-
const char* found = strstr(start, "/CN=");
1452-
if (found) {
1453-
found += 4; // advance to str
1454-
idx = found - start + lastpos + 1;
1455-
}
1456-
break;
1456+
cnPos = name->GetCnPosition();
1457+
if (lastpos < cnPos)
1458+
idx = cnPos;
1459+
break;
14571460
}
14581461

14591462
return idx;

extra/yassl/src/yassl_int.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,9 @@ void SSL_SESSION::CopyX509(X509* x)
16071607

16081608
peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(),
16091609
subject->GetName(), subject->GetLength(),
1610-
before, after);
1610+
before, after,
1611+
issuer->GetCnPosition(), issuer->GetCnLength(),
1612+
subject->GetCnPosition(), subject->GetCnLength());
16111613
}
16121614

16131615

@@ -2583,8 +2585,8 @@ void Security::set_resuming(bool b)
25832585
}
25842586

25852587

2586-
X509_NAME::X509_NAME(const char* n, size_t sz)
2587-
: name_(0), sz_(sz)
2588+
X509_NAME::X509_NAME(const char* n, size_t sz, int pos, int len)
2589+
: name_(0), sz_(sz), cnPosition_(pos), cnLen_(len)
25882590
{
25892591
if (sz) {
25902592
name_ = NEW_YS char[sz];
@@ -2614,8 +2616,10 @@ size_t X509_NAME::GetLength() const
26142616

26152617

26162618
X509::X509(const char* i, size_t iSz, const char* s, size_t sSz,
2617-
ASN1_STRING *b, ASN1_STRING *a)
2618-
: issuer_(i, iSz), subject_(s, sSz),
2619+
ASN1_STRING *b, ASN1_STRING *a,
2620+
int issPos, int issLen,
2621+
int subPos, int subLen)
2622+
: issuer_(i, iSz, issPos, issLen), subject_(s, sSz, subPos, subLen),
26192623
beforeDate_((char *) b->data, b->length, b->type),
26202624
afterDate_((char *) a->data, a->length, a->type)
26212625
{}
@@ -2650,19 +2654,20 @@ ASN1_STRING* X509_NAME::GetEntry(int i)
26502654
if (i < 0 || i >= int(sz_))
26512655
return 0;
26522656

2657+
if (i != cnPosition_ || cnLen_ <= 0) // only entry currently supported
2658+
return 0;
2659+
2660+
if (cnLen_ > int(sz_-i)) // make sure there's room in read buffer
2661+
return 0;
2662+
26532663
if (entry_.data)
26542664
ysArrayDelete(entry_.data);
2655-
entry_.data = NEW_YS byte[sz_]; // max size;
2665+
entry_.data = NEW_YS byte[cnLen_+1]; // max size;
26562666

2657-
memcpy(entry_.data, &name_[i], sz_ - i);
2658-
if (entry_.data[sz_ -i - 1]) {
2659-
entry_.data[sz_ - i] = 0;
2660-
entry_.length = int(sz_) - i;
2661-
}
2662-
else
2663-
entry_.length = int(sz_) - i - 1;
2667+
memcpy(entry_.data, &name_[i], cnLen_);
2668+
entry_.data[cnLen_] = 0;
2669+
entry_.length = cnLen_;
26642670
entry_.type = 0;
2665-
26662671
return &entry_;
26672672
}
26682673

extra/yassl/taocrypt/include/asn.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ class CertDecoder : public BER_Decoder {
286286
byte GetBeforeDateType() const { return beforeDateType_; }
287287
const char* GetAfterDate() const { return afterDate_; }
288288
byte GetAfterDateType() const { return afterDateType_; }
289-
289+
int GetSubjectCnStart() const { return subCnPos_; }
290+
int GetIssuerCnStart() const { return issCnPos_; }
291+
int GetSubjectCnLength() const { return subCnLen_; }
292+
int GetIssuerCnLength() const { return issCnLen_; }
290293
void DecodeToKey();
291294
private:
292295
PublicKey key_;
@@ -295,6 +298,10 @@ class CertDecoder : public BER_Decoder {
295298
word32 sigLength_; // length of signature
296299
word32 signatureOID_; // sum of algorithm object id
297300
word32 keyOID_; // sum of key algo object id
301+
int subCnPos_; // subject common name start, -1 is none
302+
int subCnLen_; // length of above
303+
int issCnPos_; // issuer common name start, -1 is none
304+
int issCnLen_; // length of above
298305
byte subjectHash_[SHA_SIZE]; // hash of all Names
299306
byte issuerHash_[SHA_SIZE]; // hash of all Names
300307
byte* signature_;

extra/yassl/taocrypt/src/asn.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ void DH_Decoder::Decode(DH& key)
487487

488488
CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers,
489489
bool noVerify, CertType ct)
490-
: BER_Decoder(s), certBegin_(0), sigIndex_(0), sigLength_(0),
491-
signature_(0), verify_(!noVerify)
490+
: BER_Decoder(s), certBegin_(0), sigIndex_(0), sigLength_(0), subCnPos_(-1),
491+
subCnLen_(0), issCnPos_(-1), issCnLen_(0), signature_(0),
492+
verify_(!noVerify)
492493
{
493494
issuer_[0] = 0;
494495
subject_[0] = 0;
@@ -809,6 +810,13 @@ void CertDecoder::GetName(NameType nt)
809810
case COMMON_NAME:
810811
if (!(ptr = AddTag(ptr, buf_end, "/CN=", 4, strLen)))
811812
return;
813+
if (nt == ISSUER) {
814+
issCnPos_ = (int)(ptr - strLen - issuer_);
815+
issCnLen_ = (int)strLen;
816+
} else {
817+
subCnPos_ = (int)(ptr - strLen - subject_);
818+
subCnLen_ = (int)strLen;
819+
}
812820
break;
813821
case SUR_NAME:
814822
if (!(ptr = AddTag(ptr, buf_end, "/SN=", 4, strLen)))

extra/yassl/testsuite/test.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,24 @@ inline void showPeer(SSL* ssl)
469469
if (peer) {
470470
char* issuer = X509_NAME_oneline(X509_get_issuer_name(peer), 0, 0);
471471
char* subject = X509_NAME_oneline(X509_get_subject_name(peer), 0, 0);
472+
X509_NAME_ENTRY* se = NULL;
473+
ASN1_STRING* sd = NULL;
474+
char* subCN = NULL;
475+
X509_NAME* sub = X509_get_subject_name(peer);
476+
int lastpos = -1;
477+
if (sub)
478+
lastpos = X509_NAME_get_index_by_NID(sub, NID_commonName, lastpos);
479+
if (lastpos >= 0) {
480+
se = X509_NAME_get_entry(sub, lastpos);
481+
if (se)
482+
sd = X509_NAME_ENTRY_get_data(se);
483+
if (sd)
484+
subCN = (char*)ASN1_STRING_data(sd);
485+
}
486+
487+
printf("peer's cert info:\n issuer : %s\n subject: %s\n"
488+
" subject cn: %s\n", issuer, subject, subCN);
472489

473-
printf("peer's cert info:\n issuer : %s\n subject: %s\n", issuer,
474-
subject);
475490
free(subject);
476491
free(issuer);
477492
}

0 commit comments

Comments
 (0)