Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit 1661320

Browse files
author
Yashwant Sahu
committed
Merge branch 'mysql-5.5' into mysql-5.6
Conflicts: extra/yassl/include/yassl_int.hpp extra/yassl/src/cert_wrapper.cpp extra/yassl/src/yassl_int.cpp extra/yassl/taocrypt/include/asn.hpp
2 parents 50946d0 + e7061f7 commit 1661320

File tree

9 files changed

+83
-32
lines changed

9 files changed

+83
-32
lines changed

extra/yassl/README

+6
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+
yashwant.sahu@oracle.com . 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

+1-1
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

+7-2
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

+10-3
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

+5-7
Original file line numberDiff line numberDiff line change
@@ -1350,16 +1350,14 @@ int ASN1_STRING_type(ASN1_STRING *x)
13501350
int X509_NAME_get_index_by_NID(X509_NAME* name,int nid, int lastpos)
13511351
{
13521352
int idx = -1; // not found
1353-
const char* start = &name->GetName()[lastpos + 1];
1353+
int cnPos = -1;
13541354

13551355
switch (nid) {
13561356
case NID_commonName:
1357-
const char* found = strstr(start, "/CN=");
1358-
if (found) {
1359-
found += 4; // advance to str
1360-
idx = found - start + lastpos + 1;
1361-
}
1362-
break;
1357+
cnPos = name->GetCnPosition();
1358+
if (lastpos < cnPos)
1359+
idx = cnPos;
1360+
break;
13631361
}
13641362

13651363
return idx;

extra/yassl/src/yassl_int.cpp

+19-14
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

@@ -2575,8 +2577,8 @@ void Security::set_resuming(bool b)
25752577
}
25762578

25772579

2578-
X509_NAME::X509_NAME(const char* n, size_t sz)
2579-
: name_(0), sz_(sz)
2580+
X509_NAME::X509_NAME(const char* n, size_t sz, int pos, int len)
2581+
: name_(0), sz_(sz), cnPosition_(pos), cnLen_(len)
25802582
{
25812583
if (sz) {
25822584
name_ = NEW_YS char[sz];
@@ -2606,8 +2608,10 @@ size_t X509_NAME::GetLength() const
26062608

26072609

26082610
X509::X509(const char* i, size_t iSz, const char* s, size_t sSz,
2609-
ASN1_STRING *b, ASN1_STRING *a)
2610-
: issuer_(i, iSz), subject_(s, sSz),
2611+
ASN1_STRING *b, ASN1_STRING *a,
2612+
int issPos, int issLen,
2613+
int subPos, int subLen)
2614+
: issuer_(i, iSz, issPos, issLen), subject_(s, sSz, subPos, subLen),
26112615
beforeDate_((char *) b->data, b->length, b->type),
26122616
afterDate_((char *) a->data, a->length, a->type)
26132617
{}
@@ -2642,19 +2646,20 @@ ASN1_STRING* X509_NAME::GetEntry(int i)
26422646
if (i < 0 || i >= int(sz_))
26432647
return 0;
26442648

2649+
if (i != cnPosition_ || cnLen_ <= 0) // only entry currently supported
2650+
return 0;
2651+
2652+
if (cnLen_ > int(sz_-i)) // make sure there's room in read buffer
2653+
return 0;
2654+
26452655
if (entry_.data)
26462656
ysArrayDelete(entry_.data);
2647-
entry_.data = NEW_YS byte[sz_]; // max size;
2657+
entry_.data = NEW_YS byte[cnLen_+1]; // max size;
26482658

2649-
memcpy(entry_.data, &name_[i], sz_ - i);
2650-
if (entry_.data[sz_ -i - 1]) {
2651-
entry_.data[sz_ - i] = 0;
2652-
entry_.length = int(sz_) - i;
2653-
}
2654-
else
2655-
entry_.length = int(sz_) - i - 1;
2659+
memcpy(entry_.data, &name_[i], cnLen_);
2660+
entry_.data[cnLen_] = 0;
2661+
entry_.length = cnLen_;
26562662
entry_.type = 0;
2657-
26582663
return &entry_;
26592664
}
26602665

extra/yassl/taocrypt/include/asn.hpp

+8-1
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

+10-2
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

+17-2
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)