Skip to content

Commit

Permalink
Merge pull request #20 from X-Ryl669/authentication
Browse files Browse the repository at this point in the history
This adds code for working authentication scheme in multiple scenario include testing code.
  • Loading branch information
X-Ryl669 authored Feb 16, 2024
2 parents 98005eb + 79a177a commit cb0f9cc
Showing 4 changed files with 456 additions and 237 deletions.
11 changes: 8 additions & 3 deletions lib/include/Network/Clients/MQTT.hpp
Original file line number Diff line number Diff line change
@@ -40,13 +40,18 @@ namespace Network
virtual uint32 maxPacketSize() const { return 2048U; }

#if MQTTUseAuth == 1
/** An authentication packet was received.
@param reasonCode Any of Success, ContinueAuthentication, ReAuthenticate
/** An authentication packet was received.
This is called either during connection and in the event loop in case the server started it
@param reasonCode Any of Success, ContinueAuthentication, ReAuthenticate or NotAuthorized, BadAuthenticationMethod
@param authMethod The authentication method
@param authData The authentication data
@param properties If any attached to the packet, you'll find the list here.
@return true If authentication was a success or false otherwise
@warning By default, no action is done upon authentication packets. It's up to you to implement those packets */
virtual void authReceived(const ReasonCodes reasonCode, const DynamicStringView & authMethod, const DynamicBinDataView & authData, const PropertiesView & properties) { }
virtual bool authReceived(const ReasonCodes reasonCode, const DynamicStringView & authMethod, const DynamicBinDataView & authData, const PropertiesView & properties)
{
return false;
}
#endif
virtual ~MessageReceived() {}
};
44 changes: 22 additions & 22 deletions lib/include/Network/Clients/MQTTConfig.hpp
Original file line number Diff line number Diff line change
@@ -12,21 +12,21 @@
#define MQTTUseAuth 0

/** Unsubscribe support. Set to 1 if you intend to unsubscribe dynamically and partially from the broker.
Typically unused for the majority of embedded case where the client is subscribing all topics at once and let
Typically unused for the majority of embedded case where the client is subscribing all topics at once and let
the broker unsubscribe by itself upon disconnection, this saves binary size if left disabled
Default: 0 */
#define MQTTUseUnsubscribe 0


/** Dump all MQTT communication.
This causes a large increase in binary size, induce an important latency cost, and lower the security by
displaying potentially private informations
Default: 0 */
/** Dump all MQTT communication.
This causes a large increase in binary size, induce an important latency cost, and lower the security by
displaying potentially private informations
Default: 0 */
#define MQTTDumpCommunication 0

/** Remove all validation from MQTT types.
This removes validation check for all MQTT types in order to save binary size.
This is only recommanded if you are sure about your broker implementation (don't set this to 1 if you
This removes validation check for all MQTT types in order to save binary size.
This is only recommanded if you are sure about your broker implementation (don't set this to 1 if you
intend to connect to unknown broker)
Default: 0 */
#define MQTTAvoidValidation 1
@@ -36,29 +36,29 @@
This adds a large impact to the binary size since the socket code is then duplicated (SSL and non SSL).
The SSL socket code provided is using mbedtls, but one could use BearSSL if size is really limited instead.
Please notice that this has no effect if MQTTOnlyBSDSocket is 0, since ClassPath embeds its own SSL socket
Please notice that this has no effect if MQTTOnlyBSDSocket is 0, since ClassPath embeds its own SSL socket
code (abstracted away at a higher level)
Default: 1 */
#ifndef MQTTUseTLS
#define MQTTUseTLS 0
#endif

/** Simple socket code.
If set to true, this disables the optimized network code from ClassPath and fallback to the minimal subset
If set to true, this disables the optimized network code from ClassPath and fallback to the minimal subset
of BSD socket API (typically send / recv / connect / select / close / setsockopt).
This also limits binary code size but prevent using SSL/TLS (unless you write a wrapper for it).
This is usually enabled for embedded system with very limited resources.
Please notice that this also change the meaning of timeout values. If it's not set, then timeouts represent
the maximum time that a method could spend (including all sub-functions calls). It's deterministic.
When it's set, then timeouts represent the maximum inactivity time before any method times out. So if you
have a very slow connection sending 1 byte per the timeout delay, in the former case, it'll timeout after
the first byte is received, while in the latter case, it might never timeout and take up to
Please notice that this also change the meaning of timeout values. If it's not set, then timeouts represent
the maximum time that a method could spend (including all sub-functions calls). It's deterministic.
When it's set, then timeouts represent the maximum inactivity time before any method times out. So if you
have a very slow connection sending 1 byte per the timeout delay, in the former case, it'll timeout after
the first byte is received, while in the latter case, it might never timeout and take up to
`timeout * packetLength` time to return.
Default: 0 */
#ifndef MQTTOnlyBSDSocket
#ifndef MQTTOnlyBSDSocket
#define MQTTOnlyBSDSocket 1
#endif

@@ -76,31 +76,31 @@
#define CONF_UNSUB "_"
#endif


#if MQTTDumpCommunication == 1
#define CONF_DUMP "Dump_"
#else
#define CONF_DUMP "_"
#endif

#if MQTTAvoidValidation == 1
#define CONF_VALID "Check_"
#else
#define CONF_VALID "_"
#endif

#if MQTTUseTLS == 1
#define CONF_TLS "TLS_"
#else
#define CONF_TLS "_"
#endif

#if MQTTOnlyBSDSocket == 1
#define CONF_SOCKET "BSD"
#else
#define CONF_SOCKET "CP"
#endif

#pragma message("Building eMQTT5 with flags: " CONF_AUTH CONF_UNSUB CONF_DUMP CONF_VALID CONF_TLS CONF_SOCKET)
#endif

Loading
Oops, something went wrong.

0 comments on commit cb0f9cc

Please sign in to comment.