-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #790 from akx/alpn-2
Add ALPN support
- Loading branch information
Showing
10 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
import paho.mqtt.client as mqtt | ||
|
||
from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt | ||
|
||
|
||
def on_connect(mqttc, obj, flags, rc): | ||
assert rc == 0, f"Connect failed ({rc})" | ||
mqttc.disconnect() | ||
|
||
|
||
mqttc = mqtt.Client("08-ssl-connect-alpn", clean_session=True) | ||
mqttc.tls_set( | ||
os.path.join(os.environ["PAHO_SSL_PATH"], "all-ca.crt"), | ||
os.path.join(os.environ["PAHO_SSL_PATH"], "client.crt"), | ||
os.path.join(os.environ["PAHO_SSL_PATH"], "client.key"), | ||
alpn_protocols=["paho-test-protocol"], | ||
) | ||
mqttc.on_connect = on_connect | ||
|
||
mqttc.connect("localhost", get_test_server_port()) | ||
loop_until_keyboard_interrupt(mqttc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Test whether a client produces a correct connect and subsequent disconnect when using SSL. | ||
# Client must provide a certificate. | ||
# | ||
# The client should connect with keepalive=60, clean session set, | ||
# and client id 08-ssl-connect-alpn | ||
# It should use the CA certificate ssl/all-ca.crt for verifying the server. | ||
# The test will send a CONNACK message to the client with rc=0. Upon receiving | ||
# the CONNACK and verifying that rc=0, the client should send a DISCONNECT | ||
# message. If rc!=0, the client should exit with an error. | ||
# | ||
# Additionally, the secure socket must have been negotiated with the "paho-test-protocol" | ||
|
||
|
||
from tests import paho_test | ||
from tests.paho_test import ssl | ||
|
||
|
||
def test_08_ssl_connect_alpn(alpn_ssl_server_socket, start_client): | ||
connect_packet = paho_test.gen_connect("08-ssl-connect-alpn", keepalive=60) | ||
connack_packet = paho_test.gen_connack(rc=0) | ||
disconnect_packet = paho_test.gen_disconnect() | ||
|
||
start_client("08-ssl-connect-alpn.py") | ||
|
||
(conn, address) = alpn_ssl_server_socket.accept() | ||
conn.settimeout(10) | ||
|
||
paho_test.expect_packet(conn, "connect", connect_packet) | ||
conn.send(connack_packet) | ||
|
||
paho_test.expect_packet(conn, "disconnect", disconnect_packet) | ||
|
||
if ssl.HAS_ALPN: | ||
negotiated_protocol = conn.selected_alpn_protocol() | ||
if negotiated_protocol != "paho-test-protocol": | ||
raise Exception(f"Unexpected protocol '{negotiated_protocol}'") | ||
|
||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters