Skip to content

Commit fb82496

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 8093875 commit fb82496

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
@@ -26305,6 +26305,11 @@ int SendData(WOLFSSL* ssl, const void* data, size_t sz)
2630526305
if (sent == (word32)sz) break;
2630626306

2630726307
buffSz = (word32)sz - sent;
26308+
{
26309+
int maxFrag = wolfSSL_GetMaxFragSize(ssl);
26310+
if (maxFrag > 0 && (int)buffSz > maxFrag)
26311+
buffSz = (word32)maxFrag;
26312+
}
2630826313
outputSz = wolfssl_local_GetRecordSize(ssl, (word32)buffSz, 1);
2630926314
#if defined(WOLFSSL_DTLS)
2631026315
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
@@ -10462,8 +10462,7 @@ const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher)
1046210462
return NULL;
1046310463
}
1046410464

10465-
#if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
10466-
!defined(WOLFSSL_QT)
10465+
#if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS)
1046710466
return GetCipherNameIana(cipher->cipherSuite0, cipher->cipherSuite);
1046810467
#else
1046910468
return wolfSSL_get_cipher_name_from_suite(cipher->cipherSuite0,
@@ -14033,12 +14032,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl)
1403314032
}
1403414033
if (i == (int)WOLFSSL_OBJECT_INFO_SZ) {
1403514034
WOLFSSL_MSG("NID not in table");
14036-
#ifdef WOLFSSL_QT
14037-
sName = NULL;
14038-
type = (word32)id;
14039-
#else
1404014035
return NULL;
14041-
#endif
1404214036
}
1404314037

1404414038
#ifdef HAVE_ECC
@@ -16027,9 +16021,8 @@ static WC_INLINE int sslCipherMinMaxCheck(const WOLFSSL *ssl, byte suite0,
1602716021
*/
1602816022
WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1602916023
{
16030-
WOLF_STACK_OF(WOLFSSL_CIPHER)* ret = NULL;
1603116024
const Suites* suites;
16032-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16025+
#if defined(OPENSSL_ALL)
1603316026
const CipherSuiteInfo* cipher_names = GetCipherNames();
1603416027
int cipherSz = GetCipherNamesSize();
1603516028
#endif
@@ -16045,15 +16038,20 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1604516038
/* check if stack needs populated */
1604616039
if (ssl->suitesStack == NULL) {
1604716040
int i;
16048-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16049-
int j;
16041+
16042+
((WOLFSSL*)ssl)->suitesStack =
16043+
wolfssl_sk_new_type_ex(STACK_TYPE_CIPHER, ssl->heap);
16044+
if (ssl->suitesStack == NULL)
16045+
return NULL;
1605016046

1605116047
/* higher priority of cipher suite will be on top of stack */
16052-
for (i = suites->suiteSz - 2; i >=0; i-=2) {
16048+
#if defined(OPENSSL_ALL)
16049+
for (i = suites->suiteSz - 2; i >=0; i-=2)
1605316050
#else
16054-
for (i = 0; i < suites->suiteSz; i+=2) {
16051+
for (i = 0; i < suites->suiteSz; i+=2)
1605516052
#endif
16056-
WOLFSSL_STACK* add;
16053+
{
16054+
struct WOLFSSL_CIPHER cipher;
1605716055

1605816056
/* A couple of suites are placeholders for special options,
1605916057
* skip those. */
@@ -16063,39 +16061,30 @@ WOLF_STACK_OF(WOLFSSL_CIPHER) *wolfSSL_get_ciphers_compat(const WOLFSSL *ssl)
1606316061
continue;
1606416062
}
1606516063

16066-
add = wolfSSL_sk_new_node(ssl->heap);
16067-
if (add != NULL) {
16068-
add->type = STACK_TYPE_CIPHER;
16069-
add->data.cipher.cipherSuite0 = suites->suites[i];
16070-
add->data.cipher.cipherSuite = suites->suites[i+1];
16071-
add->data.cipher.ssl = ssl;
16072-
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
16064+
XMEMSET(&cipher, 0, sizeof(cipher));
16065+
cipher.cipherSuite0 = suites->suites[i];
16066+
cipher.cipherSuite = suites->suites[i+1];
16067+
cipher.ssl = ssl;
16068+
#if defined(OPENSSL_ALL)
16069+
cipher.in_stack = 1;
16070+
{
16071+
int j;
1607316072
for (j = 0; j < cipherSz; j++) {
16074-
if (cipher_names[j].cipherSuite0 ==
16075-
add->data.cipher.cipherSuite0 &&
16076-
cipher_names[j].cipherSuite ==
16077-
add->data.cipher.cipherSuite) {
16078-
add->data.cipher.offset = (unsigned long)j;
16073+
if (cipher_names[j].cipherSuite0 == cipher.cipherSuite0 &&
16074+
cipher_names[j].cipherSuite == cipher.cipherSuite) {
16075+
cipher.offset = (unsigned long)j;
1607916076
break;
1608016077
}
1608116078
}
16079+
}
1608216080
#endif
16083-
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
16084-
/* in_stack is checked in wolfSSL_CIPHER_description */
16085-
add->data.cipher.in_stack = 1;
16086-
#endif
16087-
16088-
add->next = ret;
16089-
if (ret != NULL) {
16090-
add->num = ret->num + 1;
16091-
}
16092-
else {
16093-
add->num = 1;
16094-
}
16095-
ret = add;
16081+
if (wolfSSL_sk_insert(ssl->suitesStack, &cipher, 0) <= 0) {
16082+
WOLFSSL_MSG("Error inserting cipher onto stack");
16083+
wolfSSL_sk_CIPHER_free(ssl->suitesStack);
16084+
((WOLFSSL*)ssl)->suitesStack = NULL;
16085+
break;
1609616086
}
1609716087
}
16098-
((WOLFSSL*)ssl)->suitesStack = ret;
1609916088
}
1610016089
return ssl->suitesStack;
1610116090
}

0 commit comments

Comments
 (0)