-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
574 additions
and
2 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
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
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,64 @@ | ||
/* | ||
Copyright (c) 2019-2024 Roger Light <[email protected]> | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License 2.0 | ||
and Eclipse Distribution License v1.0 which accompany this distribution. | ||
The Eclipse Public License is available at | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
and the Eclipse Distribution License is available at | ||
http://www.eclipse.org/org/documents/edl-v10.php. | ||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
Contributors: | ||
Roger Light - initial implementation and documentation. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "mosquitto/mqtt_protocol.h" | ||
#include "packet_mosq.h" | ||
#include "property_mosq.h" | ||
#include "util_mosq.h" | ||
|
||
int mosquitto_ext_auth_continue(struct mosquitto *context, const char *auth_method, uint16_t auth_data_len, const void *auth_data, const mosquitto_property *input_props) | ||
{ | ||
struct mosquitto__packet *packet = NULL; | ||
int rc; | ||
uint32_t remaining_length; | ||
mosquitto_property *properties = NULL; | ||
|
||
rc = mosquitto_property_copy_all(&properties, input_props); | ||
if(rc) return rc; | ||
|
||
if(!context || context->protocol != mosq_p_mqtt5 || !auth_method) return MOSQ_ERR_PROTOCOL; | ||
|
||
remaining_length = 1; | ||
|
||
rc = mosquitto_property_add_string(&properties, MQTT_PROP_AUTHENTICATION_METHOD, auth_method); | ||
if(rc) goto error; | ||
|
||
if(auth_data != NULL && auth_data_len > 0){ | ||
rc = mosquitto_property_add_binary(&properties, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len); | ||
if(rc) goto error; | ||
} | ||
|
||
remaining_length += mosquitto_property_get_remaining_length(properties); | ||
|
||
rc = packet__check_oversize(context, remaining_length); | ||
if(rc) goto error; | ||
|
||
rc = packet__alloc(&packet, CMD_AUTH, remaining_length); | ||
if(rc) goto error; | ||
|
||
packet__write_byte(packet, MQTT_RC_CONTINUE_AUTHENTICATION); | ||
property__write_all(packet, properties, true); | ||
mosquitto_property_free_all(&properties); | ||
|
||
return packet__queue(context, packet); | ||
error: | ||
mosquitto_property_free_all(&properties); | ||
return rc; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from mosq_test_helper import * | ||
import mqtt5_rc | ||
|
||
def do_test(conn, data): | ||
props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_MAXIMUM_PACKET_SIZE, 1000) | ||
props += mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 20) | ||
connect_packet = mosq_test.gen_connect("01-extended-auth", proto_ver=5, properties=props) | ||
|
||
props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_METHOD, "test-method") | ||
props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_DATA, "test-request") # This is really a binary property | ||
auth_continue_b2c = mosq_test.gen_auth(reason_code=mqtt5_rc.MQTT_RC_CONTINUE_AUTHENTICATION, properties=props) | ||
|
||
props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_METHOD, "test-method") | ||
props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_DATA, "test-reply") # This is really a binary property | ||
auth_continue_c2b = mosq_test.gen_auth(reason_code=mqtt5_rc.MQTT_RC_CONTINUE_AUTHENTICATION, properties=props) | ||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
mosq_test.do_receive_send(conn, connect_packet, auth_continue_b2c, "auth_b2c") | ||
mosq_test.do_receive_send(conn, auth_continue_c2b, connack_packet, "connack") | ||
mosq_test.expect_packet(conn, "disconnect", disconnect_packet) | ||
|
||
|
||
mosq_test.client_test("c/01-extended-auth-continue.test", [], do_test, None) | ||
mosq_test.client_test("cpp/01-extended-auth-continue.test", [], do_test, None) |
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,24 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from mosq_test_helper import * | ||
import mqtt5_rc | ||
|
||
def do_test(conn, data): | ||
props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_MAXIMUM_PACKET_SIZE, 1000) | ||
props += mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 20) | ||
connect_packet = mosq_test.gen_connect("01-extended-auth", proto_ver=5, properties=props) | ||
|
||
props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_METHOD, "test-method") | ||
props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_AUTHENTICATION_DATA, "test-request") # This is really a binary property | ||
auth_continue_b2c = mosq_test.gen_auth(reason_code=mqtt5_rc.MQTT_RC_CONTINUE_AUTHENTICATION, properties=props) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
mosq_test.do_receive_send(conn, connect_packet, auth_continue_b2c, "auth_b2c") | ||
p = conn.recv(1) | ||
if len(p) == 1: | ||
exit(1) | ||
|
||
|
||
mosq_test.client_test("c/01-extended-auth-failure.test", [], do_test, None) | ||
mosq_test.client_test("cpp/01-extended-auth-failure.test", [], do_test, None) |
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
Oops, something went wrong.