Skip to content

Commit 171ee7a

Browse files
Slight tweaks and integration CI to support Bind9 (#1423)
1. This adds an integration CI dimension for Bind9 2. Resolved "cmocka unit tests" for Bind9 * Additional <openssl/asn1.h> import in <openssl/objects.h>: Bind depends on some ASN1 functions, but does not directly import the corresponding header. OpenSSL imports the asn1 header file in objects.h (which Bind is pulling these symbols from), so I've added the header file reference to objects.h. * SSL_get_error error anticipation fixing: There were several failures discovered to be related this, thanks to research done in Implement SSL_MODE_AUTO_RETRY #1333. The issue was pinned down the check implemented in google/boringssl@9a38e92. This check used to exist before the final return of SSL_get_error in OpenSSL. Upstream moved this earlier in the function with google/boringssl@fcf2583. However, much of the functions guards for i < 0 checks have been removed since OpenSSL 1.1.1, so the early logic no longer applies. This check has evolved into SSL_ERROR_ZERO_RETURN in our code. Moving the check further down helps us gain better parity with OpenSSL 1.1.1. Doing so passes the bind test failures for proxystream_test, tls_test, and doh_test. This also happens to help our integration with CPython, so I've reconfigured that patch. We actually already use SSL_AUTO_RETRY by default in AWS-LC. The recent change mentioned in the point above surrounding the flag (208327e) was just to make some of the errors consistent in CPython when the flag was used. I've reverted the special behavior surrounding it since it should no longer be needed. * Assertion for SSL_set_shutdown: The assertion was added in 63006a9, where it’s stated that we didn’t want SSL_set_shutdown messing up the state machine. This assertion is causing failures in tlsdns_test for Bind9, so it appears that we'll have to remove this to gain better OpenSSL parity. 3. Patch file needed for Bind seems to be slight bug in their build configuration. This was from a fairly recent commit. We can look to contribute this sometime soon.
1 parent edcb202 commit 171ee7a

File tree

12 files changed

+170
-146
lines changed

12 files changed

+170
-146
lines changed

.github/workflows/integrations.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,14 @@ jobs:
102102
- name: Build AWS-LC, build python, run tests
103103
run: |
104104
./tests/ci/integration/run_python_integration.sh
105+
bind9:
106+
runs-on: ubuntu-latest
107+
steps:
108+
- name: Install OS Dependencies
109+
run: |
110+
sudo apt-get update
111+
sudo apt-get -y --no-install-recommends install cmake gcc ninja-build golang make python3 python3-pytest autoconf pkg-config libcmocka-dev liburcu-dev libuv1-dev libnghttp2-dev libcap-dev libprotobuf-c-dev protobuf-c-compiler libfstrm-dev libjemalloc-dev
112+
- uses: actions/checkout@v3
113+
- name: Run bind9 build
114+
run: |
115+
./tests/ci/integration/run_bind9_integration.sh

include/openssl/objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
OpenSSL easier. */
1717

1818
#include "obj.h"
19+
#include "asn1.h"

include/openssl/ssl.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,6 @@ OPENSSL_EXPORT uint32_t SSL_get_options(const SSL *ssl);
836836
// |write|. In DTLS, it does nothing.
837837
#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
838838

839-
// SSL_MODE_AUTO_RETRY suppresses terminal errors on empty reads if the
840-
// underlying connection state is retryable, allowing for automatic retries.
841-
#define SSL_MODE_AUTO_RETRY 0x00000004L
842-
843839
// SSL_MODE_NO_AUTO_CHAIN disables automatically building a certificate chain
844840
// before sending certificates to the peer. This flag is set (and the feature
845841
// disabled) by default.
@@ -5281,6 +5277,7 @@ DEFINE_STACK_OF(SSL_COMP)
52815277

52825278
// The following flags do nothing and are included only to make it easier to
52835279
// compile code with BoringSSL.
5280+
#define SSL_MODE_AUTO_RETRY 0
52845281
#define SSL_MODE_RELEASE_BUFFERS 0
52855282
#define SSL_MODE_SEND_CLIENTHELLO_TIME 0
52865283
#define SSL_MODE_SEND_SERVERHELLO_TIME 0
@@ -5454,9 +5451,8 @@ OPENSSL_EXPORT int SSL_state(const SSL *ssl);
54545451
// receiving close_notify in |SSL_shutdown| by causing the implementation to
54555452
// believe the events already happened.
54565453
//
5457-
// It is an error to use |SSL_set_shutdown| to unset a bit that has already been
5458-
// set. Doing so will trigger an |assert| in debug builds and otherwise be
5459-
// ignored.
5454+
// Note: |SSL_set_shutdown| cannot be used to unset a bit that has already
5455+
// been set in AWS-LC. Doing so will be ignored.
54605456
//
54615457
// Use |SSL_CTX_set_quiet_shutdown| instead.
54625458
OPENSSL_EXPORT void SSL_set_shutdown(SSL *ssl, int mode);

ssl/ssl_lib.cc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,23 +1382,6 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
13821382
return SSL_ERROR_SSL;
13831383
}
13841384

1385-
if (ret_code == 0) {
1386-
if (ssl->s3->rwstate == SSL_ERROR_ZERO_RETURN) {
1387-
return SSL_ERROR_ZERO_RETURN;
1388-
}
1389-
// An EOF was observed which violates the protocol, and the underlying
1390-
// transport does not participate in the error queue. If
1391-
// |SSL_MODE_AUTO_RETRY| is unset, bubble up to the caller.
1392-
if ((ssl->ctx->mode & SSL_MODE_AUTO_RETRY) == 0) {
1393-
return SSL_ERROR_SYSCALL;
1394-
}
1395-
// If |SSL_MODE_AUTO_RETRY| is set, proceed if in a retryable state.
1396-
if (ssl->s3->rwstate != SSL_ERROR_WANT_READ
1397-
&& ssl->s3->rwstate != SSL_ERROR_WANT_WRITE) {
1398-
return SSL_ERROR_SYSCALL;
1399-
}
1400-
}
1401-
14021385
switch (ssl->s3->rwstate) {
14031386
case SSL_ERROR_PENDING_SESSION:
14041387
case SSL_ERROR_PENDING_CERTIFICATE:
@@ -1411,6 +1394,7 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
14111394
case SSL_ERROR_WANT_CERTIFICATE_VERIFY:
14121395
case SSL_ERROR_WANT_RENEGOTIATE:
14131396
case SSL_ERROR_HANDSHAKE_HINTS_READY:
1397+
case SSL_ERROR_ZERO_RETURN:
14141398
return ssl->s3->rwstate;
14151399

14161400
case SSL_ERROR_WANT_READ: {
@@ -2611,10 +2595,6 @@ void SSL_set_quiet_shutdown(SSL *ssl, int mode) {
26112595
int SSL_get_quiet_shutdown(const SSL *ssl) { return ssl->quiet_shutdown; }
26122596

26132597
void SSL_set_shutdown(SSL *ssl, int mode) {
2614-
// It is an error to clear any bits that have already been set. (We can't try
2615-
// to get a second close_notify or send two.)
2616-
assert((SSL_get_shutdown(ssl) & mode) == SSL_get_shutdown(ssl));
2617-
26182598
if (mode & SSL_RECEIVED_SHUTDOWN &&
26192599
ssl->s3->read_shutdown == ssl_shutdown_none) {
26202600
ssl->s3->read_shutdown = ssl_shutdown_close_notify;

ssl/ssl_test.cc

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10458,7 +10458,9 @@ TEST(SSLTest, ErrorSyscallAfterCloseNotify) {
1045810458
write_failed = false;
1045910459
}
1046010460

10461-
static void TestIntermittentEmptyRead(bool auto_retry) {
10461+
// Test that failures are supressed on (potentially)
10462+
// transient empty reads.
10463+
TEST(SSLTest, IntermittentEmptyRead) {
1046210464
bssl::UniquePtr<SSL_CTX> client_ctx(SSL_CTX_new(TLS_method()));
1046310465
bssl::UniquePtr<SSL_CTX> server_ctx =
1046410466
CreateContextWithTestCertificate(TLS_method());
@@ -10489,15 +10491,6 @@ static void TestIntermittentEmptyRead(bool auto_retry) {
1048910491
ASSERT_TRUE(BIO_up_ref(client_rbio.get()));
1049010492
SSL_set0_rbio(client.get(), rbio_empty.release());
1049110493

10492-
if (auto_retry) {
10493-
// Set flag under test
10494-
ASSERT_TRUE(SSL_CTX_set_mode(client_ctx.get(), SSL_MODE_AUTO_RETRY));
10495-
ASSERT_TRUE(SSL_CTX_get_mode(client_ctx.get()) & SSL_MODE_AUTO_RETRY);
10496-
} else {
10497-
// |SSL_MODE_AUTO_RETRY| is off by default
10498-
ASSERT_FALSE(SSL_CTX_get_mode(client_ctx.get()) & SSL_MODE_AUTO_RETRY);
10499-
}
10500-
1050110494
// Server writes some data to the client
1050210495
const uint8_t write_data[] = {1, 2, 3};
1050310496
int ret = SSL_write(server.get(), write_data, (int) sizeof(write_data));
@@ -10507,13 +10500,9 @@ static void TestIntermittentEmptyRead(bool auto_retry) {
1050710500
uint8_t read_data[] = {0, 0, 0};
1050810501
ret = SSL_read(client.get(), read_data, sizeof(read_data));
1050910502
EXPECT_EQ(ret, 0);
10510-
if (auto_retry) {
10511-
// On empty read, client should still want a read so caller will retry
10512-
EXPECT_EQ(SSL_get_error(client.get(), ret), SSL_ERROR_WANT_READ);
10513-
} else {
10514-
// On empty read, client should error out signaling EOF
10515-
EXPECT_EQ(SSL_get_error(client.get(), ret), SSL_ERROR_SYSCALL);
10516-
}
10503+
// On empty read, client should still want a read so caller will retry.
10504+
// This would have returned |SSL_ERROR_SYSCALL| in OpenSSL 1.0.2.
10505+
EXPECT_EQ(SSL_get_error(client.get(), ret), SSL_ERROR_WANT_READ);
1051710506

1051810507
// Reset client rbio, read should succeed
1051910508
SSL_set0_rbio(client.get(), client_rbio.release());
@@ -10528,13 +10517,6 @@ static void TestIntermittentEmptyRead(bool auto_retry) {
1052810517
EXPECT_EQ(SSL_get_error(client.get(), ret), SSL_ERROR_WANT_READ);
1052910518
}
1053010519

10531-
// Test that |SSL_MODE_AUTO_RETRY| suppresses failure on (potentially)
10532-
// transient empty reads.
10533-
TEST(SSLTest, IntermittentEmptyRead) {
10534-
TestIntermittentEmptyRead(false);
10535-
TestIntermittentEmptyRead(true);
10536-
}
10537-
1053810520
// Test that |SSL_shutdown|, when quiet shutdown is enabled, simulates receiving
1053910521
// a close_notify, down to |SSL_read| reporting |SSL_ERROR_ZERO_RETURN|.
1054010522
TEST(SSLTest, QuietShutdown) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/tests/isc/Makefile.am b/tests/isc/Makefile.am
2+
index 5cdd915..6ee1935 100644
3+
--- a/tests/isc/Makefile.am
4+
+++ b/tests/isc/Makefile.am
5+
@@ -115,10 +115,12 @@ proxyheader_test_SOURCES = \
6+
proxyheader_test_data.h
7+
8+
proxystream_test_CPPFLAGS = \
9+
- $(AM_CPPFLAGS)
10+
+ $(AM_CPPFLAGS) \
11+
+ $(OPENSSL_CFLAGS)
12+
13+
proxystream_test_LDADD = \
14+
- $(LDADD)
15+
+ $(LDADD) \
16+
+ $(OPENSSL_LIBS)
17+
18+
proxystream_test_SOURCES = \
19+
proxystream_test.c \

tests/ci/integration/python_patch/3.10/aws-lc-cpython.patch

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
2-
index 253a6c119c..2d0d10642d 100644
2+
index 253a6c1..2d0d106 100644
33
--- a/Lib/test/test_asyncio/test_events.py
44
+++ b/Lib/test/test_asyncio/test_events.py
55
@@ -1106,12 +1106,12 @@ def test_create_server_ssl_match_failed(self):
@@ -20,7 +20,7 @@ index 253a6c119c..2d0d10642d 100644
2020

2121
# close connection
2222
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
23-
index 77152cf645..be3d11b993 100644
23+
index 77152cf..be3d11b 100644
2424
--- a/Lib/test/test_httplib.py
2525
+++ b/Lib/test/test_httplib.py
2626
@@ -1863,7 +1863,7 @@ def test_host_port(self):
@@ -33,7 +33,7 @@ index 77152cf645..be3d11b993 100644
3333
# just check status of PHA flag
3434
h = client.HTTPSConnection('localhost', 443)
3535
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
36-
index b5c78a5d49..41235c17fc 100644
36+
index b5c78a5..41235c1 100644
3737
--- a/Lib/test/test_imaplib.py
3838
+++ b/Lib/test/test_imaplib.py
3939
@@ -555,9 +555,10 @@ def test_ssl_raises(self):
@@ -66,7 +66,7 @@ index b5c78a5d49..41235c17fc 100644
6666
client = self.imap_class(*server.server_address,
6767
ssl_context=ssl_context)
6868
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
69-
index a1a581a907..c69e71159a 100644
69+
index a1a581a..c69e711 100644
7070
--- a/Lib/test/test_ssl.py
7171
+++ b/Lib/test/test_ssl.py
7272
@@ -44,6 +44,7 @@
@@ -319,8 +319,8 @@ index a1a581a907..c69e71159a 100644
319319
protocols = [
320320
@@ -4752,6 +4776,31 @@ def test_internal_chain_server(self):
321321
self.assertEqual(res, b'\x02\n')
322-
323-
322+
323+
324324
+@unittest.skipUnless(Py_OPENSSL_IS_AWSLC, "Only test this against AWS-LC")
325325
+class TestPostHandshakeAuthAwsLc(unittest.TestCase):
326326
+ def test_pha(self):
@@ -350,7 +350,7 @@ index a1a581a907..c69e71159a 100644
350350
requires_keylog = unittest.skipUnless(
351351
HAS_KEYLOG, 'test requires OpenSSL 1.1.1 with keylog callback')
352352
diff --git a/Modules/Setup b/Modules/Setup
353-
index 87c6a152f8..3a9bc54bab 100644
353+
index 87c6a15..f67d7ec 100644
354354
--- a/Modules/Setup
355355
+++ b/Modules/Setup
356356
@@ -208,8 +208,8 @@ _symtable symtablemodule.c
@@ -386,7 +386,7 @@ index 87c6a152f8..3a9bc54bab 100644
386386
# The crypt module is now disabled by default because it breaks builds
387387
# on many systems (where -lcrypt is needed), e.g. Linux (I believe).
388388
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
389-
index 35addf49e9..77a12c6af5 100644
389+
index 35addf4..77a12c6 100644
390390
--- a/Modules/_hashopenssl.c
391391
+++ b/Modules/_hashopenssl.c
392392
@@ -131,8 +131,12 @@ static const py_hashentry_t py_hashes[] = {
@@ -403,7 +403,7 @@ index 35addf49e9..77a12c6af5 100644
403403
};
404404

405405
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
406-
index 7a28f2d37f..07740af98b 100644
406+
index 7a28f2d..b0d2ea1 100644
407407
--- a/Modules/_ssl.c
408408
+++ b/Modules/_ssl.c
409409
@@ -181,6 +181,12 @@ extern const SSL_METHOD *TLSv1_2_method(void);
@@ -463,15 +463,6 @@ index 7a28f2d37f..07740af98b 100644
463463
int err = SSL_verify_client_post_handshake(self->ssl);
464464
if (err == 0)
465465
return _setSSLError(get_state_sock(self), NULL, 0, __FILE__, __LINE__);
466-
@@ -3186,7 +3198,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
467-
468-
/* Set SSL_MODE_RELEASE_BUFFERS. This potentially greatly reduces memory
469-
usage for no cost at all. */
470-
- SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS);
471-
+ SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_AUTO_RETRY);
472-
473-
#define SID_CTX "Python"
474-
SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX,
475466
@@ -3199,7 +3211,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
476467
X509_VERIFY_PARAM_set_flags(params, X509_V_FLAG_TRUSTED_FIRST);
477468
X509_VERIFY_PARAM_set_hostflags(params, self->hostflags);

tests/ci/integration/python_patch/3.11/aws-lc-cpython.patch

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
2-
index d7871d3e53..fb65ee3b8b 100644
2+
index d7871d3..fb65ee3 100644
33
--- a/Lib/test/test_asyncio/test_events.py
44
+++ b/Lib/test/test_asyncio/test_events.py
55
@@ -1103,12 +1103,12 @@ def test_create_server_ssl_match_failed(self):
@@ -20,7 +20,7 @@ index d7871d3e53..fb65ee3b8b 100644
2020

2121
# close connection
2222
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
23-
index 015a3d1e87..ec565ad181 100644
23+
index 015a3d1..ec565ad 100644
2424
--- a/Lib/test/test_httplib.py
2525
+++ b/Lib/test/test_httplib.py
2626
@@ -2040,7 +2040,7 @@ def test_host_port(self):
@@ -33,7 +33,7 @@ index 015a3d1e87..ec565ad181 100644
3333
# just check status of PHA flag
3434
h = client.HTTPSConnection('localhost', 443)
3535
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
36-
index bd0fc9c2da..3ab70f5c1f 100644
36+
index bd0fc9c..3ab70f5 100644
3737
--- a/Lib/test/test_imaplib.py
3838
+++ b/Lib/test/test_imaplib.py
3939
@@ -561,9 +561,10 @@ def test_ssl_raises(self):
@@ -66,7 +66,7 @@ index bd0fc9c2da..3ab70f5c1f 100644
6666
client = self.imap_class(*server.server_address,
6767
ssl_context=ssl_context)
6868
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
69-
index 1f881038c3..36fa1e32e8 100644
69+
index 1f88103..36fa1e3 100644
7070
--- a/Lib/test/test_ssl.py
7171
+++ b/Lib/test/test_ssl.py
7272
@@ -44,6 +44,7 @@
@@ -359,7 +359,7 @@ index 1f881038c3..36fa1e32e8 100644
359359
requires_keylog = unittest.skipUnless(
360360
HAS_KEYLOG, 'test requires OpenSSL 1.1.1 with keylog callback')
361361
diff --git a/Modules/Setup b/Modules/Setup
362-
index d3647ecb99..a0ff874b6d 100644
362+
index d3647ec..a0ff874 100644
363363
--- a/Modules/Setup
364364
+++ b/Modules/Setup
365365
@@ -216,11 +216,11 @@ PYTHONPATH=$(COREPYTHONPATH)
@@ -380,7 +380,7 @@ index d3647ecb99..a0ff874b6d 100644
380380
# The _tkinter module.
381381
#
382382
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
383-
index 57d64bd80c..1132fa520c 100644
383+
index 57d64bd..1132fa5 100644
384384
--- a/Modules/_hashopenssl.c
385385
+++ b/Modules/_hashopenssl.c
386386
@@ -131,8 +131,12 @@ static const py_hashentry_t py_hashes[] = {
@@ -397,7 +397,7 @@ index 57d64bd80c..1132fa520c 100644
397397
};
398398

399399
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
400-
index 67ce6e97af..1132d82dd9 100644
400+
index 67ce6e9..6f38611 100644
401401
--- a/Modules/_ssl.c
402402
+++ b/Modules/_ssl.c
403403
@@ -179,6 +179,12 @@ extern const SSL_METHOD *TLSv1_2_method(void);
@@ -457,15 +457,6 @@ index 67ce6e97af..1132d82dd9 100644
457457
int err = SSL_verify_client_post_handshake(self->ssl);
458458
if (err == 0)
459459
return _setSSLError(get_state_sock(self), NULL, 0, __FILE__, __LINE__);
460-
@@ -3191,7 +3203,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
461-
462-
/* Set SSL_MODE_RELEASE_BUFFERS. This potentially greatly reduces memory
463-
usage for no cost at all. */
464-
- SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS);
465-
+ SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_AUTO_RETRY);
466-
467-
#define SID_CTX "Python"
468-
SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX,
469460
@@ -3204,7 +3216,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
470461
X509_VERIFY_PARAM_set_flags(params, X509_V_FLAG_TRUSTED_FIRST);
471462
X509_VERIFY_PARAM_set_hostflags(params, self->hostflags);

0 commit comments

Comments
 (0)