Skip to content

Commit 707a45a

Browse files
committed
fixes for python
1 parent 594bd4a commit 707a45a

6 files changed

Lines changed: 67 additions & 79 deletions

File tree

src/ssl.c

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10450,8 +10450,7 @@ const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher)
1045010450
return NULL;
1045110451
}
1045210452

10453-
#if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
10454-
!defined(WOLFSSL_QT)
10453+
#if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS)
1045510454
return GetCipherNameIana(cipher->cipherSuite0, cipher->cipherSuite);
1045610455
#else
1045710456
return wolfSSL_get_cipher_name_from_suite(cipher->cipherSuite0,
@@ -14015,12 +14014,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl)
1401514014
}
1401614015
if (i == (int)WOLFSSL_OBJECT_INFO_SZ) {
1401714016
WOLFSSL_MSG("NID not in table");
14018-
#ifdef WOLFSSL_QT
14019-
sName = NULL;
14020-
type = (word32)id;
14021-
#else
1402214017
return NULL;
14023-
#endif
1402414018
}
1402514019

1402614020
#ifdef HAVE_ECC
@@ -16010,9 +16004,8 @@ static WC_INLINE int sslCipherMinMaxCheck(const WOLFSSL *ssl, byte suite0,
1601016004
*/
1601116005
WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1601216006
{
16013-
WOLF_STACK_OF(WOLFSSL_CIPHER)* ret = NULL;
1601416007
const Suites* suites;
16015-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16008+
#if defined(OPENSSL_ALL)
1601616009
const CipherSuiteInfo* cipher_names = GetCipherNames();
1601716010
int cipherSz = GetCipherNamesSize();
1601816011
#endif
@@ -16028,15 +16021,20 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1602816021
/* check if stack needs populated */
1602916022
if (ssl->suitesStack == NULL) {
1603016023
int i;
16031-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16032-
int j;
16024+
16025+
((WOLFSSL*)ssl)->suitesStack =
16026+
wolfssl_sk_new_type_ex(STACK_TYPE_CIPHER, ssl->heap);
16027+
if (ssl->suitesStack == NULL)
16028+
return NULL;
1603316029

1603416030
/* higher priority of cipher suite will be on top of stack */
16035-
for (i = suites->suiteSz - 2; i >=0; i-=2) {
16031+
#if defined(OPENSSL_ALL)
16032+
for (i = suites->suiteSz - 2; i >=0; i-=2)
1603616033
#else
16037-
for (i = 0; i < suites->suiteSz; i+=2) {
16034+
for (i = 0; i < suites->suiteSz; i+=2)
1603816035
#endif
16039-
WOLFSSL_STACK* add;
16036+
{
16037+
struct WOLFSSL_CIPHER cipher;
1604016038

1604116039
/* A couple of suites are placeholders for special options,
1604216040
* skip those. */
@@ -16046,39 +16044,30 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1604616044
continue;
1604716045
}
1604816046

16049-
add = wolfSSL_sk_new_node(ssl->heap);
16050-
if (add != NULL) {
16051-
add->type = STACK_TYPE_CIPHER;
16052-
add->data.cipher.cipherSuite0 = suites->suites[i];
16053-
add->data.cipher.cipherSuite = suites->suites[i+1];
16054-
add->data.cipher.ssl = ssl;
16055-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16047+
XMEMSET(&cipher, 0, sizeof(cipher));
16048+
cipher.cipherSuite0 = suites->suites[i];
16049+
cipher.cipherSuite = suites->suites[i+1];
16050+
cipher.ssl = ssl;
16051+
#if defined(OPENSSL_ALL)
16052+
cipher.in_stack = 1;
16053+
{
16054+
int j;
1605616055
for (j = 0; j < cipherSz; j++) {
16057-
if (cipher_names[j].cipherSuite0 ==
16058-
add->data.cipher.cipherSuite0 &&
16059-
cipher_names[j].cipherSuite ==
16060-
add->data.cipher.cipherSuite) {
16061-
add->data.cipher.offset = (unsigned long)j;
16056+
if (cipher_names[j].cipherSuite0 == cipher.cipherSuite0 &&
16057+
cipher_names[j].cipherSuite == cipher.cipherSuite) {
16058+
cipher.offset = (unsigned long)j;
1606216059
break;
1606316060
}
1606416061
}
16062+
}
1606516063
#endif
16066-
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
16067-
/* in_stack is checked in wolfSSL_CIPHER_description */
16068-
add->data.cipher.in_stack = 1;
16069-
#endif
16070-
16071-
add->next = ret;
16072-
if (ret != NULL) {
16073-
add->num = ret->num + 1;
16074-
}
16075-
else {
16076-
add->num = 1;
16077-
}
16078-
ret = add;
16064+
if (wolfSSL_sk_insert(ssl->suitesStack, &cipher, 0) <= 0) {
16065+
WOLFSSL_MSG("Error inserting cipher onto stack");
16066+
wolfSSL_sk_CIPHER_free(ssl->suitesStack);
16067+
((WOLFSSL*)ssl)->suitesStack = NULL;
16068+
break;
1607916069
}
1608016070
}
16081-
((WOLFSSL*)ssl)->suitesStack = ret;
1608216071
}
1608316072
return ssl->suitesStack;
1608416073
}

src/ssl_sk.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,6 @@ WOLFSSL_STACK* wolfSSL_sk_get_node(WOLFSSL_STACK* stack, int idx)
113113
#endif /* !NO_CERT && OPENSSL_EXTRA*/
114114

115115
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
116-
/* Copy all fields from src into dst.
117-
*
118-
* Shallow copy only.
119-
*
120-
* @param [in, out] dst Node to copy into.
121-
* @param [in] src Node to copy.
122-
*/
123-
static void wolfssl_sk_node_copy(WOLFSSL_STACK* dst, WOLFSSL_STACK* src)
124-
{
125-
dst->data.generic = src->data.generic;
126-
dst->next = src->next;
127-
#ifdef OPENSSL_ALL
128-
dst->hash_fn = src->hash_fn;
129-
dst->hash = src->hash;
130-
#endif
131-
dst->type = src->type;
132-
dst->num = src->num;
133-
}
134116

135117
#ifndef NO_CERTS
136118
/* Get data pointer from node.
@@ -188,13 +170,12 @@ static void wolfssl_sk_node_set_data(WOLFSSL_STACK* node, WOLF_STACK_TYPE type,
188170
{
189171
switch (type) {
190172
case STACK_TYPE_CIPHER:
191-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
192173
node->data.cipher = *(WOLFSSL_CIPHER*)data;
193-
if (node->hash_fn != NULL) {
174+
#ifdef OPENSSL_ALL
175+
if (node->hash_fn != NULL)
194176
node->hash = node->hash_fn(&node->data.cipher);
195-
}
196-
break;
197177
#endif
178+
break;
198179
case STACK_TYPE_X509:
199180
case STACK_TYPE_GEN_NAME:
200181
case STACK_TYPE_BIO:
@@ -331,7 +312,7 @@ void* wolfSSL_sk_pop_node(WOLFSSL_STACK* stack, int idx)
331312
if (stack->next) {
332313
/* Keep the first node as it is the pointer passed in. */
333314
tmp = stack->next;
334-
wolfssl_sk_node_copy(stack, stack->next);
315+
XMEMCPY(stack, stack->next, sizeof(WOLFSSL_STACK));
335316
wolfSSL_sk_free_node(tmp);
336317
}
337318
}
@@ -374,7 +355,12 @@ void* wolfSSL_sk_pop_node(WOLFSSL_STACK* stack, int idx)
374355
*/
375356
WOLFSSL_STACK* wolfssl_sk_new_type(WOLF_STACK_TYPE type)
376357
{
377-
WOLFSSL_STACK* stack = wolfSSL_sk_new_node(NULL);
358+
return wolfssl_sk_new_type_ex(type, NULL);
359+
}
360+
361+
WOLFSSL_STACK* wolfssl_sk_new_type_ex(WOLF_STACK_TYPE type, void* heap)
362+
{
363+
WOLFSSL_STACK* stack = wolfSSL_sk_new_node(heap);
378364
if (stack != NULL) {
379365
stack->type = type;
380366
}
@@ -527,7 +513,7 @@ WOLFSSL_STACK* wolfSSL_sk_dup(WOLFSSL_STACK* stack)
527513
/* Update last node in linked list. */
528514
last = cur;
529515

530-
wolfssl_sk_node_copy(cur, stack);
516+
XMEMCPY(cur, stack, sizeof(WOLFSSL_STACK));
531517
/* We will allocate new memory for this */
532518
XMEMSET(&cur->data, 0, sizeof(cur->data));
533519
cur->next = NULL;
@@ -569,7 +555,7 @@ WOLFSSL_STACK* wolfSSL_shallow_sk_dup(WOLFSSL_STACK* stack)
569555
break;
570556
}
571557

572-
wolfssl_sk_node_copy(cur, stack);
558+
XMEMCPY(cur, stack, sizeof(WOLFSSL_STACK));
573559
cur->next = NULL;
574560

575561
*prev = cur;
@@ -737,7 +723,7 @@ int wolfSSL_sk_insert(WOLFSSL_STACK *stack, const void *data, int idx)
737723
if (idx == 0) {
738724
/* Special case where we need to change the values in the head
739725
* element to avoid changing the initial pointer. */
740-
wolfssl_sk_node_copy(node, stack);
726+
XMEMCPY(node, stack, sizeof(WOLFSSL_STACK));
741727
wolfssl_sk_node_set_data(stack, stack->type, data);
742728
stack->num++;
743729
stack->next = node;

src/x509.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10824,15 +10824,10 @@ WOLFSSL_ASN1_INTEGER* wolfSSL_X509_get_serialNumber(WOLFSSL_X509* x509)
1082410824
a->dataMax = WOLFSSL_ASN1_INTEGER_MAX;
1082510825
}
1082610826

10827-
#if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
10828-
XMEMCPY(&a->data[i], x509->serial, x509->serialSz);
10829-
a->length = x509->serialSz;
10830-
#else
10831-
a->data[i++] = ASN_INTEGER;
10832-
i += SetLength(x509->serialSz, a->data + i);
10833-
XMEMCPY(&a->data[i], x509->serial, x509->serialSz);
10834-
a->length = x509->serialSz + 2;
10835-
#endif
10827+
a->data[i++] = ASN_INTEGER;
10828+
i += SetLength(x509->serialSz, a->data + i);
10829+
XMEMCPY(&a->data[i], x509->serial, x509->serialSz);
10830+
a->length = x509->serialSz + 2;
1083610831

1083710832
x509->serialNumber = a;
1083810833

wolfcrypt/src/evp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5820,9 +5820,15 @@ void wolfSSL_EVP_init(void)
58205820
case WC_HASH_TYPE_BLAKE2S:
58215821
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE128)
58225822
case WC_HASH_TYPE_SHAKE128:
5823+
ret = wc_Shake128_Copy((wc_Shake*)&src->hash.digest.shake,
5824+
(wc_Sha3*)&des->hash.digest.shake);
5825+
break;
58235826
#endif
58245827
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE256)
58255828
case WC_HASH_TYPE_SHAKE256:
5829+
ret = wc_Shake256_Copy((wc_Shake*)&src->hash.digest.shake,
5830+
(wc_Sha3*)&des->hash.digest.shake);
5831+
break;
58265832
#endif
58275833
default:
58285834
ret = BAD_FUNC_ARG;
@@ -11353,6 +11359,16 @@ int wolfSSL_EVP_MD_block_size(const WOLFSSL_EVP_MD* type)
1135311359
return WC_SHA3_512_BLOCK_SIZE;
1135411360
} else
1135511361
#endif
11362+
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE128)
11363+
if (XSTRCMP(type, WC_SN_shake128) == 0) {
11364+
return WC_SHA3_128_BLOCK_SIZE;
11365+
} else
11366+
#endif
11367+
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE256)
11368+
if (XSTRCMP(type, WC_SN_shake256) == 0) {
11369+
return WC_SHA3_256_BLOCK_SIZE;
11370+
} else
11371+
#endif
1135611372
#endif /* WOLFSSL_SHA3 */
1135711373
#ifdef WOLFSSL_SM3
1135811374
if (XSTRCMP(type, WC_SN_sm3) == 0) {

wolfssl/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7292,6 +7292,8 @@ WOLFSSL_LOCAL void* wolfssl_sk_pop_type(WOLFSSL_STACK* sk,
72927292
WOLF_STACK_TYPE type);
72937293
WOLFSSL_LOCAL void* wolfSSL_sk_pop_node(WOLFSSL_STACK* sk, int idx);
72947294
WOLFSSL_LOCAL WOLFSSL_STACK* wolfssl_sk_new_type(WOLF_STACK_TYPE type);
7295+
WOLFSSL_LOCAL WOLFSSL_STACK* wolfssl_sk_new_type_ex(WOLF_STACK_TYPE type,
7296+
void* heap);
72957297

72967298
WOLFSSL_LOCAL int wolfssl_asn1_obj_set(WOLFSSL_ASN1_OBJECT* obj,
72977299
const byte* der, word32 len, int addHdr);

wolfssl/openssl/opensslv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#elif defined(OPENSSL_VERSION_NUMBER)
4141
/* unrecognized version, but continue. */
4242
#define WOLFSSL_OPENSSL_VERSION_NUMBER_UNRECOGNIZED
43+
#elif defined(WOLFSSL_QT) || defined(WOLFSSL_PYTHON)
44+
/* For Qt and Python 3.8.5 compatibility */
45+
#define OPENSSL_VERSION_NUMBER 0x10101000L
4346
#elif defined(HAVE_MOSQUITTO)
4447
#define OPENSSL_VERSION_NUMBER 0x10100000L
4548
#elif defined(WOLFSSL_APACHE_HTTPD) || defined(HAVE_LIBEST) || \
@@ -48,9 +51,6 @@
4851
defined(WOLFSSL_OPENSSH)
4952
/* For Apache httpd, Use 1.1.0 compatibility */
5053
#define OPENSSL_VERSION_NUMBER 0x10100003L
51-
#elif defined(WOLFSSL_QT) || defined(WOLFSSL_PYTHON)
52-
/* For Qt and Python 3.8.5 compatibility */
53-
#define OPENSSL_VERSION_NUMBER 0x10101000L
5454
#elif defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_FFMPEG)
5555
#define OPENSSL_VERSION_NUMBER 0x1010000fL
5656
#elif defined(OPENSSL_ALL) || defined(HAVE_LIGHTY) || \

0 commit comments

Comments
 (0)