Skip to content

Commit 6009b6f

Browse files
committed
Add Python CI workflow and Blake2 EVP support
- Add a GitHub Actions workflow to automate testing of Python integration - Implement Blake2b and Blake2s hash functions into the EVP API. - Improve OpenSSL compatibility by standardizing ASN.1 encoding for serial numbers and registered IDs, streamlining cipher stack management, and optimizing stack node copying. - Enforce maximum fragment size during data transmission to ensure proper TLS/DTLS record fragmentation.
1 parent b5b7dc8 commit 6009b6f

11 files changed

Lines changed: 349 additions & 111 deletions

File tree

.github/workflows/python.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Python Tests
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
build_wolfssl:
17+
name: Build wolfSSL
18+
if: github.repository_owner == 'wolfssl'
19+
runs-on: ubuntu-24.04
20+
timeout-minutes: 10
21+
steps:
22+
- name: Build wolfSSL
23+
uses: wolfSSL/actions-build-autotools-project@v1
24+
with:
25+
path: wolfssl
26+
configure: >-
27+
--enable-all --enable-tlsv10
28+
'CPPFLAGS=-DHAVE_SECRET_CALLBACK -DWOLFSSL_PYTHON'
29+
check: false
30+
install: true
31+
32+
- name: tar build-dir
33+
run: tar -zcf build-dir.tgz build-dir
34+
35+
- name: Upload built lib
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: wolf-install-python
39+
path: build-dir.tgz
40+
retention-days: 5
41+
42+
python_check:
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
include:
47+
- python_ver: 3.12.11
48+
tests: >-
49+
test_ssl
50+
test.test_asyncio.test_ssl
51+
test.test_asyncio.test_sslproto
52+
test_hashlib
53+
test_hmac
54+
test_secrets
55+
test_ftplib
56+
test_imaplib
57+
test_poplib
58+
test_smtplib
59+
test_httplib
60+
test_urllib2_localnet
61+
test_xmlrpc
62+
test_docxmlrpc
63+
- python_ver: 3.13.4
64+
tests: >-
65+
test_ssl
66+
test.test_asyncio.test_ssl
67+
test.test_asyncio.test_sslproto
68+
test_hashlib
69+
test_hmac
70+
test_secrets
71+
test_ftplib
72+
test_imaplib
73+
test_poplib
74+
test_smtplib
75+
test_httplib
76+
test_urllib2_localnet
77+
test_xmlrpc
78+
test_docxmlrpc
79+
- python_ver: 3.13.7
80+
tests: >-
81+
test_ssl
82+
test.test_asyncio.test_ssl
83+
test.test_asyncio.test_sslproto
84+
test_hashlib
85+
test_hmac
86+
test_secrets
87+
test_ftplib
88+
test_imaplib
89+
test_poplib
90+
test_smtplib
91+
test_httplib
92+
test_urllib2_localnet
93+
test_xmlrpc
94+
test_docxmlrpc
95+
name: Python ${{ matrix.python_ver }}
96+
if: github.repository_owner == 'wolfssl'
97+
runs-on: ubuntu-24.04
98+
timeout-minutes: 60
99+
needs: build_wolfssl
100+
steps:
101+
- name: Install dependencies
102+
run: |
103+
sudo apt-get update
104+
sudo apt-get install -y \
105+
build-essential autoconf automake autoconf-archive pkgconf \
106+
libffi-dev libbz2-dev libreadline-dev libsqlite3-dev \
107+
zlib1g-dev libncursesw5-dev libgdbm-dev libnss3-dev \
108+
liblzma-dev uuid-dev pkg-config
109+
110+
- name: Download wolfSSL
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: wolf-install-python
114+
115+
- name: Untar wolfSSL build
116+
run: tar -xf build-dir.tgz
117+
118+
- name: Checkout OSP
119+
uses: actions/checkout@v4
120+
with:
121+
repository: wolfssl/osp
122+
path: osp
123+
124+
- name: Checkout CPython
125+
uses: actions/checkout@v4
126+
with:
127+
repository: python/cpython
128+
ref: v${{ matrix.python_ver }}
129+
path: cpython
130+
131+
- name: Apply wolfSSL patch
132+
working-directory: cpython
133+
run: patch -p1 < $GITHUB_WORKSPACE/osp/Python/wolfssl-python-${{ matrix.python_ver }}.patch
134+
135+
- name: Build CPython and run SSL and crypto tests
136+
working-directory: cpython
137+
run: |
138+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
139+
rm aclocal.m4
140+
autoreconf -if
141+
./configure --with-wolfssl=$GITHUB_WORKSPACE/build-dir
142+
make -j test TESTOPTS="-v \
143+
test_ssl \
144+
test.test_asyncio.test_ssl \
145+
test.test_asyncio.test_sslproto \
146+
test_hashlib \
147+
test_hmac \
148+
test_secrets \
149+
test_ftplib \
150+
test_imaplib \
151+
test_poplib \
152+
test_smtplib \
153+
test_httplib \
154+
test_urllib2_localnet \
155+
test_xmlrpc \
156+
test_docxmlrpc"

src/internal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26285,6 +26285,11 @@ int SendData(WOLFSSL* ssl, const void* data, size_t sz)
2628526285
if (sent == (word32)sz) break;
2628626286

2628726287
buffSz = (word32)sz - sent;
26288+
{
26289+
int maxFrag = wolfSSL_GetMaxFragSize(ssl);
26290+
if (maxFrag > 0 && (int)buffSz > maxFrag)
26291+
buffSz = (word32)maxFrag;
26292+
}
2628826293
outputSz = wolfssl_local_GetRecordSize(ssl, (word32)buffSz, 1);
2628926294
#if defined(WOLFSSL_DTLS)
2629026295
if (ssl->options.dtls) {

src/ocsp.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,18 +1995,11 @@ int wolfSSL_OCSP_id_get0_info(WOLFSSL_ASN1_STRING **name,
19951995
ser->dataMax = WOLFSSL_ASN1_INTEGER_MAX;
19961996
}
19971997

1998-
#if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
1999-
/* Serial number starts at 0 index of ser->data */
2000-
XMEMCPY(&ser->data[i], cid->status->serial,
2001-
(size_t)cid->status->serialSz);
2002-
ser->length = cid->status->serialSz;
2003-
#else
2004-
ser->data[i++] = ASN_INTEGER;
2005-
i += SetLength(cid->status->serialSz, ser->data + i);
2006-
XMEMCPY(&ser->data[i], cid->status->serial,
2007-
(size_t)cid->status->serialSz);
2008-
ser->length = i + cid->status->serialSz;
2009-
#endif
1998+
ser->data[i++] = ASN_INTEGER;
1999+
i += SetLength(cid->status->serialSz, ser->data + i);
2000+
XMEMCPY(&ser->data[i], cid->status->serial,
2001+
(size_t)cid->status->serialSz);
2002+
ser->length = i + cid->status->serialSz;
20102003

20112004
cid->status->serialInt = ser;
20122005
*serial = ser;

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,
@@ -14021,12 +14020,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl)
1402114020
}
1402214021
if (i == (int)WOLFSSL_OBJECT_INFO_SZ) {
1402314022
WOLFSSL_MSG("NID not in table");
14024-
#ifdef WOLFSSL_QT
14025-
sName = NULL;
14026-
type = (word32)id;
14027-
#else
1402814023
return NULL;
14029-
#endif
1403014024
}
1403114025

1403214026
#ifdef HAVE_ECC
@@ -16016,9 +16010,8 @@ static WC_INLINE int sslCipherMinMaxCheck(const WOLFSSL *ssl, byte suite0,
1601616010
*/
1601716011
WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1601816012
{
16019-
WOLF_STACK_OF(WOLFSSL_CIPHER)* ret = NULL;
1602016013
const Suites* suites;
16021-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16014+
#if defined(OPENSSL_ALL)
1602216015
const CipherSuiteInfo* cipher_names = GetCipherNames();
1602316016
int cipherSz = GetCipherNamesSize();
1602416017
#endif
@@ -16034,15 +16027,20 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1603416027
/* check if stack needs populated */
1603516028
if (ssl->suitesStack == NULL) {
1603616029
int i;
16037-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16038-
int j;
16030+
16031+
((WOLFSSL*)ssl)->suitesStack =
16032+
wolfssl_sk_new_type_ex(STACK_TYPE_CIPHER, ssl->heap);
16033+
if (ssl->suitesStack == NULL)
16034+
return NULL;
1603916035

1604016036
/* higher priority of cipher suite will be on top of stack */
16041-
for (i = suites->suiteSz - 2; i >=0; i-=2) {
16037+
#if defined(OPENSSL_ALL)
16038+
for (i = suites->suiteSz - 2; i >=0; i-=2)
1604216039
#else
16043-
for (i = 0; i < suites->suiteSz; i+=2) {
16040+
for (i = 0; i < suites->suiteSz; i+=2)
1604416041
#endif
16045-
WOLFSSL_STACK* add;
16042+
{
16043+
struct WOLFSSL_CIPHER cipher;
1604616044

1604716045
/* A couple of suites are placeholders for special options,
1604816046
* skip those. */
@@ -16052,39 +16050,30 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1605216050
continue;
1605316051
}
1605416052

16055-
add = wolfSSL_sk_new_node(ssl->heap);
16056-
if (add != NULL) {
16057-
add->type = STACK_TYPE_CIPHER;
16058-
add->data.cipher.cipherSuite0 = suites->suites[i];
16059-
add->data.cipher.cipherSuite = suites->suites[i+1];
16060-
add->data.cipher.ssl = ssl;
16061-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16053+
XMEMSET(&cipher, 0, sizeof(cipher));
16054+
cipher.cipherSuite0 = suites->suites[i];
16055+
cipher.cipherSuite = suites->suites[i+1];
16056+
cipher.ssl = ssl;
16057+
#if defined(OPENSSL_ALL)
16058+
cipher.in_stack = 1;
16059+
{
16060+
int j;
1606216061
for (j = 0; j < cipherSz; j++) {
16063-
if (cipher_names[j].cipherSuite0 ==
16064-
add->data.cipher.cipherSuite0 &&
16065-
cipher_names[j].cipherSuite ==
16066-
add->data.cipher.cipherSuite) {
16067-
add->data.cipher.offset = (unsigned long)j;
16062+
if (cipher_names[j].cipherSuite0 == cipher.cipherSuite0 &&
16063+
cipher_names[j].cipherSuite == cipher.cipherSuite) {
16064+
cipher.offset = (unsigned long)j;
1606816065
break;
1606916066
}
1607016067
}
16068+
}
1607116069
#endif
16072-
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
16073-
/* in_stack is checked in wolfSSL_CIPHER_description */
16074-
add->data.cipher.in_stack = 1;
16075-
#endif
16076-
16077-
add->next = ret;
16078-
if (ret != NULL) {
16079-
add->num = ret->num + 1;
16080-
}
16081-
else {
16082-
add->num = 1;
16083-
}
16084-
ret = add;
16070+
if (wolfSSL_sk_insert(ssl->suitesStack, &cipher, 0) <= 0) {
16071+
WOLFSSL_MSG("Error inserting cipher onto stack");
16072+
wolfSSL_sk_CIPHER_free(ssl->suitesStack);
16073+
((WOLFSSL*)ssl)->suitesStack = NULL;
16074+
break;
1608516075
}
1608616076
}
16087-
((WOLFSSL*)ssl)->suitesStack = ret;
1608816077
}
1608916078
return ssl->suitesStack;
1609016079
}

0 commit comments

Comments
 (0)